diff --git a/src/angle.rs b/src/angle.rs index 0858817..71c7bec 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -218,7 +218,7 @@ macro_rules! impl_angle { } } - impl fmt::Debug for $Angle { + impl fmt::Debug for $Angle { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, $fmt, self.s) } diff --git a/src/matrix.rs b/src/matrix.rs index d205a63..6287ebe 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1111,30 +1111,24 @@ impl From> for Quaternion { } } -impl fmt::Debug for Matrix2 { +impl fmt::Debug for Matrix2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[[{:?}, {:?}], [{:?}, {:?}]]", - self[0][0], self[0][1], - self[1][0], self[1][1]) + try!(write!(f, "Matrix2 ")); + <[[S; 2]; 2] as fmt::Debug>::fmt(self.as_ref(), f) } } -impl fmt::Debug for Matrix3 { +impl fmt::Debug for Matrix3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[[{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}], [{:?}, {:?}, {:?}]]", - self[0][0], self[0][1], self[0][2], - self[1][0], self[1][1], self[1][2], - self[2][0], self[2][1], self[2][2]) + try!(write!(f, "Matrix3 ")); + <[[S; 3]; 3] as fmt::Debug>::fmt(self.as_ref(), f) } } -impl fmt::Debug for Matrix4 { +impl fmt::Debug for Matrix4 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[[{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}], [{:?}, {:?}, {:?}, {:?}]]", - self[0][0], self[0][1], self[0][2], self[0][3], - self[1][0], self[1][1], self[1][2], self[1][3], - self[2][0], self[2][1], self[2][2], self[2][3], - self[3][0], self[3][1], self[3][2], self[3][3]) + try!(write!(f, "Matrix4 ")); + <[[S; 4]; 4] as fmt::Debug>::fmt(self.as_ref(), f) } } diff --git a/src/point.rs b/src/point.rs index 1acd820..362f1b8 100644 --- a/src/point.rs +++ b/src/point.rs @@ -189,15 +189,17 @@ impl_fixed_array_conversions!(Point3 { x: 0, y: 1, z: 2 }, 3); impl_tuple_conversions!(Point2 { x, y }, (S, S)); impl_tuple_conversions!(Point3 { x, y, z }, (S, S, S)); -impl fmt::Debug for Point2 { +impl fmt::Debug for Point2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?}, {:?}]", self.x, self.y) + try!(write!(f, "Point2 ")); + <[S; 2] as fmt::Debug>::fmt(self.as_ref(), f) } } -impl fmt::Debug for Point3 { +impl fmt::Debug for Point3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z) + try!(write!(f, "Point3 ")); + <[S; 3] as fmt::Debug>::fmt(self.as_ref(), f) } } diff --git a/src/projection.rs b/src/projection.rs index 4aaee72..c7f96d0 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -64,7 +64,7 @@ pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S } /// A perspective projection based on a vertical field-of-view angle. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] pub struct PerspectiveFov { pub fovy: Rad, pub aspect: S, @@ -130,7 +130,7 @@ impl From> for Matrix4 { } /// A perspective projection with arbitrary left/right/bottom/top distances -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] pub struct Perspective { pub left: S, pub right: S, @@ -176,7 +176,7 @@ impl From> for Matrix4 { } /// An orthographic projection with arbitrary left/right/bottom/top distances -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] pub struct Ortho { pub left: S, pub right: S, diff --git a/src/quaternion.rs b/src/quaternion.rs index 4a65b01..a20690d 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fmt; use std::mem; use std::ops::*; @@ -32,7 +31,7 @@ use vector::{Vector3, Vector, EuclideanVector}; /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// form. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] pub struct Quaternion { pub s: S, pub v: Vector3, @@ -312,16 +311,6 @@ impl From> for Matrix4 { } } -impl fmt::Debug for Quaternion { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?} + {:?}i + {:?}j + {:?}k", - self.s, - self.v.x, - self.v.y, - self.v.z) - } -} - // Quaternion Rotation impls impl From> for Basis3 { diff --git a/src/rotation.rs b/src/rotation.rs index d69e648..993188e 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::fmt; + use angle::{Angle, Rad}; use approx::ApproxEq; use matrix::SquareMatrix; @@ -222,6 +224,13 @@ impl Rotation2 for Basis2 { fn from_angle(theta: Rad) -> Basis2 { Basis2 { mat: Matrix2::from_angle(theta) } } } +impl fmt::Debug for Basis2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "Basis2 ")); + <[[S; 2]; 2] as fmt::Debug>::fmt(self.mat.as_ref(), f) + } +} + /// A three-dimensional rotation matrix. /// /// The matrix is guaranteed to be orthogonal, so some operations, specifically @@ -323,3 +332,10 @@ impl Rotation3 for Basis3 { Basis3 { mat: Matrix3::from_angle_z(theta) } } } + +impl fmt::Debug for Basis3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "Basis3 ")); + <[[S; 3]; 3] as fmt::Debug>::fmt(self.mat.as_ref(), f) + } +} diff --git a/src/transform.rs b/src/transform.rs index dfe99fd..59e6826 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -71,7 +71,7 @@ pub trait Transform: Sized { /// A generic transformation consisting of a rotation, /// displacement vector and scale amount. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] pub struct Decomposed { pub scale: V::Scalar, pub rot: R, @@ -163,13 +163,6 @@ impl> Transform2 for Decomposed, R> impl> Transform3 for Decomposed, R> {} -impl> fmt::Debug for Decomposed, R> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "(scale({:?}), rot({:?}), disp{:?})", - self.scale, self.rot, self.disp) - } -} - /// A homogeneous transformation matrix. #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] pub struct AffineMatrix3 { @@ -213,3 +206,10 @@ impl From> for Matrix4 { } impl Transform3 for AffineMatrix3 {} + +impl fmt::Debug for AffineMatrix3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "AffineMatrix3 ")); + <[[S; 4]; 4] as fmt::Debug>::fmt(self.mat.as_ref(), f) + } +} diff --git a/src/vector.rs b/src/vector.rs index 8d287a3..91abfcb 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -489,21 +489,24 @@ impl EuclideanVector for Vector4 { } } -impl fmt::Debug for Vector2 { +impl fmt::Debug for Vector2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?}, {:?}]", self.x, self.y) + try!(write!(f, "Vector2 ")); + <[S; 2] as fmt::Debug>::fmt(self.as_ref(), f) } } -impl fmt::Debug for Vector3 { +impl fmt::Debug for Vector3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?}, {:?}, {:?}]", self.x, self.y, self.z) + try!(write!(f, "Vector3 ")); + <[S; 3] as fmt::Debug>::fmt(self.as_ref(), f) } } -impl fmt::Debug for Vector4 { +impl fmt::Debug for Vector4 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?}, {:?}, {:?}, {:?}]", self.x, self.y, self.z, self.w) + try!(write!(f, "Vector4 ")); + <[S; 4] as fmt::Debug>::fmt(self.as_ref(), f) } }