diff --git a/src/angle.rs b/src/angle.rs index c434129..050c4d9 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -35,7 +35,7 @@ use num::BaseFloat; #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "eders", derive(Serialize, Deserialize))] -pub struct Rad { pub s: S } +pub struct Rad(pub S); /// An angle, in degrees. /// @@ -44,40 +44,28 @@ pub struct Rad { pub s: S } #[derive(Copy, Clone, PartialEq, PartialOrd)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "eders", derive(Serialize, Deserialize))] -pub struct Deg { pub s: S } - -/// Create a new angle, in radians -#[inline] pub fn rad(s: S) -> Rad { Rad { s: s } } -/// Create a new angle, in degrees -#[inline] pub fn deg(s: S) -> Deg { Deg { s: s } } +pub struct Deg(pub S); impl From> for Deg where S: BaseFloat { #[inline] - fn from(r: Rad) -> Deg { - Deg::new(r.s * cast(180.0 / f64::consts::PI).unwrap()) + fn from(rad: Rad) -> Deg { + Deg(rad.0 * cast(180.0 / f64::consts::PI).unwrap()) } } impl From> for Rad where S: BaseFloat { #[inline] - fn from(d: Deg) -> Rad { - Rad::new(d.s * cast(f64::consts::PI / 180.0).unwrap()) + fn from(deg: Deg) -> Rad { + Rad(deg.0 * cast(f64::consts::PI / 180.0).unwrap()) } } macro_rules! impl_angle { ($Angle:ident, $fmt:expr, $full_turn:expr, $hi:expr) => { - impl $Angle { - #[inline] - pub fn new(value: S) -> $Angle { - $Angle { s: value } - } - } - impl Zero for $Angle { #[inline] fn zero() -> $Angle { - $Angle::new(S::zero()) + $Angle(S::zero()) } #[inline] @@ -89,66 +77,66 @@ macro_rules! impl_angle { impl Angle for $Angle { type Unitless = S; - #[inline] fn full_turn() -> $Angle { $Angle::new(cast($full_turn).unwrap()) } + #[inline] fn full_turn() -> $Angle { $Angle(cast($full_turn).unwrap()) } - #[inline] fn sin(self) -> S { Rad::from(self).s.sin() } - #[inline] fn cos(self) -> S { Rad::from(self).s.cos() } - #[inline] fn tan(self) -> S { Rad::from(self).s.tan() } - #[inline] fn sin_cos(self) -> (S, S) { Rad::from(self).s.sin_cos() } + #[inline] fn sin(self) -> S { Rad::from(self).0.sin() } + #[inline] fn cos(self) -> S { Rad::from(self).0.cos() } + #[inline] fn tan(self) -> S { Rad::from(self).0.tan() } + #[inline] fn sin_cos(self) -> (S, S) { Rad::from(self).0.sin_cos() } - #[inline] fn asin(a: S) -> $Angle { Rad::new(a.asin()).into() } - #[inline] fn acos(a: S) -> $Angle { Rad::new(a.acos()).into() } - #[inline] fn atan(a: S) -> $Angle { Rad::new(a.atan()).into() } - #[inline] fn atan2(a: S, b: S) -> $Angle { Rad::new(a.atan2(b)).into() } + #[inline] fn asin(a: S) -> $Angle { Rad(a.asin()).into() } + #[inline] fn acos(a: S) -> $Angle { Rad(a.acos()).into() } + #[inline] fn atan(a: S) -> $Angle { Rad(a.atan()).into() } + #[inline] fn atan2(a: S, b: S) -> $Angle { Rad(a.atan2(b)).into() } } impl Neg for $Angle { type Output = $Angle; #[inline] - fn neg(self) -> $Angle { $Angle::new(-self.s) } + fn neg(self) -> $Angle { $Angle(-self.0) } } impl<'a, S: BaseFloat> Neg for &'a $Angle { type Output = $Angle; #[inline] - fn neg(self) -> $Angle { $Angle::new(-self.s) } + fn neg(self) -> $Angle { $Angle(-self.0) } } impl_operator!( Add<$Angle > for $Angle { - fn add(lhs, rhs) -> $Angle { $Angle::new(lhs.s + rhs.s) } + fn add(lhs, rhs) -> $Angle { $Angle(lhs.0 + rhs.0) } }); impl_operator!( Sub<$Angle > for $Angle { - fn sub(lhs, rhs) -> $Angle { $Angle::new(lhs.s - rhs.s) } + fn sub(lhs, rhs) -> $Angle { $Angle(lhs.0 - rhs.0) } }); impl_operator!( Div<$Angle > for $Angle { - fn div(lhs, rhs) -> S { lhs.s / rhs.s } + fn div(lhs, rhs) -> S { lhs.0 / rhs.0 } }); impl_operator!( Rem<$Angle > for $Angle { - fn rem(lhs, rhs) -> $Angle { $Angle::new(lhs.s % rhs.s) } + fn rem(lhs, rhs) -> $Angle { $Angle(lhs.0 % rhs.0) } }); impl_assignment_operator!( AddAssign<$Angle > for $Angle { - fn add_assign(&mut self, other) { self.s += other.s; } + fn add_assign(&mut self, other) { self.0 += other.0; } }); impl_assignment_operator!( SubAssign<$Angle > for $Angle { - fn sub_assign(&mut self, other) { self.s -= other.s; } + fn sub_assign(&mut self, other) { self.0 -= other.0; } }); impl_assignment_operator!( RemAssign<$Angle > for $Angle { - fn rem_assign(&mut self, other) { self.s %= other.s; } + fn rem_assign(&mut self, other) { self.0 %= other.0; } }); impl_operator!( Mul for $Angle { - fn mul(lhs, scalar) -> $Angle { $Angle::new(lhs.s * scalar) } + fn mul(lhs, scalar) -> $Angle { $Angle(lhs.0 * scalar) } }); impl_operator!( Div for $Angle { - fn div(lhs, scalar) -> $Angle { $Angle::new(lhs.s / scalar) } + fn div(lhs, scalar) -> $Angle { $Angle(lhs.0 / scalar) } }); impl_assignment_operator!( MulAssign for $Angle { - fn mul_assign(&mut self, scalar) { self.s *= scalar; } + fn mul_assign(&mut self, scalar) { self.0 *= scalar; } }); impl_assignment_operator!( DivAssign for $Angle { - fn div_assign(&mut self, scalar) { self.s /= scalar; } + fn div_assign(&mut self, scalar) { self.0 /= scalar; } }); impl ApproxEq for $Angle { @@ -156,20 +144,20 @@ macro_rules! impl_angle { #[inline] fn approx_eq_eps(&self, other: &$Angle, epsilon: &S) -> bool { - self.s.approx_eq_eps(&other.s, epsilon) + self.0.approx_eq_eps(&other.0, epsilon) } } impl Rand for $Angle { #[inline] fn rand(rng: &mut R) -> $Angle { - $Angle::new(rng.gen_range(cast(-$hi).unwrap(), cast($hi).unwrap())) + $Angle(rng.gen_range(cast(-$hi).unwrap(), cast($hi).unwrap())) } } impl fmt::Debug for $Angle { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, $fmt, self.s) + write!(f, $fmt, self.0) } } } diff --git a/src/euler.rs b/src/euler.rs index 98d47e0..5de04c8 100644 --- a/src/euler.rs +++ b/src/euler.rs @@ -63,9 +63,9 @@ use num::BaseFloat; /// use cgmath::{Deg, Euler, Quaternion}; /// /// let rotation = Quaternion::from(Euler { -/// x: Deg::new(90.0), -/// y: Deg::new(45.0), -/// z: Deg::new(15.0), +/// x: Deg(90.0), +/// y: Deg(45.0), +/// z: Deg(15.0), /// }); /// ``` /// diff --git a/src/lib.rs b/src/lib.rs index 2efb293..4d93f42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ pub use matrix::{Matrix2, Matrix3, Matrix4}; pub use quaternion::Quaternion; pub use vector::{Vector1, Vector2, Vector3, Vector4, dot, vec1, vec2, vec3, vec4}; -pub use angle::{Deg, Rad, deg, rad}; +pub use angle::{Deg, Rad}; pub use euler::Euler; pub use point::{Point1, Point2, Point3}; pub use rotation::*; diff --git a/src/rotation.rs b/src/rotation.rs index 829e204..40879c1 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -110,7 +110,7 @@ pub trait Rotation3: Rotation> /// matrix: /// /// ```no_run -/// use cgmath::rad; +/// use cgmath::Rad; /// use cgmath::Vector2; /// use cgmath::{Matrix, Matrix2}; /// use cgmath::{Rotation, Rotation2, Basis2}; @@ -120,7 +120,7 @@ pub trait Rotation3: Rotation> /// // For simplicity, we will rotate the unit x vector to the unit y vector -- /// // so the angle is 90 degrees, or π/2. /// let unit_x: Vector2 = Vector2::unit_x(); -/// let rot: Basis2 = Rotation2::from_angle(rad(0.5f64 * f64::consts::PI)); +/// let rot: Basis2 = Rotation2::from_angle(Rad(0.5f64 * f64::consts::PI)); /// /// // Rotate the vector using the two-dimensional rotation matrix: /// let unit_y = rot.rotate_vector(unit_x); @@ -135,7 +135,7 @@ pub trait Rotation3: Rotation> /// assert_eq!(unit_y2, unit_y); /// /// // Note that we can also concatenate rotations: -/// let rot_half: Basis2 = Rotation2::from_angle(rad(0.25f64 * f64::consts::PI)); +/// let rot_half: Basis2 = Rotation2::from_angle(Rad(0.25f64 * f64::consts::PI)); /// let unit_y3 = (rot_half * rot_half).rotate_vector(unit_x); /// assert!(unit_y3.approx_eq(&unit_y2)); /// ``` diff --git a/src/structure.rs b/src/structure.rs index c707551..7d32f35 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -608,7 +608,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::sin(angle); /// ``` fn sin(self) -> Self::Unitless; @@ -619,7 +619,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::cos(angle); /// ``` fn cos(self) -> Self::Unitless; @@ -630,7 +630,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::tan(angle); /// ``` fn tan(self) -> Self::Unitless; @@ -645,7 +645,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let (s, c) = Rad::sin_cos(angle); /// ``` fn sin_cos(self) -> (Self::Unitless, Self::Unitless); @@ -658,7 +658,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::csc(angle); /// ``` #[inline] @@ -674,7 +674,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::cot(angle); /// ``` #[inline] @@ -690,7 +690,7 @@ pub trait Angle where /// use cgmath::prelude::*; /// use cgmath::Rad; /// - /// let angle = Rad::new(35.0); + /// let angle = Rad(35.0); /// let ratio: f32 = Rad::sec(angle); /// ``` #[inline] diff --git a/tests/angle.rs b/tests/angle.rs index c660547..15b3a0b 100644 --- a/tests/angle.rs +++ b/tests/angle.rs @@ -15,24 +15,24 @@ extern crate cgmath; -use cgmath::{Rad, Deg, rad, deg}; +use cgmath::{Rad, Deg}; use cgmath::ApproxEq; #[test] fn conv() { - let angle: Rad<_> = deg(-5.0f64).into(); + let angle: Rad<_> = Deg(-5.0f64).into(); let angle: Deg<_> = angle.into(); - assert!(angle.approx_eq(°(-5.0f64))); + assert!(angle.approx_eq(&Deg(-5.0f64))); - let angle: Rad<_> = deg(30.0f64).into(); + let angle: Rad<_> = Deg(30.0f64).into(); let angle: Deg<_> = angle.into(); - assert!(angle.approx_eq(°(30.0f64))); + assert!(angle.approx_eq(&Deg(30.0f64))); - let angle: Deg<_> = rad(-5.0f64).into(); + let angle: Deg<_> = Rad(-5.0f64).into(); let angle: Rad<_> = angle.into(); - assert!(angle.approx_eq(&rad(-5.0f64))); + assert!(angle.approx_eq(&Rad(-5.0f64))); - let angle: Deg<_> = rad(30.0f64).into(); + let angle: Deg<_> = Rad(30.0f64).into(); let angle: Rad<_> = angle.into(); - assert!(angle.approx_eq(&rad(30.0f64))); + assert!(angle.approx_eq(&Rad(30.0f64))); } diff --git a/tests/matrix.rs b/tests/matrix.rs index 9d7674f..abd6b6c 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -152,7 +152,7 @@ pub mod matrix2 { #[test] fn test_from_angle() { // Rotate the vector (1, 0) by π/2 radians to the vector (0, 1) - let rot1 = Matrix2::from_angle(rad(0.5f64 * f64::consts::PI)); + let rot1 = Matrix2::from_angle(Rad(0.5f64 * f64::consts::PI)); assert_approx_eq!(rot1 * Vector2::unit_x(), &Vector2::unit_y()); // Rotate the vector (-1, 0) by -π/2 radians to the vector (0, 1) @@ -160,7 +160,7 @@ pub mod matrix2 { assert_approx_eq!(rot2 * -Vector2::unit_x(), &Vector2::unit_y()); // Rotate the vector (1, 1) by π radians to the vector (-1, -1) - let rot3: Matrix2 = Matrix2::from_angle(rad(f64::consts::PI)); + let rot3: Matrix2 = Matrix2::from_angle(Rad(f64::consts::PI)); assert_approx_eq!(rot3 * Vector2::new(1.0, 1.0), &Vector2::new(-1.0, -1.0)); } } @@ -318,13 +318,13 @@ pub mod matrix3 { fn check_from_axis_angle_x(pitch: Rad) { let found = Matrix3::from_angle_x(pitch); - let expected = Matrix3::from(Euler { x: pitch, y: rad(0.0), z: rad(0.0) }); + let expected = Matrix3::from(Euler { x: pitch, y: Rad(0.0), z: Rad(0.0) }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_x(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_x(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_x(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_x(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_x(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_x(Rad(-1.0)); } } mod from_axis_y { @@ -332,13 +332,13 @@ pub mod matrix3 { fn check_from_axis_angle_y(yaw: Rad) { let found = Matrix3::from_angle_y(yaw); - let expected = Matrix3::from(Euler { x: rad(0.0), y: yaw, z: rad(0.0) }); + let expected = Matrix3::from(Euler { x: Rad(0.0), y: yaw, z: Rad(0.0) }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_y(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_y(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_y(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_y(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_y(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_y(Rad(-1.0)); } } mod from_axis_z { @@ -346,13 +346,13 @@ pub mod matrix3 { fn check_from_axis_angle_z(roll: Rad) { let found = Matrix3::from_angle_z(roll); - let expected = Matrix3::from(Euler { x: rad(0.0), y: rad(0.0), z: roll }); + let expected = Matrix3::from(Euler { x: Rad(0.0), y: Rad(0.0), z: roll }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_z(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_z(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_z(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_z(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_z(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_z(Rad(-1.0)); } } mod from_axis_angle { @@ -361,13 +361,13 @@ pub mod matrix3 { fn check_from_axis_angle_x(pitch: Rad) { let found = Matrix3::from_axis_angle(Vector3::unit_x(), pitch); - let expected = Matrix3::from(Euler { x: pitch, y: rad(0.0), z: rad(0.0) }); + let expected = Matrix3::from(Euler { x: pitch, y: Rad(0.0), z: Rad(0.0) }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_x(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_x(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_x(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_x(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_x(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_x(Rad(-1.0)); } } mod axis_y { @@ -375,13 +375,13 @@ pub mod matrix3 { fn check_from_axis_angle_y(yaw: Rad) { let found = Matrix3::from_axis_angle(Vector3::unit_y(), yaw); - let expected = Matrix3::from(Euler { x: rad(0.0), y: yaw, z: rad(0.0) }); + let expected = Matrix3::from(Euler { x: Rad(0.0), y: yaw, z: Rad(0.0) }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_y(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_y(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_y(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_y(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_y(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_y(Rad(-1.0)); } } mod axis_z { @@ -389,13 +389,13 @@ pub mod matrix3 { fn check_from_axis_angle_z(roll: Rad) { let found = Matrix3::from_axis_angle(Vector3::unit_z(), roll); - let expected = Matrix3::from(Euler { x: rad(0.0), y: rad(0.0), z: roll }); + let expected = Matrix3::from(Euler { x: Rad(0.0), y: Rad(0.0), z: roll }); assert_approx_eq_eps!(found, expected, 0.001); } - #[test] fn test_zero() { check_from_axis_angle_z(rad(0.0)); } - #[test] fn test_pos_1() { check_from_axis_angle_z(rad(1.0)); } - #[test] fn test_neg_1() { check_from_axis_angle_z(rad(-1.0)); } + #[test] fn test_zero() { check_from_axis_angle_z(Rad(0.0)); } + #[test] fn test_pos_1() { check_from_axis_angle_z(Rad(1.0)); } + #[test] fn test_neg_1() { check_from_axis_angle_z(Rad(-1.0)); } } } @@ -406,10 +406,10 @@ pub mod matrix3 { fn test_x() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from(Euler::new(deg(90.0), deg(0.0), deg(0.0))); + let rot = Matrix3::from(Euler::new(Deg(90.0), Deg(0.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); - let rot = Matrix3::from(Euler::new(deg(-90.0), deg(0.0), deg(0.0))); + let rot = Matrix3::from(Euler::new(Deg(-90.0), Deg(0.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); } @@ -417,10 +417,10 @@ pub mod matrix3 { fn test_y() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from(Euler::new(deg(0.0), deg(90.0), deg(0.0))); + let rot = Matrix3::from(Euler::new(Deg(0.0), Deg(90.0), Deg(0.0))); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); - let rot = Matrix3::from(Euler::new(deg(0.0), deg(-90.0), deg(0.0))); + let rot = Matrix3::from(Euler::new(Deg(0.0), Deg(-90.0), Deg(0.0))); assert_approx_eq!(vec3(-1.0, 0.0, 0.0), rot * vec); } @@ -428,10 +428,10 @@ pub mod matrix3 { fn test_z() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Matrix3::from(Euler::new(deg(0.0), deg(0.0), deg(90.0))); + let rot = Matrix3::from(Euler::new(Deg(0.0), Deg(0.0), Deg(90.0))); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); - let rot = Matrix3::from(Euler::new(deg(0.0), deg(0.0), deg(-90.0))); + let rot = Matrix3::from(Euler::new(Deg(0.0), Deg(0.0), Deg(-90.0))); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); } @@ -441,7 +441,7 @@ pub mod matrix3 { fn test_x_then_y() { let vec = vec3(0.0, 1.0, 0.0); - let rot = Matrix3::from(Euler::new(deg(90.0), deg(90.0), deg(0.0))); + let rot = Matrix3::from(Euler::new(Deg(90.0), Deg(90.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, 0.0, 1.0), rot * vec); } @@ -450,7 +450,7 @@ pub mod matrix3 { fn test_y_then_z() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from(Euler::new(deg(0.0), deg(90.0), deg(90.0))); + let rot = Matrix3::from(Euler::new(Deg(0.0), Deg(90.0), Deg(90.0))); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); } } @@ -462,7 +462,7 @@ pub mod matrix3 { fn test_x() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from_angle_x(deg(90.0)); + let rot = Matrix3::from_angle_x(Deg(90.0)); println!("x mat: {:?}", rot); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); } @@ -471,7 +471,7 @@ pub mod matrix3 { fn test_y() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from_angle_y(deg(90.0)); + let rot = Matrix3::from_angle_y(Deg(90.0)); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); } @@ -479,7 +479,7 @@ pub mod matrix3 { fn test_z() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Matrix3::from_angle_z(deg(90.0)); + let rot = Matrix3::from_angle_z(Deg(90.0)); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); } @@ -487,7 +487,7 @@ pub mod matrix3 { fn test_xy() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Matrix3::from_axis_angle(vec3(1.0, 1.0, 0.0).normalize(), deg(90.0)); + let rot = Matrix3::from_axis_angle(vec3(1.0, 1.0, 0.0).normalize(), Deg(90.0)); assert_approx_eq!(vec3(2.0f32.sqrt() / 2.0, -2.0f32.sqrt() / 2.0, 0.0), rot * vec); } @@ -495,7 +495,7 @@ pub mod matrix3 { fn test_yz() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Matrix3::from_axis_angle(vec3(0.0, 1.0, 1.0).normalize(), deg(-90.0)); + let rot = Matrix3::from_axis_angle(vec3(0.0, 1.0, 1.0).normalize(), Deg(-90.0)); assert_approx_eq!(vec3(0.0, -2.0f32.sqrt() / 2.0, 2.0f32.sqrt() / 2.0), rot * vec); } @@ -503,7 +503,7 @@ pub mod matrix3 { fn test_xz() { let vec = vec3(0.0, 1.0, 0.0); - let rot = Matrix3::from_axis_angle(vec3(1.0, 0.0, 1.0).normalize(), deg(90.0)); + let rot = Matrix3::from_axis_angle(vec3(1.0, 0.0, 1.0).normalize(), Deg(90.0)); assert_approx_eq!(vec3(-2.0f32.sqrt() / 2.0, 0.0, 2.0f32.sqrt() / 2.0), rot * vec); } } diff --git a/tests/quaternion.rs b/tests/quaternion.rs index c73ad07..a99ddda 100644 --- a/tests/quaternion.rs +++ b/tests/quaternion.rs @@ -43,12 +43,12 @@ mod operators { #[test] fn test_mul() { - impl_test_mul!(2.0f32, Quaternion::from(Euler { x: rad(1f32), y: rad(1f32), z: rad(1f32) })); + impl_test_mul!(2.0f32, Quaternion::from(Euler { x: Rad(1f32), y: Rad(1f32), z: Rad(1f32) })); } #[test] fn test_div() { - impl_test_div!(2.0f32, Quaternion::from(Euler { x: rad(1f32), y: rad(1f32), z: rad(1f32) })); + impl_test_div!(2.0f32, Quaternion::from(Euler { x: Rad(1f32), y: Rad(1f32), z: Rad(1f32) })); } } @@ -63,17 +63,17 @@ mod to_from_euler { const HPI: f32 = f32::consts::FRAC_PI_2; - #[test] fn test_zero() { check_euler(Euler { x: rad( 0f32), y: rad( 0f32), z: rad( 0f32) }); } - #[test] fn test_yaw_pos_1() { check_euler(Euler { x: rad( 0f32), y: rad( 1f32), z: rad( 0f32) }); } - #[test] fn test_yaw_neg_1() { check_euler(Euler { x: rad( 0f32), y: rad(-1f32), z: rad( 0f32) }); } - #[test] fn test_pitch_pos_1() { check_euler(Euler { x: rad( 1f32), y: rad( 0f32), z: rad( 0f32) }); } - #[test] fn test_pitch_neg_1() { check_euler(Euler { x: rad(-1f32), y: rad( 0f32), z: rad( 0f32) }); } - #[test] fn test_roll_pos_1() { check_euler(Euler { x: rad( 0f32), y: rad( 0f32), z: rad( 1f32) }); } - #[test] fn test_roll_neg_1() { check_euler(Euler { x: rad( 0f32), y: rad( 0f32), z: rad(-1f32) }); } - #[test] fn test_pitch_yaw_roll_pos_1() { check_euler(Euler { x: rad( 1f32), y: rad( 1f32), z: rad( 1f32) }); } - #[test] fn test_pitch_yaw_roll_neg_1() { check_euler(Euler { x: rad(-1f32), y: rad(-1f32), z: rad(-1f32) }); } - #[test] fn test_pitch_yaw_roll_pos_hp() { check_euler(Euler { x: rad( 0f32), y: rad( HPI), z: rad( 1f32) }); } - #[test] fn test_pitch_yaw_roll_neg_hp() { check_euler(Euler { x: rad( 0f32), y: rad( -HPI), z: rad( 1f32) }); } + #[test] fn test_zero() { check_euler(Euler { x: Rad( 0f32), y: Rad( 0f32), z: Rad( 0f32) }); } + #[test] fn test_yaw_pos_1() { check_euler(Euler { x: Rad( 0f32), y: Rad( 1f32), z: Rad( 0f32) }); } + #[test] fn test_yaw_neg_1() { check_euler(Euler { x: Rad( 0f32), y: Rad(-1f32), z: Rad( 0f32) }); } + #[test] fn test_pitch_pos_1() { check_euler(Euler { x: Rad( 1f32), y: Rad( 0f32), z: Rad( 0f32) }); } + #[test] fn test_pitch_neg_1() { check_euler(Euler { x: Rad(-1f32), y: Rad( 0f32), z: Rad( 0f32) }); } + #[test] fn test_roll_pos_1() { check_euler(Euler { x: Rad( 0f32), y: Rad( 0f32), z: Rad( 1f32) }); } + #[test] fn test_roll_neg_1() { check_euler(Euler { x: Rad( 0f32), y: Rad( 0f32), z: Rad(-1f32) }); } + #[test] fn test_pitch_yaw_roll_pos_1() { check_euler(Euler { x: Rad( 1f32), y: Rad( 1f32), z: Rad( 1f32) }); } + #[test] fn test_pitch_yaw_roll_neg_1() { check_euler(Euler { x: Rad(-1f32), y: Rad(-1f32), z: Rad(-1f32) }); } + #[test] fn test_pitch_yaw_roll_pos_hp() { check_euler(Euler { x: Rad( 0f32), y: Rad( HPI), z: Rad( 1f32) }); } + #[test] fn test_pitch_yaw_roll_neg_hp() { check_euler(Euler { x: Rad( 0f32), y: Rad( -HPI), z: Rad( 1f32) }); } } mod from { @@ -90,25 +90,25 @@ mod from { // triggers: trace >= S::zero() #[test] fn test_positive_trace() { - check_with_euler(rad(0.0f32), rad(0.0), rad(0.0f32)); + check_with_euler(Rad(0.0f32), Rad(0.0), Rad(0.0f32)); } // triggers: (mat[0][0] > mat[1][1]) && (mat[0][0] > mat[2][2]) #[test] fn test_xx_maximum() { - check_with_euler(rad(2.0f32), rad(1.0), rad(-1.2f32)); + check_with_euler(Rad(2.0f32), Rad(1.0), Rad(-1.2f32)); } // triggers: mat[1][1] > mat[2][2] #[test] fn test_yy_maximum() { - check_with_euler(rad(2.0f32), rad(1.0), rad(3.0f32)); + check_with_euler(Rad(2.0f32), Rad(1.0), Rad(3.0f32)); } // base case #[test] fn test_zz_maximum() { - check_with_euler(rad(1.0f32), rad(1.0), rad(3.0f32)); + check_with_euler(Rad(1.0f32), Rad(1.0), Rad(3.0f32)); } } } @@ -156,10 +156,10 @@ mod rotate_from_euler { fn test_x() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from(Euler::new(deg(90.0), deg(0.0), deg(0.0))); + let rot = Quaternion::from(Euler::new(Deg(90.0), Deg(0.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); - let rot = Quaternion::from(Euler::new(deg(-90.0), deg(0.0), deg(0.0))); + let rot = Quaternion::from(Euler::new(Deg(-90.0), Deg(0.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); } @@ -167,10 +167,10 @@ mod rotate_from_euler { fn test_y() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from(Euler::new(deg(0.0), deg(90.0), deg(0.0))); + let rot = Quaternion::from(Euler::new(Deg(0.0), Deg(90.0), Deg(0.0))); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); - let rot = Quaternion::from(Euler::new(deg(0.0), deg(-90.0), deg(0.0))); + let rot = Quaternion::from(Euler::new(Deg(0.0), Deg(-90.0), Deg(0.0))); assert_approx_eq!(vec3(-1.0, 0.0, 0.0), rot * vec); } @@ -178,10 +178,10 @@ mod rotate_from_euler { fn test_z() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Quaternion::from(Euler::new(deg(0.0), deg(0.0), deg(90.0))); + let rot = Quaternion::from(Euler::new(Deg(0.0), Deg(0.0), Deg(90.0))); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); - let rot = Quaternion::from(Euler::new(deg(0.0), deg(0.0), deg(-90.0))); + let rot = Quaternion::from(Euler::new(Deg(0.0), Deg(0.0), Deg(-90.0))); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); } @@ -191,7 +191,7 @@ mod rotate_from_euler { fn test_x_then_y() { let vec = vec3(0.0, 1.0, 0.0); - let rot = Quaternion::from(Euler::new(deg(90.0), deg(90.0), deg(0.0))); + let rot = Quaternion::from(Euler::new(Deg(90.0), Deg(90.0), Deg(0.0))); assert_approx_eq!(vec3(0.0, 0.0, 1.0), rot * vec); } @@ -200,7 +200,7 @@ mod rotate_from_euler { fn test_y_then_z() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from(Euler::new(deg(0.0), deg(90.0), deg(90.0))); + let rot = Quaternion::from(Euler::new(Deg(0.0), Deg(90.0), Deg(90.0))); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); } } @@ -212,7 +212,7 @@ mod rotate_from_axis_angle { fn test_x() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from_angle_x(deg(90.0)); + let rot = Quaternion::from_angle_x(Deg(90.0)); assert_approx_eq!(vec3(0.0, -1.0, 0.0), rot * vec); } @@ -220,7 +220,7 @@ mod rotate_from_axis_angle { fn test_y() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from_angle_y(deg(90.0)); + let rot = Quaternion::from_angle_y(Deg(90.0)); assert_approx_eq!(vec3(1.0, 0.0, 0.0), rot * vec); } @@ -228,7 +228,7 @@ mod rotate_from_axis_angle { fn test_z() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Quaternion::from_angle_z(deg(90.0)); + let rot = Quaternion::from_angle_z(Deg(90.0)); assert_approx_eq!(vec3(0.0, 1.0, 0.0), rot * vec); } @@ -236,7 +236,7 @@ mod rotate_from_axis_angle { fn test_xy() { let vec = vec3(0.0, 0.0, 1.0); - let rot = Quaternion::from_axis_angle(vec3(1.0, 1.0, 0.0).normalize(), deg(90.0)); + let rot = Quaternion::from_axis_angle(vec3(1.0, 1.0, 0.0).normalize(), Deg(90.0)); assert_approx_eq!(vec3(2.0f32.sqrt() / 2.0, -2.0f32.sqrt() / 2.0, 0.0), rot * vec); } @@ -244,7 +244,7 @@ mod rotate_from_axis_angle { fn test_yz() { let vec = vec3(1.0, 0.0, 0.0); - let rot = Quaternion::from_axis_angle(vec3(0.0, 1.0, 1.0).normalize(), deg(-90.0)); + let rot = Quaternion::from_axis_angle(vec3(0.0, 1.0, 1.0).normalize(), Deg(-90.0)); assert_approx_eq!(vec3(0.0, -2.0f32.sqrt() / 2.0, 2.0f32.sqrt() / 2.0), rot * vec); } @@ -252,7 +252,7 @@ mod rotate_from_axis_angle { fn test_xz() { let vec = vec3(0.0, 1.0, 0.0); - let rot = Quaternion::from_axis_angle(vec3(1.0, 0.0, 1.0).normalize(), deg(90.0)); + let rot = Quaternion::from_axis_angle(vec3(1.0, 0.0, 1.0).normalize(), Deg(90.0)); assert_approx_eq!(vec3(-2.0f32.sqrt() / 2.0, 0.0, 2.0f32.sqrt() / 2.0), rot * vec); } } diff --git a/tests/rotation.rs b/tests/rotation.rs index 97d3169..b661d31 100644 --- a/tests/rotation.rs +++ b/tests/rotation.rs @@ -21,12 +21,12 @@ mod rotation { use super::cgmath::*; pub fn a2>() -> R { - Rotation2::from_angle(deg(30.0)) + Rotation2::from_angle(Deg(30.0)) } pub fn a3>() -> R { let axis = Vector3::new(1.0, 1.0, 0.0).normalize(); - Rotation3::from_axis_angle(axis, deg(30.0)) + Rotation3::from_axis_angle(axis, Deg(30.0)) } } diff --git a/tests/vector.rs b/tests/vector.rs index d7ed20b..57a9f9d 100644 --- a/tests/vector.rs +++ b/tests/vector.rs @@ -229,17 +229,17 @@ mod test_magnitude { #[test] fn test_angle() { - assert!(Vector2::new(1.0f64, 0.0f64).angle(Vector2::new(0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) )); - assert!(Vector2::new(10.0f64, 0.0f64).angle(Vector2::new(0.0f64, 5.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) )); - assert!(Vector2::new(-1.0f64, 0.0f64).angle(Vector2::new(0.0f64, 1.0f64)).approx_eq( &-rad(f64::consts::FRAC_PI_2) )); + assert!(Vector2::new(1.0f64, 0.0f64).angle(Vector2::new(0.0f64, 1.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_2) )); + assert!(Vector2::new(10.0f64, 0.0f64).angle(Vector2::new(0.0f64, 5.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_2) )); + assert!(Vector2::new(-1.0f64, 0.0f64).angle(Vector2::new(0.0f64, 1.0f64)).approx_eq( &-Rad(f64::consts::FRAC_PI_2) )); - assert!(Vector3::new(1.0f64, 0.0f64, 1.0f64).angle(Vector3::new(1.0f64, 1.0f64, 0.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_3) )); - assert!(Vector3::new(10.0f64, 0.0f64, 10.0f64).angle(Vector3::new(5.0f64, 5.0f64, 0.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_3) )); - assert!(Vector3::new(-1.0f64, 0.0f64, -1.0f64).angle(Vector3::new(1.0f64, -1.0f64, 0.0f64)).approx_eq( &rad(2.0f64 * f64::consts::FRAC_PI_3) )); + assert!(Vector3::new(1.0f64, 0.0f64, 1.0f64).angle(Vector3::new(1.0f64, 1.0f64, 0.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_3) )); + assert!(Vector3::new(10.0f64, 0.0f64, 10.0f64).angle(Vector3::new(5.0f64, 5.0f64, 0.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_3) )); + assert!(Vector3::new(-1.0f64, 0.0f64, -1.0f64).angle(Vector3::new(1.0f64, -1.0f64, 0.0f64)).approx_eq( &Rad(2.0f64 * f64::consts::FRAC_PI_3) )); - assert!(Vector4::new(1.0f64, 0.0f64, 1.0f64, 0.0f64).angle(Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) )); - assert!(Vector4::new(10.0f64, 0.0f64, 10.0f64, 0.0f64).angle(Vector4::new(0.0f64, 5.0f64, 0.0f64, 5.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) )); - assert!(Vector4::new(-1.0f64, 0.0f64, -1.0f64, 0.0f64).angle(Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) )); + assert!(Vector4::new(1.0f64, 0.0f64, 1.0f64, 0.0f64).angle(Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_2) )); + assert!(Vector4::new(10.0f64, 0.0f64, 10.0f64, 0.0f64).angle(Vector4::new(0.0f64, 5.0f64, 0.0f64, 5.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_2) )); + assert!(Vector4::new(-1.0f64, 0.0f64, -1.0f64, 0.0f64).angle(Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &Rad(f64::consts::FRAC_PI_2) )); } #[test]