diff --git a/src/bench/matrix.rs b/src/bench/matrix.rs index 7545aaa..51389a8 100644 --- a/src/bench/matrix.rs +++ b/src/bench/matrix.rs @@ -20,462 +20,462 @@ use extra; type float = f32; -pub mod mat2 { +pub mod matrix2 { use cgmath::matrix::*; use cgmath::vector::*; type float = f32; - pub static A: Mat2 = Mat2 { x: Vec2 { x: 1.0, y: 3.0 }, - y: Vec2 { x: 2.0, y: 4.0 } }; - pub static B: Mat2 = Mat2 { x: Vec2 { x: 2.0, y: 4.0 }, - y: Vec2 { x: 3.0, y: 5.0 } }; + 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 mod mat3 { +pub mod matrix3 { use cgmath::matrix::*; use cgmath::vector::*; type float = f32; - pub static A: Mat3 = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 }, - y: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, - z: Vec3 { x: 3.0, y: 6.0, z: 9.0 } }; - pub static B: Mat3 = Mat3 { x: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, - y: Vec3 { x: 3.0, y: 6.0, z: 9.0 }, - z: Vec3 { x: 4.0, y: 7.0, z: 10.0 } }; + 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 mod mat4 { +pub mod matrix4 { use cgmath::matrix::*; use cgmath::vector::*; type float = f32; - pub static A: Mat4 = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 }, - y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - z: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - w: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } }; - pub static B: Mat4 = Mat4 { x: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - y: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - z: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 }, - w: Vec4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } }; + 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 } }; } #[bench] -fn bench_mat2_mul_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_mul_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_m(&mat2::B); + matrix_a = matrix_a.mul_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_mul_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_mul_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_m(&mat3::B); + matrix_a = matrix_a.mul_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_mul_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_mul_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_m(&mat4::B); + matrix_a = matrix_a.mul_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_add_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_add_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.add_m(&mat2::B); + matrix_a = matrix_a.add_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_add_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_add_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.add_m(&mat3::B); + matrix_a = matrix_a.add_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_add_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_add_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.add_m(&mat4::B); + matrix_a = matrix_a.add_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_sub_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_sub_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.sub_m(&mat2::B); + matrix_a = matrix_a.sub_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_sub_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_sub_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.sub_m(&mat3::B); + matrix_a = matrix_a.sub_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_sub_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_sub_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.sub_m(&mat4::B); + matrix_a = matrix_a.sub_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_mul_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_mul_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_s(2.0); + matrix_a = matrix_a.mul_s(2.0); } }) } #[bench] -fn bench_mat3_mul_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_mul_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_s(2.0); + matrix_a = matrix_a.mul_s(2.0); } }) } #[bench] -fn bench_mat4_mul_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_mul_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.mul_s(2.0); + matrix_a = matrix_a.mul_s(2.0); } }) } #[bench] -fn bench_mat2_div_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_div_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.div_s(2.); + matrix_a = matrix_a.div_s(2.); } }) } #[bench] -fn bench_mat3_div_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_div_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.div_s(2.); + matrix_a = matrix_a.div_s(2.); } }) } #[bench] -fn bench_mat4_div_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_div_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.div_s(2.); + matrix_a = matrix_a.div_s(2.); } }) } #[bench] -fn bench_mat2_rem_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_rem_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.rem_s(2.); + matrix_a = matrix_a.rem_s(2.); } }) } #[bench] -fn bench_mat3_rem_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_rem_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.rem_s(2.); + matrix_a = matrix_a.rem_s(2.); } }) } #[bench] -fn bench_mat4_rem_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_rem_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.rem_s(2.); + matrix_a = matrix_a.rem_s(2.); } }) } #[bench] -fn bench_mat2_neg_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_neg_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.neg_self(); + matrix_a.neg_self(); } }) } #[bench] -fn bench_mat3_neg_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_neg_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.neg_self(); + matrix_a.neg_self(); } }) } #[bench] -fn bench_mat4_neg_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_neg_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.neg_self(); + matrix_a.neg_self(); } }) } #[bench] -fn bench_mat2_div_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_div_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.div_self_s(2.); + matrix_a.div_self_s(2.); } }) } #[bench] -fn bench_mat3_div_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_div_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.div_self_s(2.); + matrix_a.div_self_s(2.); } }) } #[bench] -fn bench_mat4_div_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_div_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.div_self_s(2.); + matrix_a.div_self_s(2.); } }) } #[bench] -fn bench_mat2_rem_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_rem_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.rem_self_s(2.); + matrix_a.rem_self_s(2.); } }) } #[bench] -fn bench_mat3_rem_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_rem_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.rem_self_s(2.); + matrix_a.rem_self_s(2.); } }) } #[bench] -fn bench_mat4_rem_self_s(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_rem_self_s(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.rem_self_s(2.); + matrix_a.rem_self_s(2.); } }) } #[bench] -fn bench_mat2_mul_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_mul_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.mul_self_m(&mat2::B); + matrix_a.mul_self_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_mul_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_mul_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.mul_self_m(&mat3::B); + matrix_a.mul_self_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_mul_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_mul_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.mul_self_m(&mat4::B); + matrix_a.mul_self_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_add_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_add_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.add_self_m(&mat2::B); + matrix_a.add_self_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_add_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_add_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.add_self_m(&mat3::B); + matrix_a.add_self_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_add_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_add_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.add_self_m(&mat4::B); + matrix_a.add_self_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_sub_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_sub_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.sub_self_m(&mat2::B); + matrix_a.sub_self_m(&matrix2::B); } }) } #[bench] -fn bench_mat3_sub_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_sub_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.sub_self_m(&mat3::B); + matrix_a.sub_self_m(&matrix3::B); } }) } #[bench] -fn bench_mat4_sub_self_m(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_sub_self_m(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.add_self_m(&mat4::B); + matrix_a.add_self_m(&matrix4::B); } }) } #[bench] -fn bench_mat2_transpose(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_transpose(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.transpose(); + matrix_a = matrix_a.transpose(); } }) } #[bench] -fn bench_mat3_transpose(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_transpose(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.transpose(); + matrix_a = matrix_a.transpose(); } }) } #[bench] -fn bench_mat4_transpose(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_transpose(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a = mat_a.transpose(); + matrix_a = matrix_a.transpose(); } }) } #[bench] -fn bench_mat2_transpose_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat2::A.clone(); +fn bench_matrix2_transpose_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix2::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.transpose_self(); + matrix_a.transpose_self(); } }) } #[bench] -fn bench_mat3_transpose_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat3::A.clone(); +fn bench_matrix3_transpose_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix3::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.transpose_self(); + matrix_a.transpose_self(); } }) } #[bench] -fn bench_mat4_transpose_self(b: &mut extra::test::BenchHarness) { - let mut mat_a = mat4::A.clone(); +fn bench_matrix4_transpose_self(b: &mut extra::test::BenchHarness) { + let mut matrix_a = matrix4::A.clone(); b.iter(|| { for _ in range(0, 1000) { - mat_a.transpose_self(); + matrix_a.transpose_self(); } }) } diff --git a/src/cgmath/aabb.rs b/src/cgmath/aabb.rs index c6532cb..878b8f5 100644 --- a/src/cgmath/aabb.rs +++ b/src/cgmath/aabb.rs @@ -16,7 +16,7 @@ //! Axis-aligned bounding boxes use point::{Point, Point2, Point3}; -use vector::{Vector, Vec2, Vec3}; +use vector::{Vector, Vector2, Vector3}; use array::build; use partial_ord::PartOrdPrim; use std::fmt; @@ -89,7 +89,7 @@ impl Aabb2 { } } -impl Aabb, Point2, [S, ..2]> for Aabb2 { +impl Aabb, Point2, [S, ..2]> for Aabb2 { fn new(p1: Point2, p2: Point2) -> Aabb2 { Aabb2::new(p1, p2) } #[inline] fn min<'a>(&'a self) -> &'a Point2 { &self.min } #[inline] fn max<'a>(&'a self) -> &'a Point2 { &self.max } @@ -122,7 +122,7 @@ impl Aabb3 { } } -impl Aabb, Point3, [S, ..3]> for Aabb3 { +impl Aabb, Point3, [S, ..3]> for Aabb3 { fn new(p1: Point3, p2: Point3) -> Aabb3 { Aabb3::new(p1, p2) } #[inline] fn min<'a>(&'a self) -> &'a Point3 { &self.min } #[inline] fn max<'a>(&'a self) -> &'a Point3 { &self.max } diff --git a/src/cgmath/approx.rs b/src/cgmath/approx.rs index 6d39d9d..9f0b7e0 100644 --- a/src/cgmath/approx.rs +++ b/src/cgmath/approx.rs @@ -16,10 +16,10 @@ use std::num; use array::Array; -use matrix::{Mat2, Mat3, Mat4}; +use matrix::{Matrix2, Matrix3, Matrix4}; use point::{Point2, Point3}; -use quaternion::Quat; -use vector::{Vec2, Vec3, Vec4}; +use quaternion::Quaternion; +use vector::{Vector2, Vector3, Vector4}; pub trait ApproxEq { fn approx_epsilon(_hack: Option) -> T { @@ -62,15 +62,15 @@ macro_rules! approx_array( ) ) -approx_array!(impl Mat2) -approx_array!(impl Mat3) -approx_array!(impl Mat4) +approx_array!(impl Matrix2) +approx_array!(impl Matrix3) +approx_array!(impl Matrix4) -approx_array!(impl Quat) +approx_array!(impl Quaternion) -approx_array!(impl Vec2) -approx_array!(impl Vec3) -approx_array!(impl Vec4) +approx_array!(impl Vector2) +approx_array!(impl Vector3) +approx_array!(impl Vector4) approx_array!(impl Point2) approx_array!(impl Point3) diff --git a/src/cgmath/cylinder.rs b/src/cgmath/cylinder.rs index 32c4298..d1a1089 100644 --- a/src/cgmath/cylinder.rs +++ b/src/cgmath/cylinder.rs @@ -16,11 +16,11 @@ //! Oriented bounding cylinder use point::Point3; -use vector::Vec3; +use vector::Vector3; #[deriving(Clone, Eq)] pub struct Cylinder { pub center: Point3, - pub axis: Vec3, + pub axis: Vector3, pub radius: S, } diff --git a/src/cgmath/frustum.rs b/src/cgmath/frustum.rs index f0b0ee4..3fbf2b8 100644 --- a/src/cgmath/frustum.rs +++ b/src/cgmath/frustum.rs @@ -15,7 +15,7 @@ //! View frustum for visibility determination -use matrix::{Matrix, Mat4}; +use matrix::{Matrix, Matrix4}; use plane::Plane; use point::Point3; use vector::{Vector, EuclideanVector}; @@ -48,13 +48,13 @@ Frustum { } /// Extracts frustum planes from a projection matrix - pub fn from_mat4(mat: Mat4) -> Frustum { - Frustum::new(Plane::from_vec4(mat.r(3).add_v(&mat.r(0)).normalize()), - Plane::from_vec4(mat.r(3).sub_v(&mat.r(0)).normalize()), - Plane::from_vec4(mat.r(3).add_v(&mat.r(1)).normalize()), - Plane::from_vec4(mat.r(3).sub_v(&mat.r(1)).normalize()), - Plane::from_vec4(mat.r(3).add_v(&mat.r(2)).normalize()), - Plane::from_vec4(mat.r(3).sub_v(&mat.r(2)).normalize())) + pub fn from_matrix4(mat: Matrix4) -> Frustum { + Frustum::new(Plane::from_vector4(mat.r(3).add_v(&mat.r(0)).normalize()), + Plane::from_vector4(mat.r(3).sub_v(&mat.r(0)).normalize()), + Plane::from_vector4(mat.r(3).add_v(&mat.r(1)).normalize()), + Plane::from_vector4(mat.r(3).sub_v(&mat.r(1)).normalize()), + Plane::from_vector4(mat.r(3).add_v(&mat.r(2)).normalize()), + Plane::from_vector4(mat.r(3).sub_v(&mat.r(2)).normalize())) } } diff --git a/src/cgmath/matrix.rs b/src/cgmath/matrix.rs index e7596a7..85ae43d 100644 --- a/src/cgmath/matrix.rs +++ b/src/cgmath/matrix.rs @@ -22,136 +22,136 @@ use angle::{Rad, sin, cos, sin_cos}; use approx::ApproxEq; use array::{Array, build}; use point::{Point, Point3}; -use quaternion::{Quat, ToQuat}; +use quaternion::{Quaternion, ToQuaternion}; use vector::{Vector, EuclideanVector}; -use vector::{Vec2, Vec3, Vec4}; +use vector::{Vector2, Vector3, Vector4}; use partial_ord::PartOrdFloat; /// A 2 x 2, column major matrix #[deriving(Clone, Eq)] -pub struct Mat2 { pub x: Vec2, pub y: Vec2 } +pub struct Matrix2 { pub x: Vector2, pub y: Vector2 } /// A 3 x 3, column major matrix #[deriving(Clone, Eq)] -pub struct Mat3 { pub x: Vec3, pub y: Vec3, pub z: Vec3 } +pub struct Matrix3 { pub x: Vector3, pub y: Vector3, pub z: Vector3 } /// A 4 x 4, column major matrix #[deriving(Clone, Eq)] -pub struct Mat4 { pub x: Vec4, pub y: Vec4, pub z: Vec4, pub w: Vec4 } +pub struct Matrix4 { pub x: Vector4, pub y: Vector4, pub z: Vector4, pub w: Vector4 } -impl Mat2 { +impl Matrix2 { #[inline] pub fn new(c0r0: S, c0r1: S, - c1r0: S, c1r1: S) -> Mat2 { - Mat2::from_cols(Vec2::new(c0r0, c0r1), - Vec2::new(c1r0, c1r1)) + c1r0: S, c1r1: S) -> Matrix2 { + Matrix2::from_cols(Vector2::new(c0r0, c0r1), + Vector2::new(c1r0, c1r1)) } #[inline] - pub fn from_cols(c0: Vec2, c1: Vec2) -> Mat2 { - Mat2 { x: c0, y: c1 } + pub fn from_cols(c0: Vector2, c1: Vector2) -> Matrix2 { + Matrix2 { x: c0, y: c1 } } #[inline] - pub fn from_value(value: S) -> Mat2 { - Mat2::new(value.clone(), zero(), + pub fn from_value(value: S) -> Matrix2 { + Matrix2::new(value.clone(), zero(), zero(), value.clone()) } #[inline] - pub fn zero() -> Mat2 { - Mat2::from_value(zero()) + pub fn zero() -> Matrix2 { + Matrix2::from_value(zero()) } #[inline] - pub fn identity() -> Mat2 { - Mat2::from_value(one()) + pub fn identity() -> Matrix2 { + Matrix2::from_value(one()) } } -impl> Mat2 { - pub fn look_at(dir: &Vec2, up: &Vec2) -> Mat2 { +impl> Matrix2 { + pub fn look_at(dir: &Vector2, up: &Vector2) -> Matrix2 { //TODO: verify look_at 2D - Mat2::from_cols(up.clone(), dir.clone()).transpose() + Matrix2::from_cols(up.clone(), dir.clone()).transpose() } #[inline] - pub fn from_angle(theta: Rad) -> Mat2 { + pub fn from_angle(theta: Rad) -> Matrix2 { let cos_theta = cos(theta.clone()); let sin_theta = sin(theta.clone()); - Mat2::new(cos_theta.clone(), -sin_theta.clone(), + Matrix2::new(cos_theta.clone(), -sin_theta.clone(), sin_theta.clone(), cos_theta.clone()) } } -impl Mat3 { +impl Matrix3 { #[inline] pub fn new(c0r0:S, c0r1:S, c0r2:S, c1r0:S, c1r1:S, c1r2:S, - c2r0:S, c2r1:S, c2r2:S) -> Mat3 { - Mat3::from_cols(Vec3::new(c0r0, c0r1, c0r2), - Vec3::new(c1r0, c1r1, c1r2), - Vec3::new(c2r0, c2r1, c2r2)) + c2r0:S, c2r1:S, c2r2:S) -> Matrix3 { + Matrix3::from_cols(Vector3::new(c0r0, c0r1, c0r2), + Vector3::new(c1r0, c1r1, c1r2), + Vector3::new(c2r0, c2r1, c2r2)) } #[inline] - pub fn from_cols(c0: Vec3, c1: Vec3, c2: Vec3) -> Mat3 { - Mat3 { x: c0, y: c1, z: c2 } + pub fn from_cols(c0: Vector3, c1: Vector3, c2: Vector3) -> Matrix3 { + Matrix3 { x: c0, y: c1, z: c2 } } #[inline] - pub fn from_value(value: S) -> Mat3 { - Mat3::new(value.clone(), zero(), zero(), + pub fn from_value(value: S) -> Matrix3 { + Matrix3::new(value.clone(), zero(), zero(), zero(), value.clone(), zero(), zero(), zero(), value.clone()) } #[inline] - pub fn zero() -> Mat3 { - Mat3::from_value(zero()) + pub fn zero() -> Matrix3 { + Matrix3::from_value(zero()) } #[inline] - pub fn identity() -> Mat3 { - Mat3::from_value(one()) + pub fn identity() -> Matrix3 { + Matrix3::from_value(one()) } } impl> -Mat3 { - pub fn look_at(dir: &Vec3, up: &Vec3) -> Mat3 { +Matrix3 { + pub fn look_at(dir: &Vector3, up: &Vector3) -> Matrix3 { let dir = dir.normalize(); let side = up.cross(&dir).normalize(); let up = dir.cross(&side).normalize(); - Mat3::from_cols(side, up, dir).transpose() + Matrix3::from_cols(side, up, dir).transpose() } /// Create a matrix from a rotation around the `x` axis (pitch). - pub fn from_angle_x(theta: Rad) -> Mat3 { + pub fn from_angle_x(theta: Rad) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations let (s, c) = sin_cos(theta); - Mat3::new(one(), zero(), zero(), + Matrix3::new(one(), zero(), zero(), zero(), c.clone(), s.clone(), zero(), -s.clone(), c.clone()) } /// Create a matrix from a rotation around the `y` axis (yaw). - pub fn from_angle_y(theta: Rad) -> Mat3 { + pub fn from_angle_y(theta: Rad) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations let (s, c) = sin_cos(theta); - Mat3::new(c.clone(), zero(), -s.clone(), + Matrix3::new(c.clone(), zero(), -s.clone(), zero(), one(), zero(), s.clone(), zero(), c.clone()) } /// Create a matrix from a rotation around the `z` axis (roll). - pub fn from_angle_z(theta: Rad) -> Mat3 { + pub fn from_angle_z(theta: Rad) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations let (s, c) = sin_cos(theta); - Mat3::new(c.clone(), s.clone(), zero(), + Matrix3::new(c.clone(), s.clone(), zero(), -s.clone(), c.clone(), zero(), zero(), zero(), one()) } @@ -163,23 +163,23 @@ Mat3 { /// - `x`: the angular rotation around the `x` axis (pitch). /// - `y`: the angular rotation around the `y` axis (yaw). /// - `z`: the angular rotation around the `z` axis (roll). - pub fn from_euler(x: Rad, y: Rad, z: Rad) -> Mat3 { + pub fn from_euler(x: Rad, y: Rad, z: Rad) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#General_rotations let (sx, cx) = sin_cos(x); let (sy, cy) = sin_cos(y); let (sz, cz) = sin_cos(z); - Mat3::new(cy * cz, cy * sz, -sy, + Matrix3::new(cy * cz, cy * sz, -sy, -cx * sz + sx * sy * cz, cx * cz + sx * sy * sz, sx * cy, sx * sz + cx * sy * cz, -sx * cz + cx * sy * sz, cx * cy) } /// Create a matrix from a rotation around an arbitrary axis - pub fn from_axis_angle(axis: &Vec3, angle: Rad) -> Mat3 { + pub fn from_axis_angle(axis: &Vector3, angle: Rad) -> Matrix3 { let (s, c) = sin_cos(angle); let _1subc = one::() - c; - Mat3::new(_1subc * axis.x * axis.x + c, + Matrix3::new(_1subc * axis.x * axis.x + c, _1subc * axis.x * axis.y + s * axis.z, _1subc * axis.x * axis.z - s * axis.y, @@ -193,59 +193,59 @@ Mat3 { } } -impl Mat4 { +impl Matrix4 { #[inline] pub fn new(c0r0: S, c0r1: S, c0r2: S, c0r3: S, c1r0: S, c1r1: S, c1r2: S, c1r3: S, c2r0: S, c2r1: S, c2r2: S, c2r3: S, - c3r0: S, c3r1: S, c3r2: S, c3r3: S) -> Mat4 { - Mat4::from_cols(Vec4::new(c0r0, c0r1, c0r2, c0r3), - Vec4::new(c1r0, c1r1, c1r2, c1r3), - Vec4::new(c2r0, c2r1, c2r2, c2r3), - Vec4::new(c3r0, c3r1, c3r2, c3r3)) + c3r0: S, c3r1: S, c3r2: S, c3r3: S) -> Matrix4 { + Matrix4::from_cols(Vector4::new(c0r0, c0r1, c0r2, c0r3), + Vector4::new(c1r0, c1r1, c1r2, c1r3), + Vector4::new(c2r0, c2r1, c2r2, c2r3), + Vector4::new(c3r0, c3r1, c3r2, c3r3)) } #[inline] - pub fn from_cols(c0: Vec4, c1: Vec4, c2: Vec4, c3: Vec4) -> Mat4 { - Mat4 { x: c0, y: c1, z: c2, w: c3 } + pub fn from_cols(c0: Vector4, c1: Vector4, c2: Vector4, c3: Vector4) -> Matrix4 { + Matrix4 { x: c0, y: c1, z: c2, w: c3 } } #[inline] - pub fn from_value(value: S) -> Mat4 { - Mat4::new(value.clone(), zero(), zero(), zero(), + pub fn from_value(value: S) -> Matrix4 { + Matrix4::new(value.clone(), zero(), zero(), zero(), zero(), value.clone(), zero(), zero(), zero(), zero(), value.clone(), zero(), zero(), zero(), zero(), value.clone()) } #[inline] - pub fn zero() -> Mat4 { - Mat4::from_value(zero()) + pub fn zero() -> Matrix4 { + Matrix4::from_value(zero()) } #[inline] - pub fn identity() -> Mat4 { - Mat4::from_value(one()) + pub fn identity() -> Matrix4 { + Matrix4::from_value(one()) } } impl> -Mat4 { - pub fn look_at(eye: &Point3, center: &Point3, up: &Vec3) -> Mat4 { +Matrix4 { + pub fn look_at(eye: &Point3, center: &Point3, up: &Vector3) -> Matrix4 { let f = center.sub_p(eye).normalize(); let s = f.cross(up).normalize(); let u = s.cross(&f); - Mat4::new(s.x.clone(), u.x.clone(), -f.x.clone(), zero(), + Matrix4::new(s.x.clone(), u.x.clone(), -f.x.clone(), zero(), s.y.clone(), u.y.clone(), -f.y.clone(), zero(), s.z.clone(), u.z.clone(), -f.z.clone(), zero(), -eye.dot(&s), -eye.dot(&u), eye.dot(&f), one()) } } -array!(impl Mat2 -> [Vec2, ..2] _2) -array!(impl Mat3 -> [Vec3, ..3] _3) -array!(impl Mat4 -> [Vec4, ..4] _4) +array!(impl Matrix2 -> [Vector2, ..2] _2) +array!(impl Matrix3 -> [Vector3, ..3] _3) +array!(impl Matrix4 -> [Vector4, ..4] _4) pub trait Matrix < @@ -361,41 +361,41 @@ pub trait Matrix fn is_symmetric(&self) -> bool; } -impl> Add, Mat2> for Mat2 { #[inline] fn add(&self, other: &Mat2) -> Mat2 { build(|i| self.i(i).add_v(other.i(i))) } } -impl> Add, Mat3> for Mat3 { #[inline] fn add(&self, other: &Mat3) -> Mat3 { build(|i| self.i(i).add_v(other.i(i))) } } -impl> Add, Mat4> for Mat4 { #[inline] fn add(&self, other: &Mat4) -> Mat4 { build(|i| self.i(i).add_v(other.i(i))) } } +impl> Add, Matrix2> for Matrix2 { #[inline] fn add(&self, other: &Matrix2) -> Matrix2 { build(|i| self.i(i).add_v(other.i(i))) } } +impl> Add, Matrix3> for Matrix3 { #[inline] fn add(&self, other: &Matrix3) -> Matrix3 { build(|i| self.i(i).add_v(other.i(i))) } } +impl> Add, Matrix4> for Matrix4 { #[inline] fn add(&self, other: &Matrix4) -> Matrix4 { build(|i| self.i(i).add_v(other.i(i))) } } -impl> Sub, Mat2> for Mat2 { #[inline] fn sub(&self, other: &Mat2) -> Mat2 { build(|i| self.i(i).sub_v(other.i(i))) } } -impl> Sub, Mat3> for Mat3 { #[inline] fn sub(&self, other: &Mat3) -> Mat3 { build(|i| self.i(i).sub_v(other.i(i))) } } -impl> Sub, Mat4> for Mat4 { #[inline] fn sub(&self, other: &Mat4) -> Mat4 { build(|i| self.i(i).sub_v(other.i(i))) } } +impl> Sub, Matrix2> for Matrix2 { #[inline] fn sub(&self, other: &Matrix2) -> Matrix2 { build(|i| self.i(i).sub_v(other.i(i))) } } +impl> Sub, Matrix3> for Matrix3 { #[inline] fn sub(&self, other: &Matrix3) -> Matrix3 { build(|i| self.i(i).sub_v(other.i(i))) } } +impl> Sub, Matrix4> for Matrix4 { #[inline] fn sub(&self, other: &Matrix4) -> Matrix4 { build(|i| self.i(i).sub_v(other.i(i))) } } -impl> Neg> for Mat2 { #[inline] fn neg(&self) -> Mat2 { build(|i| self.i(i).neg()) } } -impl> Neg> for Mat3 { #[inline] fn neg(&self) -> Mat3 { build(|i| self.i(i).neg()) } } -impl> Neg> for Mat4 { #[inline] fn neg(&self) -> Mat4 { build(|i| self.i(i).neg()) } } +impl> Neg> for Matrix2 { #[inline] fn neg(&self) -> Matrix2 { build(|i| self.i(i).neg()) } } +impl> Neg> for Matrix3 { #[inline] fn neg(&self) -> Matrix3 { build(|i| self.i(i).neg()) } } +impl> Neg> for Matrix4 { #[inline] fn neg(&self) -> Matrix4 { build(|i| self.i(i).neg()) } } -impl> Zero for Mat2 { #[inline] fn zero() -> Mat2 { Mat2::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } -impl> Zero for Mat3 { #[inline] fn zero() -> Mat3 { Mat3::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } -impl> Zero for Mat4 { #[inline] fn zero() -> Mat4 { Mat4::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } +impl> Zero for Matrix2 { #[inline] fn zero() -> Matrix2 { Matrix2::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } +impl> Zero for Matrix3 { #[inline] fn zero() -> Matrix3 { Matrix3::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } +impl> Zero for Matrix4 { #[inline] fn zero() -> Matrix4 { Matrix4::zero() } #[inline] fn is_zero(&self) -> bool { *self == zero() } } -impl> Mul, Mat2> for Mat2 { #[inline] fn mul(&self, other: &Mat2) -> Mat2 { build(|i| self.i(i).mul_v(other.i(i))) } } -impl> Mul, Mat3> for Mat3 { #[inline] fn mul(&self, other: &Mat3) -> Mat3 { build(|i| self.i(i).mul_v(other.i(i))) } } -impl> Mul, Mat4> for Mat4 { #[inline] fn mul(&self, other: &Mat4) -> Mat4 { build(|i| self.i(i).mul_v(other.i(i))) } } +impl> Mul, Matrix2> for Matrix2 { #[inline] fn mul(&self, other: &Matrix2) -> Matrix2 { build(|i| self.i(i).mul_v(other.i(i))) } } +impl> Mul, Matrix3> for Matrix3 { #[inline] fn mul(&self, other: &Matrix3) -> Matrix3 { build(|i| self.i(i).mul_v(other.i(i))) } } +impl> Mul, Matrix4> for Matrix4 { #[inline] fn mul(&self, other: &Matrix4) -> Matrix4 { build(|i| self.i(i).mul_v(other.i(i))) } } -impl> One for Mat2 { #[inline] fn one() -> Mat2 { Mat2::identity() } } -impl> One for Mat3 { #[inline] fn one() -> Mat3 { Mat3::identity() } } -impl> One for Mat4 { #[inline] fn one() -> Mat4 { Mat4::identity() } } +impl> One for Matrix2 { #[inline] fn one() -> Matrix2 { Matrix2::identity() } } +impl> One for Matrix3 { #[inline] fn one() -> Matrix3 { Matrix3::identity() } } +impl> One for Matrix4 { #[inline] fn one() -> Matrix4 { Matrix4::identity() } } impl> -Matrix, ..2], Vec2, [S, ..2]> -for Mat2 +Matrix, ..2], Vector2, [S, ..2]> +for Matrix2 { - fn mul_m(&self, other: &Mat2) -> Mat2 { - Mat2::new(self.r(0).dot(other.c(0)), self.r(1).dot(other.c(0)), + fn mul_m(&self, other: &Matrix2) -> Matrix2 { + Matrix2::new(self.r(0).dot(other.c(0)), self.r(1).dot(other.c(0)), self.r(0).dot(other.c(1)), self.r(1).dot(other.c(1))) } - fn transpose(&self) -> Mat2 { - Mat2::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), + fn transpose(&self) -> Matrix2 { + Matrix2::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(0, 1).clone(), self.cr(1, 1).clone()) } @@ -410,12 +410,12 @@ for Mat2 } #[inline] - fn invert(&self) -> Option> { + fn invert(&self) -> Option> { let det = self.determinant(); if det.approx_eq(&zero()) { None } else { - Some(Mat2::new( *self.cr(1, 1) / det, -*self.cr(0, 1) / det, + Some(Matrix2::new( *self.cr(1, 1) / det, -*self.cr(0, 1) / det, -*self.cr(1, 0) / det, *self.cr(0, 0) / det)) } } @@ -435,17 +435,17 @@ for Mat2 } impl> -Matrix, ..3], Vec3, [S, ..3]> -for Mat3 +Matrix, ..3], Vector3, [S, ..3]> +for Matrix3 { - fn mul_m(&self, other: &Mat3) -> Mat3 { - Mat3::new(self.r(0).dot(other.c(0)),self.r(1).dot(other.c(0)),self.r(2).dot(other.c(0)), + fn mul_m(&self, other: &Matrix3) -> Matrix3 { + Matrix3::new(self.r(0).dot(other.c(0)),self.r(1).dot(other.c(0)),self.r(2).dot(other.c(0)), self.r(0).dot(other.c(1)),self.r(1).dot(other.c(1)),self.r(2).dot(other.c(1)), self.r(0).dot(other.c(2)),self.r(1).dot(other.c(2)),self.r(2).dot(other.c(2))) } - fn transpose(&self) -> Mat3 { - Mat3::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(), + fn transpose(&self) -> Matrix3 { + Matrix3::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(), self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone()) } @@ -463,10 +463,10 @@ for Mat3 *self.cr(2, 0) * (*self.cr(0, 1) * *self.cr(1, 2) - *self.cr(1, 1) * *self.cr(0, 2)) } - fn invert(&self) -> Option> { + fn invert(&self) -> Option> { let det = self.determinant(); if det.approx_eq(&zero()) { None } else { - Some(Mat3::from_cols(self.c(1).cross(self.c(2)).div_s(det.clone()), + Some(Matrix3::from_cols(self.c(1).cross(self.c(2)).div_s(det.clone()), self.c(2).cross(self.c(0)).div_s(det.clone()), self.c(0).cross(self.c(1)).div_s(det.clone())).transpose()) } @@ -499,7 +499,7 @@ for Mat3 // causes the LLVM to miss identical loads and multiplies. This optimization // causes the code to be auto vectorized properly increasing the performance // around ~4 times. -macro_rules! dot_mat4( +macro_rules! dot_matrix4( ($A:expr, $B:expr, $I:expr, $J:expr) => ( (*$A.cr(0, $I)) * (*$B.cr($J, 0)) + (*$A.cr(1, $I)) * (*$B.cr($J, 1)) + @@ -508,18 +508,18 @@ macro_rules! dot_mat4( )) impl> -Matrix, ..4], Vec4, [S, ..4]> -for Mat4 +Matrix, ..4], Vector4, [S, ..4]> +for Matrix4 { - fn mul_m(&self, other: &Mat4) -> Mat4 { - Mat4::new(dot_mat4!(self, other, 0, 0), dot_mat4!(self, other, 1, 0), dot_mat4!(self, other, 2, 0), dot_mat4!(self, other, 3, 0), - dot_mat4!(self, other, 0, 1), dot_mat4!(self, other, 1, 1), dot_mat4!(self, other, 2, 1), dot_mat4!(self, other, 3, 1), - dot_mat4!(self, other, 0, 2), dot_mat4!(self, other, 1, 2), dot_mat4!(self, other, 2, 2), dot_mat4!(self, other, 3, 2), - dot_mat4!(self, other, 0, 3), dot_mat4!(self, other, 1, 3), dot_mat4!(self, other, 2, 3), dot_mat4!(self, other, 3, 3)) + fn mul_m(&self, other: &Matrix4) -> Matrix4 { + Matrix4::new(dot_matrix4!(self, other, 0, 0), dot_matrix4!(self, other, 1, 0), dot_matrix4!(self, other, 2, 0), dot_matrix4!(self, other, 3, 0), + dot_matrix4!(self, other, 0, 1), dot_matrix4!(self, other, 1, 1), dot_matrix4!(self, other, 2, 1), dot_matrix4!(self, other, 3, 1), + dot_matrix4!(self, other, 0, 2), dot_matrix4!(self, other, 1, 2), dot_matrix4!(self, other, 2, 2), dot_matrix4!(self, other, 3, 2), + dot_matrix4!(self, other, 0, 3), dot_matrix4!(self, other, 1, 3), dot_matrix4!(self, other, 2, 3), dot_matrix4!(self, other, 3, 3)) } - fn transpose(&self) -> Mat4 { - Mat4::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(), self.cr(3, 0).clone(), + fn transpose(&self) -> Matrix4 { + Matrix4::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(), self.cr(3, 0).clone(), self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(), self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(), self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone()) @@ -535,16 +535,16 @@ for Mat4 } fn determinant(&self) -> S { - let m0 = Mat3::new(self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(), + let m0 = Matrix3::new(self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone()); - let m1 = Mat3::new(self.cr(0, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(), + let m1 = Matrix3::new(self.cr(0, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(), self.cr(0, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(), self.cr(0, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone()); - let m2 = Mat3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(3, 1).clone(), + let m2 = Matrix3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(3, 1).clone(), self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(3, 2).clone(), self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(3, 3).clone()); - let m3 = Mat3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), + let m3 = Matrix3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone()); @@ -554,14 +554,14 @@ for Mat4 *self.cr(3, 0) * m3.determinant() } - fn invert(&self) -> Option> { + fn invert(&self) -> Option> { if self.is_invertible() { // Gauss Jordan Elimination with partial pivoting // So take this matrix ('mat') augmented with the identity ('ident'), // and essentially reduce [mat|ident] let mut mat = self.clone(); - let mut ident = Mat4::identity(); + let mut ident = Matrix4::identity(); for j in range(0u, 4u) { // Find largest element in col j @@ -636,27 +636,27 @@ for Mat4 } // Conversion traits -pub trait ToMat2 { fn to_mat2(&self) -> Mat2; } -pub trait ToMat3 { fn to_mat3(&self) -> Mat3; } -pub trait ToMat4 { fn to_mat4(&self) -> Mat4; } +pub trait ToMatrix2 { fn to_matrix2(&self) -> Matrix2; } +pub trait ToMatrix3 { fn to_matrix3(&self) -> Matrix3; } +pub trait ToMatrix4 { fn to_matrix4(&self) -> Matrix4; } impl> -ToMat3 for Mat2 { +ToMatrix3 for Matrix2 { /// Clone the elements of a 2-dimensional matrix into the top corner of a /// 3-dimensional identity matrix. - fn to_mat3(&self) -> Mat3 { - Mat3::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(), + fn to_matrix3(&self) -> Matrix3 { + Matrix3::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(), self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(), zero(), zero(), one()) } } impl> -ToMat4 for Mat2 { +ToMatrix4 for Matrix2 { /// Clone the elements of a 2-dimensional matrix into the top corner of a /// 4-dimensional identity matrix. - fn to_mat4(&self) -> Mat4 { - Mat4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(), zero(), + fn to_matrix4(&self) -> Matrix4 { + Matrix4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(), zero(), self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(), zero(), zero(), zero(), one(), zero(), zero(), zero(), zero(), one()) @@ -664,11 +664,11 @@ ToMat4 for Mat2 { } impl> -ToMat4 for Mat3 { +ToMatrix4 for Matrix3 { /// Clone the elements of a 3-dimensional matrix into the top corner of a /// 4-dimensional identity matrix. - fn to_mat4(&self) -> Mat4 { - Mat4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), self.cr(0, 2).clone(), zero(), + fn to_matrix4(&self) -> Matrix4 { + Matrix4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), self.cr(0, 2).clone(), zero(), self.cr(1, 0).clone(), self.cr(1, 1).clone(), self.cr(1, 2).clone(), zero(), self.cr(2, 0).clone(), self.cr(2, 1).clone(), self.cr(2, 2).clone(), zero(), zero(), zero(), zero(), one()) @@ -676,9 +676,9 @@ ToMat4 for Mat3 { } impl> -ToQuat for Mat3 { +ToQuaternion for Matrix3 { /// Convert the matrix to a quaternion - fn to_quat(&self) -> Quat { + 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(); @@ -690,7 +690,7 @@ ToQuat for Mat3 { let x = (*self.cr(1, 2) - *self.cr(2, 1)) * s; let y = (*self.cr(2, 0) - *self.cr(0, 2)) * s; let z = (*self.cr(0, 1) - *self.cr(1, 0)) * s; - Quat::new(w, x, y, z) + Quaternion::new(w, x, y, z) } () if (*self.cr(0, 0) > *self.cr(1, 1)) && (*self.cr(0, 0) > *self.cr(2, 2)) => { let s = (half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2))).sqrt(); @@ -699,7 +699,7 @@ ToQuat for Mat3 { let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; let y = (*self.cr(2, 0) - *self.cr(0, 2)) * s; let z = (*self.cr(1, 2) - *self.cr(2, 1)) * s; - Quat::new(w, x, y, z) + Quaternion::new(w, x, y, z) } () if *self.cr(1, 1) > *self.cr(2, 2) => { let s = (half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2))).sqrt(); @@ -708,7 +708,7 @@ ToQuat for Mat3 { let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; let y = (*self.cr(1, 2) - *self.cr(2, 1)) * s; let z = (*self.cr(2, 0) - *self.cr(0, 2)) * s; - Quat::new(w, x, y, z) + Quaternion::new(w, x, y, z) } () => { let s = (half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1))).sqrt(); @@ -717,13 +717,13 @@ ToQuat for Mat3 { let x = (*self.cr(2, 0) - *self.cr(0, 2)) * s; let y = (*self.cr(1, 2) - *self.cr(2, 1)) * s; let z = (*self.cr(0, 1) - *self.cr(1, 0)) * s; - Quat::new(w, x, y, z) + Quaternion::new(w, x, y, z) } } } } -impl + fmt::Show> fmt::Show for Mat2 { +impl + fmt::Show> fmt::Show for Matrix2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[[{}, {}], [{}, {}]]", self.cr(0, 0), self.cr(0, 1), @@ -731,7 +731,7 @@ impl + fmt::Show> fmt::Show for Mat2 { } } -impl + fmt::Show> fmt::Show for Mat3 { +impl + fmt::Show> fmt::Show for Matrix3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]", self.cr(0, 0), self.cr(0, 1), self.cr(0, 2), @@ -740,7 +740,7 @@ impl + fmt::Show> fmt::Show for Mat3 { } } -impl + fmt::Show> fmt::Show for Mat4 { +impl + fmt::Show> fmt::Show for Matrix4 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[[{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}]]", self.cr(0, 0), self.cr(0, 1), self.cr(0, 2), self.cr(0, 3), diff --git a/src/cgmath/obb.rs b/src/cgmath/obb.rs index f89d483..9157f84 100644 --- a/src/cgmath/obb.rs +++ b/src/cgmath/obb.rs @@ -16,18 +16,18 @@ //! Oriented bounding boxes use point::{Point2, Point3}; -use vector::{Vec2, Vec3}; +use vector::{Vector2, Vector3}; #[deriving(Clone, Eq)] pub struct Obb2 { pub center: Point2, - pub axis: Vec2, - pub extents: Vec2, + pub axis: Vector2, + pub extents: Vector2, } #[deriving(Clone, Eq)] pub struct Obb3 { pub center: Point3, - pub axis: Vec3, - pub extents: Vec3, + pub axis: Vector3, + pub extents: Vector3, } diff --git a/src/cgmath/plane.rs b/src/cgmath/plane.rs index 0054333..175c7f6 100644 --- a/src/cgmath/plane.rs +++ b/src/cgmath/plane.rs @@ -21,12 +21,12 @@ use approx::ApproxEq; use intersect::Intersect; use point::{Point, Point3}; use ray::Ray3; -use vector::{Vec3, Vec4}; +use vector::{Vector3, Vector4}; use vector::{Vector, EuclideanVector}; use partial_ord::PartOrdFloat; -/// A 3-dimendional plane formed from the equation: `a*x + b*y + c*z - d = 0`. +/// A 3-dimensional plane formed from the equation: `a*x + b*y + c*z - d = 0`. /// /// # Fields /// @@ -43,14 +43,14 @@ use partial_ord::PartOrdFloat; /// superfluous negations (see _Real Time Collision Detection_, p. 55). #[deriving(Clone, Eq)] pub struct Plane { - pub n: Vec3, + pub n: Vector3, pub d: S, } impl> Plane { /// Construct a plane from a normal vector and a scalar distance - pub fn new(n: Vec3, d: S) -> Plane { + pub fn new(n: Vector3, d: S) -> Plane { Plane { n: n, d: d } } @@ -61,11 +61,11 @@ Plane { /// - `c`: the `z` component of the normal /// - `d`: the plane's distance value pub fn from_abcd(a: S, b: S, c: S, d: S) -> Plane { - Plane { n: Vec3::new(a, b, c), d: d } + Plane { n: Vector3::new(a, b, c), d: d } } /// Construct a plane from the components of a four-dimensional vector - pub fn from_vec4(v: Vec4) -> Plane { + pub fn from_vector4(v: Vector4) -> Plane { unsafe { transmute(v) } } @@ -78,7 +78,7 @@ Plane { // find the normal vector that is perpendicular to v1 and v2 let mut n = v0.cross(&v1); - if n.approx_eq(&Vec3::zero()) { None } + if n.approx_eq(&Vector3::zero()) { None } else { // compute the normal and the distance to the plane n.normalize_self(); diff --git a/src/cgmath/point.rs b/src/cgmath/point.rs index f1794f2..b6bcf9e 100644 --- a/src/cgmath/point.rs +++ b/src/cgmath/point.rs @@ -49,14 +49,14 @@ impl Point3 { impl Point3 { #[inline] - pub fn from_homogeneous(v: &Vec4) -> Point3 { + pub fn from_homogeneous(v: &Vector4) -> Point3 { let e = v.truncate().mul_s(one::() / v.w); Point3::new(e.x.clone(), e.y.clone(), e.z.clone()) //FIXME } #[inline] - pub fn to_homogeneous(&self) -> Vec4 { - Vec4::new(self.x.clone(), self.y.clone(), self.z.clone(), one()) + pub fn to_homogeneous(&self) -> Vector4 { + Vector4::new(self.x.clone(), self.y.clone(), self.z.clone(), one()) } } @@ -97,8 +97,8 @@ pub trait Point array!(impl Point2 -> [S, ..2] _2) array!(impl Point3 -> [S, ..3] _3) -impl Point, [S, ..2]> for Point2 {} -impl Point, [S, ..3]> for Point3 {} +impl Point, [S, ..2]> for Point2 {} +impl Point, [S, ..3]> for Point3 {} impl fmt::Show for Point2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/cgmath/projection.rs b/src/cgmath/projection.rs index 8c240db..9500b11 100644 --- a/src/cgmath/projection.rs +++ b/src/cgmath/projection.rs @@ -17,7 +17,7 @@ use std::num::{zero, one, cast}; use angle::{Angle, tan, cot}; use frustum::Frustum; -use matrix::{Mat4, ToMat4}; +use matrix::{Matrix4, ToMatrix4}; use plane::Plane; use partial_ord::PartOrdFloat; @@ -25,20 +25,20 @@ use partial_ord::PartOrdFloat; /// /// This is the equivalent to the [gluPerspective] /// (http://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml) function. -pub fn perspective>(fovy: A, aspect: S, near: S, far: S) -> Mat4 { +pub fn perspective>(fovy: A, aspect: S, near: S, far: S) -> Matrix4 { PerspectiveFov { fovy: fovy, aspect: aspect, near: near, far: far, - }.to_mat4() + }.to_matrix4() } /// Create a perspective matrix from a view frustrum. /// /// This is the equivalent of the now deprecated [glFrustrum] /// (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function. -pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { +pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4 { Perspective { left: left, right: right, @@ -46,14 +46,14 @@ pub fn frustum(left: S, right: S, bottom: S, top: S, near: S, far: S) top: top, near: near, far: far, - }.to_mat4() + }.to_matrix4() } /// Create an orthographic projection matrix. /// /// This is the equivalent of the now deprecated [glOrtho] /// (http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) function. -pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Mat4 { +pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> Matrix4 { Ortho { left: left, right: right, @@ -61,10 +61,10 @@ pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S) -> top: top, near: near, far: far, - }.to_mat4() + }.to_matrix4() } -pub trait Projection: ToMat4 { +pub trait Projection: ToMatrix4 { fn to_frustum(&self) -> Frustum; } @@ -98,12 +98,12 @@ impl, A: Angle> Projection for PerspectiveFov { fn to_frustum(&self) -> Frustum { // TODO: Could this be faster? - Frustum::from_mat4(self.to_mat4()) + Frustum::from_matrix4(self.to_matrix4()) } } -impl> ToMat4 for PerspectiveFov { - fn to_mat4(&self) -> Mat4 { +impl> ToMatrix4 for PerspectiveFov { + fn to_matrix4(&self) -> Matrix4 { let half_turn: A = Angle::turn_div_2(); assert!(self.fovy > zero(), "The vertical field of view cannot be below zero, found: {:?}", self.fovy); @@ -136,7 +136,7 @@ impl> ToMat4 for PerspectiveFov { let c3r2 = (two * self.far * self.near) / (self.near - self.far); let c3r3 = zero(); - Mat4::new(c0r0, c0r1, c0r2, c0r3, + Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) @@ -155,12 +155,12 @@ impl> Projection for Perspective { fn to_frustum(&self) -> Frustum { // TODO: Could this be faster? - Frustum::from_mat4(self.to_mat4()) + Frustum::from_matrix4(self.to_matrix4()) } } -impl ToMat4 for Perspective { - fn to_mat4(&self) -> Mat4 { +impl ToMatrix4 for Perspective { + fn to_matrix4(&self) -> Matrix4 { assert!(self.left > self.right, "`left` cannot be greater than `right`, found: left: {:?} right: {:?}", self.left, self.right); 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); @@ -187,7 +187,7 @@ impl ToMat4 for Perspective { let c3r2 = -(two * self.far * self.near) / (self.far - self.near); let c3r3 = zero(); - Mat4::new(c0r0, c0r1, c0r2, c0r3, + Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) @@ -216,8 +216,8 @@ Projection for Ortho { } } -impl ToMat4 for Ortho { - fn to_mat4(&self) -> Mat4 { +impl ToMatrix4 for Ortho { + fn to_matrix4(&self) -> Matrix4 { assert!(self.left < self.right, "`left` cannot be greater than `right`, found: left: {:?} right: {:?}", self.left, self.right); 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); @@ -244,7 +244,7 @@ impl ToMat4 for Ortho { let c3r2 = -(self.far + self.near) / (self.far - self.near); let c3r3 = one::(); - Mat4::new(c0r0, c0r1, c0r2, c0r3, + Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) diff --git a/src/cgmath/ptr.rs b/src/cgmath/ptr.rs index d1de91d..d3565e1 100644 --- a/src/cgmath/ptr.rs +++ b/src/cgmath/ptr.rs @@ -14,24 +14,24 @@ // limitations under the License. use array::Array; -use matrix::{Mat2, Mat3, Mat4}; +use matrix::{Matrix2, Matrix3, Matrix4}; use point::{Point2, Point3}; -use vector::{Vec2, Vec3, Vec4}; +use vector::{Vector2, Vector3, Vector4}; pub trait Ptr { fn ptr<'a>(&'a self) -> &'a T; } -impl Ptr for Vec2 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } -impl Ptr for Vec3 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } -impl Ptr for Vec4 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } +impl Ptr for Vector2 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } +impl Ptr for Vector3 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } +impl Ptr for Vector4 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } impl Ptr for Point2 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } impl Ptr for Point3 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0) } } -impl Ptr for Mat2 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } -impl Ptr for Mat3 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } -impl Ptr for Mat4 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } +impl Ptr for Matrix2 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } +impl Ptr for Matrix3 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } +impl Ptr for Matrix4 { #[inline] fn ptr<'a>(&'a self) -> &'a S { self.i(0).i(0) } } impl<'a, T, P: Ptr> Ptr for &'a [P] { #[inline] fn ptr<'a>(&'a self) -> &'a T { self[0].ptr() } diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 10be2a1..bd9feef 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -19,83 +19,83 @@ use std::num::{zero, one, cast}; use angle::{Angle, Rad, acos, sin, sin_cos}; use approx::ApproxEq; use array::{Array, build}; -use matrix::{Mat3, ToMat3, ToMat4, Mat4}; +use matrix::{Matrix3, ToMatrix3, ToMatrix4, Matrix4}; use point::{Point3}; use rotation::{Rotation, Rotation3, Basis3, ToBasis3}; -use vector::{Vec3, Vector, EuclideanVector}; +use vector::{Vector3, Vector, EuclideanVector}; use partial_ord::PartOrdFloat; /// A quaternion in scalar/vector form #[deriving(Clone, Eq)] -pub struct Quat { pub s: S, pub v: Vec3 } +pub struct Quaternion { pub s: S, pub v: Vector3 } -array!(impl Quat -> [S, ..4] _4) +array!(impl Quaternion -> [S, ..4] _4) -pub trait ToQuat { - fn to_quat(&self) -> Quat; +pub trait ToQuaternion { + fn to_quaternion(&self) -> Quaternion; } impl> -Quat { +Quaternion { /// Construct a new quaternion from one scalar component and three /// imaginary components #[inline] - pub fn new(w: S, xi: S, yj: S, zk: S) -> Quat { - Quat::from_sv(w, Vec3::new(xi, yj, zk)) + pub fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion { + Quaternion::from_sv(w, Vector3::new(xi, yj, zk)) } /// Construct a new quaternion from a scalar and a vector #[inline] - pub fn from_sv(s: S, v: Vec3) -> Quat { - Quat { s: s, v: v } + pub fn from_sv(s: S, v: Vector3) -> Quaternion { + Quaternion { s: s, v: v } } /// The additive identity, ie: `q = 0 + 0i + 0j + 0i` #[inline] - pub fn zero() -> Quat { - Quat::new(zero(), zero(), zero(), zero()) + pub fn zero() -> Quaternion { + Quaternion::new(zero(), zero(), zero(), zero()) } /// The multiplicative identity, ie: `q = 1 + 0i + 0j + 0i` #[inline] - pub fn identity() -> Quat { - Quat::from_sv(one::(), Vec3::zero()) + pub fn identity() -> Quaternion { + Quaternion::from_sv(one::(), Vector3::zero()) } /// The result of multiplying the quaternion a scalar #[inline] - pub fn mul_s(&self, value: S) -> Quat { - Quat::from_sv(self.s * value, self.v.mul_s(value)) + pub fn mul_s(&self, value: S) -> Quaternion { + Quaternion::from_sv(self.s * value, self.v.mul_s(value)) } /// The result of dividing the quaternion a scalar #[inline] - pub fn div_s(&self, value: S) -> Quat { - Quat::from_sv(self.s / value, self.v.div_s(value)) + pub fn div_s(&self, value: S) -> Quaternion { + Quaternion::from_sv(self.s / value, self.v.div_s(value)) } /// The result of multiplying the quaternion by a vector #[inline] - pub fn mul_v(&self, vec: &Vec3) -> Vec3 { + 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) } /// The sum of this quaternion and `other` #[inline] - pub fn add_q(&self, other: &Quat) -> Quat { + pub fn add_q(&self, other: &Quaternion) -> Quaternion { build(|i| self.i(i).add(other.i(i))) } /// The difference between this quaternion and `other` #[inline] - pub fn sub_q(&self, other: &Quat) -> Quat { + pub fn sub_q(&self, other: &Quaternion) -> Quaternion { build(|i| self.i(i).add(other.i(i))) } /// The the result of multipliplying the quaternion by `other` - pub fn mul_q(&self, other: &Quat) -> Quat { - Quat::new(self.s * other.s - self.v.x * other.v.x - self.v.y * other.v.y - self.v.z * other.v.z, + pub fn mul_q(&self, other: &Quaternion) -> Quaternion { + Quaternion::new(self.s * other.s - self.v.x * other.v.x - self.v.y * other.v.y - self.v.z * other.v.z, self.s * other.v.x + self.v.x * other.s + self.v.y * other.v.z - self.v.z * other.v.y, self.s * other.v.y + self.v.y * other.s + self.v.z * other.v.x - self.v.x * other.v.z, self.s * other.v.z + self.v.z * other.s + self.v.x * other.v.y - self.v.y * other.v.x) @@ -112,30 +112,30 @@ Quat { } #[inline] - pub fn add_self_q(&mut self, other: &Quat) { + pub fn add_self_q(&mut self, other: &Quaternion) { self.each_mut(|i, x| *x = x.add(other.i(i))); } #[inline] - pub fn sub_self_q(&mut self, other: &Quat) { + pub fn sub_self_q(&mut self, other: &Quaternion) { self.each_mut(|i, x| *x = x.sub(other.i(i))); } #[inline] - pub fn mul_self_q(&mut self, other: &Quat) { + pub fn mul_self_q(&mut self, other: &Quaternion) { *self = self.mul_q(other); } /// The dot product of the quaternion and `other` #[inline] - pub fn dot(&self, other: &Quat) -> S { + pub fn dot(&self, other: &Quaternion) -> S { self.s * other.s + self.v.dot(&other.v) } /// The conjugate of the quaternion #[inline] - pub fn conjugate(&self) -> Quat { - Quat::from_sv(self.s.clone(), -self.v.clone()) + pub fn conjugate(&self) -> Quaternion { + Quaternion::from_sv(self.s.clone(), -self.v.clone()) } /// The squared magnitude of the quaternion. This is useful for @@ -160,7 +160,7 @@ Quat { /// The normalized quaternion #[inline] - pub fn normalize(&self) -> Quat { + pub fn normalize(&self) -> Quaternion { self.mul_s(one::() / self.magnitude()) } @@ -169,13 +169,13 @@ Quat { /// # Return value /// /// The intoperlated quaternion - pub fn nlerp(&self, other: &Quat, amount: S) -> Quat { + pub fn nlerp(&self, other: &Quaternion, amount: S) -> Quaternion { self.mul_s(one::() - amount).add_q(&other.mul_s(amount)).normalize() } } impl> -Quat { +Quaternion { /// Spherical Linear Intoperlation /// /// Perform a spherical linear interpolation between the quaternion and @@ -195,7 +195,7 @@ Quat { /// (http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/) /// - [Arcsynthesis OpenGL tutorial] /// (http://www.arcsynthesis.org/gltut/Positioning/Tut08%20Interpolation.html) - pub fn slerp(&self, other: &Quat, amount: S) -> Quat { + pub fn slerp(&self, other: &Quaternion, amount: S) -> Quaternion { use std::num::cast; let dot = self.dot(other); @@ -228,9 +228,9 @@ Quat { } impl> -ToMat3 for Quat { +ToMatrix3 for Quaternion { /// Convert the quaternion to a 3 x 3 rotation matrix - fn to_mat3(&self) -> Mat3 { + fn to_matrix3(&self) -> Matrix3 { let x2 = self.v.x + self.v.x; let y2 = self.v.y + self.v.y; let z2 = self.v.z + self.v.z; @@ -247,16 +247,16 @@ ToMat3 for Quat { let sz2 = z2 * self.s; let sx2 = x2 * self.s; - Mat3::new(one::() - yy2 - zz2, xy2 + sz2, xz2 - sy2, + Matrix3::new(one::() - yy2 - zz2, xy2 + sz2, xz2 - sy2, xy2 - sz2, one::() - xx2 - zz2, yz2 + sx2, xz2 + sy2, yz2 - sx2, one::() - xx2 - yy2) } } impl> -ToMat4 for Quat { +ToMatrix4 for Quaternion { /// Convert the quaternion to a 4 x 4 rotation matrix - fn to_mat4(&self) -> Mat4 { + fn to_matrix4(&self) -> Matrix4 { let x2 = self.v.x + self.v.x; let y2 = self.v.y + self.v.y; let z2 = self.v.z + self.v.z; @@ -273,7 +273,7 @@ ToMat4 for Quat { let sz2 = z2 * self.s; let sx2 = x2 * self.s; - Mat4::new(one::() - yy2 - zz2, xy2 + sz2, xz2 - sy2, zero::(), + Matrix4::new(one::() - yy2 - zz2, xy2 + sz2, xz2 - sy2, zero::(), xy2 - sz2, one::() - xx2 - zz2, yz2 + sx2, zero::(), xz2 + sy2, yz2 - sx2, one::() - xx2 - yy2, zero::(), zero::(), zero::(), zero::(), one::()) @@ -281,14 +281,14 @@ ToMat4 for Quat { } impl> -Neg> for Quat { +Neg> for Quaternion { #[inline] - fn neg(&self) -> Quat { - Quat::from_sv(-self.s, -self.v) + fn neg(&self) -> Quaternion { + Quaternion::from_sv(-self.s, -self.v) } } -impl fmt::Show for Quat { +impl fmt::Show for Quaternion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "{} + {}i + {}j + {}k", self.s, @@ -301,65 +301,65 @@ impl fmt::Show for Quat { // Quaternion Rotation impls impl> -ToBasis3 for Quat { +ToBasis3 for Quaternion { #[inline] - fn to_rot3(&self) -> Basis3 { Basis3::from_quat(self) } + fn to_rot3(&self) -> Basis3 { Basis3::from_quaternion(self) } } -impl ToQuat for Quat { +impl ToQuaternion for Quaternion { #[inline] - fn to_quat(&self) -> Quat { self.clone() } + fn to_quaternion(&self) -> Quaternion { self.clone() } } impl> -Rotation, Point3> for Quat { +Rotation, Point3> for Quaternion { #[inline] - fn identity() -> Quat { Quat::identity() } + fn identity() -> Quaternion { Quaternion::identity() } #[inline] - fn look_at(dir: &Vec3, up: &Vec3) -> Quat { - Mat3::look_at(dir, up).to_quat() + fn look_at(dir: &Vector3, up: &Vector3) -> Quaternion { + Matrix3::look_at(dir, up).to_quaternion() } #[inline] - fn between_vecs(a: &Vec3, b: &Vec3) -> Quat { + fn between_vectors(a: &Vector3, b: &Vector3) -> Quaternion { //http://stackoverflow.com/questions/1171849/ //finding-quaternion-representing-the-rotation-from-one-vector-to-another - Quat::from_sv(one::() + a.dot(b), a.cross(b)).normalize() + Quaternion::from_sv(one::() + a.dot(b), a.cross(b)).normalize() } #[inline] - fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mul_v(vec) } + fn rotate_vector(&self, vec: &Vector3) -> Vector3 { self.mul_v(vec) } #[inline] - fn concat(&self, other: &Quat) -> Quat { self.mul_q(other) } + fn concat(&self, other: &Quaternion) -> Quaternion { self.mul_q(other) } #[inline] - fn concat_self(&mut self, other: &Quat) { self.mul_self_q(other); } + fn concat_self(&mut self, other: &Quaternion) { self.mul_self_q(other); } #[inline] - fn invert(&self) -> Quat { self.conjugate().div_s(self.magnitude2()) } + fn invert(&self) -> Quaternion { self.conjugate().div_s(self.magnitude2()) } #[inline] fn invert_self(&mut self) { *self = self.invert() } } impl> -Rotation3 for Quat +Rotation3 for Quaternion { #[inline] - fn from_axis_angle(axis: &Vec3, angle: Rad) -> Quat { + fn from_axis_angle(axis: &Vector3, angle: Rad) -> Quaternion { let (s, c) = sin_cos(angle.mul_s(cast(0.5).unwrap())); - Quat::from_sv(c, axis.mul_s(s)) + Quaternion::from_sv(c, axis.mul_s(s)) } - fn from_euler(x: Rad, y: Rad, z: Rad) -> Quat { + 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())); - Quat::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2, + Quaternion::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2, sz2 * cx2 * cy2 - cz2 * sx2 * sy2, cz2 * sx2 * cy2 + sz2 * cx2 * sy2, cz2 * cx2 * sy2 - sz2 * sx2 * cy2) diff --git a/src/cgmath/ray.rs b/src/cgmath/ray.rs index b75c8dd..3431ab4 100644 --- a/src/cgmath/ray.rs +++ b/src/cgmath/ray.rs @@ -14,7 +14,7 @@ // limitations under the License. use point::{Point, Point2, Point3}; -use vector::{Vector, Vec2, Vec3}; +use vector::{Vector, Vector2, Vector3}; /// A generic ray #[deriving(Clone, Eq)] @@ -37,5 +37,5 @@ impl } } -pub type Ray2 = Ray,Vec2>; -pub type Ray3 = Ray,Vec3>; +pub type Ray2 = Ray,Vector2>; +pub type Ray3 = Ray,Vector3>; diff --git a/src/cgmath/rotation.rs b/src/cgmath/rotation.rs index 866e65e..85ac745 100644 --- a/src/cgmath/rotation.rs +++ b/src/cgmath/rotation.rs @@ -17,12 +17,12 @@ use angle::{Rad, acos}; use approx::ApproxEq; use array::Array; use matrix::Matrix; -use matrix::{Mat2, ToMat2}; -use matrix::{Mat3, ToMat3}; +use matrix::{Matrix2, ToMatrix2}; +use matrix::{Matrix3, ToMatrix3}; use point::{Point, Point2, Point3}; -use quaternion::{Quat, ToQuat}; +use quaternion::{Quaternion, ToQuaternion}; use ray::Ray; -use vector::{Vector, Vec2, Vec3}; +use vector::{Vector, Vector2, Vector3}; use partial_ord::{PartOrdPrim, PartOrdFloat}; /// A trait for generic rotation @@ -43,20 +43,20 @@ pub trait Rotation /// Create a shortest rotation to transform vector 'a' into 'b'. /// Both given vectors are assumed to have unit length. - fn between_vecs(a: &V, b: &V) -> Self; + fn between_vectors(a: &V, b: &V) -> Self; - fn rotate_vec(&self, vec: &V) -> V; + fn rotate_vector(&self, vec: &V) -> V; #[inline] fn rotate_point(&self, point: &P) -> P { - Point::from_vec( &self.rotate_vec( &point.to_vec() ) ) + Point::from_vec( &self.rotate_vector( &point.to_vec() ) ) } #[inline] fn rotate_ray(&self, ray: &Ray) -> Ray { Ray::new( //FIXME: use clone derived from Array Array::build(|i| ray.origin.i(i).clone()), - self.rotate_vec(&ray.direction) ) + self.rotate_vector(&ray.direction) ) } fn concat(&self, other: &Self) -> Self; @@ -78,8 +78,8 @@ pub trait Rotation2 < S > -: Rotation, Point2> -+ ToMat2 +: Rotation, Point2> ++ ToMatrix2 + ToBasis2 { // Create a rotation by a given angle. Thus is a redundant case of both @@ -92,13 +92,13 @@ pub trait Rotation3 < S: Primitive > -: Rotation, Point3> -+ ToMat3 +: Rotation, Point3> ++ ToMatrix3 + ToBasis3 -+ ToQuat ++ ToQuaternion { /// Create a rotation around a given axis. - fn from_axis_angle(axis: &Vec3, angle: Rad) -> Self; + fn from_axis_angle(axis: &Vector3, angle: Rad) -> Self; /// Create a rotation from a set of euler angles. /// @@ -112,17 +112,17 @@ pub trait Rotation3 /// Create a rotation matrix from a rotation around the `x` axis (pitch). #[inline] fn from_angle_x(theta: Rad) -> Self { - Rotation3::from_axis_angle( &Vec3::unit_x(), theta ) + Rotation3::from_axis_angle( &Vector3::unit_x(), theta ) } #[inline] fn from_angle_y(theta: Rad) -> Self { - Rotation3::from_axis_angle( &Vec3::unit_y(), theta ) + Rotation3::from_axis_angle( &Vector3::unit_y(), theta ) } #[inline] fn from_angle_z(theta: Rad) -> Self { - Rotation3::from_axis_angle( &Vec3::unit_z(), theta ) + Rotation3::from_axis_angle( &Vector3::unit_z(), theta ) } } @@ -130,17 +130,17 @@ pub trait Rotation3 /// A two-dimensional rotation matrix. /// /// The matrix is guaranteed to be orthogonal, so some operations can be -/// implemented more efficiently than the implementations for `math::Mat2`. To +/// implemented more efficiently than the implementations for `math::Matrix2`. To /// enforce orthogonality at the type level the operations have been restricted -/// to a subset of those implemented on `Mat2`. +/// to a subset of those implemented on `Matrix2`. #[deriving(Eq, Clone)] pub struct Basis2 { - mat: Mat2 + mat: Matrix2 } impl Basis2 { #[inline] - pub fn as_mat2<'a>(&'a self) -> &'a Mat2 { &'a self.mat } + pub fn as_matrix2<'a>(&'a self) -> &'a Matrix2 { &'a self.mat } } pub trait ToBasis2 { @@ -152,28 +152,28 @@ impl ToBasis2 for Basis2 { fn to_rot2(&self) -> Basis2 { self.clone() } } -impl ToMat2 for Basis2 { +impl ToMatrix2 for Basis2 { #[inline] - fn to_mat2(&self) -> Mat2 { self.mat.clone() } + fn to_matrix2(&self) -> Matrix2 { self.mat.clone() } } impl> -Rotation, Point2> for Basis2 { +Rotation, Point2> for Basis2 { #[inline] - fn identity() -> Basis2 { Basis2{ mat: Mat2::identity() } } + fn identity() -> Basis2 { Basis2{ mat: Matrix2::identity() } } #[inline] - fn look_at(dir: &Vec2, up: &Vec2) -> Basis2 { - Basis2 { mat: Mat2::look_at(dir, up) } + fn look_at(dir: &Vector2, up: &Vector2) -> Basis2 { + Basis2 { mat: Matrix2::look_at(dir, up) } } #[inline] - fn between_vecs(a: &Vec2, b: &Vec2) -> Basis2 { + fn between_vectors(a: &Vector2, b: &Vector2) -> Basis2 { Rotation2::from_angle( acos(a.dot(b)) ) } #[inline] - fn rotate_vec(&self, vec: &Vec2) -> Vec2 { self.mat.mul_v(vec) } + fn rotate_vector(&self, vec: &Vector2) -> Vector2 { self.mat.mul_v(vec) } #[inline] fn concat(&self, other: &Basis2) -> Basis2 { Basis2 { mat: self.mat.mul_m(&other.mat) } } @@ -202,27 +202,29 @@ ApproxEq for Basis2 { impl> Rotation2 for Basis2 { - fn from_angle(theta: Rad) -> Basis2 { Basis2 { mat: Mat2::from_angle(theta) } } + fn from_angle(theta: Rad) -> Basis2 { Basis2 { mat: Matrix2::from_angle(theta) } } } /// A three-dimensional rotation matrix. /// /// The matrix is guaranteed to be orthogonal, so some operations, specifically /// inversion, can be implemented more efficiently than the implementations for -/// `math::Mat3`. To ensure orthogonality is maintained, the operations have -/// been restricted to a subeset of those implemented on `Mat3`. +/// `math::Matrix3`. To ensure orthogonality is maintained, the operations have +/// been restricted to a subeset of those implemented on `Matrix3`. #[deriving(Eq, Clone)] pub struct Basis3 { - mat: Mat3 + mat: Matrix3 } impl> Basis3 { #[inline] - pub fn from_quat(quat: &Quat) -> Basis3 { Basis3 { mat: quat.to_mat3() } } + pub fn from_quaternion(quaternion: &Quaternion) -> Basis3 { + Basis3 { mat: quaternion.to_matrix3() } + } #[inline] - pub fn as_mat3<'a>(&'a self) -> &'a Mat3 { &'a self.mat } + pub fn as_matrix3<'a>(&'a self) -> &'a Matrix3 { &'a self.mat } } pub trait ToBasis3 { @@ -234,35 +236,35 @@ impl ToBasis3 for Basis3 { fn to_rot3(&self) -> Basis3 { self.clone() } } -impl ToMat3 for Basis3 { +impl ToMatrix3 for Basis3 { #[inline] - fn to_mat3(&self) -> Mat3 { self.mat.clone() } + fn to_matrix3(&self) -> Matrix3 { self.mat.clone() } } impl> -ToQuat for Basis3 { +ToQuaternion for Basis3 { #[inline] - fn to_quat(&self) -> Quat { self.mat.to_quat() } + fn to_quaternion(&self) -> Quaternion { self.mat.to_quaternion() } } impl> -Rotation, Point3> for Basis3 { +Rotation, Point3> for Basis3 { #[inline] - fn identity() -> Basis3 { Basis3{ mat: Mat3::identity() } } + fn identity() -> Basis3 { Basis3{ mat: Matrix3::identity() } } #[inline] - fn look_at(dir: &Vec3, up: &Vec3) -> Basis3 { - Basis3 { mat: Mat3::look_at(dir, up) } + fn look_at(dir: &Vector3, up: &Vector3) -> Basis3 { + Basis3 { mat: Matrix3::look_at(dir, up) } } #[inline] - fn between_vecs(a: &Vec3, b: &Vec3) -> Basis3 { - let q: Quat = Rotation::between_vecs(a, b); + fn between_vectors(a: &Vector3, b: &Vector3) -> Basis3 { + let q: Quaternion = Rotation::between_vectors(a, b); q.to_rot3() } #[inline] - fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mat.mul_v(vec) } + fn rotate_vector(&self, vec: &Vector3) -> Vector3 { self.mat.mul_v(vec) } #[inline] fn concat(&self, other: &Basis3) -> Basis3 { Basis3 { mat: self.mat.mul_m(&other.mat) } } @@ -291,23 +293,23 @@ ApproxEq for Basis3 { impl> Rotation3 for Basis3 { - fn from_axis_angle(axis: &Vec3, angle: Rad) -> Basis3 { - Basis3 { mat: Mat3::from_axis_angle(axis, angle) } + fn from_axis_angle(axis: &Vector3, angle: Rad) -> Basis3 { + Basis3 { mat: Matrix3::from_axis_angle(axis, angle) } } fn from_euler(x: Rad, y: Rad, z: Rad) -> Basis3 { - Basis3 { mat: Mat3::from_euler(x, y ,z) } + Basis3 { mat: Matrix3::from_euler(x, y ,z) } } fn from_angle_x(theta: Rad) -> Basis3 { - Basis3 { mat: Mat3::from_angle_x(theta) } + Basis3 { mat: Matrix3::from_angle_x(theta) } } fn from_angle_y(theta: Rad) -> Basis3 { - Basis3 { mat: Mat3::from_angle_y(theta) } + Basis3 { mat: Matrix3::from_angle_y(theta) } } fn from_angle_z(theta: Rad) -> Basis3 { - Basis3 { mat: Mat3::from_angle_z(theta) } + Basis3 { mat: Matrix3::from_angle_z(theta) } } } diff --git a/src/cgmath/transform.rs b/src/cgmath/transform.rs index e8dc1e0..a9c47de 100644 --- a/src/cgmath/transform.rs +++ b/src/cgmath/transform.rs @@ -18,12 +18,12 @@ use std::{fmt,num}; use std::num::one; use approx::ApproxEq; -use matrix::{Matrix, Mat4, ToMat4}; +use matrix::{Matrix, Matrix4, ToMatrix4}; use point::{Point, Point3}; use ray::Ray; use rotation::{Rotation, Rotation3}; -use quaternion::Quat; -use vector::{Vector, Vec3}; +use quaternion::Quaternion; +use vector::{Vector, Vector3}; use partial_ord::{PartOrdPrim, PartOrdFloat}; /// A trait of affine transformation, that can be applied to points or vectors @@ -38,12 +38,12 @@ pub trait Transform fn identity() -> Self; fn look_at(eye: &P, center: &P, up: &V) -> Self; - fn transform_vec(&self, vec: &V) -> V; + fn transform_vector(&self, vec: &V) -> V; fn transform_point(&self, point: &P) -> P; #[inline] fn transform_ray(&self, ray: &Ray) -> Ray { - Ray::new( self.transform_point(&ray.origin), self.transform_vec(&ray.direction) ) + Ray::new( self.transform_point(&ray.origin), self.transform_vector(&ray.direction) ) } #[inline] @@ -98,7 +98,7 @@ Transform for Decomposed { fn look_at(eye: &P, center: &P, up: &V) -> Decomposed { let origin :P = Point::origin(); let rot :R = Rotation::look_at( ¢er.sub_p(eye), up ); - let disp :V = rot.rotate_vec( &origin.sub_p(eye) ); + let disp :V = rot.rotate_vector( &origin.sub_p(eye) ); Decomposed { scale: num::one(), rot: rot, @@ -107,8 +107,8 @@ Transform for Decomposed { } #[inline] - fn transform_vec(&self, vec: &V) -> V { - self.rot.rotate_vec( &vec.mul_s( self.scale.clone() )) + fn transform_vector(&self, vec: &V) -> V { + self.rot.rotate_vector( &vec.mul_s( self.scale.clone() )) } #[inline] @@ -131,7 +131,7 @@ Transform for Decomposed { let _1 : S = num::one(); let s = _1 / self.scale; let r = self.rot.invert(); - let d = r.rotate_vec( &self.disp ).mul_s( -s ); + let d = r.rotate_vector( &self.disp ).mul_s( -s ); Some( Decomposed { scale: s, rot: r, @@ -142,24 +142,24 @@ Transform for Decomposed { } pub trait Transform3 -: Transform, Point3> -+ ToMat4 +: Transform, Point3> ++ ToMatrix4 {} impl, R: Rotation3> -ToMat4 for Decomposed, R> { - fn to_mat4(&self) -> Mat4 { - let mut m = self.rot.to_mat3().mul_s( self.scale.clone() ).to_mat4(); +ToMatrix4 for Decomposed, R> { + fn to_matrix4(&self) -> Matrix4 { + let mut m = self.rot.to_matrix3().mul_s( self.scale.clone() ).to_matrix4(); m.w = self.disp.extend( num::one() ); m } } impl, R: Rotation3> -Transform3 for Decomposed,R> {} +Transform3 for Decomposed,R> {} impl> -fmt::Show for Decomposed,R> { +fmt::Show for Decomposed,R> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "(scale({}), rot({}), disp{})", self.scale, self.rot, self.disp) @@ -169,23 +169,23 @@ fmt::Show for Decomposed,R> { /// A homogeneous transformation matrix. pub struct AffineMatrix3 { - pub mat: Mat4, + pub mat: Matrix4, } impl> -Transform, Point3> for AffineMatrix3 { +Transform, Point3> for AffineMatrix3 { #[inline] fn identity() -> AffineMatrix3 { - AffineMatrix3 { mat: Mat4::identity() } + AffineMatrix3 { mat: Matrix4::identity() } } #[inline] - fn look_at(eye: &Point3, center: &Point3, up: &Vec3) -> AffineMatrix3 { - AffineMatrix3 { mat: Mat4::look_at(eye, center, up) } + fn look_at(eye: &Point3, center: &Point3, up: &Vector3) -> AffineMatrix3 { + AffineMatrix3 { mat: Matrix4::look_at(eye, center, up) } } #[inline] - fn transform_vec(&self, vec: &Vec3) -> Vec3 { + fn transform_vector(&self, vec: &Vector3) -> Vector3 { self.mat.mul_v( &vec.extend(num::zero()) ).truncate() } @@ -206,8 +206,8 @@ Transform, Point3> for AffineMatrix3 { } impl -ToMat4 for AffineMatrix3 { - #[inline] fn to_mat4(&self) -> Mat4 { self.mat.clone() } +ToMatrix4 for AffineMatrix3 { + #[inline] fn to_matrix4(&self) -> Matrix4 { self.mat.clone() } } impl> @@ -216,26 +216,26 @@ Transform3 for AffineMatrix3 {} /// A transformation in three dimensions consisting of a rotation, /// displacement vector and scale amount. -pub struct Transform3D( Decomposed,Quat> ); +pub struct Transform3D( Decomposed,Quaternion> ); impl> Transform3D { #[inline] - pub fn new(scale: S, rot: Quat, disp: Vec3) -> Transform3D { + pub fn new(scale: S, rot: Quaternion, disp: Vector3) -> Transform3D { Transform3D( Decomposed { scale: scale, rot: rot, disp: disp }) } #[inline] pub fn translate(x: S, y: S, z: S) -> Transform3D { - Transform3D( Decomposed { scale: one(), rot: Quat::zero(), disp: Vec3::new(x, y, z) }) + Transform3D( Decomposed { scale: one(), rot: Quaternion::zero(), disp: Vector3::new(x, y, z) }) } #[inline] - pub fn get<'a>(&'a self) -> &'a Decomposed,Quat> { + pub fn get<'a>(&'a self) -> &'a Decomposed,Quaternion> { let &Transform3D(ref d) = self; d } } -impl> ToMat4 for Transform3D { - fn to_mat4(&self) -> Mat4 { self.get().to_mat4() } +impl> ToMatrix4 for Transform3D { + fn to_matrix4(&self) -> Matrix4 { self.get().to_matrix4() } } diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index c95824f..7bd5d84 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -133,41 +133,41 @@ macro_rules! vec( ) ) -vec!(Vec2 { x, y }, 2) -vec!(Vec3 { x, y, z }, 3) -vec!(Vec4 { x, y, z, w }, 4) +vec!(Vector2 { x, y }, 2) +vec!(Vector3 { x, y, z }, 3) +vec!(Vector4 { x, y, z, w }, 4) -array!(impl Vec2 -> [S, ..2] _2) -array!(impl Vec3 -> [S, ..3] _3) -array!(impl Vec4 -> [S, ..4] _4) +array!(impl Vector2 -> [S, ..2] _2) +array!(impl Vector3 -> [S, ..3] _3) +array!(impl Vector4 -> [S, ..4] _4) /// Operations specific to numeric two-dimensional vectors. -impl Vec2 { - #[inline] pub fn unit_x() -> Vec2 { Vec2::new(one(), zero()) } - #[inline] pub fn unit_y() -> Vec2 { Vec2::new(zero(), one()) } +impl Vector2 { + #[inline] pub fn unit_x() -> Vector2 { Vector2::new(one(), zero()) } + #[inline] pub fn unit_y() -> Vector2 { Vector2::new(zero(), one()) } /// The perpendicular dot product of the vector and `other`. #[inline] - pub fn perp_dot(&self, other: &Vec2) -> S { + pub fn perp_dot(&self, other: &Vector2) -> S { (self.x * other.y) - (self.y * other.x) } #[inline] - pub fn extend(&self, z: S)-> Vec3 { - Vec3::new(self.x.clone(), self.y.clone(), z) + pub fn extend(&self, z: S)-> Vector3 { + Vector3::new(self.x.clone(), self.y.clone(), z) } } /// Operations specific to numeric three-dimensional vectors. -impl Vec3 { - #[inline] pub fn unit_x() -> Vec3 { Vec3::new(one(), zero(), zero()) } - #[inline] pub fn unit_y() -> Vec3 { Vec3::new(zero(), one(), zero()) } - #[inline] pub fn unit_z() -> Vec3 { Vec3::new(zero(), zero(), one()) } +impl Vector3 { + #[inline] pub fn unit_x() -> Vector3 { Vector3::new(one(), zero(), zero()) } + #[inline] pub fn unit_y() -> Vector3 { Vector3::new(zero(), one(), zero()) } + #[inline] pub fn unit_z() -> Vector3 { Vector3::new(zero(), zero(), one()) } /// Returns the cross product of the vector and `other`. #[inline] - pub fn cross(&self, other: &Vec3) -> Vec3 { - Vec3::new((self.y * other.z) - (self.z * other.y), + pub fn cross(&self, other: &Vector3) -> Vector3 { + Vector3::new((self.y * other.z) - (self.z * other.y), (self.z * other.x) - (self.x * other.z), (self.x * other.y) - (self.y * other.x)) } @@ -175,31 +175,31 @@ impl Vec3 { /// Calculates the cross product of the vector and `other`, then stores the /// result in `self`. #[inline] - pub fn cross_self(&mut self, other: &Vec3) { + pub fn cross_self(&mut self, other: &Vector3) { *self = self.cross(other) } #[inline] - pub fn extend(&self, w: S)-> Vec4 { - Vec4::new(self.x.clone(), self.y.clone(), self.z.clone(), w) + pub fn extend(&self, w: S)-> Vector4 { + Vector4::new(self.x.clone(), self.y.clone(), self.z.clone(), w) } #[inline] - pub fn truncate(&self)-> Vec2 { - Vec2::new(self.x.clone(), self.y.clone()) //ignore Z + pub fn truncate(&self)-> Vector2 { + Vector2::new(self.x.clone(), self.y.clone()) //ignore Z } } /// Operations specific to numeric four-dimensional vectors. -impl Vec4 { - #[inline] pub fn unit_x() -> Vec4 { Vec4::new(one(), zero(), zero(), zero()) } - #[inline] pub fn unit_y() -> Vec4 { Vec4::new(zero(), one(), zero(), zero()) } - #[inline] pub fn unit_z() -> Vec4 { Vec4::new(zero(), zero(), one(), zero()) } - #[inline] pub fn unit_w() -> Vec4 { Vec4::new(zero(), zero(), zero(), one()) } +impl Vector4 { + #[inline] pub fn unit_x() -> Vector4 { Vector4::new(one(), zero(), zero(), zero()) } + #[inline] pub fn unit_y() -> Vector4 { Vector4::new(zero(), one(), zero(), zero()) } + #[inline] pub fn unit_z() -> Vector4 { Vector4::new(zero(), zero(), one(), zero()) } + #[inline] pub fn unit_w() -> Vector4 { Vector4::new(zero(), zero(), zero(), one()) } #[inline] - pub fn truncate(&self)-> Vec3 { - Vec3::new(self.x.clone(), self.y.clone(), self.z.clone()) //ignore W + pub fn truncate(&self)-> Vector3 { + Vector3::new(self.x.clone(), self.y.clone(), self.z.clone()) //ignore W } } @@ -279,42 +279,42 @@ pub trait EuclideanVector } impl> -EuclideanVector for Vec2 { +EuclideanVector for Vector2 { #[inline] - fn angle(&self, other: &Vec2) -> Rad { + fn angle(&self, other: &Vector2) -> Rad { atan2(self.perp_dot(other), self.dot(other)) } } impl> -EuclideanVector for Vec3 { +EuclideanVector for Vector3 { #[inline] - fn angle(&self, other: &Vec3) -> Rad { + fn angle(&self, other: &Vector3) -> Rad { atan2(self.cross(other).length(), self.dot(other)) } } impl> -EuclideanVector for Vec4 { +EuclideanVector for Vector4 { #[inline] - fn angle(&self, other: &Vec4) -> Rad { + fn angle(&self, other: &Vector4) -> Rad { acos(self.dot(other) / (self.length() * other.length())) } } -impl fmt::Show for Vec2 { +impl fmt::Show for Vector2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[{}, {}]", self.x, self.y) } } -impl fmt::Show for Vec3 { +impl fmt::Show for Vector3 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[{}, {}, {}]", self.x, self.y, self.z) } } -impl fmt::Show for Vec4 { +impl fmt::Show for Vector4 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f.buf, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) } diff --git a/src/test/aabb.rs b/src/test/aabb.rs index 189120d..8d4f67c 100644 --- a/src/test/aabb.rs +++ b/src/test/aabb.rs @@ -1,13 +1,13 @@ use cgmath::aabb::*; use cgmath::point::{Point2, Point3}; -use cgmath::vector::{Vec2, Vec3}; +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(), Vec2::new(30, 40)); + assert_eq!(aabb.dim(), Vector2::new(30, 40)); assert_eq!(aabb.volume(), 30 * 40); assert_eq!(aabb.center(), Point2::new(-5, 10)); @@ -24,7 +24,7 @@ fn test_aabb() { 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(), Vec3::new(30, 40, 10)); + 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)); @@ -36,12 +36,12 @@ fn test_aabb() { assert!(aabb.contains(&Point3::new(-20, -10, -5))); assert!(!aabb.contains(&Point3::new(-21, -11, -6))); - assert_eq!(aabb.add_v(&Vec3::new(1, 2, 3)), + 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.mul_s(2), Aabb3::new(Point3::new(-40, -20, -10), Point3::new(20, 60, 10))); - assert_eq!(aabb.mul_v(&Vec3::new(1, 2, 3)), + assert_eq!(aabb.mul_v(&Vector3::new(1, 2, 3)), Aabb3::new(Point3::new(-20, -20, -15), Point3::new(10, 60, 15))); } diff --git a/src/test/matrix.rs b/src/test/matrix.rs index 2fd9417..8d2072c 100644 --- a/src/test/matrix.rs +++ b/src/test/matrix.rs @@ -17,81 +17,81 @@ use cgmath::matrix::*; use cgmath::vector::*; use cgmath::approx::ApproxEq; -pub mod mat2 { +pub mod matrix2 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Mat2 = Mat2 { x: Vec2 { x: 1.0, y: 3.0 }, - y: Vec2 { x: 2.0, y: 4.0 } }; - pub static B: Mat2 = Mat2 { x: Vec2 { x: 2.0, y: 4.0 }, - y: Vec2 { x: 3.0, y: 5.0 } }; - pub static C: Mat2 = Mat2 { x: Vec2 { x: 2.0, y: 1.0 }, - y: Vec2 { x: 1.0, y: 2.0 } }; + 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 V: Vec2 = Vec2 { x: 1.0, y: 2.0 }; + pub static V: Vector2 = Vector2 { x: 1.0, y: 2.0 }; pub static F: f64 = 0.5; } -pub mod mat3 { +pub mod matrix3 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Mat3 = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 }, - y: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, - z: Vec3 { x: 3.0, y: 6.0, z: 9.0 } }; - pub static B: Mat3 = Mat3 { x: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, - y: Vec3 { x: 3.0, y: 6.0, z: 9.0 }, - z: Vec3 { x: 4.0, y: 7.0, z: 10.0 } }; - pub static C: Mat3 = Mat3 { x: Vec3 { x: 2.0, y: 4.0, z: 6.0 }, - y: Vec3 { x: 0.0, y: 2.0, z: 4.0 }, - z: Vec3 { x: 0.0, y: 0.0, z: 1.0 } }; - pub static D: Mat3 = Mat3 { x: Vec3 { x: 3.0, y: 2.0, z: 1.0 }, - y: Vec3 { x: 2.0, y: 3.0, z: 2.0 }, - z: Vec3 { x: 1.0, y: 2.0, z: 3.0 } }; + 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 V: Vec3 = Vec3 { x: 1.0, y: 2.0, z: 3.0 }; + pub static V: Vector3 = Vector3 { x: 1.0, y: 2.0, z: 3.0 }; pub static F: f64 = 0.5; } -pub mod mat4 { +pub mod matrix4 { use cgmath::matrix::*; use cgmath::vector::*; - pub static A: Mat4 = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 }, - y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - z: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - w: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } }; - pub static B: Mat4 = Mat4 { x: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, - y: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 }, - z: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 }, - w: Vec4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } }; - pub static C: Mat4 = Mat4 { x: Vec4 { x: 3.0, y: 2.0, z: 1.0, w: 1.0 }, - y: Vec4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 }, - z: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 }, - w: Vec4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } }; - pub static D: Mat4 = Mat4 { x: Vec4 { x: 4.0, y: 3.0, z: 2.0, w: 1.0 }, - y: Vec4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 }, - z: Vec4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 }, - w: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } }; + 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 V: Vec4 = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 }; + pub static V: Vector4 = Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 }; pub static F: f64 = 0.5; } #[test] fn test_neg() { - // Mat2 - assert_eq!(-mat2::A, - Mat2::new(-1.0, -3.0, + // Matrix2 + assert_eq!(-matrix2::A, + Matrix2::new(-1.0, -3.0, -2.0, -4.0)); - // Mat3 - assert_eq!(-mat3::A, - Mat3::new(-1.0, -4.0, -7.0, + // 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)); - // Mat4 - assert_eq!(-mat4::A, - Mat4::new(-1.0, -5.0, -9.0, -13.0, + // 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)); @@ -99,112 +99,112 @@ fn test_neg() { #[test] fn test_mul_s() { - // Mat2 - assert_eq!(mat2::A.mul_s(mat2::F), - Mat2::new(0.5, 1.5, + // Matrix2 + assert_eq!(matrix2::A.mul_s(matrix2::F), + Matrix2::new(0.5, 1.5, 1.0, 2.0)); - let mut mut_a = mat2::A; - mut_a.mul_self_s(mat2::F); - assert_eq!(mut_a, mat2::A.mul_s(mat2::F)); + let mut mut_a = matrix2::A; + mut_a.mul_self_s(matrix2::F); + assert_eq!(mut_a, matrix2::A.mul_s(matrix2::F)); - // Mat3 - assert_eq!(mat3::A.mul_s(mat3::F), - Mat3::new(0.5, 2.0, 3.5, + // 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)); - let mut mut_a = mat3::A; - mut_a.mul_self_s(mat3::F); - assert_eq!(mut_a, mat3::A.mul_s(mat3::F)); + let mut mut_a = matrix3::A; + mut_a.mul_self_s(matrix3::F); + assert_eq!(mut_a, matrix3::A.mul_s(matrix3::F)); - // Mat4 - assert_eq!(mat4::A.mul_s(mat4::F), - Mat4::new(0.5, 2.5, 4.5, 6.5, + // 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)); - let mut mut_a = mat4::A; - mut_a.mul_self_s(mat4::F); - assert_eq!(mut_a, mat4::A.mul_s(mat4::F)); + let mut mut_a = matrix4::A; + mut_a.mul_self_s(matrix4::F); + assert_eq!(mut_a, matrix4::A.mul_s(matrix4::F)); } #[test] fn test_add_m() { - // Mat2 - assert_eq!(mat2::A.add_m(&mat2::B), - Mat2::new(3.0, 7.0, + // Matrix2 + assert_eq!(matrix2::A.add_m(&matrix2::B), + Matrix2::new(3.0, 7.0, 5.0, 9.0)); - let mut mut_a = mat2::A; - mut_a.add_self_m(&mat2::B); - assert_eq!(mut_a, mat2::A.add_m(&mat2::B)); + let mut mut_a = matrix2::A; + mut_a.add_self_m(&matrix2::B); + assert_eq!(mut_a, matrix2::A.add_m(&matrix2::B)); - // Mat3 - assert_eq!(mat3::A.add_m(&mat3::B), - Mat3::new(3.0, 9.0, 15.0, + // 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)); - let mut mut_a = mat3::A; - mut_a.add_self_m(&mat3::B); - assert_eq!(mut_a, mat3::A.add_m(&mat3::B)); + let mut mut_a = matrix3::A; + mut_a.add_self_m(&matrix3::B); + assert_eq!(mut_a, matrix3::A.add_m(&matrix3::B)); - // Mat4 - assert_eq!(mat4::A.add_m(&mat4::B), - Mat4::new(3.0, 11.0, 19.0, 27.0, + // 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)); - let mut mut_a = mat4::A; - mut_a.add_self_m(&mat4::B); - assert_eq!(mut_a, mat4::A.add_m(&mat4::B)); + let mut mut_a = matrix4::A; + mut_a.add_self_m(&matrix4::B); + assert_eq!(mut_a, matrix4::A.add_m(&matrix4::B)); } #[test] fn test_sub_m() { - // Mat2 - assert_eq!(mat2::A.sub_m(&mat2::B), - Mat2::new(-1.0, -1.0, + // Matrix2 + assert_eq!(matrix2::A.sub_m(&matrix2::B), + Matrix2::new(-1.0, -1.0, -1.0, -1.0)); - let mut mut_a = mat2::A; - mut_a.sub_self_m(&mat2::B); - assert_eq!(mut_a, mat2::A.sub_m(&mat2::B)); + let mut mut_a = matrix2::A; + mut_a.sub_self_m(&matrix2::B); + assert_eq!(mut_a, matrix2::A.sub_m(&matrix2::B)); - // Mat3 - assert_eq!(mat3::A.sub_m(&mat3::B), - Mat3::new(-1.0, -1.0, -1.0, + // 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)); - let mut mut_a = mat3::A; - mut_a.sub_self_m(&mat3::B); - assert_eq!(mut_a, mat3::A.sub_m(&mat3::B)); + let mut mut_a = matrix3::A; + mut_a.sub_self_m(&matrix3::B); + assert_eq!(mut_a, matrix3::A.sub_m(&matrix3::B)); - // Mat4 - assert_eq!(mat4::A.sub_m(&mat4::B), - Mat4::new(-1.0, -1.0, -1.0, -1.0, + // 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)); - let mut mut_a = mat4::A; - mut_a.sub_self_m(&mat4::B); - assert_eq!(mut_a, mat4::A.sub_m(&mat4::B)); + let mut mut_a = matrix4::A; + mut_a.sub_self_m(&matrix4::B); + assert_eq!(mut_a, matrix4::A.sub_m(&matrix4::B)); } #[test] fn test_mul_v() { - assert_eq!(mat2::A.mul_v(&mat2::V), Vec2::new(5.0, 11.0)); - assert_eq!(mat3::A.mul_v(&mat3::V), Vec3::new(14.0, 32.0, 50.0)); - assert_eq!(mat4::A.mul_v(&mat4::V), Vec4::new(30.0, 70.0, 110.0, 150.0)); + 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)); } #[test] fn test_mul_m() { - assert_eq!(mat2::A.mul_m(&mat2::B), - Mat2::new(10.0, 22.0, + assert_eq!(matrix2::A.mul_m(&matrix2::B), + Matrix2::new(10.0, 22.0, 13.0, 29.0)); - assert_eq!(mat3::A.mul_m(&mat3::B), - Mat3::new(36.0, 81.0, 126.0, + 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)); - assert_eq!(mat4::A.mul_m(&mat4::B), - Mat4::new(100.0, 228.0, 356.0, 484.0, + 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)); @@ -212,153 +212,153 @@ fn test_mul_m() { #[test] fn test_determinant() { - assert_eq!(mat2::A.determinant(), -2.0); - assert_eq!(mat3::A.determinant(), 0.0); - assert_eq!(mat4::A.determinant(), 0.0); + assert_eq!(matrix2::A.determinant(), -2.0); + assert_eq!(matrix3::A.determinant(), 0.0); + assert_eq!(matrix4::A.determinant(), 0.0); } #[test] fn test_trace() { - assert_eq!(mat2::A.trace(), 5.0); - assert_eq!(mat3::A.trace(), 15.0); - assert_eq!(mat4::A.trace(), 34.0); + assert_eq!(matrix2::A.trace(), 5.0); + assert_eq!(matrix3::A.trace(), 15.0); + assert_eq!(matrix4::A.trace(), 34.0); } #[test] fn test_transpose() { - // Mat2 - assert_eq!(mat2::A.transpose(), - Mat2::::new(1.0, 2.0, + // Matrix2 + assert_eq!(matrix2::A.transpose(), + Matrix2::::new(1.0, 2.0, 3.0, 4.0)); - let mut mut_a = mat2::A; + let mut mut_a = matrix2::A; mut_a.transpose_self(); - assert_eq!(mut_a, mat2::A.transpose()); + assert_eq!(mut_a, matrix2::A.transpose()); - // Mat3 - assert_eq!(mat3::A.transpose(), - Mat3::::new(1.0, 2.0, 3.0, + // 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)); - let mut mut_a = mat3::A; + let mut mut_a = matrix3::A; mut_a.transpose_self(); - assert_eq!(mut_a, mat3::A.transpose()); + assert_eq!(mut_a, matrix3::A.transpose()); - // Mat4 - assert_eq!(mat4::A.transpose(), - Mat4::::new( 1.0, 2.0, 3.0, 4.0, + // 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)); - let mut mut_a = mat4::A; + let mut mut_a = matrix4::A; mut_a.transpose_self(); - assert_eq!(mut_a, mat4::A.transpose()); + assert_eq!(mut_a, matrix4::A.transpose()); } #[test] fn test_invert() { - // Mat2 - assert!(Mat2::::identity().invert().unwrap().is_identity()); + // Matrix2 + assert!(Matrix2::::identity().invert().unwrap().is_identity()); - assert_eq!(mat2::A.invert().unwrap(), - Mat2::new(-2.0, 1.5, + assert_eq!(matrix2::A.invert().unwrap(), + Matrix2::new(-2.0, 1.5, 1.0, -0.5)); - assert!(Mat2::new(0.0, 2.0, + assert!(Matrix2::new(0.0, 2.0, 0.0, 5.0).invert().is_none()); - let mut mut_a = mat2::A; + let mut mut_a = matrix2::A; mut_a.invert_self(); - assert_eq!(mut_a, mat2::A.invert().unwrap()); + assert_eq!(mut_a, matrix2::A.invert().unwrap()); - // Mat3 - assert!(Mat3::::identity().invert().unwrap().is_identity()); + // Matrix3 + assert!(Matrix3::::identity().invert().unwrap().is_identity()); - assert_eq!(mat3::A.invert(), None); + assert_eq!(matrix3::A.invert(), None); - assert_eq!(mat3::C.invert().unwrap(), - Mat3::new(0.5, -1.0, 1.0, + 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)); - let mut mut_c = mat3::C; + let mut mut_c = matrix3::C; mut_c.invert_self(); - assert_eq!(mut_c, mat3::C.invert().unwrap()); + assert_eq!(mut_c, matrix3::C.invert().unwrap()); - // Mat4 - assert!(Mat4::::identity().invert().unwrap().is_identity()); + // Matrix4 + assert!(Matrix4::::identity().invert().unwrap().is_identity()); - assert!(mat4::C.invert().unwrap().approx_eq(& - Mat4::new( 5.0, -4.0, 1.0, 0.0, + 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))); - let mut mut_c = mat4::C; + let mut mut_c = matrix4::C; mut_c.invert_self(); - assert_eq!(mut_c, mat4::C.invert().unwrap()); + assert_eq!(mut_c, matrix4::C.invert().unwrap()); } #[test] fn test_predicates() { - // Mat2 + // Matrix2 - assert!(Mat2::::identity().is_identity()); - assert!(Mat2::::identity().is_symmetric()); - assert!(Mat2::::identity().is_diagonal()); - assert!(!Mat2::::identity().is_rotated()); - assert!(Mat2::::identity().is_invertible()); + assert!(Matrix2::::identity().is_identity()); + assert!(Matrix2::::identity().is_symmetric()); + assert!(Matrix2::::identity().is_diagonal()); + assert!(!Matrix2::::identity().is_rotated()); + assert!(Matrix2::::identity().is_invertible()); - assert!(!mat2::A.is_identity()); - assert!(!mat2::A.is_symmetric()); - assert!(!mat2::A.is_diagonal()); - assert!(mat2::A.is_rotated()); - assert!(mat2::A.is_invertible()); + assert!(!matrix2::A.is_identity()); + assert!(!matrix2::A.is_symmetric()); + assert!(!matrix2::A.is_diagonal()); + assert!(matrix2::A.is_rotated()); + assert!(matrix2::A.is_invertible()); - assert!(!mat2::C.is_identity()); - assert!(mat2::C.is_symmetric()); - assert!(!mat2::C.is_diagonal()); - assert!(mat2::C.is_rotated()); - assert!(mat2::C.is_invertible()); + assert!(!matrix2::C.is_identity()); + assert!(matrix2::C.is_symmetric()); + assert!(!matrix2::C.is_diagonal()); + assert!(matrix2::C.is_rotated()); + assert!(matrix2::C.is_invertible()); - assert!(Mat2::from_value(6.0).is_diagonal()); + assert!(Matrix2::from_value(6.0).is_diagonal()); - // Mat3 + // Matrix3 - assert!(Mat3::::identity().is_identity()); - assert!(Mat3::::identity().is_symmetric()); - assert!(Mat3::::identity().is_diagonal()); - assert!(!Mat3::::identity().is_rotated()); - assert!(Mat3::::identity().is_invertible()); + assert!(Matrix3::::identity().is_identity()); + assert!(Matrix3::::identity().is_symmetric()); + assert!(Matrix3::::identity().is_diagonal()); + assert!(!Matrix3::::identity().is_rotated()); + assert!(Matrix3::::identity().is_invertible()); - assert!(!mat3::A.is_identity()); - assert!(!mat3::A.is_symmetric()); - assert!(!mat3::A.is_diagonal()); - assert!(mat3::A.is_rotated()); - assert!(!mat3::A.is_invertible()); + assert!(!matrix3::A.is_identity()); + assert!(!matrix3::A.is_symmetric()); + assert!(!matrix3::A.is_diagonal()); + assert!(matrix3::A.is_rotated()); + assert!(!matrix3::A.is_invertible()); - assert!(!mat3::D.is_identity()); - assert!(mat3::D.is_symmetric()); - assert!(!mat3::D.is_diagonal()); - assert!(mat3::D.is_rotated()); - assert!(mat3::D.is_invertible()); + assert!(!matrix3::D.is_identity()); + assert!(matrix3::D.is_symmetric()); + assert!(!matrix3::D.is_diagonal()); + assert!(matrix3::D.is_rotated()); + assert!(matrix3::D.is_invertible()); - assert!(Mat3::from_value(6.0).is_diagonal()); + assert!(Matrix3::from_value(6.0).is_diagonal()); - // Mat4 + // Matrix4 - assert!(Mat4::::identity().is_identity()); - assert!(Mat4::::identity().is_symmetric()); - assert!(Mat4::::identity().is_diagonal()); - assert!(!Mat4::::identity().is_rotated()); - assert!(Mat4::::identity().is_invertible()); + assert!(Matrix4::::identity().is_identity()); + assert!(Matrix4::::identity().is_symmetric()); + assert!(Matrix4::::identity().is_diagonal()); + assert!(!Matrix4::::identity().is_rotated()); + assert!(Matrix4::::identity().is_invertible()); - assert!(!mat4::A.is_identity()); - assert!(!mat4::A.is_symmetric()); - assert!(!mat4::A.is_diagonal()); - assert!(mat4::A.is_rotated()); - assert!(!mat4::A.is_invertible()); + assert!(!matrix4::A.is_identity()); + assert!(!matrix4::A.is_symmetric()); + assert!(!matrix4::A.is_diagonal()); + assert!(matrix4::A.is_rotated()); + assert!(!matrix4::A.is_invertible()); - assert!(!mat4::D.is_identity()); - assert!(mat4::D.is_symmetric()); - assert!(!mat4::D.is_diagonal()); - assert!(mat4::D.is_rotated()); - assert!(mat4::D.is_invertible()); + assert!(!matrix4::D.is_identity()); + assert!(matrix4::D.is_symmetric()); + assert!(!matrix4::D.is_diagonal()); + assert!(matrix4::D.is_rotated()); + assert!(matrix4::D.is_invertible()); - assert!(Mat4::from_value(6.0).is_diagonal()); + assert!(Matrix4::from_value(6.0).is_diagonal()); } diff --git a/src/test/plane.rs b/src/test/plane.rs index 57a480e..75cc90e 100644 --- a/src/test/plane.rs +++ b/src/test/plane.rs @@ -35,12 +35,12 @@ fn test_from_points() { #[test] fn test_ray_intersection() { let p0 = Plane::from_abcd(1f64, 0f64, 0f64, -7f64); - let r0: Ray3 = Ray::new(Point3::new(2f64, 3f64, 4f64), Vec3::new(1f64, 1f64, 1f64).normalize()); + let r0: Ray3 = Ray::new(Point3::new(2f64, 3f64, 4f64), Vector3::new(1f64, 1f64, 1f64).normalize()); assert_eq!((p0, r0).intersection(), Some(Point3::new(7f64, 8f64, 9f64))); let p1 = Plane::from_points(Point3::new(5f64, 0f64, 5f64), Point3::new(5f64, 5f64, 5f64), Point3::new(5f64, 0f64, -1f64)).unwrap(); - let r1: Ray3 = Ray::new(Point3::new(0f64, 0f64, 0f64), Vec3::new(-1f64, 0f64, 0f64).normalize()); + let r1: Ray3 = Ray::new(Point3::new(0f64, 0f64, 0f64), Vector3::new(-1f64, 0f64, 0f64).normalize()); assert_eq!((p1, r1).intersection(), None); // r1 points away from p1 } diff --git a/src/test/quaternion.rs b/src/test/quaternion.rs index e6d90cc..b65d258 100644 --- a/src/test/quaternion.rs +++ b/src/test/quaternion.rs @@ -13,16 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use cgmath::matrix::{ToMat4, ToMat3}; -use cgmath::quaternion::Quat; +use cgmath::matrix::{ToMatrix4, ToMatrix3}; +use cgmath::quaternion::Quaternion; #[test] -fn to_mat4() +fn to_matrix4() { - let quat = Quat::new(2f32, 3f32, 4f32, 5f32); + let quaternion = Quaternion::new(2f32, 3f32, 4f32, 5f32); - let mat_short = quat.to_mat4(); - let mat_long = quat.to_mat3().to_mat4(); + let matrix_short = quaternion.to_matrix4(); + let matrix_long = quaternion.to_matrix3().to_matrix4(); - assert!(mat_short == mat_long); + assert!(matrix_short == matrix_long); } diff --git a/src/test/sphere.rs b/src/test/sphere.rs index f53d58b..1d9475a 100644 --- a/src/test/sphere.rs +++ b/src/test/sphere.rs @@ -8,10 +8,10 @@ use cgmath::intersect::Intersect; #[test] fn test_intersection() { let sphere = Sphere {center: Point3::new(0f64,0f64,0f64), radius: 1f64}; - let r0 = Ray::new(Point3::new(0f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); - let r1 = Ray::new(Point3::new(1f64.cos(), 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); - let r2 = Ray::new(Point3::new(1f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); - let r3 = Ray::new(Point3::new(2f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize()); + let r0 = Ray::new(Point3::new(0f64, 0f64, 5f64), Vector3::new(0f64, 0f64, -5f64).normalize()); + let r1 = Ray::new(Point3::new(1f64.cos(), 0f64, 5f64), Vector3::new(0f64, 0f64, -5f64).normalize()); + let r2 = Ray::new(Point3::new(1f64, 0f64, 5f64), Vector3::new(0f64, 0f64, -5f64).normalize()); + let r3 = Ray::new(Point3::new(2f64, 0f64, 5f64), Vector3::new(0f64, 0f64, -5f64).normalize()); assert_eq!((sphere,r0).intersection(), Some(Point3::new(0f64, 0f64, 1f64))); assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(1f64.cos(), 0f64, 1f64.sin()) )); assert_eq!((sphere,r2).intersection(), Some(Point3::new(1f64, 0f64, 0f64))); diff --git a/src/test/transform.rs b/src/test/transform.rs index eac50af..aa1dc49 100644 --- a/src/test/transform.rs +++ b/src/test/transform.rs @@ -21,19 +21,19 @@ use cgmath::approx::ApproxEq; #[test] fn test_invert() { - let v = Vec3::new(1.0, 2.0, 3.0); - let t = Transform3D::new(1.5, Quat::new(0.5,0.5,0.5,0.5), Vec3::new(6.0,-7.0,8.0)); + let v = Vector3::new(1.0, 2.0, 3.0); + let t = Transform3D::new(1.5, Quaternion::new(0.5,0.5,0.5,0.5), Vector3::new(6.0,-7.0,8.0)); let ti = t.get().invert().expect("Expected successful inversion"); - let vt = t.get().transform_vec( &v ); - assert!(v.approx_eq( &ti.transform_vec( &vt ) )); + let vt = t.get().transform_vector( &v ); + assert!(v.approx_eq( &ti.transform_vector( &vt ) )); } #[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 = Vec3::new(1.0, 0.0, 0.0); - let t: Decomposed,Quat> = Transform::look_at(&eye, ¢er, &up); + let up = Vector3::new(1.0, 0.0, 0.0); + 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); assert!( t.transform_point(&point).approx_eq(&view_point) ); diff --git a/src/test/vector.rs b/src/test/vector.rs index 61e4978..3ca9e50 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!(Vec2::from_value(102), Vec2::new(102, 102)); - assert_eq!(Vec3::from_value(22), Vec3::new(22, 22, 22)); - assert_eq!(Vec4::from_value(76.5), Vec4::new(76.5, 76.5, 76.5, 76.5)); + 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)); } #[test] fn test_dot() { - assert_eq!(Vec2::new(1, 2).dot(&Vec2::new(3, 4)), 11); - assert_eq!(Vec3::new(1, 2, 3).dot(&Vec3::new(4, 5, 6)), 32); - assert_eq!(Vec4::new(1, 2, 3, 4).dot(&Vec4::new(5, 6, 7, 8)), 70); + 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); } #[test] fn test_comp_add() { - assert_eq!(Vec2::new(1, 2).comp_add(), 3); - assert_eq!(Vec3::new(1, 2, 3).comp_add(), 6); - assert_eq!(Vec4::new(1, 2, 3, 4).comp_add(), 10); + 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!(Vec2::new(3.0, 4.0).comp_add(), 7.0); - assert_eq!(Vec3::new(4.0, 5.0, 6.0).comp_add(), 15.0); - assert_eq!(Vec4::new(5.0, 6.0, 7.0, 8.0).comp_add(), 26.0); + 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); } #[test] fn test_comp_mul() { - assert_eq!(Vec2::new(1, 2).comp_mul(), 2); - assert_eq!(Vec3::new(1, 2, 3).comp_mul(), 6); - assert_eq!(Vec4::new(1, 2, 3, 4).comp_mul(), 24); + 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!(Vec2::new(3.0, 4.0).comp_mul(), 12.0); - assert_eq!(Vec3::new(4.0, 5.0, 6.0).comp_mul(), 120.0); - assert_eq!(Vec4::new(5.0, 6.0, 7.0, 8.0).comp_mul(), 1680.0); + 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); } #[test] fn test_comp_min() { - assert_eq!(Vec2::new(1, 2).comp_min(), 1); - assert_eq!(Vec3::new(1, 2, 3).comp_min(), 1); - assert_eq!(Vec4::new(1, 2, 3, 4).comp_min(), 1); + 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!(Vec2::new(3.0, 4.0).comp_min(), 3.0); - assert_eq!(Vec3::new(4.0, 5.0, 6.0).comp_min(), 4.0); - assert_eq!(Vec4::new(5.0, 6.0, 7.0, 8.0).comp_min(), 5.0); + 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); } #[test] fn test_comp_max() { - assert_eq!(Vec2::new(1, 2).comp_max(), 2); - assert_eq!(Vec3::new(1, 2, 3).comp_max(), 3); - assert_eq!(Vec4::new(1, 2, 3, 4).comp_max(), 4); + 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!(Vec2::new(3.0, 4.0).comp_max(), 4.0); - assert_eq!(Vec3::new(4.0, 5.0, 6.0).comp_max(), 6.0); - assert_eq!(Vec4::new(5.0, 6.0, 7.0, 8.0).comp_max(), 8.0); + 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); } #[test] fn test_cross() { - let a = Vec3::new(1, 2, 3); - let b = Vec3::new(4, 5, 6); - let r = Vec3::new(-3, 6, -3); + let a = Vector3::new(1, 2, 3); + let b = Vector3::new(4, 5, 6); + let r = Vector3::new(-3, 6, -3); assert_eq!(a.cross(&b), r); let mut a = a; @@ -89,9 +89,9 @@ fn test_cross() { #[test] fn test_is_perpendicular() { - assert!(Vec2::new(1.0, 0.0).is_perpendicular(&Vec2::new(0.0, 1.0))); - assert!(Vec3::new(0.0, 1.0, 0.0).is_perpendicular(&Vec3::new(0.0, 0.0, 1.0))); - assert!(Vec4::new(1.0, 0.0, 0.0, 0.0).is_perpendicular(&Vec4::new(0.0, 0.0, 0.0, 1.0))); + 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))); } #[cfg(test)] @@ -99,9 +99,9 @@ mod test_length { use cgmath::vector::*; #[test] - fn test_vec2(){ - let (a, a_res) = (Vec2::new(3.0, 4.0), 5.0); // (3, 4, 5) Pythagorean triple - let (b, b_res) = (Vec2::new(5.0, 12.0), 13.0); // (5, 12, 13) Pythagorean triple + 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 assert_eq!(a.length2(), a_res * a_res); assert_eq!(b.length2(), b_res * b_res); @@ -111,9 +111,9 @@ mod test_length { } #[test] - fn test_vec3(){ - let (a, a_res) = (Vec3::new(2.0, 3.0, 6.0), 7.0); // (2, 3, 6, 7) Pythagorean quadruple - let (b, b_res) = (Vec3::new(1.0, 4.0, 8.0), 9.0); // (1, 4, 8, 9) Pythagorean quadruple + 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 assert_eq!(a.length2(), a_res * a_res); assert_eq!(b.length2(), b_res * b_res); @@ -123,9 +123,9 @@ mod test_length { } #[test] - fn test_vec4(){ - let (a, a_res) = (Vec4::new(1.0, 2.0, 4.0, 10.0), 11.0); // (1, 2, 4, 10, 11) Pythagorean quintuple - let (b, b_res) = (Vec4::new(1.0, 2.0, 8.0, 10.0), 13.0); // (1, 2, 8, 10, 13) Pythagorean quintuple + 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 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!(Vec2::new(1.0, 0.0).angle(&Vec2::new(0.0, 1.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vec2::new(10.0, 0.0).angle(&Vec2::new(0.0, 5.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vec2::new(-1.0, 0.0).angle(&Vec2::new(0.0, 1.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(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!(Vec3::new(1.0, 0.0, 1.0).angle(&Vec3::new(1.0, 1.0, 0.0)).approx_eq( &rad(Float::frac_pi_3()) )); - assert!(Vec3::new(10.0, 0.0, 10.0).angle(&Vec3::new(5.0, 5.0, 0.0)).approx_eq( &rad(Float::frac_pi_3()) )); - assert!(Vec3::new(-1.0, 0.0, -1.0).angle(&Vec3::new(1.0, -1.0, 0.0)).approx_eq( &rad(2.0 * 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(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!(Vec4::new(1.0, 0.0, 1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vec4::new(10.0, 0.0, 10.0, 0.0).angle(&Vec4::new(0.0, 5.0, 0.0, 5.0)).approx_eq( &rad(Float::frac_pi_2()) )); - assert!(Vec4::new(-1.0, 0.0, -1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.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(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()) )); } #[test] fn test_normalize() { // TODO: test normalize_to, normalize_sel.0, and normalize_self_to - assert!(Vec2::new(3.0, 4.0).normalize().approx_eq( &Vec2::new(3.0/5.0, 4.0/5.0) )); - assert!(Vec3::new(2.0, 3.0, 6.0).normalize().approx_eq( &Vec3::new(2.0/7.0, 3.0/7.0, 6.0/7.0) )); - assert!(Vec4::new(1.0, 2.0, 4.0, 10.0).normalize().approx_eq( &Vec4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) )); + 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) )); }