diff --git a/src/angle.rs b/src/angle.rs index a7a1356..515869e 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -141,15 +141,15 @@ pub trait Angle /// Returns the interior bisector of the two angles #[inline] fn bisect(&self, other: Self) -> Self { - self.add_a(self.sub_a(other).mul_s(cast(0.5).unwrap())).normalize() + self.add_a(self.sub_a(other).mul_s(cast(0.5f64).unwrap())).normalize() } fn full_turn() -> Self; - #[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2).unwrap()) } - #[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3).unwrap()) } - #[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4).unwrap()) } - #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6).unwrap()) } + #[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2i).unwrap()) } + #[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3i).unwrap()) } + #[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4i).unwrap()) } + #[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6i).unwrap()) } } #[inline] pub fn bisect>(a: A, b: A) -> A { a.bisect(b) } @@ -216,7 +216,7 @@ Angle for Rad { impl Angle for Deg { #[inline] fn from>(theta: A) -> Deg { theta.to_deg() } - #[inline] fn full_turn() -> Deg { deg(cast(360).unwrap()) } + #[inline] fn full_turn() -> Deg { deg(cast(360i).unwrap()) } } #[inline] pub fn sin(theta: Rad) -> S { theta.s.sin() } diff --git a/src/approx.rs b/src/approx.rs index dced6dd..1604280 100644 --- a/src/approx.rs +++ b/src/approx.rs @@ -17,7 +17,7 @@ use std::num; pub trait ApproxEq { fn approx_epsilon(_hack: Option) -> T { - num::cast(1.0e-5).unwrap() + num::cast(1.0e-5f64).unwrap() } fn approx_eq(&self, other: &Self) -> bool { diff --git a/src/matrix.rs b/src/matrix.rs index 4e064fd..8f54056 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1069,7 +1069,7 @@ impl ToQuaternion for Matrix3 { fn to_quaternion(&self) -> Quaternion { // http://www.cs.ucr.edu/~vbz/resources/quatut.pdf let trace = self.trace(); - let half: S = cast(0.5).unwrap(); + let half: S = cast(0.5f64).unwrap(); match () { () if trace >= zero::() => { let s = (one::() + trace).sqrt(); diff --git a/src/projection.rs b/src/projection.rs index 3dc82a0..7f05663 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -79,7 +79,7 @@ pub struct PerspectiveFov { impl> PerspectiveFov { pub fn to_perspective(&self) -> Perspective { - let angle = self.fovy.div_s(cast(2).unwrap()); + let angle = self.fovy.div_s(cast(2i).unwrap()); let ymax = self.near * tan(angle.to_rad()); let xmax = ymax * self.aspect; @@ -112,8 +112,8 @@ impl> ToMatrix4 for PerspectiveFov { assert!(self.far > zero(), "The far plane distance cannot be below zero, found: {}", self.far); assert!(self.far > self.near, "The far plane cannot be closer than the near plane, found: far: {}, near: {}", self.far, self.near); - let f = cot(self.fovy.div_s(cast(2).unwrap()).to_rad()); - let two: S = cast(2).unwrap(); + let f = cot(self.fovy.div_s(cast(2i).unwrap()).to_rad()); + let two: S = cast(2i).unwrap(); let c0r0 = f / self.aspect; let c0r1 = zero(); @@ -163,7 +163,7 @@ impl ToMatrix4 for Perspective { assert!(self.bottom > self.top, "`bottom` cannot be greater than `top`, found: bottom: {} top: {}", self.bottom, self.top); assert!(self.near > self.far, "`near` cannot be greater than `far`, found: near: {} far: {}", self.near, self.far); - let two: S = cast(2).unwrap(); + let two: S = cast(2i).unwrap(); let c0r0 = (two * self.near) / (self.right - self.left); let c0r1 = zero(); @@ -219,7 +219,7 @@ impl ToMatrix4 for Ortho { assert!(self.bottom < self.top, "`bottom` cannot be greater than `top`, found: bottom: {} top: {}", self.bottom, self.top); assert!(self.near < self.far, "`near` cannot be greater than `far`, found: near: {} far: {}", self.near, self.far); - let two: S = cast(2).unwrap(); + let two: S = cast(2i).unwrap(); let c0r0 = two / (self.right - self.left); let c0r1 = zero(); diff --git a/src/quaternion.rs b/src/quaternion.rs index 40b0a56..06e4b27 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -99,7 +99,7 @@ impl Quaternion { #[inline] pub fn mul_v(&self, vec: &Vector3) -> Vector3 { let tmp = self.v.cross(vec).add_v(&vec.mul_s(self.s.clone())); - self.v.cross(&tmp).mul_s(cast(2).unwrap()).add_v(vec) + self.v.cross(&tmp).mul_s(cast(2i).unwrap()).add_v(vec) } /// The sum of this quaternion and `other` @@ -230,7 +230,7 @@ impl Quaternion { use std::num::cast; let dot = self.dot(other); - let dot_threshold = cast(0.9995).unwrap(); + let dot_threshold = cast(0.9995f64).unwrap(); // if quaternions are close together use `nlerp` if dot > dot_threshold { @@ -373,15 +373,15 @@ impl Rotation, Point3> for Quaternion { impl Rotation3 for Quaternion { #[inline] fn from_axis_angle(axis: &Vector3, angle: Rad) -> Quaternion { - let (s, c) = sin_cos(angle.mul_s(cast(0.5).unwrap())); + let (s, c) = sin_cos(angle.mul_s(cast(0.5f64).unwrap())); Quaternion::from_sv(c, axis.mul_s(s)) } fn from_euler(x: Rad, y: Rad, z: Rad) -> Quaternion { // http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion - let (sx2, cx2) = sin_cos(x.mul_s(cast(0.5).unwrap())); - let (sy2, cy2) = sin_cos(y.mul_s(cast(0.5).unwrap())); - let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5).unwrap())); + let (sx2, cx2) = sin_cos(x.mul_s(cast(0.5f64).unwrap())); + let (sy2, cy2) = sin_cos(y.mul_s(cast(0.5f64).unwrap())); + let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5f64).unwrap())); Quaternion::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2, sz2 * cx2 * cy2 - cz2 * sx2 * sy2, diff --git a/src/test/aabb.rs b/src/test/aabb.rs index 8d4f67c..ae1ff80 100644 --- a/src/test/aabb.rs +++ b/src/test/aabb.rs @@ -4,44 +4,44 @@ use cgmath::vector::{Vector2, Vector3}; #[test] fn test_aabb() { - let aabb = Aabb2::new(Point2::new(-20, 30), Point2::new(10, -10)); - assert_eq!(aabb.min(), &Point2::new(-20, -10)); - assert_eq!(aabb.max(), &Point2::new(10, 30)); - assert_eq!(aabb.dim(), Vector2::new(30, 40)); - assert_eq!(aabb.volume(), 30 * 40); - assert_eq!(aabb.center(), Point2::new(-5, 10)); + let aabb = Aabb2::new(Point2::new(-20i, 30i), Point2::new(10i, -10i)); + assert_eq!(aabb.min(), &Point2::new(-20i, -10i)); + assert_eq!(aabb.max(), &Point2::new(10i, 30i)); + assert_eq!(aabb.dim(), Vector2::new(30i, 40i)); + assert_eq!(aabb.volume(), 30i * 40i); + assert_eq!(aabb.center(), Point2::new(-5i, 10i)); - assert!(aabb.contains(&Point2::new(0, 0))); - assert!(!aabb.contains(&Point2::new(-50, -50))); - assert!(!aabb.contains(&Point2::new(50, 50))); + assert!(aabb.contains(&Point2::new(0i, 0i))); + assert!(!aabb.contains(&Point2::new(-50i, -50i))); + assert!(!aabb.contains(&Point2::new(50i, 50i))); - assert_eq!(aabb.grow(&Point2::new(0, 0)), aabb); - assert_eq!(aabb.grow(&Point2::new(100, 100)), - Aabb2::new(Point2::new(-20, -10), Point2::new(100, 100))); - assert_eq!(aabb.grow(&Point2::new(-100, -100)), - Aabb2::new(Point2::new(-100, -100), Point2::new(10, 30))); + assert_eq!(aabb.grow(&Point2::new(0i, 0i)), aabb); + assert_eq!(aabb.grow(&Point2::new(100i, 100i)), + Aabb2::new(Point2::new(-20i, -10i), Point2::new(100i, 100i))); + assert_eq!(aabb.grow(&Point2::new(-100i, -100i)), + Aabb2::new(Point2::new(-100i, -100i), Point2::new(10i, 30i))); - let aabb = Aabb3::new(Point3::new(-20, 30, 5), Point3::new(10, -10, -5)); - assert_eq!(aabb.min(), &Point3::new(-20, -10, -5)); - assert_eq!(aabb.max(), &Point3::new(10, 30, 5)); - assert_eq!(aabb.dim(), Vector3::new(30, 40, 10)); - assert_eq!(aabb.volume(), 30 * 40 * 10); - assert_eq!(aabb.center(), Point3::new(-5, 10, 0)); + let aabb = Aabb3::new(Point3::new(-20i, 30i, 5i), Point3::new(10i, -10i, -5i)); + assert_eq!(aabb.min(), &Point3::new(-20i, -10i, -5i)); + assert_eq!(aabb.max(), &Point3::new(10i, 30i, 5i)); + assert_eq!(aabb.dim(), Vector3::new(30i, 40i, 10i)); + assert_eq!(aabb.volume(), 30i * 40i * 10i); + assert_eq!(aabb.center(), Point3::new(-5i, 10i, 0i)); - assert!(aabb.contains(&Point3::new(0, 0, 0))); - assert!(!aabb.contains(&Point3::new(-100, 0, 0))); - assert!(!aabb.contains(&Point3::new(100, 0, 0))); - assert!(aabb.contains(&Point3::new(9, 29, -1))); - assert!(!aabb.contains(&Point3::new(10, 30, 5))); - assert!(aabb.contains(&Point3::new(-20, -10, -5))); - assert!(!aabb.contains(&Point3::new(-21, -11, -6))); + assert!(aabb.contains(&Point3::new(0i, 0i, 0i))); + assert!(!aabb.contains(&Point3::new(-100i, 0i, 0i))); + assert!(!aabb.contains(&Point3::new(100i, 0i, 0i))); + assert!(aabb.contains(&Point3::new(9i, 29i, -1i))); + assert!(!aabb.contains(&Point3::new(10i, 30i, 5i))); + assert!(aabb.contains(&Point3::new(-20i, -10i, -5i))); + assert!(!aabb.contains(&Point3::new(-21i, -11i, -6i))); - assert_eq!(aabb.add_v(&Vector3::new(1, 2, 3)), - Aabb3::new(Point3::new(-19, 32, 8), Point3::new(11, -8, -2))); + assert_eq!(aabb.add_v(&Vector3::new(1i, 2i, 3i)), + Aabb3::new(Point3::new(-19i, 32i, 8i), Point3::new(11i, -8i, -2i))); - assert_eq!(aabb.mul_s(2), - Aabb3::new(Point3::new(-40, -20, -10), Point3::new(20, 60, 10))); + assert_eq!(aabb.mul_s(2i), + Aabb3::new(Point3::new(-40i, -20i, -10i), Point3::new(20i, 60i, 10i))); - assert_eq!(aabb.mul_v(&Vector3::new(1, 2, 3)), - Aabb3::new(Point3::new(-20, -20, -15), Point3::new(10, 60, 15))); + assert_eq!(aabb.mul_v(&Vector3::new(1i, 2i, 3i)), + Aabb3::new(Point3::new(-20i, -20i, -15i), Point3::new(10i, 60i, 15i))); } diff --git a/src/test/angle.rs b/src/test/angle.rs index f50e012..1b8fd2a 100644 --- a/src/test/angle.rs +++ b/src/test/angle.rs @@ -18,11 +18,11 @@ use cgmath::approx::ApproxEq; #[test] fn conv() { - assert!(deg(-5.0).to_rad().to_deg().approx_eq( °(-5.0) )); - assert!(deg(30.0).to_rad().to_deg().approx_eq( °(30.0) )); + assert!(deg(-5.0f64).to_rad().to_deg().approx_eq( °(-5.0f64) )); + assert!(deg(30.0f64).to_rad().to_deg().approx_eq( °(30.0f64) )); - assert!(rad(-5.0).to_deg().to_rad().approx_eq( &rad(-5.0) )); - assert!(rad(30.0).to_deg().to_rad().approx_eq( &rad(30.0) )); + assert!(rad(-5.0f64).to_deg().to_rad().approx_eq( &rad(-5.0f64) )); + assert!(rad(30.0f64).to_deg().to_rad().approx_eq( &rad(30.0f64) )); } #[test] diff --git a/src/test/line.rs b/src/test/line.rs index 7184c97..206a6ca 100644 --- a/src/test/line.rs +++ b/src/test/line.rs @@ -21,59 +21,59 @@ use cgmath::intersect::Intersect; fn test_line_intersection() { // collinear, origins pointing towards each other, first intersection // from l1.origin is in an endpoint in l2 - let l1 = Line::new(Point2::new(0.0, 0.0), Point2::new(10.0, 0.0)); - let l2 = Line::new(Point2::new(1.5, 0.0), Point2::new(0.5, 0.0)); - assert_eq!((l1, l2).intersection(), Some(Point2::new(0.5, 0.0))); + let l1 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(10.0f64, 0.0f64)); + let l2 = Line::new(Point2::new(1.5f64, 0.0f64), Point2::new(0.5f64, 0.0f64)); + assert_eq!((l1, l2).intersection(), Some(Point2::new(0.5f64, 0.0f64))); // collinear, first intersection from p1.origin is at p1.origin itself - let l3 = Line::new(Point2::new(0.0, 0.0), Point2::new(10.0, 0.0)); - let l4 = Line::new(Point2::new(-11.0, 0.0), Point2::new(1.0, 0.0)); - assert_eq!((l3, l4).intersection(), Some(Point2::new(0.0, 0.0))); + let l3 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(10.0f64, 0.0f64)); + let l4 = Line::new(Point2::new(-11.0f64, 0.0f64), Point2::new(1.0f64, 0.0f64)); + assert_eq!((l3, l4).intersection(), Some(Point2::new(0.0f64, 0.0f64))); // no intersection - let l5 = Line::new(Point2::new(5.0, 5.0), Point2::new(10.0, 6.0)); - let l6 = Line::new(Point2::new(5.0, 4.8), Point2::new(10.0, 4.1)); + let l5 = Line::new(Point2::new(5.0f64, 5.0f64), Point2::new(10.0f64, 6.0f64)); + let l6 = Line::new(Point2::new(5.0f64, 4.8f64), Point2::new(10.0f64, 4.1f64)); assert_eq!((l5, l6).intersection(), None); // no intersection // collinear, origins pointing same direction - let l7 = Line::new(Point2::new(0.0, 1.0), Point2::new(0.0, 0.0)); - let l8 = Line::new(Point2::new(0.0, 0.5), Point2::new(0.0, -0.5)); - assert_eq!((l7, l8).intersection(), Some(Point2::new(0.0, 0.5))); + let l7 = Line::new(Point2::new(0.0f64, 1.0f64), Point2::new(0.0f64, 0.0f64)); + let l8 = Line::new(Point2::new(0.0f64, 0.5f64), Point2::new(0.0f64, -0.5f64)); + assert_eq!((l7, l8).intersection(), Some(Point2::new(0.0f64, 0.5f64))); // collinear, no overlap - let l9 = Line::new(Point2::new(0.0, 0.0), Point2::new(3.0, 0.0)); - let l10 = Line::new(Point2::new(10.0, 0.0), Point2::new(5.0, 0.0)); + let l9 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(3.0f64, 0.0f64)); + let l10 = Line::new(Point2::new(10.0f64, 0.0f64), Point2::new(5.0f64, 0.0f64)); assert_eq!((l9, l10).intersection(), None); // intersection found - let l11 = Line::new(Point2::new(0.0, 0.0), Point2::new(10.0, 10.0)); - let l12 = Line::new(Point2::new(0.0, 10.0), Point2::new(10.0, 0.0)); - assert_eq!((l11, l12).intersection(), Some(Point2::new(5.0, 5.0))); + let l11 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(10.0f64, 10.0f64)); + let l12 = Line::new(Point2::new(0.0f64, 10.0f64), Point2::new(10.0f64, 0.0f64)); + assert_eq!((l11, l12).intersection(), Some(Point2::new(5.0f64, 5.0f64))); // special case of both lines being the same point - let l13 = Line::new(Point2::new(0.0, 0.0), Point2::new(0.0, 0.0)); - let l14 = Line::new(Point2::new(0.0, 0.0), Point2::new(0.0, 0.0)); - assert_eq!((l13, l14).intersection(), Some(Point2::new(0.0, 0.0))); + let l13 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(0.0f64, 0.0f64)); + let l14 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(0.0f64, 0.0f64)); + assert_eq!((l13, l14).intersection(), Some(Point2::new(0.0f64, 0.0f64))); // both lines are points that are distinct - let l15 = Line::new(Point2::new(0.0, 0.0), Point2::new(0.0, 0.0)); - let l16 = Line::new(Point2::new(1.0, 0.0), Point2::new(1.0, 0.0)); + let l15 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(0.0f64, 0.0f64)); + let l16 = Line::new(Point2::new(1.0f64, 0.0f64), Point2::new(1.0f64, 0.0f64)); assert_eq!((l15, l16).intersection(), None); // one line is a point that intersects the other segment - let l15 = Line::new(Point2::new(0.0, 0.0), Point2::new(10.0, 0.0)); - let l16 = Line::new(Point2::new(3.0, 0.0), Point2::new(3.0, 0.0)); - assert_eq!((l15, l16).intersection(), Some(Point2::new(3.0, 0.0))); + let l15 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(10.0f64, 0.0f64)); + let l16 = Line::new(Point2::new(3.0f64, 0.0f64), Point2::new(3.0f64, 0.0f64)); + assert_eq!((l15, l16).intersection(), Some(Point2::new(3.0f64, 0.0f64))); // one line is a point that is collinear but does not intersect with // the other line - let l17 = Line::new(Point2::new(0.0, 0.0), Point2::new(0.0, 0.0)); - let l18 = Line::new(Point2::new(1.0, 0.0), Point2::new(3.0, 0.0)); + let l17 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(0.0f64, 0.0f64)); + let l18 = Line::new(Point2::new(1.0f64, 0.0f64), Point2::new(3.0f64, 0.0f64)); assert_eq!((l17, l18).intersection(), None); // one line is a point that is not collinear but does not intersect // with the other line - let l19 = Line::new(Point2::new(0.0, 0.0), Point2::new(0.0, 0.0)); - let l20 = Line::new(Point2::new(1.0, 0.0), Point2::new(2.0, 10.0)); + let l19 = Line::new(Point2::new(0.0f64, 0.0f64), Point2::new(0.0f64, 0.0f64)); + let l20 = Line::new(Point2::new(1.0f64, 0.0f64), Point2::new(2.0f64, 10.0f64)); assert_eq!((l19, l20).intersection(), None); } diff --git a/src/test/matrix.rs b/src/test/matrix.rs index 4c5f66c..4eedc35 100644 --- a/src/test/matrix.rs +++ b/src/test/matrix.rs @@ -21,14 +21,14 @@ pub mod matrix2 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Matrix2 = Matrix2 { x: Vector2 { x: 1.0, y: 3.0 }, - y: Vector2 { x: 2.0, y: 4.0 } }; - pub static B: Matrix2 = Matrix2 { x: Vector2 { x: 2.0, y: 4.0 }, - y: Vector2 { x: 3.0, y: 5.0 } }; - pub static C: Matrix2 = Matrix2 { x: Vector2 { x: 2.0, y: 1.0 }, - y: Vector2 { x: 1.0, y: 2.0 } }; + pub static A: Matrix2 = Matrix2 { x: Vector2 { x: 1.0f64, y: 3.0f64 }, + y: Vector2 { x: 2.0f64, y: 4.0f64 } }; + pub static B: Matrix2 = Matrix2 { x: Vector2 { x: 2.0f64, y: 4.0f64 }, + y: Vector2 { x: 3.0f64, y: 5.0f64 } }; + pub static C: Matrix2 = Matrix2 { x: Vector2 { x: 2.0f64, y: 1.0f64 }, + y: Vector2 { x: 1.0f64, y: 2.0f64 } }; - pub static V: Vector2 = Vector2 { x: 1.0, y: 2.0 }; + pub static V: Vector2 = Vector2 { x: 1.0f64, y: 2.0f64 }; pub static F: f64 = 0.5; } @@ -36,20 +36,20 @@ pub mod matrix3 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Matrix3 = Matrix3 { x: Vector3 { x: 1.0, y: 4.0, z: 7.0 }, - y: Vector3 { x: 2.0, y: 5.0, z: 8.0 }, - z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } }; - pub static B: Matrix3 = Matrix3 { x: Vector3 { x: 2.0, y: 5.0, z: 8.0 }, - y: Vector3 { x: 3.0, y: 6.0, z: 9.0 }, - z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } }; - pub static C: Matrix3 = Matrix3 { x: Vector3 { x: 2.0, y: 4.0, z: 6.0 }, - y: Vector3 { x: 0.0, y: 2.0, z: 4.0 }, - z: Vector3 { x: 0.0, y: 0.0, z: 1.0 } }; - pub static D: Matrix3 = Matrix3 { x: Vector3 { x: 3.0, y: 2.0, z: 1.0 }, - y: Vector3 { x: 2.0, y: 3.0, z: 2.0 }, - z: Vector3 { x: 1.0, y: 2.0, z: 3.0 } }; + pub static A: Matrix3 = Matrix3 { x: Vector3 { x: 1.0f64, y: 4.0f64, z: 7.0f64 }, + y: Vector3 { x: 2.0f64, y: 5.0f64, z: 8.0f64 }, + z: Vector3 { x: 3.0f64, y: 6.0f64, z: 9.0f64 } }; + pub static B: Matrix3 = Matrix3 { x: Vector3 { x: 2.0f64, y: 5.0f64, z: 8.0f64 }, + y: Vector3 { x: 3.0f64, y: 6.0f64, z: 9.0f64 }, + z: Vector3 { x: 4.0f64, y: 7.0f64, z: 10.0f64 } }; + pub static C: Matrix3 = Matrix3 { x: Vector3 { x: 2.0f64, y: 4.0f64, z: 6.0f64 }, + y: Vector3 { x: 0.0f64, y: 2.0f64, z: 4.0f64 }, + z: Vector3 { x: 0.0f64, y: 0.0f64, z: 1.0f64 } }; + pub static D: Matrix3 = Matrix3 { x: Vector3 { x: 3.0f64, y: 2.0f64, z: 1.0f64 }, + y: Vector3 { x: 2.0f64, y: 3.0f64, z: 2.0f64 }, + z: Vector3 { x: 1.0f64, y: 2.0f64, z: 3.0f64 } }; - pub static V: Vector3 = Vector3 { x: 1.0, y: 2.0, z: 3.0 }; + pub static V: Vector3 = Vector3 { x: 1.0f64, y: 2.0f64, z: 3.0f64 }; pub static F: f64 = 0.5; } @@ -57,24 +57,24 @@ pub mod matrix4 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Matrix4 = Matrix4 { x: Vector4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 }, - y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } }; - pub static B: Matrix4 = Matrix4 { x: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 }, - w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } }; - pub static C: Matrix4 = Matrix4 { x: Vector4 { x: 3.0, y: 2.0, z: 1.0, w: 1.0 }, - y: Vector4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 }, - z: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 }, - w: Vector4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } }; - pub static D: Matrix4 = Matrix4 { x: Vector4 { x: 4.0, y: 3.0, z: 2.0, w: 1.0 }, - y: Vector4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 }, - z: Vector4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 }, - w: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } }; + pub static A: Matrix4 = Matrix4 { x: Vector4 { x: 1.0f64, y: 5.0f64, z: 9.0f64, w: 13.0f64 }, + y: Vector4 { x: 2.0f64, y: 6.0f64, z: 10.0f64, w: 14.0f64 }, + z: Vector4 { x: 3.0f64, y: 7.0f64, z: 11.0f64, w: 15.0f64 }, + w: Vector4 { x: 4.0f64, y: 8.0f64, z: 12.0f64, w: 16.0f64 } }; + pub static B: Matrix4 = Matrix4 { x: Vector4 { x: 2.0f64, y: 6.0f64, z: 10.0f64, w: 14.0f64 }, + y: Vector4 { x: 3.0f64, y: 7.0f64, z: 11.0f64, w: 15.0f64 }, + z: Vector4 { x: 4.0f64, y: 8.0f64, z: 12.0f64, w: 16.0f64 }, + w: Vector4 { x: 5.0f64, y: 9.0f64, z: 13.0f64, w: 17.0f64 } }; + pub static C: Matrix4 = Matrix4 { x: Vector4 { x: 3.0f64, y: 2.0f64, z: 1.0f64, w: 1.0f64 }, + y: Vector4 { x: 2.0f64, y: 3.0f64, z: 2.0f64, w: 2.0f64 }, + z: Vector4 { x: 1.0f64, y: 2.0f64, z: 3.0f64, w: 3.0f64 }, + w: Vector4 { x: 0.0f64, y: 1.0f64, z: 1.0f64, w: 0.0f64 } }; + pub static D: Matrix4 = Matrix4 { x: Vector4 { x: 4.0f64, y: 3.0f64, z: 2.0f64, w: 1.0f64 }, + y: Vector4 { x: 3.0f64, y: 4.0f64, z: 3.0f64, w: 2.0f64 }, + z: Vector4 { x: 2.0f64, y: 3.0f64, z: 4.0f64, w: 3.0f64 }, + w: Vector4 { x: 1.0f64, y: 2.0f64, z: 3.0f64, w: 4.0f64 } }; - pub static V: Vector4 = Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 }; + pub static V: Vector4 = Vector4 { x: 1.0f64, y: 2.0f64, z: 3.0f64, w: 4.0f64 }; pub static F: f64 = 0.5; } @@ -82,46 +82,46 @@ pub mod matrix4 { fn test_neg() { // Matrix2 assert_eq!(-matrix2::A, - Matrix2::new(-1.0, -3.0, - -2.0, -4.0)); + Matrix2::new(-1.0f64, -3.0f64, + -2.0f64, -4.0f64)); // Matrix3 assert_eq!(-matrix3::A, - Matrix3::new(-1.0, -4.0, -7.0, - -2.0, -5.0, -8.0, - -3.0, -6.0, -9.0)); + Matrix3::new(-1.0f64, -4.0f64, -7.0f64, + -2.0f64, -5.0f64, -8.0f64, + -3.0f64, -6.0f64, -9.0f64)); // Matrix4 assert_eq!(-matrix4::A, - Matrix4::new(-1.0, -5.0, -9.0, -13.0, - -2.0, -6.0, -10.0, -14.0, - -3.0, -7.0, -11.0, -15.0, - -4.0, -8.0, -12.0, -16.0)); + Matrix4::new(-1.0f64, -5.0f64, -9.0f64, -13.0f64, + -2.0f64, -6.0f64, -10.0f64, -14.0f64, + -3.0f64, -7.0f64, -11.0f64, -15.0f64, + -4.0f64, -8.0f64, -12.0f64, -16.0f64)); } #[test] fn test_mul_s() { // Matrix2 assert_eq!(matrix2::A.mul_s(matrix2::F), - Matrix2::new(0.5, 1.5, - 1.0, 2.0)); + Matrix2::new(0.5f64, 1.5f64, + 1.0f64, 2.0f64)); let mut mut_a = matrix2::A; mut_a.mul_self_s(matrix2::F); assert_eq!(mut_a, matrix2::A.mul_s(matrix2::F)); // Matrix3 assert_eq!(matrix3::A.mul_s(matrix3::F), - Matrix3::new(0.5, 2.0, 3.5, - 1.0, 2.5, 4.0, - 1.5, 3.0, 4.5)); + Matrix3::new(0.5f64, 2.0f64, 3.5f64, + 1.0f64, 2.5f64, 4.0f64, + 1.5f64, 3.0f64, 4.5f64)); let mut mut_a = matrix3::A; mut_a.mul_self_s(matrix3::F); assert_eq!(mut_a, matrix3::A.mul_s(matrix3::F)); // Matrix4 assert_eq!(matrix4::A.mul_s(matrix4::F), - Matrix4::new(0.5, 2.5, 4.5, 6.5, - 1.0, 3.0, 5.0, 7.0, - 1.5, 3.5, 5.5, 7.5, - 2.0, 4.0, 6.0, 8.0)); + Matrix4::new(0.5f64, 2.5f64, 4.5f64, 6.5f64, + 1.0f64, 3.0f64, 5.0f64, 7.0f64, + 1.5f64, 3.5f64, 5.5f64, 7.5f64, + 2.0f64, 4.0f64, 6.0f64, 8.0f64)); let mut mut_a = matrix4::A; mut_a.mul_self_s(matrix4::F); assert_eq!(mut_a, matrix4::A.mul_s(matrix4::F)); @@ -131,8 +131,8 @@ fn test_mul_s() { fn test_add_m() { // Matrix2 assert_eq!(matrix2::A.add_m(&matrix2::B), - Matrix2::new(3.0, 7.0, - 5.0, 9.0)); + Matrix2::new(3.0f64, 7.0f64, + 5.0f64, 9.0f64)); let mut mut_a = matrix2::A; mut_a.add_self_m(&matrix2::B); assert_eq!(mut_a, matrix2::A.add_m(&matrix2::B)); @@ -140,9 +140,9 @@ fn test_add_m() { // Matrix3 assert_eq!(matrix3::A.add_m(&matrix3::B), - Matrix3::new(3.0, 9.0, 15.0, - 5.0, 11.0, 17.0, - 7.0, 13.0, 19.0)); + Matrix3::new(3.0f64, 9.0f64, 15.0f64, + 5.0f64, 11.0f64, 17.0f64, + 7.0f64, 13.0f64, 19.0f64)); let mut mut_a = matrix3::A; mut_a.add_self_m(&matrix3::B); assert_eq!(mut_a, matrix3::A.add_m(&matrix3::B)); @@ -150,10 +150,10 @@ fn test_add_m() { // Matrix4 assert_eq!(matrix4::A.add_m(&matrix4::B), - Matrix4::new(3.0, 11.0, 19.0, 27.0, - 5.0, 13.0, 21.0, 29.0, - 7.0, 15.0, 23.0, 31.0, - 9.0, 17.0, 25.0, 33.0)); + Matrix4::new(3.0f64, 11.0f64, 19.0f64, 27.0f64, + 5.0f64, 13.0f64, 21.0f64, 29.0f64, + 7.0f64, 15.0f64, 23.0f64, 31.0f64, + 9.0f64, 17.0f64, 25.0f64, 33.0f64)); let mut mut_a = matrix4::A; mut_a.add_self_m(&matrix4::B); assert_eq!(mut_a, matrix4::A.add_m(&matrix4::B)); @@ -164,8 +164,8 @@ fn test_add_m() { fn test_sub_m() { // Matrix2 assert_eq!(matrix2::A.sub_m(&matrix2::B), - Matrix2::new(-1.0, -1.0, - -1.0, -1.0)); + Matrix2::new(-1.0f64, -1.0f64, + -1.0f64, -1.0f64)); let mut mut_a = matrix2::A; mut_a.sub_self_m(&matrix2::B); assert_eq!(mut_a, matrix2::A.sub_m(&matrix2::B)); @@ -173,9 +173,9 @@ fn test_sub_m() { // Matrix3 assert_eq!(matrix3::A.sub_m(&matrix3::B), - Matrix3::new(-1.0, -1.0, -1.0, - -1.0, -1.0, -1.0, - -1.0, -1.0, -1.0)); + Matrix3::new(-1.0f64, -1.0f64, -1.0f64, + -1.0f64, -1.0f64, -1.0f64, + -1.0f64, -1.0f64, -1.0f64)); let mut mut_a = matrix3::A; mut_a.sub_self_m(&matrix3::B); assert_eq!(mut_a, matrix3::A.sub_m(&matrix3::B)); @@ -183,10 +183,10 @@ fn test_sub_m() { // Matrix4 assert_eq!(matrix4::A.sub_m(&matrix4::B), - Matrix4::new(-1.0, -1.0, -1.0, -1.0, - -1.0, -1.0, -1.0, -1.0, - -1.0, -1.0, -1.0, -1.0, - -1.0, -1.0, -1.0, -1.0)); + Matrix4::new(-1.0f64, -1.0f64, -1.0f64, -1.0f64, + -1.0f64, -1.0f64, -1.0f64, -1.0f64, + -1.0f64, -1.0f64, -1.0f64, -1.0f64, + -1.0f64, -1.0f64, -1.0f64, -1.0f64)); let mut mut_a = matrix4::A; mut_a.sub_self_m(&matrix4::B); assert_eq!(mut_a, matrix4::A.sub_m(&matrix4::B)); @@ -195,25 +195,25 @@ fn test_sub_m() { #[test] fn test_mul_v() { - assert_eq!(matrix2::A.mul_v(&matrix2::V), Vector2::new(5.0, 11.0)); - assert_eq!(matrix3::A.mul_v(&matrix3::V), Vector3::new(14.0, 32.0, 50.0)); - assert_eq!(matrix4::A.mul_v(&matrix4::V), Vector4::new(30.0, 70.0, 110.0, 150.0)); + assert_eq!(matrix2::A.mul_v(&matrix2::V), Vector2::new(5.0f64, 11.0f64)); + assert_eq!(matrix3::A.mul_v(&matrix3::V), Vector3::new(14.0f64, 32.0f64, 50.0f64)); + assert_eq!(matrix4::A.mul_v(&matrix4::V), Vector4::new(30.0f64, 70.0f64, 110.0f64, 150.0f64)); } #[test] fn test_mul_m() { assert_eq!(matrix2::A.mul_m(&matrix2::B), - Matrix2::new(10.0, 22.0, - 13.0, 29.0)); + Matrix2::new(10.0f64, 22.0f64, + 13.0f64, 29.0f64)); assert_eq!(matrix3::A.mul_m(&matrix3::B), - Matrix3::new(36.0, 81.0, 126.0, - 42.0, 96.0, 150.0, - 48.0, 111.0, 174.0)); + Matrix3::new(36.0f64, 81.0f64, 126.0f64, + 42.0f64, 96.0f64, 150.0f64, + 48.0f64, 111.0f64, 174.0f64)); assert_eq!(matrix4::A.mul_m(&matrix4::B), - Matrix4::new(100.0, 228.0, 356.0, 484.0, - 110.0, 254.0, 398.0, 542.0, - 120.0, 280.0, 440.0, 600.0, - 130.0, 306.0, 482.0, 658.0)); + Matrix4::new(100.0f64, 228.0f64, 356.0f64, 484.0f64, + 110.0f64, 254.0f64, 398.0f64, 542.0f64, + 120.0f64, 280.0f64, 440.0f64, 600.0f64, + 130.0f64, 306.0f64, 482.0f64, 658.0f64)); assert_eq!(matrix2::A.mul_m(&matrix2::B), matrix2::A * matrix2::B); assert_eq!(matrix3::A.mul_m(&matrix3::B), matrix3::A * matrix3::B); @@ -222,43 +222,43 @@ fn test_mul_m() { #[test] fn test_determinant() { - assert_eq!(matrix2::A.determinant(), -2.0); - assert_eq!(matrix3::A.determinant(), 0.0); - assert_eq!(matrix4::A.determinant(), 0.0); + assert_eq!(matrix2::A.determinant(), -2.0f64); + assert_eq!(matrix3::A.determinant(), 0.0f64); + assert_eq!(matrix4::A.determinant(), 0.0f64); } #[test] fn test_trace() { - assert_eq!(matrix2::A.trace(), 5.0); - assert_eq!(matrix3::A.trace(), 15.0); - assert_eq!(matrix4::A.trace(), 34.0); + assert_eq!(matrix2::A.trace(), 5.0f64); + assert_eq!(matrix3::A.trace(), 15.0f64); + assert_eq!(matrix4::A.trace(), 34.0f64); } #[test] fn test_transpose() { // Matrix2 assert_eq!(matrix2::A.transpose(), - Matrix2::::new(1.0, 2.0, - 3.0, 4.0)); + Matrix2::::new(1.0f64, 2.0f64, + 3.0f64, 4.0f64)); let mut mut_a = matrix2::A; mut_a.transpose_self(); assert_eq!(mut_a, matrix2::A.transpose()); // Matrix3 assert_eq!(matrix3::A.transpose(), - Matrix3::::new(1.0, 2.0, 3.0, - 4.0, 5.0, 6.0, - 7.0, 8.0, 9.0)); + Matrix3::::new(1.0f64, 2.0f64, 3.0f64, + 4.0f64, 5.0f64, 6.0f64, + 7.0f64, 8.0f64, 9.0f64)); let mut mut_a = matrix3::A; mut_a.transpose_self(); assert_eq!(mut_a, matrix3::A.transpose()); // Matrix4 assert_eq!(matrix4::A.transpose(), - Matrix4::::new( 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 10.0, 11.0, 12.0, - 13.0, 14.0, 15.0, 16.0)); + Matrix4::::new( 1.0f64, 2.0f64, 3.0f64, 4.0f64, + 5.0f64, 6.0f64, 7.0f64, 8.0f64, + 9.0f64, 10.0f64, 11.0f64, 12.0f64, + 13.0f64, 14.0f64, 15.0f64, 16.0f64)); let mut mut_a = matrix4::A; mut_a.transpose_self(); assert_eq!(mut_a, matrix4::A.transpose()); @@ -270,10 +270,10 @@ fn test_invert() { assert!(Matrix2::::identity().invert().unwrap().is_identity()); assert_eq!(matrix2::A.invert().unwrap(), - Matrix2::new(-2.0, 1.5, - 1.0, -0.5)); - assert!(Matrix2::new(0.0, 2.0, - 0.0, 5.0).invert().is_none()); + Matrix2::new(-2.0f64, 1.5f64, + 1.0f64, -0.5f64)); + assert!(Matrix2::new(0.0f64, 2.0f64, + 0.0f64, 5.0f64).invert().is_none()); let mut mut_a = matrix2::A; mut_a.invert_self(); assert_eq!(mut_a, matrix2::A.invert().unwrap()); @@ -284,9 +284,9 @@ fn test_invert() { assert_eq!(matrix3::A.invert(), None); assert_eq!(matrix3::C.invert().unwrap(), - Matrix3::new(0.5, -1.0, 1.0, - 0.0, 0.5, -2.0, - 0.0, 0.0, 1.0)); + Matrix3::new(0.5f64, -1.0f64, 1.0f64, + 0.0f64, 0.5f64, -2.0f64, + 0.0f64, 0.0f64, 1.0f64)); let mut mut_c = matrix3::C; mut_c.invert_self(); assert_eq!(mut_c, matrix3::C.invert().unwrap()); @@ -295,36 +295,36 @@ fn test_invert() { assert!(Matrix4::::identity().invert().unwrap().is_identity()); assert!(matrix4::C.invert().unwrap().approx_eq(& - Matrix4::new( 5.0, -4.0, 1.0, 0.0, - -4.0, 8.0, -4.0, 0.0, - 4.0, -8.0, 4.0, 8.0, - -3.0, 4.0, 1.0, -8.0).mul_s(0.125))); + Matrix4::new( 5.0f64, -4.0f64, 1.0f64, 0.0f64, + -4.0f64, 8.0f64, -4.0f64, 0.0f64, + 4.0f64, -8.0f64, 4.0f64, 8.0f64, + -3.0f64, 4.0f64, 1.0f64, -8.0f64).mul_s(0.125f64))); let mut mut_c = matrix4::C; mut_c.invert_self(); assert_eq!(mut_c, matrix4::C.invert().unwrap()); - let mat_c = Matrix4::new(-0.131917, -0.76871, 0.625846, 0., - -0., 0.631364, 0.775487, 0., - -0.991261, 0.1023, -0.083287, 0., - 0., -1.262728, -1.550973, 1.); + let mat_c = Matrix4::new(-0.131917f64, -0.76871f64, 0.625846f64, 0.0f64, + -0., 0.631364f64, 0.775487f64, 0.0f64, + -0.991261f64, 0.1023f64, -0.083287f64, 0.0f64, + 0., -1.262728f64, -1.550973f64, 1.0f64); assert!(mat_c.invert().unwrap().mul_m(&mat_c).is_identity()); - let mat_d = Matrix4::new( 0.065455, -0.720002, 0.690879, 0., - -0., 0.692364, 0.721549, 0., - -0.997856, -0.047229, 0.045318, 0., - 0., -1.384727, -1.443098, 1.); + let mat_d = Matrix4::new( 0.065455f64, -0.720002f64, 0.690879f64, 0.0f64, + -0., 0.692364f64, 0.721549f64, 0.0f64, + -0.997856f64, -0.047229f64, 0.045318f64, 0.0f64, + 0., -1.384727f64, -1.443098f64, 1.0f64); assert!(mat_d.invert().unwrap().mul_m(&mat_d).is_identity()); - let mat_e = Matrix4::new( 0.409936, 0.683812, -0.603617, 0., - 0., 0.661778, 0.7497, 0., - 0.912114, -0.307329, 0.271286, 0., - -0., -1.323555, -1.499401, 1.); + let mat_e = Matrix4::new( 0.409936f64, 0.683812f64, -0.603617f64, 0.0f64, + 0., 0.661778f64, 0.7497f64, 0.0f64, + 0.912114f64, -0.307329f64, 0.271286f64, 0.0f64, + -0., -1.323555f64, -1.499401f64, 1.0f64); assert!(mat_e.invert().unwrap().mul_m(&mat_e).is_identity()); - let mat_f = Matrix4::new(-0.160691, -0.772608, 0.614211, 0., - -0., 0.622298, 0.78278, 0., - -0.987005, 0.125786, -0.099998, 0., - 0., -1.244597, -1.565561, 1.); + let mat_f = Matrix4::new(-0.160691f64, -0.772608f64, 0.614211f64, 0.0f64, + -0., 0.622298f64, 0.78278f64, 0.0f64, + -0.987005f64, 0.125786f64, -0.099998f64, 0.0f64, + 0., -1.244597f64, -1.565561f64, 1.0f64); assert!(mat_f.invert().unwrap().mul_m(&mat_f).is_identity()); } @@ -347,7 +347,7 @@ fn test_predicates() { assert!(!matrix2::C.is_diagonal()); assert!(matrix2::C.is_invertible()); - assert!(Matrix2::from_value(6.0).is_diagonal()); + assert!(Matrix2::from_value(6.0f64).is_diagonal()); // Matrix3 @@ -366,7 +366,7 @@ fn test_predicates() { assert!(!matrix3::D.is_diagonal()); assert!(matrix3::D.is_invertible()); - assert!(Matrix3::from_value(6.0).is_diagonal()); + assert!(Matrix3::from_value(6.0f64).is_diagonal()); // Matrix4 @@ -385,5 +385,5 @@ fn test_predicates() { assert!(!matrix4::D.is_diagonal()); assert!(matrix4::D.is_invertible()); - assert!(Matrix4::from_value(6.0).is_diagonal()); + assert!(Matrix4::from_value(6.0f64).is_diagonal()); } diff --git a/src/test/plane.rs b/src/test/plane.rs index e297b9c..823d023 100644 --- a/src/test/plane.rs +++ b/src/test/plane.rs @@ -21,14 +21,14 @@ use cgmath::intersect::Intersect; #[test] fn test_from_points() { - assert_eq!(Plane::from_points(Point3::new(5.0, 0.0, 5.0), - Point3::new(5.0, 5.0, 5.0), - Point3::new(5.0, 0.0, -1.0)), - Some(Plane::from_abcd(-1.0, 0.0, 0.0, 5.0))); + assert_eq!(Plane::from_points(Point3::new(5.0f64, 0.0f64, 5.0f64), + Point3::new(5.0f64, 5.0f64, 5.0f64), + Point3::new(5.0f64, 0.0f64, -1.0f64)), + Some(Plane::from_abcd(-1.0f64, 0.0f64, 0.0f64, 5.0f64))); - assert_eq!(Plane::from_points(Point3::new(0.0, 5.0, -5.0), - Point3::new(0.0, 5.0, 0.0), - Point3::new(0.0, 5.0, 5.0)), + assert_eq!(Plane::from_points(Point3::new(0.0f64, 5.0f64, -5.0f64), + Point3::new(0.0f64, 5.0f64, 0.0f64), + Point3::new(0.0f64, 5.0f64, 5.0f64)), None); // The points are parallel } diff --git a/src/test/point.rs b/src/test/point.rs index 4b5f206..938800b 100644 --- a/src/test/point.rs +++ b/src/test/point.rs @@ -18,6 +18,6 @@ use cgmath::approx::ApproxEq; #[test] fn test_homogeneous() { - let p = Point3::new(1.0, 2.0, 3.0); + let p = Point3::new(1.0f64, 2.0f64, 3.0f64); assert!(p.approx_eq( &Point3::from_homogeneous( &p.to_homogeneous() ) )); } diff --git a/src/test/transform.rs b/src/test/transform.rs index ed9df02..526841b 100644 --- a/src/test/transform.rs +++ b/src/test/transform.rs @@ -21,11 +21,11 @@ use cgmath::approx::ApproxEq; #[test] fn test_invert() { - let v = Vector3::new(1.0, 2.0, 3.0); + let v = Vector3::new(1.0f64, 2.0f64, 3.0f64); let t = Decomposed { - scale: 1.5, - rot: Quaternion::new(0.5,0.5,0.5,0.5), - disp: Vector3::new(6.0,-7.0,8.0) + scale: 1.5f64, + rot: Quaternion::new(0.5f64,0.5,0.5,0.5), + disp: Vector3::new(6.0f64,-7.0f64,8.0) }; let ti = t.invert().expect("Expected successful inversion"); let vt = t.transform_vector( &v ); @@ -34,11 +34,11 @@ fn test_invert() { #[test] fn test_look_at() { - let eye = Point3::new(0.0, 0.0, -5.0); - let center = Point3::new(0.0, 0.0, 0.0); - let up = Vector3::new(1.0, 0.0, 0.0); + let eye = Point3::new(0.0f64, 0.0f64, -5.0f64); + let center = Point3::new(0.0f64, 0.0f64, 0.0f64); + let up = Vector3::new(1.0f64, 0.0f64, 0.0f64); let t: Decomposed,Quaternion> = Transform::look_at(&eye, ¢er, &up); - let point = Point3::new(1.0, 0.0, 0.0); - let view_point = Point3::new(0.0, 1.0, 5.0); + let point = Point3::new(1.0f64, 0.0f64, 0.0f64); + let view_point = Point3::new(0.0f64, 1.0f64, 5.0f64); assert!( t.transform_point(&point).approx_eq(&view_point) ); } diff --git a/src/test/vector.rs b/src/test/vector.rs index 3ca9e50..9f1a5d2 100644 --- a/src/test/vector.rs +++ b/src/test/vector.rs @@ -19,67 +19,67 @@ use cgmath::approx::ApproxEq; #[test] fn test_from_value() { - assert_eq!(Vector2::from_value(102), Vector2::new(102, 102)); - assert_eq!(Vector3::from_value(22), Vector3::new(22, 22, 22)); - assert_eq!(Vector4::from_value(76.5), Vector4::new(76.5, 76.5, 76.5, 76.5)); + assert_eq!(Vector2::from_value(102i), Vector2::new(102i, 102i)); + assert_eq!(Vector3::from_value(22i), Vector3::new(22i, 22i, 22i)); + assert_eq!(Vector4::from_value(76.5f64), Vector4::new(76.5f64, 76.5f64, 76.5f64, 76.5f64)); } #[test] fn test_dot() { - assert_eq!(Vector2::new(1, 2).dot(&Vector2::new(3, 4)), 11); - assert_eq!(Vector3::new(1, 2, 3).dot(&Vector3::new(4, 5, 6)), 32); - assert_eq!(Vector4::new(1, 2, 3, 4).dot(&Vector4::new(5, 6, 7, 8)), 70); + assert_eq!(Vector2::new(1i, 2i).dot(&Vector2::new(3i, 4i)), 11i); + assert_eq!(Vector3::new(1i, 2i, 3i).dot(&Vector3::new(4i, 5i, 6i)), 32i); + assert_eq!(Vector4::new(1i, 2i, 3i, 4i).dot(&Vector4::new(5i, 6i, 7i, 8i)), 70i); } #[test] fn test_comp_add() { - assert_eq!(Vector2::new(1, 2).comp_add(), 3); - assert_eq!(Vector3::new(1, 2, 3).comp_add(), 6); - assert_eq!(Vector4::new(1, 2, 3, 4).comp_add(), 10); + assert_eq!(Vector2::new(1i, 2i).comp_add(), 3i); + assert_eq!(Vector3::new(1i, 2i, 3i).comp_add(), 6i); + assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_add(), 10i); - assert_eq!(Vector2::new(3.0, 4.0).comp_add(), 7.0); - assert_eq!(Vector3::new(4.0, 5.0, 6.0).comp_add(), 15.0); - assert_eq!(Vector4::new(5.0, 6.0, 7.0, 8.0).comp_add(), 26.0); + assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_add(), 7.0f64); + assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_add(), 15.0f64); + assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_add(), 26.0f64); } #[test] fn test_comp_mul() { - assert_eq!(Vector2::new(1, 2).comp_mul(), 2); - assert_eq!(Vector3::new(1, 2, 3).comp_mul(), 6); - assert_eq!(Vector4::new(1, 2, 3, 4).comp_mul(), 24); + assert_eq!(Vector2::new(1i, 2i).comp_mul(), 2i); + assert_eq!(Vector3::new(1i, 2i, 3i).comp_mul(), 6i); + assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_mul(), 24i); - assert_eq!(Vector2::new(3.0, 4.0).comp_mul(), 12.0); - assert_eq!(Vector3::new(4.0, 5.0, 6.0).comp_mul(), 120.0); - assert_eq!(Vector4::new(5.0, 6.0, 7.0, 8.0).comp_mul(), 1680.0); + assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_mul(), 12.0f64); + assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_mul(), 120.0f64); + assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_mul(), 1680.0f64); } #[test] fn test_comp_min() { - assert_eq!(Vector2::new(1, 2).comp_min(), 1); - assert_eq!(Vector3::new(1, 2, 3).comp_min(), 1); - assert_eq!(Vector4::new(1, 2, 3, 4).comp_min(), 1); + assert_eq!(Vector2::new(1i, 2i).comp_min(), 1i); + assert_eq!(Vector3::new(1i, 2i, 3i).comp_min(), 1i); + assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_min(), 1i); - assert_eq!(Vector2::new(3.0, 4.0).comp_min(), 3.0); - assert_eq!(Vector3::new(4.0, 5.0, 6.0).comp_min(), 4.0); - assert_eq!(Vector4::new(5.0, 6.0, 7.0, 8.0).comp_min(), 5.0); + assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_min(), 3.0f64); + assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_min(), 4.0f64); + assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_min(), 5.0f64); } #[test] fn test_comp_max() { - assert_eq!(Vector2::new(1, 2).comp_max(), 2); - assert_eq!(Vector3::new(1, 2, 3).comp_max(), 3); - assert_eq!(Vector4::new(1, 2, 3, 4).comp_max(), 4); + assert_eq!(Vector2::new(1i, 2i).comp_max(), 2i); + assert_eq!(Vector3::new(1i, 2i, 3i).comp_max(), 3i); + assert_eq!(Vector4::new(1i, 2i, 3i, 4i).comp_max(), 4i); - assert_eq!(Vector2::new(3.0, 4.0).comp_max(), 4.0); - assert_eq!(Vector3::new(4.0, 5.0, 6.0).comp_max(), 6.0); - assert_eq!(Vector4::new(5.0, 6.0, 7.0, 8.0).comp_max(), 8.0); + assert_eq!(Vector2::new(3.0f64, 4.0f64).comp_max(), 4.0f64); + assert_eq!(Vector3::new(4.0f64, 5.0f64, 6.0f64).comp_max(), 6.0f64); + assert_eq!(Vector4::new(5.0f64, 6.0f64, 7.0f64, 8.0f64).comp_max(), 8.0f64); } #[test] fn test_cross() { - let a = Vector3::new(1, 2, 3); - let b = Vector3::new(4, 5, 6); - let r = Vector3::new(-3, 6, -3); + let a = Vector3::new(1i, 2i, 3i); + let b = Vector3::new(4i, 5i, 6i); + let r = Vector3::new(-3i, 6i, -3i); assert_eq!(a.cross(&b), r); let mut a = a; @@ -89,9 +89,9 @@ fn test_cross() { #[test] fn test_is_perpendicular() { - assert!(Vector2::new(1.0, 0.0).is_perpendicular(&Vector2::new(0.0, 1.0))); - assert!(Vector3::new(0.0, 1.0, 0.0).is_perpendicular(&Vector3::new(0.0, 0.0, 1.0))); - assert!(Vector4::new(1.0, 0.0, 0.0, 0.0).is_perpendicular(&Vector4::new(0.0, 0.0, 0.0, 1.0))); + assert!(Vector2::new(1.0f64, 0.0f64).is_perpendicular(&Vector2::new(0.0f64, 1.0f64))); + assert!(Vector3::new(0.0f64, 1.0f64, 0.0f64).is_perpendicular(&Vector3::new(0.0f64, 0.0f64, 1.0f64))); + assert!(Vector4::new(1.0f64, 0.0f64, 0.0f64, 0.0f64).is_perpendicular(&Vector4::new(0.0f64, 0.0f64, 0.0f64, 1.0f64))); } #[cfg(test)] @@ -100,8 +100,8 @@ mod test_length { #[test] fn test_vector2(){ - let (a, a_res) = (Vector2::new(3.0, 4.0), 5.0); // (3, 4, 5) Pythagorean triple - let (b, b_res) = (Vector2::new(5.0, 12.0), 13.0); // (5, 12, 13) Pythagorean triple + let (a, a_res) = (Vector2::new(3.0f64, 4.0f64), 5.0f64); // (3i, 4i, 5i) Pythagorean triple + let (b, b_res) = (Vector2::new(5.0f64, 12.0f64), 13.0f64); // (5i, 12i, 13i) Pythagorean triple assert_eq!(a.length2(), a_res * a_res); assert_eq!(b.length2(), b_res * b_res); @@ -112,8 +112,8 @@ mod test_length { #[test] fn test_vector3(){ - let (a, a_res) = (Vector3::new(2.0, 3.0, 6.0), 7.0); // (2, 3, 6, 7) Pythagorean quadruple - let (b, b_res) = (Vector3::new(1.0, 4.0, 8.0), 9.0); // (1, 4, 8, 9) Pythagorean quadruple + let (a, a_res) = (Vector3::new(2.0f64, 3.0f64, 6.0f64), 7.0f64); // (2i, 3i, 6i, 7i) Pythagorean quadruple + let (b, b_res) = (Vector3::new(1.0f64, 4.0f64, 8.0f64), 9.0f64); // (1i, 4i, 8i, 9i) Pythagorean quadruple assert_eq!(a.length2(), a_res * a_res); assert_eq!(b.length2(), b_res * b_res); @@ -124,8 +124,8 @@ mod test_length { #[test] fn test_vector4(){ - let (a, a_res) = (Vector4::new(1.0, 2.0, 4.0, 10.0), 11.0); // (1, 2, 4, 10, 11) Pythagorean quintuple - let (b, b_res) = (Vector4::new(1.0, 2.0, 8.0, 10.0), 13.0); // (1, 2, 8, 10, 13) Pythagorean quintuple + let (a, a_res) = (Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64), 11.0f64); // (1i, 2i, 4i, 10i, 11i) Pythagorean quintuple + let (b, b_res) = (Vector4::new(1.0f64, 2.0f64, 8.0f64, 10.0f64), 13.0f64); // (1i, 2i, 8i, 10i, 13i) Pythagorean quintuple assert_eq!(a.length2(), a_res * a_res); assert_eq!(b.length2(), b_res * b_res); @@ -137,23 +137,23 @@ mod test_length { #[test] fn test_angle() { - assert!(Vector2::new(1.0, 0.0).angle(&Vector2::new(0.0, 1.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vector2::new(10.0, 0.0).angle(&Vector2::new(0.0, 5.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vector2::new(-1.0, 0.0).angle(&Vector2::new(0.0, 1.0)).approx_eq( &-rad(Float::frac_pi_2()) )); + assert!(Vector2::new(1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &rad(Float::frac_pi_2()) )); + assert!(Vector2::new(10.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 5.0f64)).approx_eq( &rad(Float::frac_pi_2()) )); + assert!(Vector2::new(-1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &-rad(Float::frac_pi_2()) )); - assert!(Vector3::new(1.0, 0.0, 1.0).angle(&Vector3::new(1.0, 1.0, 0.0)).approx_eq( &rad(Float::frac_pi_3()) )); - assert!(Vector3::new(10.0, 0.0, 10.0).angle(&Vector3::new(5.0, 5.0, 0.0)).approx_eq( &rad(Float::frac_pi_3()) )); - assert!(Vector3::new(-1.0, 0.0, -1.0).angle(&Vector3::new(1.0, -1.0, 0.0)).approx_eq( &rad(2.0 * Float::frac_pi_3()) )); + assert!(Vector3::new(1.0f64, 0.0f64, 1.0f64).angle(&Vector3::new(1.0f64, 1.0f64, 0.0f64)).approx_eq( &rad(Float::frac_pi_3()) )); + assert!(Vector3::new(10.0f64, 0.0f64, 10.0f64).angle(&Vector3::new(5.0f64, 5.0f64, 0.0f64)).approx_eq( &rad(Float::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 * Float::frac_pi_3()) )); - assert!(Vector4::new(1.0, 0.0, 1.0, 0.0).angle(&Vector4::new(0.0, 1.0, 0.0, 1.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vector4::new(10.0, 0.0, 10.0, 0.0).angle(&Vector4::new(0.0, 5.0, 0.0, 5.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vector4::new(-1.0, 0.0, -1.0, 0.0).angle(&Vector4::new(0.0, 1.0, 0.0, 1.0)).approx_eq( &rad(Float::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(Float::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(Float::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(Float::frac_pi_2()) )); } #[test] fn test_normalize() { // TODO: test normalize_to, normalize_sel.0, and normalize_self_to - assert!(Vector2::new(3.0, 4.0).normalize().approx_eq( &Vector2::new(3.0/5.0, 4.0/5.0) )); - assert!(Vector3::new(2.0, 3.0, 6.0).normalize().approx_eq( &Vector3::new(2.0/7.0, 3.0/7.0, 6.0/7.0) )); - assert!(Vector4::new(1.0, 2.0, 4.0, 10.0).normalize().approx_eq( &Vector4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) )); + assert!(Vector2::new(3.0f64, 4.0f64).normalize().approx_eq( &Vector2::new(3.0/5.0, 4.0/5.0) )); + assert!(Vector3::new(2.0f64, 3.0f64, 6.0f64).normalize().approx_eq( &Vector3::new(2.0/7.0, 3.0/7.0, 6.0/7.0) )); + assert!(Vector4::new(1.0f64, 2.0f64, 4.0f64, 10.0f64).normalize().approx_eq( &Vector4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) )); }