Improve fmt::Debug impls
This commit is contained in:
parent
2449a283a2
commit
429d2659fe
8 changed files with 53 additions and 49 deletions
|
@ -218,7 +218,7 @@ macro_rules! impl_angle {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> fmt::Debug for $Angle<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for $Angle<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, $fmt, self.s)
|
||||
}
|
||||
|
|
|
@ -1111,30 +1111,24 @@ impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> fmt::Debug for Matrix2<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Matrix2<S> {
|
||||
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<S: BaseFloat> fmt::Debug for Matrix3<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Matrix3<S> {
|
||||
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<S: BaseFloat> fmt::Debug for Matrix4<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Matrix4<S> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
src/point.rs
10
src/point.rs
|
@ -189,15 +189,17 @@ impl_fixed_array_conversions!(Point3<S> { x: 0, y: 1, z: 2 }, 3);
|
|||
impl_tuple_conversions!(Point2<S> { x, y }, (S, S));
|
||||
impl_tuple_conversions!(Point3<S> { x, y, z }, (S, S, S));
|
||||
|
||||
impl<S: BaseNum> fmt::Debug for Point2<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Point2<S> {
|
||||
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<S: BaseNum> fmt::Debug for Point3<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Point3<S> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn ortho<S: BaseFloat>(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<S> {
|
||||
pub fovy: Rad<S>,
|
||||
pub aspect: S,
|
||||
|
@ -130,7 +130,7 @@ impl<S: BaseFloat> From<PerspectiveFov<S>> for Matrix4<S> {
|
|||
}
|
||||
|
||||
/// 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<S> {
|
||||
pub left: S,
|
||||
pub right: S,
|
||||
|
@ -176,7 +176,7 @@ impl<S: BaseFloat> From<Perspective<S>> for Matrix4<S> {
|
|||
}
|
||||
|
||||
/// 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<S> {
|
||||
pub left: S,
|
||||
pub right: S,
|
||||
|
|
|
@ -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<S> {
|
||||
pub s: S,
|
||||
pub v: Vector3<S>,
|
||||
|
@ -312,16 +311,6 @@ impl<S: BaseFloat> From<Quaternion<S>> for Matrix4<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> fmt::Debug for Quaternion<S> {
|
||||
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<S: BaseFloat> From<Quaternion<S>> for Basis3<S> {
|
||||
|
|
|
@ -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<S: BaseFloat> Rotation2<S> for Basis2<S> {
|
|||
fn from_angle(theta: Rad<S>) -> Basis2<S> { Basis2 { mat: Matrix2::from_angle(theta) } }
|
||||
}
|
||||
|
||||
impl<S: fmt::Debug> fmt::Debug for Basis2<S> {
|
||||
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<S: BaseFloat> Rotation3<S> for Basis3<S> {
|
|||
Basis3 { mat: Matrix3::from_angle_z(theta) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: fmt::Debug> fmt::Debug for Basis3<S> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ pub trait Transform<P: Point>: 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<V: Vector, R> {
|
||||
pub scale: V::Scalar,
|
||||
pub rot: R,
|
||||
|
@ -163,13 +163,6 @@ impl<S: BaseFloat, R: Rotation2<S>> Transform2<S> for Decomposed<Vector2<S>, R>
|
|||
|
||||
impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<Vector3<S>, R> {}
|
||||
|
||||
impl<S: BaseFloat, R: fmt::Debug + Rotation3<S>> fmt::Debug for Decomposed<Vector3<S>, 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<S> {
|
||||
|
@ -213,3 +206,10 @@ impl<S: BaseNum> From<AffineMatrix3<S>> for Matrix4<S> {
|
|||
}
|
||||
|
||||
impl<S: BaseFloat> Transform3<S> for AffineMatrix3<S> {}
|
||||
|
||||
impl<S: fmt::Debug> fmt::Debug for AffineMatrix3<S> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -489,21 +489,24 @@ impl<S: BaseFloat> EuclideanVector for Vector4<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: BaseNum> fmt::Debug for Vector2<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Vector2<S> {
|
||||
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<S: BaseNum> fmt::Debug for Vector3<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Vector3<S> {
|
||||
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<S: BaseNum> fmt::Debug for Vector4<S> {
|
||||
impl<S: fmt::Debug> fmt::Debug for Vector4<S> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue