From e6265da98033c6ebf4e939737b8de2cd4d38cbd6 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 16 Apr 2019 10:11:27 +0200 Subject: [PATCH 1/2] Implement Default for MatrixMN. --- src/base/array_storage.rs | 13 +++++++++++++ src/base/matrix.rs | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index bebb8740..450127ba 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -48,6 +48,19 @@ where /// Renamed to [ArrayStorage]. pub type MatrixArray = ArrayStorage; +impl Default for ArrayStorage +where + R: DimName, + C: DimName, + R::Value: Mul, + Prod: ArrayLength, + N: Default, +{ + fn default() -> Self { + ArrayStorage { data: Default::default() } + } +} + impl Hash for ArrayStorage where N: Hash, diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 7119a8ad..1aa171e4 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -90,6 +90,21 @@ impl fmt::Debug for Matrix } } +impl Default for Matrix +where + N: Scalar, + R: Dim, + C: Dim, + S: Default, +{ + fn default() -> Self { + Matrix { + data: Default::default(), + _phantoms: PhantomData, + } + } +} + #[cfg(feature = "serde-serialize")] impl Serialize for Matrix where From 85c931520abc0fd0d416327062b35fcb5ba56320 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 16 Apr 2019 10:12:09 +0200 Subject: [PATCH 2/2] Implement Default for Quaternion and UnitQuaternion. --- src/geometry/quaternion.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 40c085f2..5b126983 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -30,6 +30,14 @@ pub struct Quaternion { pub coords: Vector4, } +impl Default for Quaternion { + fn default() -> Self { + Quaternion { + coords: Vector4::zeros() + } + } +} + #[cfg(feature = "abomonation-serialize")] impl Abomonation for Quaternion where Vector4: Abomonation @@ -1422,6 +1430,12 @@ impl UnitQuaternion { } } +impl Default for UnitQuaternion { + fn default() -> Self { + Self::identity() + } +} + impl fmt::Display for UnitQuaternion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(axis) = self.axis() {