diff --git a/src/bounds/frustum.rs b/src/bounds/frustum.rs index d6ae3a3..d23d307 100644 --- a/src/bounds/frustum.rs +++ b/src/bounds/frustum.rs @@ -76,12 +76,12 @@ impl Frustum { /// Extracts frustum planes from a projection matrix pub fn from_matrix(mat: Mat4) -> Frustum { Frustum { - left: Plane3::from_vec4(mat.row(3).add_v(&mat.row(0)).normalize()), - right: Plane3::from_vec4(mat.row(3).sub_v(&mat.row(0)).normalize()), - bottom: Plane3::from_vec4(mat.row(3).add_v(&mat.row(1)).normalize()), - top: Plane3::from_vec4(mat.row(3).sub_v(&mat.row(1)).normalize()), - near: Plane3::from_vec4(mat.row(3).add_v(&mat.row(2)).normalize()), - far: Plane3::from_vec4(mat.row(3).sub_v(&mat.row(2)).normalize()), + left: Plane3::from_vec4(mat.r(3).add_v(&mat.r(0)).normalize()), + right: Plane3::from_vec4(mat.r(3).sub_v(&mat.r(0)).normalize()), + bottom: Plane3::from_vec4(mat.r(3).add_v(&mat.r(1)).normalize()), + top: Plane3::from_vec4(mat.r(3).sub_v(&mat.r(1)).normalize()), + near: Plane3::from_vec4(mat.r(3).add_v(&mat.r(2)).normalize()), + far: Plane3::from_vec4(mat.r(3).sub_v(&mat.r(2)).normalize()), } } } diff --git a/src/math/macros.rs b/src/math/macros.rs index 94b06ad..7794107 100644 --- a/src/math/macros.rs +++ b/src/math/macros.rs @@ -19,12 +19,12 @@ macro_rules! impl_dimensioned( ($Self:ident, $T:ty, $n:expr) => ( impl Dimensioned<$T,[$T,..$n]> for $Self { #[inline] - pub fn index<'a>(&'a self, i: uint) -> &'a $T { + pub fn i<'a>(&'a self, i: uint) -> &'a $T { &'a self.as_slice()[i] } #[inline] - pub fn index_mut<'a>(&'a mut self, i: uint) -> &'a mut $T { + pub fn mut_i<'a>(&'a mut self, i: uint) -> &'a mut $T { &'a mut self.as_mut_slice()[i] } @@ -99,9 +99,9 @@ macro_rules! impl_swap_components( impl SwapComponents for $Self { #[inline] pub fn swap(&mut self, a: uint, b: uint) { - let tmp = self.index(a).clone(); - *self.index_mut(a) = self.index(b).clone(); - *self.index_mut(b) = tmp; + let tmp = self.i(a).clone(); + *self.mut_i(a) = self.i(b).clone(); + *self.mut_i(b) = tmp; } } ) diff --git a/src/math/mat.rs b/src/math/mat.rs index c0462be..6dd8f78 100644 --- a/src/math/mat.rs +++ b/src/math/mat.rs @@ -21,14 +21,14 @@ use math::{Vec2, Vec3, Vec4}; pub trait Mat: Dimensioned + SwapComponents { - pub fn col<'a>(&'a self, i: uint) -> &'a Vec; - pub fn col_mut<'a>(&'a mut self, i: uint) -> &'a mut Vec; - pub fn elem<'a>(&'a self, col: uint, row: uint) -> &'a T; - pub fn elem_mut<'a>(&'a mut self, col: uint, row: uint) -> &'a mut T; - pub fn swap_cols(&mut self, a: uint, b: uint); - pub fn row(&self, i: uint) -> Vec; - pub fn swap_rows(&mut self, a: uint, b: uint); - pub fn swap_elem(&mut self, a: (uint, uint), b: (uint, uint)); + pub fn c<'a>(&'a self, c: uint) -> &'a Vec; + pub fn r(&self, r: uint) -> Vec; + pub fn cr<'a>(&'a self, c: uint, r: uint) -> &'a T; + pub fn mut_c<'a>(&'a mut self, c: uint) -> &'a mut Vec; + pub fn mut_cr<'a>(&'a mut self, c: uint, r: uint) -> &'a mut T; + pub fn swap_c(&mut self, a: uint, b: uint); + pub fn swap_r(&mut self, a: uint, b: uint); + pub fn swap_cr(&mut self, a: (uint, uint), b: (uint, uint)); pub fn transpose(&self) -> Self; pub fn transpose_self(&mut self); } @@ -98,72 +98,69 @@ impl Mat2 { impl Mat,[Vec2,..2]> for Mat2 { #[inline] - pub fn col<'a>(&'a self, i: uint) -> &'a Vec2 { - self.index(i) + pub fn c<'a>(&'a self, c: uint) -> &'a Vec2 { + self.i(c) } #[inline] - pub fn col_mut<'a>(&'a mut self, i: uint) -> &'a mut Vec2 { - self.index_mut(i) + pub fn r(&self, r: uint) -> Vec2 { + Vec2::new(self.i(0).i(r).clone(), + self.i(1).i(r).clone()) } #[inline] - pub fn elem<'a>(&'a self, col: uint, row: uint) -> &'a T { - self.index(col).index(row) + pub fn cr<'a>(&'a self, c: uint, r: uint) -> &'a T { + self.i(c).i(r) } #[inline] - pub fn elem_mut<'a>(&'a mut self, col: uint, row: uint) -> &'a mut T { - self.index_mut(col).index_mut(row) + pub fn mut_c<'a>(&'a mut self, c: uint) -> &'a mut Vec2 { + self.mut_i(c) } #[inline] - pub fn swap_cols(&mut self, a: uint, b: uint) { - let tmp = self.col(a).clone(); - *self.col_mut(a) = self.col(b).clone(); - *self.col_mut(b) = tmp; + pub fn mut_cr<'a>(&'a mut self, c: uint, r: uint) -> &'a mut T { + self.mut_i(c).mut_i(r) } #[inline] - pub fn row(&self, i: uint) -> Vec2 { - Vec2::new(self.col(0).index(i).clone(), - self.col(1).index(i).clone()) + pub fn swap_c(&mut self, a: uint, b: uint) { + let tmp = self.c(a).clone(); + *self.mut_c(a) = self.c(b).clone(); + *self.mut_c(b) = tmp; } #[inline] - pub fn swap_rows(&mut self, a: uint, b: uint) { - self.col_mut(0).swap(a, b); - self.col_mut(1).swap(a, b); + pub fn swap_r(&mut self, a: uint, b: uint) { + self.mut_c(0).swap(a, b); + self.mut_c(1).swap(a, b); } #[inline] - pub fn swap_elem(&mut self, (col_a, row_a): (uint, uint), + pub fn swap_cr(&mut self, (col_a, row_a): (uint, uint), (col_b, row_b): (uint, uint)) { - let tmp = self.elem(col_a, row_a).clone(); - *self.elem_mut(col_a, row_a) = self.elem(col_b, row_b).clone(); - *self.elem_mut(col_b, row_b) = tmp; + let tmp = self.cr(col_a, row_a).clone(); + *self.mut_cr(col_a, row_a) = self.cr(col_b, row_b).clone(); + *self.mut_cr(col_b, row_b) = tmp; } #[inline] pub fn transpose(&self) -> Mat2 { - Mat2::new(self.elem(0, 0).clone(), - self.elem(1, 0).clone(), - - self.elem(0, 1).clone(), - self.elem(1, 1).clone()) + Mat2::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), + self.cr(0, 1).clone(), self.cr(1, 1).clone()) } #[inline] pub fn transpose_self(&mut self) { - self.swap_elem((0, 1), (1, 0)); + self.swap_cr((0, 1), (1, 0)); } } impl ToMat3 for Mat2 { #[inline] pub fn to_mat3(&self) -> Mat3 { - Mat3::new(self.elem(0, 0).clone(), self.elem(0, 1).clone(), zero!(T), - self.elem(1, 0).clone(), self.elem(1, 1).clone(), zero!(T), + Mat3::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero!(T), + self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero!(T), zero!(T), zero!(T), one!(T)) } } @@ -171,8 +168,8 @@ impl ToMat3 for Mat2 { impl ToMat4 for Mat2 { #[inline] pub fn to_mat4(&self) -> Mat4 { - Mat4::new(self.elem(0, 0).clone(), self.elem(0, 1).clone(), zero!(T), zero!(T), - self.elem(1, 0).clone(), self.elem(1, 1).clone(), zero!(T), zero!(T), + Mat4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero!(T), zero!(T), + self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero!(T), zero!(T), zero!(T), zero!(T), one!(T), zero!(T), zero!(T), zero!(T), zero!(T), one!(T)) } @@ -203,53 +200,50 @@ impl Mat2 { impl NumMat,[Vec2,..2]> for Mat2 { #[inline] pub fn mul_s(&self, value: T) -> Mat2 { - Mat2::from_cols(self.col(0).mul_s(value.clone()), - self.col(1).mul_s(value.clone())) + Mat2::from_cols(self.c(0).mul_s(value.clone()), + self.c(1).mul_s(value.clone())) } #[inline] pub fn mul_v(&self, vec: &Vec2) -> Vec2 { - Vec2::new(self.row(0).dot(vec), - self.row(1).dot(vec)) + Vec2::new(self.r(0).dot(vec), + self.r(1).dot(vec)) } #[inline] pub fn add_m(&self, other: &Mat2) -> Mat2 { - Mat2::from_cols(self.col(0).add_v(other.col(0)), - self.col(1).add_v(other.col(1))) + Mat2::from_cols(self.c(0).add_v(other.c(0)), + self.c(1).add_v(other.c(1))) } #[inline] pub fn sub_m(&self, other: &Mat2) -> Mat2 { - Mat2::from_cols(self.col(0).sub_v(other.col(0)), - self.col(1).sub_v(other.col(1))) + Mat2::from_cols(self.c(0).sub_v(other.c(0)), + self.c(1).sub_v(other.c(1))) } #[inline] pub fn mul_m(&self, other: &Mat2) -> Mat2 { - Mat2::new(self.row(0).dot(other.col(0)), - self.row(1).dot(other.col(0)), - - self.row(0).dot(other.col(1)), - self.row(1).dot(other.col(1))) + Mat2::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))) } #[inline] pub fn mul_self_s(&mut self, value: T) { - self.col_mut(0).mul_self_s(value.clone()); - self.col_mut(1).mul_self_s(value.clone()); + self.mut_c(0).mul_self_s(value.clone()); + self.mut_c(1).mul_self_s(value.clone()); } #[inline] pub fn add_self_m(&mut self, other: &Mat2) { - self.col_mut(0).add_self_v(other.col(0)); - self.col_mut(1).add_self_v(other.col(1)); + self.mut_c(0).add_self_v(other.c(0)); + self.mut_c(1).add_self_v(other.c(1)); } #[inline] pub fn sub_self_m(&mut self, other: &Mat2) { - self.col_mut(0).sub_self_v(other.col(0)); - self.col_mut(1).sub_self_v(other.col(1)); + self.mut_c(0).sub_self_v(other.c(0)); + self.mut_c(1).sub_self_v(other.c(1)); } pub fn dot(&self, other: &Mat2) -> T { @@ -257,11 +251,11 @@ impl NumMat,[Vec2,..2]> for Mat2 { } pub fn determinant(&self) -> T { - *self.elem(0, 0) * *self.elem(1, 1) - *self.elem(1, 0) * *self.elem(0, 1) + *self.cr(0, 0) * *self.cr(1, 1) - *self.cr(1, 0) * *self.cr(0, 1) } pub fn trace(&self) -> T { - *self.elem(0, 0) + *self.elem(1, 1) + *self.cr(0, 0) + *self.cr(1, 1) } #[inline] @@ -278,8 +272,8 @@ impl NumMat,[Vec2,..2]> for Mat2 { impl Neg> for Mat2 { #[inline] pub fn neg(&self) -> Mat2 { - Mat2::from_cols(-*self.col(0), - -*self.col(1)) + Mat2::from_cols(-*self.c(0), + -*self.c(1)) } } @@ -301,8 +295,8 @@ impl FloatMat,[Vec3,..3]> for Mat2 { if d.approx_eq(&zero!(T)) { None } else { - Some(Mat2::new(self.elem(1, 1) / d, -self.elem(0, 1) / d, - -self.elem(1, 0) / d, self.elem(0, 0) / d)) + Some(Mat2::new(self.cr(1, 1) / d, -self.cr(0, 1) / d, + -self.cr(1, 0) / d, self.cr(0, 0) / d)) } } @@ -318,8 +312,8 @@ impl FloatMat,[Vec3,..3]> for Mat2 { #[inline] pub fn is_diagonal(&self) -> bool { - self.elem(0, 1).approx_eq(&zero!(T)) && - self.elem(1, 0).approx_eq(&zero!(T)) + self.cr(0, 1).approx_eq(&zero!(T)) && + self.cr(1, 0).approx_eq(&zero!(T)) } #[inline] @@ -329,8 +323,8 @@ impl FloatMat,[Vec3,..3]> for Mat2 { #[inline] pub fn is_symmetric(&self) -> bool { - self.elem(0, 1).approx_eq(self.elem(1, 0)) && - self.elem(1, 0).approx_eq(self.elem(0, 1)) + self.cr(0, 1).approx_eq(self.cr(1, 0)) && + self.cr(1, 0).approx_eq(self.cr(0, 1)) } #[inline] @@ -355,19 +349,19 @@ mod mat2_tests{ static F: float = 0.5; #[test] - fn test_swap_cols() { + fn test_swap_c() { let mut mut_a = A; - mut_a.swap_cols(0, 1); - assert_eq!(mut_a.col(0), A.col(1)); - assert_eq!(mut_a.col(1), A.col(0)); + mut_a.swap_c(0, 1); + assert_eq!(mut_a.c(0), A.c(1)); + assert_eq!(mut_a.c(1), A.c(0)); } #[test] - fn test_swap_rows() { + fn test_swap_r() { let mut mut_a = A; - mut_a.swap_rows(0, 1); - assert_eq!(mut_a.row(0), A.row(1)); - assert_eq!(mut_a.row(1), A.row(0)); + mut_a.swap_r(0, 1); + assert_eq!(mut_a.r(0), A.r(1)); + assert_eq!(mut_a.r(1), A.r(0)); } #[test] @@ -389,6 +383,7 @@ mod mat2_tests{ mut_a.to_zero(); assert_eq!(mut_a, Mat2::zero::()); } + #[test] fn test_determinant() { assert_eq!(A.determinant(), -2.0); @@ -577,83 +572,75 @@ impl Mat3 { impl Mat,[Vec3,..3]> for Mat3 { #[inline] - pub fn col<'a>(&'a self, i: uint) -> &'a Vec3 { - self.index(i) + pub fn c<'a>(&'a self, c: uint) -> &'a Vec3 { + self.i(c) } #[inline] - pub fn col_mut<'a>(&'a mut self, i: uint) -> &'a mut Vec3 { - self.index_mut(i) + pub fn r(&self, r: uint) -> Vec3 { + Vec3::new(self.i(0).i(r).clone(), + self.i(1).i(r).clone(), + self.i(2).i(r).clone()) } #[inline] - pub fn elem<'a>(&'a self, col: uint, row: uint) -> &'a T { - self.index(col).index(row) + pub fn cr<'a>(&'a self, c: uint, r: uint) -> &'a T { + self.i(c).i(r) } #[inline] - pub fn elem_mut<'a>(&'a mut self, col: uint, row: uint) -> &'a mut T { - self.index_mut(col).index_mut(row) + pub fn mut_c<'a>(&'a mut self, c: uint) -> &'a mut Vec3 { + self.mut_i(c) } #[inline] - pub fn swap_cols(&mut self, a: uint, b: uint) { - let tmp = self.col(a).clone(); - *self.col_mut(a) = self.col(b).clone(); - *self.col_mut(b) = tmp; + pub fn mut_cr<'a>(&'a mut self, c: uint, r: uint) -> &'a mut T { + self.mut_i(c).mut_i(r) } #[inline] - pub fn row(&self, i: uint) -> Vec3 { - Vec3::new(self.col(0).index(i).clone(), - self.col(1).index(i).clone(), - self.col(2).index(i).clone()) + pub fn swap_c(&mut self, a: uint, b: uint) { + let tmp = self.c(a).clone(); + *self.mut_c(a) = self.c(b).clone(); + *self.mut_c(b) = tmp; } #[inline] - pub fn swap_rows(&mut self, a: uint, b: uint) { - self.col_mut(0).swap(a, b); - self.col_mut(1).swap(a, b); - self.col_mut(2).swap(a, b); + pub fn swap_r(&mut self, a: uint, b: uint) { + self.mut_c(0).swap(a, b); + self.mut_c(1).swap(a, b); + self.mut_c(2).swap(a, b); } #[inline] - pub fn swap_elem(&mut self, (col_a, row_a): (uint, uint), + pub fn swap_cr(&mut self, (col_a, row_a): (uint, uint), (col_b, row_b): (uint, uint)) { - let tmp = self.elem(col_a, row_a).clone(); - *self.elem_mut(col_a, row_a) = self.elem(col_b, row_b).clone(); - *self.elem_mut(col_b, row_b) = tmp; + let tmp = self.cr(col_a, row_a).clone(); + *self.mut_cr(col_a, row_a) = self.cr(col_b, row_b).clone(); + *self.mut_cr(col_b, row_b) = tmp; } #[inline] pub fn transpose(&self) -> Mat3 { - Mat3::new(self.elem(0, 0).clone(), - self.elem(1, 0).clone(), - self.elem(2, 0).clone(), - - self.elem(0, 1).clone(), - self.elem(1, 1).clone(), - self.elem(2, 1).clone(), - - self.elem(0, 2).clone(), - self.elem(1, 2).clone(), - self.elem(2, 2).clone()) + Mat3::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()) } #[inline] pub fn transpose_self(&mut self) { - self.swap_elem((0, 1), (1, 0)); - self.swap_elem((0, 2), (2, 0)); - self.swap_elem((1, 2), (2, 1)); + self.swap_cr((0, 1), (1, 0)); + self.swap_cr((0, 2), (2, 0)); + self.swap_cr((1, 2), (2, 1)); } } impl ToMat4 for Mat3 { #[inline] pub fn to_mat4(&self) -> Mat4 { - Mat4::new(self.elem(0, 0).clone(), self.elem(0, 1).clone(), self.elem(0, 2).clone(), zero!(T), - self.elem(1, 0).clone(), self.elem(1, 1).clone(), self.elem(1, 2).clone(), zero!(T), - self.elem(2, 0).clone(), self.elem(2, 1).clone(), self.elem(2, 2).clone(), zero!(T), + Mat4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), self.cr(0, 2).clone(), zero!(T), + self.cr(1, 0).clone(), self.cr(1, 1).clone(), self.cr(1, 2).clone(), zero!(T), + self.cr(2, 0).clone(), self.cr(2, 1).clone(), self.cr(2, 2).clone(), zero!(T), zero!(T), zero!(T), zero!(T), one!(T)) } } @@ -686,66 +673,58 @@ impl Mat3 { impl NumMat,[Vec3,..3]> for Mat3 { #[inline] pub fn mul_s(&self, value: T) -> Mat3 { - Mat3::from_cols(self.col(0).mul_s(value.clone()), - self.col(1).mul_s(value.clone()), - self.col(2).mul_s(value.clone())) + Mat3::from_cols(self.c(0).mul_s(value.clone()), + self.c(1).mul_s(value.clone()), + self.c(2).mul_s(value.clone())) } #[inline] pub fn mul_v(&self, vec: &Vec3) -> Vec3 { - Vec3::new(self.row(0).dot(vec), - self.row(1).dot(vec), - self.row(2).dot(vec)) + Vec3::new(self.r(0).dot(vec), + self.r(1).dot(vec), + self.r(2).dot(vec)) } #[inline] pub fn add_m(&self, other: &Mat3) -> Mat3 { - Mat3::from_cols(self.col(0).add_v(other.col(0)), - self.col(1).add_v(other.col(1)), - self.col(2).add_v(other.col(2))) + Mat3::from_cols(self.c(0).add_v(other.c(0)), + self.c(1).add_v(other.c(1)), + self.c(2).add_v(other.c(2))) } #[inline] pub fn sub_m(&self, other: &Mat3) -> Mat3 { - Mat3::from_cols(self.col(0).sub_v(other.col(0)), - self.col(1).sub_v(other.col(1)), - self.col(2).sub_v(other.col(2))) + Mat3::from_cols(self.c(0).sub_v(other.c(0)), + self.c(1).sub_v(other.c(1)), + self.c(2).sub_v(other.c(2))) } #[inline] pub fn mul_m(&self, other: &Mat3) -> Mat3 { - Mat3::new(self.row(0).dot(other.col(0)), - self.row(1).dot(other.col(0)), - self.row(2).dot(other.col(0)), - - self.row(0).dot(other.col(1)), - self.row(1).dot(other.col(1)), - self.row(2).dot(other.col(1)), - - self.row(0).dot(other.col(2)), - self.row(1).dot(other.col(2)), - self.row(2).dot(other.col(2))) + Mat3::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))) } #[inline] pub fn mul_self_s(&mut self, value: T) { - self.col_mut(0).mul_self_s(value.clone()); - self.col_mut(1).mul_self_s(value.clone()); - self.col_mut(2).mul_self_s(value.clone()); + self.mut_c(0).mul_self_s(value.clone()); + self.mut_c(1).mul_self_s(value.clone()); + self.mut_c(2).mul_self_s(value.clone()); } #[inline] pub fn add_self_m(&mut self, other: &Mat3) { - self.col_mut(0).add_self_v(other.col(0)); - self.col_mut(1).add_self_v(other.col(1)); - self.col_mut(2).add_self_v(other.col(2)); + self.mut_c(0).add_self_v(other.c(0)); + self.mut_c(1).add_self_v(other.c(1)); + self.mut_c(2).add_self_v(other.c(2)); } #[inline] pub fn sub_self_m(&mut self, other: &Mat3) { - self.col_mut(0).sub_self_v(other.col(0)); - self.col_mut(1).sub_self_v(other.col(1)); - self.col_mut(2).sub_self_v(other.col(2)); + self.mut_c(0).sub_self_v(other.c(0)); + self.mut_c(1).sub_self_v(other.c(1)); + self.mut_c(2).sub_self_v(other.c(2)); } pub fn dot(&self, other: &Mat3) -> T { @@ -753,13 +732,13 @@ impl NumMat,[Vec3,..3]> for Mat3 { } pub fn determinant(&self) -> T { - *self.elem(0, 0) * (*self.elem(1, 1) * *self.elem(2, 2) - *self.elem(2, 1) * *self.elem(1, 2)) - - *self.elem(1, 0) * (*self.elem(0, 1) * *self.elem(2, 2) - *self.elem(2, 1) * *self.elem(0, 2)) - + *self.elem(2, 0) * (*self.elem(0, 1) * *self.elem(1, 2) - *self.elem(1, 1) * *self.elem(0, 2)) + *self.cr(0, 0) * (*self.cr(1, 1) * *self.cr(2, 2) - *self.cr(2, 1) * *self.cr(1, 2)) + - *self.cr(1, 0) * (*self.cr(0, 1) * *self.cr(2, 2) - *self.cr(2, 1) * *self.cr(0, 2)) + + *self.cr(2, 0) * (*self.cr(0, 1) * *self.cr(1, 2) - *self.cr(1, 1) * *self.cr(0, 2)) } pub fn trace(&self) -> T { - (*self.elem(0, 0)) + (*self.elem(1, 1)) + (*self.elem(2, 2)) + (*self.cr(0, 0)) + (*self.cr(1, 1)) + (*self.cr(2, 2)) } #[inline] @@ -776,9 +755,9 @@ impl NumMat,[Vec3,..3]> for Mat3 { impl Neg> for Mat3 { #[inline] pub fn neg(&self) -> Mat3 { - Mat3::from_cols(-*self.col(0), - -*self.col(1), - -*self.col(2)) + Mat3::from_cols(-*self.c(0), + -*self.c(1), + -*self.c(2)) } } @@ -810,34 +789,34 @@ impl ToQuat for Mat3 { s = (one!(T) + trace).sqrt(); w = half * s; s = half / s; - x = (*self.elem(1, 2) - *self.elem(2, 1)) * s; - y = (*self.elem(2, 0) - *self.elem(0, 2)) * s; - z = (*self.elem(0, 1) - *self.elem(1, 0)) * s; + x = (*self.cr(1, 2) - *self.cr(2, 1)) * s; + y = (*self.cr(2, 0) - *self.cr(0, 2)) * s; + z = (*self.cr(0, 1) - *self.cr(1, 0)) * s; } - ((*self.elem(0, 0) > *self.elem(1, 1)) - && (*self.elem(0, 0) > *self.elem(2, 2))) { - s = (half + (*self.elem(0, 0) - *self.elem(1, 1) - *self.elem(2, 2))).sqrt(); + ((*self.cr(0, 0) > *self.cr(1, 1)) + && (*self.cr(0, 0) > *self.cr(2, 2))) { + s = (half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2))).sqrt(); w = half * s; s = half / s; - x = (*self.elem(0, 1) - *self.elem(1, 0)) * s; - y = (*self.elem(2, 0) - *self.elem(0, 2)) * s; - z = (*self.elem(1, 2) - *self.elem(2, 1)) * s; + x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; + y = (*self.cr(2, 0) - *self.cr(0, 2)) * s; + z = (*self.cr(1, 2) - *self.cr(2, 1)) * s; } - (*self.elem(1, 1) > *self.elem(2, 2)) { - s = (half + (*self.elem(1, 1) - *self.elem(0, 0) - *self.elem(2, 2))).sqrt(); + (*self.cr(1, 1) > *self.cr(2, 2)) { + s = (half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2))).sqrt(); w = half * s; s = half / s; - x = (*self.elem(0, 1) - *self.elem(1, 0)) * s; - y = (*self.elem(1, 2) - *self.elem(2, 1)) * s; - z = (*self.elem(2, 0) - *self.elem(0, 2)) * s; + x = (*self.cr(0, 1) - *self.cr(1, 0)) * s; + y = (*self.cr(1, 2) - *self.cr(2, 1)) * s; + z = (*self.cr(2, 0) - *self.cr(0, 2)) * s; } _ { - s = (half + (*self.elem(2, 2) - *self.elem(0, 0) - *self.elem(1, 1))).sqrt(); + s = (half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1))).sqrt(); w = half * s; s = half / s; - x = (*self.elem(2, 0) - *self.elem(0, 2)) * s; - y = (*self.elem(1, 2) - *self.elem(2, 1)) * s; - z = (*self.elem(0, 1) - *self.elem(1, 0)) * s; + x = (*self.cr(2, 0) - *self.cr(0, 2)) * s; + y = (*self.cr(1, 2) - *self.cr(2, 1)) * s; + z = (*self.cr(0, 1) - *self.cr(1, 0)) * s; } ) Quat::new(w, x, y, z) @@ -851,9 +830,9 @@ impl FloatMat,[Vec4,..4]> for Mat3 { if d.approx_eq(&zero!(T)) { None } else { - Some(Mat3::from_cols(self.col(1).cross(self.col(2)).div_s(d.clone()), - self.col(2).cross(self.col(0)).div_s(d.clone()), - self.col(0).cross(self.col(1)).div_s(d.clone())).transpose()) + Some(Mat3::from_cols(self.c(1).cross(self.c(2)).div_s(d.clone()), + self.c(2).cross(self.c(0)).div_s(d.clone()), + self.c(0).cross(self.c(1)).div_s(d.clone())).transpose()) } } @@ -869,14 +848,14 @@ impl FloatMat,[Vec4,..4]> for Mat3 { #[inline] pub fn is_diagonal(&self) -> bool { - self.elem(0, 1).approx_eq(&zero!(T)) && - self.elem(0, 2).approx_eq(&zero!(T)) && + self.cr(0, 1).approx_eq(&zero!(T)) && + self.cr(0, 2).approx_eq(&zero!(T)) && - self.elem(1, 0).approx_eq(&zero!(T)) && - self.elem(1, 2).approx_eq(&zero!(T)) && + self.cr(1, 0).approx_eq(&zero!(T)) && + self.cr(1, 2).approx_eq(&zero!(T)) && - self.elem(2, 0).approx_eq(&zero!(T)) && - self.elem(2, 1).approx_eq(&zero!(T)) + self.cr(2, 0).approx_eq(&zero!(T)) && + self.cr(2, 1).approx_eq(&zero!(T)) } #[inline] @@ -886,14 +865,14 @@ impl FloatMat,[Vec4,..4]> for Mat3 { #[inline] pub fn is_symmetric(&self) -> bool { - self.elem(0, 1).approx_eq(self.elem(1, 0)) && - self.elem(0, 2).approx_eq(self.elem(2, 0)) && + self.cr(0, 1).approx_eq(self.cr(1, 0)) && + self.cr(0, 2).approx_eq(self.cr(2, 0)) && - self.elem(1, 0).approx_eq(self.elem(0, 1)) && - self.elem(1, 2).approx_eq(self.elem(2, 1)) && + self.cr(1, 0).approx_eq(self.cr(0, 1)) && + self.cr(1, 2).approx_eq(self.cr(2, 1)) && - self.elem(2, 0).approx_eq(self.elem(0, 2)) && - self.elem(2, 1).approx_eq(self.elem(1, 2)) + self.cr(2, 0).approx_eq(self.cr(0, 2)) && + self.cr(2, 1).approx_eq(self.cr(1, 2)) } #[inline] @@ -924,29 +903,29 @@ mod mat3_tests{ static F: float = 0.5; #[test] - fn test_swap_cols() { + fn test_swap_c() { let mut mut_a0 = A; - mut_a0.swap_cols(0, 2); - assert_eq!(mut_a0.col(0), A.col(2)); - assert_eq!(mut_a0.col(2), A.col(0)); + mut_a0.swap_c(0, 2); + assert_eq!(mut_a0.c(0), A.c(2)); + assert_eq!(mut_a0.c(2), A.c(0)); let mut mut_a1 = A; - mut_a1.swap_cols(1, 2); - assert_eq!(mut_a1.col(1), A.col(2)); - assert_eq!(mut_a1.col(2), A.col(1)); + mut_a1.swap_c(1, 2); + assert_eq!(mut_a1.c(1), A.c(2)); + assert_eq!(mut_a1.c(2), A.c(1)); } #[test] - fn test_swap_rows() { + fn test_swap_r() { let mut mut_a0 = A; - mut_a0.swap_rows(0, 2); - assert_eq!(mut_a0.row(0), A.row(2)); - assert_eq!(mut_a0.row(2), A.row(0)); + mut_a0.swap_r(0, 2); + assert_eq!(mut_a0.r(0), A.r(2)); + assert_eq!(mut_a0.r(2), A.r(0)); let mut mut_a1 = A; - mut_a1.swap_rows(1, 2); - assert_eq!(mut_a1.row(1), A.row(2)); - assert_eq!(mut_a1.row(2), A.row(1)); + mut_a1.swap_r(1, 2); + assert_eq!(mut_a1.r(1), A.r(2)); + assert_eq!(mut_a1.r(2), A.r(1)); } #[test] @@ -1161,87 +1140,72 @@ impl Mat4 { impl Mat,[Vec4,..4]> for Mat4 { #[inline] - pub fn col<'a>(&'a self, i: uint) -> &'a Vec4 { - self.index(i) + pub fn c<'a>(&'a self, c: uint) -> &'a Vec4 { + self.i(c) } #[inline] - pub fn col_mut<'a>(&'a mut self, i: uint) -> &'a mut Vec4 { - self.index_mut(i) + pub fn r(&self, r: uint) -> Vec4 { + Vec4::new(self.i(0).i(r).clone(), + self.i(1).i(r).clone(), + self.i(2).i(r).clone(), + self.i(3).i(r).clone()) } #[inline] - pub fn elem<'a>(&'a self, col: uint, row: uint) -> &'a T { - self.index(col).index(row) + pub fn cr<'a>(&'a self, c: uint, r: uint) -> &'a T { + self.i(c).i(r) } #[inline] - pub fn elem_mut<'a>(&'a mut self, col: uint, row: uint) -> &'a mut T { - self.index_mut(col).index_mut(row) + pub fn mut_c<'a>(&'a mut self, c: uint) -> &'a mut Vec4 { + self.mut_i(c) } #[inline] - pub fn swap_cols(&mut self, a: uint, b: uint) { - let tmp = self.col(a).clone(); - *self.col_mut(a) = self.col(b).clone(); - *self.col_mut(b) = tmp; + pub fn mut_cr<'a>(&'a mut self, c: uint, r: uint) -> &'a mut T { + self.mut_i(c).mut_i(r) } #[inline] - pub fn row(&self, i: uint) -> Vec4 { - Vec4::new(self.col(0).index(i).clone(), - self.col(1).index(i).clone(), - self.col(2).index(i).clone(), - self.col(3).index(i).clone()) + pub fn swap_c(&mut self, a: uint, b: uint) { + let tmp = self.c(a).clone(); + *self.mut_c(a) = self.c(b).clone(); + *self.mut_c(b) = tmp; } #[inline] - pub fn swap_rows(&mut self, a: uint, b: uint) { - self.col_mut(0).swap(a, b); - self.col_mut(1).swap(a, b); - self.col_mut(2).swap(a, b); - self.col_mut(3).swap(a, b); + pub fn swap_r(&mut self, a: uint, b: uint) { + self.mut_c(0).swap(a, b); + self.mut_c(1).swap(a, b); + self.mut_c(2).swap(a, b); + self.mut_c(3).swap(a, b); } #[inline] - pub fn swap_elem(&mut self, (col_a, row_a): (uint, uint), + pub fn swap_cr(&mut self, (col_a, row_a): (uint, uint), (col_b, row_b): (uint, uint)) { - let tmp = self.elem(col_a, row_a).clone(); - *self.elem_mut(col_a, row_a) = self.elem(col_b, row_b).clone(); - *self.elem_mut(col_b, row_b) = tmp; + let tmp = self.cr(col_a, row_a).clone(); + *self.mut_cr(col_a, row_a) = self.cr(col_b, row_b).clone(); + *self.mut_cr(col_b, row_b) = tmp; } #[inline] pub fn transpose(&self) -> Mat4 { - Mat4::new(self.elem(0, 0).clone(), - self.elem(1, 0).clone(), - self.elem(2, 0).clone(), - self.elem(3, 0).clone(), - - self.elem(0, 1).clone(), - self.elem(1, 1).clone(), - self.elem(2, 1).clone(), - self.elem(3, 1).clone(), - - self.elem(0, 2).clone(), - self.elem(1, 2).clone(), - self.elem(2, 2).clone(), - self.elem(3, 2).clone(), - - self.elem(0, 3).clone(), - self.elem(1, 3).clone(), - self.elem(2, 3).clone(), - self.elem(3, 3).clone()) + Mat4::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()) } #[inline] pub fn transpose_self(&mut self) { - self.swap_elem((0, 1), (1, 0)); - self.swap_elem((0, 2), (2, 0)); - self.swap_elem((0, 3), (3, 0)); - self.swap_elem((1, 2), (2, 1)); - self.swap_elem((1, 3), (3, 1)); - self.swap_elem((2, 3), (3, 2)); + self.swap_cr((0, 1), (1, 0)); + self.swap_cr((0, 2), (2, 0)); + self.swap_cr((0, 3), (3, 0)); + self.swap_cr((1, 2), (2, 1)); + self.swap_cr((1, 3), (3, 1)); + self.swap_cr((2, 3), (3, 2)); } } @@ -1276,81 +1240,66 @@ impl Mat4 { impl NumMat,[Vec4,..4]> for Mat4 { #[inline] pub fn mul_s(&self, value: T) -> Mat4 { - Mat4::from_cols(self.col(0).mul_s(value.clone()), - self.col(1).mul_s(value.clone()), - self.col(2).mul_s(value.clone()), - self.col(3).mul_s(value.clone())) + Mat4::from_cols(self.c(0).mul_s(value.clone()), + self.c(1).mul_s(value.clone()), + self.c(2).mul_s(value.clone()), + self.c(3).mul_s(value.clone())) } #[inline] pub fn mul_v(&self, vec: &Vec4) -> Vec4 { - Vec4::new(self.row(0).dot(vec), - self.row(1).dot(vec), - self.row(2).dot(vec), - self.row(3).dot(vec)) + Vec4::new(self.r(0).dot(vec), + self.r(1).dot(vec), + self.r(2).dot(vec), + self.r(3).dot(vec)) } #[inline] pub fn add_m(&self, other: &Mat4) -> Mat4 { - Mat4::from_cols(self.col(0).add_v(other.col(0)), - self.col(1).add_v(other.col(1)), - self.col(2).add_v(other.col(2)), - self.col(3).add_v(other.col(3))) + Mat4::from_cols(self.c(0).add_v(other.c(0)), + self.c(1).add_v(other.c(1)), + self.c(2).add_v(other.c(2)), + self.c(3).add_v(other.c(3))) } #[inline] pub fn sub_m(&self, other: &Mat4) -> Mat4 { - Mat4::from_cols(self.col(0).sub_v(other.col(0)), - self.col(1).sub_v(other.col(1)), - self.col(2).sub_v(other.col(2)), - self.col(3).sub_v(other.col(3))) + Mat4::from_cols(self.c(0).sub_v(other.c(0)), + self.c(1).sub_v(other.c(1)), + self.c(2).sub_v(other.c(2)), + self.c(3).sub_v(other.c(3))) } #[inline] pub fn mul_m(&self, other: &Mat4) -> Mat4 { - Mat4::new(self.row(0).dot(other.col(0)), - self.row(1).dot(other.col(0)), - self.row(2).dot(other.col(0)), - self.row(3).dot(other.col(0)), - - self.row(0).dot(other.col(1)), - self.row(1).dot(other.col(1)), - self.row(2).dot(other.col(1)), - self.row(3).dot(other.col(1)), - - self.row(0).dot(other.col(2)), - self.row(1).dot(other.col(2)), - self.row(2).dot(other.col(2)), - self.row(3).dot(other.col(2)), - - self.row(0).dot(other.col(3)), - self.row(1).dot(other.col(3)), - self.row(2).dot(other.col(3)), - self.row(3).dot(other.col(3))) + Mat4::new(self.r(0).dot(other.c(0)), self.r(1).dot(other.c(0)), self.r(2).dot(other.c(0)), self.r(3).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(3).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)), self.r(3).dot(other.c(2)), + self.r(0).dot(other.c(3)), self.r(1).dot(other.c(3)), self.r(2).dot(other.c(3)), self.r(3).dot(other.c(3))) } #[inline] pub fn mul_self_s(&mut self, value: T) { - self.col_mut(0).mul_self_s(value.clone()); - self.col_mut(1).mul_self_s(value.clone()); - self.col_mut(2).mul_self_s(value.clone()); - self.col_mut(3).mul_self_s(value.clone()); + self.mut_c(0).mul_self_s(value.clone()); + self.mut_c(1).mul_self_s(value.clone()); + self.mut_c(2).mul_self_s(value.clone()); + self.mut_c(3).mul_self_s(value.clone()); } #[inline] pub fn add_self_m(&mut self, other: &Mat4) { - self.col_mut(0).add_self_v(other.col(0)); - self.col_mut(1).add_self_v(other.col(1)); - self.col_mut(2).add_self_v(other.col(2)); - self.col_mut(3).add_self_v(other.col(3)); + self.mut_c(0).add_self_v(other.c(0)); + self.mut_c(1).add_self_v(other.c(1)); + self.mut_c(2).add_self_v(other.c(2)); + self.mut_c(3).add_self_v(other.c(3)); } #[inline] pub fn sub_self_m(&mut self, other: &Mat4) { - self.col_mut(0).sub_self_v(other.col(0)); - self.col_mut(1).sub_self_v(other.col(1)); - self.col_mut(2).sub_self_v(other.col(2)); - self.col_mut(3).sub_self_v(other.col(3)); + self.mut_c(0).sub_self_v(other.c(0)); + self.mut_c(1).sub_self_v(other.c(1)); + self.mut_c(2).sub_self_v(other.c(2)); + self.mut_c(3).sub_self_v(other.c(3)); } pub fn dot(&self, other: &Mat4) -> T { @@ -1358,27 +1307,27 @@ impl NumMat,[Vec4,..4]> for Mat4 { } pub fn determinant(&self) -> T { - let m0 = Mat3::new(self.elem(1, 1).clone(), self.elem(2, 1).clone(), self.elem(3, 1).clone(), - self.elem(1, 2).clone(), self.elem(2, 2).clone(), self.elem(3, 2).clone(), - self.elem(1, 3).clone(), self.elem(2, 3).clone(), self.elem(3, 3).clone()); - let m1 = Mat3::new(self.elem(0, 1).clone(), self.elem(2, 1).clone(), self.elem(3, 1).clone(), - self.elem(0, 2).clone(), self.elem(2, 2).clone(), self.elem(3, 2).clone(), - self.elem(0, 3).clone(), self.elem(2, 3).clone(), self.elem(3, 3).clone()); - let m2 = Mat3::new(self.elem(0, 1).clone(), self.elem(1, 1).clone(), self.elem(3, 1).clone(), - self.elem(0, 2).clone(), self.elem(1, 2).clone(), self.elem(3, 2).clone(), - self.elem(0, 3).clone(), self.elem(1, 3).clone(), self.elem(3, 3).clone()); - let m3 = Mat3::new(self.elem(0, 1).clone(), self.elem(1, 1).clone(), self.elem(2, 1).clone(), - self.elem(0, 2).clone(), self.elem(1, 2).clone(), self.elem(2, 2).clone(), - self.elem(0, 3).clone(), self.elem(1, 3).clone(), self.elem(2, 3).clone()); + let m0 = Mat3::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(), + 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(), + 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(), + 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()); - self.elem(0, 0) * m0.determinant() - - self.elem(1, 0) * m1.determinant() + - self.elem(2, 0) * m2.determinant() - - self.elem(3, 0) * m3.determinant() + self.cr(0, 0) * m0.determinant() - + self.cr(1, 0) * m1.determinant() + + self.cr(2, 0) * m2.determinant() - + self.cr(3, 0) * m3.determinant() } pub fn trace(&self) -> T { - *self.elem(0, 0) + *self.elem(1, 1) + *self.elem(2, 2) + *self.elem(3, 3) + *self.cr(0, 0) + *self.cr(1, 1) + *self.cr(2, 2) + *self.cr(3, 3) } #[inline] @@ -1395,10 +1344,10 @@ impl NumMat,[Vec4,..4]> for Mat4 { impl Neg> for Mat4 { #[inline] pub fn neg(&self) -> Mat4 { - Mat4::from_cols(-*self.col(0), - -*self.col(1), - -*self.col(2), - -*self.col(3)) + Mat4::from_cols(-*self.c(0), + -*self.c(1), + -*self.c(2), + -*self.c(3)) } } @@ -1419,29 +1368,29 @@ impl FloatMat,[Vec4,..4]> for Mat4 { // Find largest element in col j let mut i1 = j; for uint::range(j + 1, 4) |i| { - if A.elem(j, i).abs() > A.elem(j, i1).abs() { + if A.cr(j, i).abs() > A.cr(j, i1).abs() { i1 = i; } } // SwapComponents columns i1 and j in A and I to // put pivot on diagonal - A.swap_cols(i1, j); - I.swap_cols(i1, j); + A.swap_c(i1, j); + I.swap_c(i1, j); // Scale col j to have a unit diagonal - let ajj = A.elem(j, j).clone(); - I.col_mut(j).div_self_s(ajj.clone()); - A.col_mut(j).div_self_s(ajj.clone()); + let ajj = A.cr(j, j).clone(); + I.mut_c(j).div_self_s(ajj.clone()); + A.mut_c(j).div_self_s(ajj.clone()); // Eliminate off-diagonal elems in col j of A, // doing identical ops to I for uint::range(0, 4) |i| { if i != j { - let ij_mul_aij = I.col(j).mul_s(A.elem(i, j).clone()); - let aj_mul_aij = A.col(j).mul_s(A.elem(i, j).clone()); - I.col_mut(i).sub_self_v(&ij_mul_aij); - A.col_mut(i).sub_self_v(&aj_mul_aij); + let ij_mul_aij = I.c(j).mul_s(A.cr(i, j).clone()); + let aj_mul_aij = A.c(j).mul_s(A.cr(i, j).clone()); + I.mut_c(i).sub_self_v(&ij_mul_aij); + A.mut_c(i).sub_self_v(&aj_mul_aij); } } } @@ -1463,21 +1412,21 @@ impl FloatMat,[Vec4,..4]> for Mat4 { #[inline] pub fn is_diagonal(&self) -> bool { - self.elem(0, 1).approx_eq(&zero!(T)) && - self.elem(0, 2).approx_eq(&zero!(T)) && - self.elem(0, 3).approx_eq(&zero!(T)) && + self.cr(0, 1).approx_eq(&zero!(T)) && + self.cr(0, 2).approx_eq(&zero!(T)) && + self.cr(0, 3).approx_eq(&zero!(T)) && - self.elem(1, 0).approx_eq(&zero!(T)) && - self.elem(1, 2).approx_eq(&zero!(T)) && - self.elem(1, 3).approx_eq(&zero!(T)) && + self.cr(1, 0).approx_eq(&zero!(T)) && + self.cr(1, 2).approx_eq(&zero!(T)) && + self.cr(1, 3).approx_eq(&zero!(T)) && - self.elem(2, 0).approx_eq(&zero!(T)) && - self.elem(2, 1).approx_eq(&zero!(T)) && - self.elem(2, 3).approx_eq(&zero!(T)) && + self.cr(2, 0).approx_eq(&zero!(T)) && + self.cr(2, 1).approx_eq(&zero!(T)) && + self.cr(2, 3).approx_eq(&zero!(T)) && - self.elem(3, 0).approx_eq(&zero!(T)) && - self.elem(3, 1).approx_eq(&zero!(T)) && - self.elem(3, 2).approx_eq(&zero!(T)) + self.cr(3, 0).approx_eq(&zero!(T)) && + self.cr(3, 1).approx_eq(&zero!(T)) && + self.cr(3, 2).approx_eq(&zero!(T)) } #[inline] @@ -1487,21 +1436,21 @@ impl FloatMat,[Vec4,..4]> for Mat4 { #[inline] pub fn is_symmetric(&self) -> bool { - self.elem(0, 1).approx_eq(self.elem(1, 0)) && - self.elem(0, 2).approx_eq(self.elem(2, 0)) && - self.elem(0, 3).approx_eq(self.elem(3, 0)) && + self.cr(0, 1).approx_eq(self.cr(1, 0)) && + self.cr(0, 2).approx_eq(self.cr(2, 0)) && + self.cr(0, 3).approx_eq(self.cr(3, 0)) && - self.elem(1, 0).approx_eq(self.elem(0, 1)) && - self.elem(1, 2).approx_eq(self.elem(2, 1)) && - self.elem(1, 3).approx_eq(self.elem(3, 1)) && + self.cr(1, 0).approx_eq(self.cr(0, 1)) && + self.cr(1, 2).approx_eq(self.cr(2, 1)) && + self.cr(1, 3).approx_eq(self.cr(3, 1)) && - self.elem(2, 0).approx_eq(self.elem(0, 2)) && - self.elem(2, 1).approx_eq(self.elem(1, 2)) && - self.elem(2, 3).approx_eq(self.elem(3, 2)) && + self.cr(2, 0).approx_eq(self.cr(0, 2)) && + self.cr(2, 1).approx_eq(self.cr(1, 2)) && + self.cr(2, 3).approx_eq(self.cr(3, 2)) && - self.elem(3, 0).approx_eq(self.elem(0, 3)) && - self.elem(3, 1).approx_eq(self.elem(1, 3)) && - self.elem(3, 2).approx_eq(self.elem(2, 3)) + self.cr(3, 0).approx_eq(self.cr(0, 3)) && + self.cr(3, 1).approx_eq(self.cr(1, 3)) && + self.cr(3, 2).approx_eq(self.cr(2, 3)) } #[inline] @@ -1536,29 +1485,29 @@ mod mat4_tests { static F: float = 0.5; #[test] - fn test_swap_cols() { + fn test_swap_c() { let mut mut_a0 = A; - mut_a0.swap_cols(0, 2); - assert_eq!(mut_a0.col(0), A.col(2)); - assert_eq!(mut_a0.col(2), A.col(0)); + mut_a0.swap_c(0, 2); + assert_eq!(mut_a0.c(0), A.c(2)); + assert_eq!(mut_a0.c(2), A.c(0)); let mut mut_a1 = A; - mut_a1.swap_cols(1, 2); - assert_eq!(mut_a1.col(1), A.col(2)); - assert_eq!(mut_a1.col(2), A.col(1)); + mut_a1.swap_c(1, 2); + assert_eq!(mut_a1.c(1), A.c(2)); + assert_eq!(mut_a1.c(2), A.c(1)); } #[test] - fn test_swap_rows() { + fn test_swap_r() { let mut mut_a0 = A; - mut_a0.swap_rows(0, 2); - assert_eq!(mut_a0.row(0), A.row(2)); - assert_eq!(mut_a0.row(2), A.row(0)); + mut_a0.swap_r(0, 2); + assert_eq!(mut_a0.r(0), A.r(2)); + assert_eq!(mut_a0.r(2), A.r(0)); let mut mut_a1 = A; - mut_a1.swap_rows(1, 2); - assert_eq!(mut_a1.row(1), A.row(2)); - assert_eq!(mut_a1.row(2), A.row(1)); + mut_a1.swap_r(1, 2); + assert_eq!(mut_a1.r(1), A.r(2)); + assert_eq!(mut_a1.r(2), A.r(1)); } #[test] diff --git a/src/math/math.rs b/src/math/math.rs index 97e8a22..2be88fa 100644 --- a/src/math/math.rs +++ b/src/math/math.rs @@ -41,8 +41,8 @@ pub mod point; pub mod ray; pub trait Dimensioned { - pub fn index<'a>(&'a self, i: uint) -> &'a T; - pub fn index_mut<'a>(&'a mut self, i: uint) -> &'a mut T; + pub fn i<'a>(&'a self, i: uint) -> &'a T; + pub fn mut_i<'a>(&'a mut self, i: uint) -> &'a mut T; pub fn as_slice<'a>(&'a self) -> &'a Slice; pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut Slice; } diff --git a/src/math/quat.rs b/src/math/quat.rs index 3e14458..ab743f7 100644 --- a/src/math/quat.rs +++ b/src/math/quat.rs @@ -114,19 +114,19 @@ impl Quat { /// The sum of this quaternion and `other` #[inline] pub fn add_q(&self, other: &Quat) -> Quat { - Quat::new(*self.index(0) + *other.index(0), - *self.index(1) + *other.index(1), - *self.index(2) + *other.index(2), - *self.index(3) + *other.index(3)) + Quat::new(*self.i(0) + *other.i(0), + *self.i(1) + *other.i(1), + *self.i(2) + *other.i(2), + *self.i(3) + *other.i(3)) } /// The sum of this quaternion and `other` #[inline] pub fn sub_q(&self, other: &Quat) -> Quat { - Quat::new(*self.index(0) - *other.index(0), - *self.index(1) - *other.index(1), - *self.index(2) - *other.index(2), - *self.index(3) - *other.index(3)) + Quat::new(*self.i(0) - *other.i(0), + *self.i(1) - *other.i(1), + *self.i(2) - *other.i(2), + *self.i(3) - *other.i(3)) } /// The the result of multipliplying the quaternion by `other` diff --git a/src/math/vec.rs b/src/math/vec.rs index a242c73..fd6a55a 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -166,8 +166,8 @@ impl ToVec3 for Vec2 { /// Converts the vector to a three-dimensional homogeneous vector: /// `[x, y] -> [x, y, 0]` pub fn to_vec3(&self) -> Vec3 { - Vec3::new((*self).index(0).clone(), - (*self).index(1).clone(), + Vec3::new((*self).i(0).clone(), + (*self).i(1).clone(), zero!(T)) } } @@ -204,8 +204,8 @@ impl Vec2 { /// The perpendicular dot product of the vector and `other`. #[inline] pub fn perp_dot(&self, other: &Vec2) -> T { - (*self.index(0) * *other.index(1)) - - (*self.index(1) * *other.index(0)) + (*self.i(0) * *other.i(1)) - + (*self.i(1) * *other.i(0)) } } @@ -215,159 +215,159 @@ impl NumVec for Vec2 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) + value, - *self.index(1) + value) + Vec2::new(*self.i(0) + value, + *self.i(1) + value) } /// Returns a new vector with `value` subtracted from each component. #[inline] pub fn sub_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) - value, - *self.index(1) - value) + Vec2::new(*self.i(0) - value, + *self.i(1) - value) } /// Returns the scalar multiplication of the vector with `value`. #[inline] pub fn mul_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) * value, - *self.index(1) * value) + Vec2::new(*self.i(0) * value, + *self.i(1) * value) } /// Returns a new vector with each component divided by `value`. #[inline] pub fn div_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) / value, - *self.index(1) / value) + Vec2::new(*self.i(0) / value, + *self.i(1) / value) } /// Returns the remainder of each component divided by `value`. #[inline] pub fn rem_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) % value, - *self.index(1) % value) + Vec2::new(*self.i(0) % value, + *self.i(1) % value) } /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) + *other.index(0), - *self.index(1) + *other.index(1)) + Vec2::new(*self.i(0) + *other.i(0), + *self.i(1) + *other.i(1)) } /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) - *other.index(0), - *self.index(1) - *other.index(1)) + Vec2::new(*self.i(0) - *other.i(0), + *self.i(1) - *other.i(1)) } /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) * *other.index(0), - *self.index(1) * *other.index(1)) + Vec2::new(*self.i(0) * *other.i(0), + *self.i(1) * *other.i(1)) } /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) / *other.index(0), - *self.index(1) / *other.index(1)) + Vec2::new(*self.i(0) / *other.i(0), + *self.i(1) / *other.i(1)) } /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) % *other.index(0), - *self.index(1) % *other.index(1)) + Vec2::new(*self.i(0) % *other.i(0), + *self.i(1) % *other.i(1)) } /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); + *self.mut_i(0) = -*self.i(0); + *self.mut_i(1) = -*self.i(1); } /// Adds `value` to each component of the vector. #[inline] pub fn add_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) + value; - *self.index_mut(1) = *self.index(1) + value; + *self.mut_i(0) = *self.i(0) + value; + *self.mut_i(1) = *self.i(1) + value; } /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) - value; - *self.index_mut(1) = *self.index(1) - value; + *self.mut_i(0) = *self.i(0) - value; + *self.mut_i(1) = *self.i(1) - value; } #[inline] pub fn mul_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) * value; - *self.index_mut(1) = *self.index(1) * value; + *self.mut_i(0) = *self.i(0) * value; + *self.mut_i(1) = *self.i(1) * value; } #[inline] pub fn div_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) / value; - *self.index_mut(1) = *self.index(1) / value; + *self.mut_i(0) = *self.i(0) / value; + *self.mut_i(1) = *self.i(1) / value; } #[inline] pub fn rem_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) % value; - *self.index_mut(1) = *self.index(1) % value; + *self.mut_i(0) = *self.i(0) % value; + *self.mut_i(1) = *self.i(1) % value; } #[inline] pub fn add_self_v(&mut self, other: &Vec2) { - *self.index_mut(0) = *self.index(0) + *other.index(0); - *self.index_mut(1) = *self.index(1) + *other.index(1); + *self.mut_i(0) = *self.i(0) + *other.i(0); + *self.mut_i(1) = *self.i(1) + *other.i(1); } #[inline] pub fn sub_self_v(&mut self, other: &Vec2) { - *self.index_mut(0) = *self.index(0) - *other.index(0); - *self.index_mut(1) = *self.index(1) - *other.index(1); + *self.mut_i(0) = *self.i(0) - *other.i(0); + *self.mut_i(1) = *self.i(1) - *other.i(1); } #[inline] pub fn mul_self_v(&mut self, other: &Vec2) { - *self.index_mut(0) = *self.index(0) * *other.index(0); - *self.index_mut(1) = *self.index(1) * *other.index(1); + *self.mut_i(0) = *self.i(0) * *other.i(0); + *self.mut_i(1) = *self.i(1) * *other.i(1); } #[inline] pub fn div_self_v(&mut self, other: &Vec2) { - *self.index_mut(0) = *self.index(0) / *other.index(0); - *self.index_mut(1) = *self.index(1) / *other.index(1); + *self.mut_i(0) = *self.i(0) / *other.i(0); + *self.mut_i(1) = *self.i(1) / *other.i(1); } #[inline] pub fn rem_self_v(&mut self, other: &Vec2) { - *self.index_mut(0) = *self.index(0) % *other.index(0); - *self.index_mut(1) = *self.index(1) % *other.index(1); + *self.mut_i(0) = *self.i(0) % *other.i(0); + *self.mut_i(1) = *self.i(1) % *other.i(1); } /// Returns the dot product of the vector and `other`. #[inline] pub fn dot(&self, other: &Vec2) -> T { - *self.index(0) * *other.index(0) + - *self.index(1) * *other.index(1) + *self.i(0) * *other.i(0) + + *self.i(1) * *other.i(1) } /// Returns the sum of the vector's components. #[inline] pub fn comp_add(&self) -> T { - *self.index(0) + *self.index(1) + *self.i(0) + *self.i(1) } /// Returns the product of the vector's components. #[inline] pub fn comp_mul(&self) -> T { - *self.index(0) * *self.index(1) + *self.i(0) * *self.i(1) } } @@ -375,8 +375,8 @@ impl Neg> for Vec2 { /// Returns the vector with each component negated. #[inline] pub fn neg(&self) -> Vec2 { - Vec2::new(-*self.index(0), - -*self.index(1)) + Vec2::new(-*self.i(0), + -*self.i(1)) } } @@ -445,124 +445,124 @@ impl FloatVec for Vec2 { impl OrdVec> for Vec2 { #[inline] pub fn lt_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) < value, - *self.index(1) < value) + Vec2::new(*self.i(0) < value, + *self.i(1) < value) } #[inline] pub fn le_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) <= value, - *self.index(1) <= value) + Vec2::new(*self.i(0) <= value, + *self.i(1) <= value) } #[inline] pub fn ge_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) >= value, - *self.index(1) >= value) + Vec2::new(*self.i(0) >= value, + *self.i(1) >= value) } #[inline] pub fn gt_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) > value, - *self.index(1) > value) + Vec2::new(*self.i(0) > value, + *self.i(1) > value) } #[inline] pub fn lt_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) < *other.index(0), - *self.index(1) < *other.index(1)) + Vec2::new(*self.i(0) < *other.i(0), + *self.i(1) < *other.i(1)) } #[inline] pub fn le_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) <= *other.index(0), - *self.index(1) <= *other.index(1)) + Vec2::new(*self.i(0) <= *other.i(0), + *self.i(1) <= *other.i(1)) } #[inline] pub fn ge_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) >= *other.index(0), - *self.index(1) >= *other.index(1)) + Vec2::new(*self.i(0) >= *other.i(0), + *self.i(1) >= *other.i(1)) } #[inline] pub fn gt_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) > *other.index(0), - *self.index(1) > *other.index(1)) + Vec2::new(*self.i(0) > *other.i(0), + *self.i(1) > *other.i(1)) } #[inline] pub fn min_s(&self, value: T) -> Vec2 { - Vec2::new(self.index(0).min(&value), - self.index(1).min(&value)) + Vec2::new(self.i(0).min(&value), + self.i(1).min(&value)) } #[inline] pub fn max_s(&self, value: T) -> Vec2 { - Vec2::new(self.index(0).max(&value), - self.index(1).max(&value)) + Vec2::new(self.i(0).max(&value), + self.i(1).max(&value)) } #[inline] pub fn clamp_s(&self, mn: T, mx: T) -> Vec2 { - Vec2::new(self.index(0).clamp(&mn, &mx), - self.index(1).clamp(&mn, &mx)) + Vec2::new(self.i(0).clamp(&mn, &mx), + self.i(1).clamp(&mn, &mx)) } #[inline] pub fn min_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(self.index(0).min(other.index(0)), - self.index(1).min(other.index(1))) + Vec2::new(self.i(0).min(other.i(0)), + self.i(1).min(other.i(1))) } #[inline] pub fn max_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(self.index(0).max(other.index(0)), - self.index(1).max(other.index(1))) + Vec2::new(self.i(0).max(other.i(0)), + self.i(1).max(other.i(1))) } #[inline] pub fn clamp_v(&self, mn: &Vec2, mx: &Vec2) -> Vec2 { - Vec2::new(self.index(0).clamp(mn.index(0), mx.index(0)), - self.index(1).clamp(mn.index(1), mx.index(1))) + Vec2::new(self.i(0).clamp(mn.i(0), mx.i(0)), + self.i(1).clamp(mn.i(1), mx.i(1))) } /// Returns the smallest component of the vector. #[inline] pub fn comp_min(&self) -> T { - self.index(0).min(self.index(1)) + self.i(0).min(self.i(1)) } /// Returns the largest component of the vector. #[inline] pub fn comp_max(&self) -> T { - self.index(0).max(self.index(1)) + self.i(0).max(self.i(1)) } } impl EqVec> for Vec2 { #[inline] pub fn eq_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) == value, - *self.index(1) == value) + Vec2::new(*self.i(0) == value, + *self.i(1) == value) } #[inline] pub fn ne_s(&self, value: T) -> Vec2 { - Vec2::new(*self.index(0) != value, - *self.index(1) != value) + Vec2::new(*self.i(0) != value, + *self.i(1) != value) } #[inline] pub fn eq_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) == *other.index(0), - *self.index(1) == *other.index(1)) + Vec2::new(*self.i(0) == *other.i(0), + *self.i(1) == *other.i(1)) } #[inline] pub fn ne_v(&self, other: &Vec2) -> Vec2 { - Vec2::new(*self.index(0) != *other.index(0), - *self.index(1) != *other.index(1)) + Vec2::new(*self.i(0) != *other.i(0), + *self.i(1) != *other.i(1)) } } @@ -571,21 +571,21 @@ impl BoolVec<[bool,..2]> for Vec2 { /// `true`, otherwise `false`. #[inline] pub fn any(&self) -> bool { - *self.index(0) || *self.index(1) + *self.i(0) || *self.i(1) } /// Returns `true` if _all_ of the components of the vector are equal to /// `true`, otherwise `false`. #[inline] pub fn all(&self) -> bool { - *self.index(0) && *self.index(1) + *self.i(0) && *self.i(1) } } impl> Not> for Vec2 { pub fn not(&self) -> Vec2 { - Vec2::new(!*self.index(0), - !*self.index(1)) + Vec2::new(!*self.i(0), + !*self.i(1)) } } @@ -603,8 +603,8 @@ mod vec2_tests { let mut mut_a = A; mut_a.swap(0, 1); - assert_eq!(*mut_a.index(0), *A.index(1)); - assert_eq!(*mut_a.index(1), *A.index(0)); + assert_eq!(*mut_a.i(0), *A.i(1)); + assert_eq!(*mut_a.i(1), *A.i(0)); } #[test] @@ -799,9 +799,9 @@ impl ToVec4 for Vec3 { /// Converts the vector to a four-dimensional homogeneous vector: /// `[x, y, z] -> [x, y, z, 0]` pub fn to_vec4(&self) -> Vec4 { - Vec4::new((*self).index(0).clone(), - (*self).index(1).clone(), - (*self).index(2).clone(), + Vec4::new((*self).i(0).clone(), + (*self).i(1).clone(), + (*self).i(2).clone(), zero!(T)) } } @@ -844,9 +844,9 @@ impl Vec3 { /// Returns the cross product of the vector and `other`. #[inline] pub fn cross(&self, other: &Vec3) -> Vec3 { - Vec3::new((*self.index(1) * *other.index(2)) - (*self.index(2) * *other.index(1)), - (*self.index(2) * *other.index(0)) - (*self.index(0) * *other.index(2)), - (*self.index(0) * *other.index(1)) - (*self.index(1) * *other.index(0))) + Vec3::new((*self.i(1) * *other.i(2)) - (*self.i(2) * *other.i(1)), + (*self.i(2) * *other.i(0)) - (*self.i(0) * *other.i(2)), + (*self.i(0) * *other.i(1)) - (*self.i(1) * *other.i(0))) } /// Calculates the cross product of the vector and `other`, then stores the @@ -863,181 +863,181 @@ impl NumVec for Vec3 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) + value, - *self.index(1) + value, - *self.index(2) + value) + Vec3::new(*self.i(0) + value, + *self.i(1) + value, + *self.i(2) + value) } /// Returns a new vector with `value` subtracted from each component. #[inline] pub fn sub_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) - value, - *self.index(1) - value, - *self.index(2) - value) + Vec3::new(*self.i(0) - value, + *self.i(1) - value, + *self.i(2) - value) } /// Returns the scalar multiplication of the vector with `value`. #[inline] pub fn mul_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) * value, - *self.index(1) * value, - *self.index(2) * value) + Vec3::new(*self.i(0) * value, + *self.i(1) * value, + *self.i(2) * value) } /// Returns a new vector with each component divided by `value`. #[inline] pub fn div_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) / value, - *self.index(1) / value, - *self.index(2) / value) + Vec3::new(*self.i(0) / value, + *self.i(1) / value, + *self.i(2) / value) } /// Returns the remainder of each component divided by `value`. #[inline] pub fn rem_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) % value, - *self.index(1) % value, - *self.index(2) % value) + Vec3::new(*self.i(0) % value, + *self.i(1) % value, + *self.i(2) % value) } /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) + *other.index(0), - *self.index(1) + *other.index(1), - *self.index(2) + *other.index(2)) + Vec3::new(*self.i(0) + *other.i(0), + *self.i(1) + *other.i(1), + *self.i(2) + *other.i(2)) } /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) - *other.index(0), - *self.index(1) - *other.index(1), - *self.index(2) - *other.index(2)) + Vec3::new(*self.i(0) - *other.i(0), + *self.i(1) - *other.i(1), + *self.i(2) - *other.i(2)) } /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) * *other.index(0), - *self.index(1) * *other.index(1), - *self.index(2) * *other.index(2)) + Vec3::new(*self.i(0) * *other.i(0), + *self.i(1) * *other.i(1), + *self.i(2) * *other.i(2)) } /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) / *other.index(0), - *self.index(1) / *other.index(1), - *self.index(2) / *other.index(2)) + Vec3::new(*self.i(0) / *other.i(0), + *self.i(1) / *other.i(1), + *self.i(2) / *other.i(2)) } /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) % *other.index(0), - *self.index(1) % *other.index(1), - *self.index(2) % *other.index(2)) + Vec3::new(*self.i(0) % *other.i(0), + *self.i(1) % *other.i(1), + *self.i(2) % *other.i(2)) } /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); - *self.index_mut(2) = -*self.index(2); + *self.mut_i(0) = -*self.i(0); + *self.mut_i(1) = -*self.i(1); + *self.mut_i(2) = -*self.i(2); } /// Adds `value` to each component of the vector. #[inline] pub fn add_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) + value; - *self.index_mut(1) = *self.index(1) + value; - *self.index_mut(2) = *self.index(2) + value; + *self.mut_i(0) = *self.i(0) + value; + *self.mut_i(1) = *self.i(1) + value; + *self.mut_i(2) = *self.i(2) + value; } /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) - value; - *self.index_mut(1) = *self.index(1) - value; - *self.index_mut(2) = *self.index(2) - value; + *self.mut_i(0) = *self.i(0) - value; + *self.mut_i(1) = *self.i(1) - value; + *self.mut_i(2) = *self.i(2) - value; } #[inline] pub fn mul_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) * value; - *self.index_mut(1) = *self.index(1) * value; - *self.index_mut(2) = *self.index(2) * value; + *self.mut_i(0) = *self.i(0) * value; + *self.mut_i(1) = *self.i(1) * value; + *self.mut_i(2) = *self.i(2) * value; } #[inline] pub fn div_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) / value; - *self.index_mut(1) = *self.index(1) / value; - *self.index_mut(2) = *self.index(2) / value; + *self.mut_i(0) = *self.i(0) / value; + *self.mut_i(1) = *self.i(1) / value; + *self.mut_i(2) = *self.i(2) / value; } #[inline] pub fn rem_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) % value; - *self.index_mut(1) = *self.index(1) % value; - *self.index_mut(2) = *self.index(2) % value; + *self.mut_i(0) = *self.i(0) % value; + *self.mut_i(1) = *self.i(1) % value; + *self.mut_i(2) = *self.i(2) % value; } #[inline] pub fn add_self_v(&mut self, other: &Vec3) { - *self.index_mut(0) = *self.index(0) + *other.index(0); - *self.index_mut(1) = *self.index(1) + *other.index(1); - *self.index_mut(2) = *self.index(2) + *other.index(2); + *self.mut_i(0) = *self.i(0) + *other.i(0); + *self.mut_i(1) = *self.i(1) + *other.i(1); + *self.mut_i(2) = *self.i(2) + *other.i(2); } #[inline] pub fn sub_self_v(&mut self, other: &Vec3) { - *self.index_mut(0) = *self.index(0) - *other.index(0); - *self.index_mut(1) = *self.index(1) - *other.index(1); - *self.index_mut(2) = *self.index(2) - *other.index(2); + *self.mut_i(0) = *self.i(0) - *other.i(0); + *self.mut_i(1) = *self.i(1) - *other.i(1); + *self.mut_i(2) = *self.i(2) - *other.i(2); } #[inline] pub fn mul_self_v(&mut self, other: &Vec3) { - *self.index_mut(0) = *self.index(0) * *other.index(0); - *self.index_mut(1) = *self.index(1) * *other.index(1); - *self.index_mut(2) = *self.index(2) * *other.index(2); + *self.mut_i(0) = *self.i(0) * *other.i(0); + *self.mut_i(1) = *self.i(1) * *other.i(1); + *self.mut_i(2) = *self.i(2) * *other.i(2); } #[inline] pub fn div_self_v(&mut self, other: &Vec3) { - *self.index_mut(0) = *self.index(0) / *other.index(0); - *self.index_mut(1) = *self.index(1) / *other.index(1); - *self.index_mut(2) = *self.index(2) / *other.index(2); + *self.mut_i(0) = *self.i(0) / *other.i(0); + *self.mut_i(1) = *self.i(1) / *other.i(1); + *self.mut_i(2) = *self.i(2) / *other.i(2); } #[inline] pub fn rem_self_v(&mut self, other: &Vec3) { - *self.index_mut(0) = *self.index(0) % *other.index(0); - *self.index_mut(1) = *self.index(1) % *other.index(1); - *self.index_mut(2) = *self.index(2) % *other.index(2); + *self.mut_i(0) = *self.i(0) % *other.i(0); + *self.mut_i(1) = *self.i(1) % *other.i(1); + *self.mut_i(2) = *self.i(2) % *other.i(2); } /// Returns the dot product of the vector and `other`. #[inline] pub fn dot(&self, other: &Vec3) -> T { - *self.index(0) * *other.index(0) + - *self.index(1) * *other.index(1) + - *self.index(2) * *other.index(2) + *self.i(0) * *other.i(0) + + *self.i(1) * *other.i(1) + + *self.i(2) * *other.i(2) } /// Returns the sum of the vector's components. #[inline] pub fn comp_add(&self) -> T { - *self.index(0) + *self.index(1) + *self.index(2) + *self.i(0) + *self.i(1) + *self.i(2) } /// Returns the product of the vector's components. #[inline] pub fn comp_mul(&self) -> T { - *self.index(0) * *self.index(1) * *self.index(2) + *self.i(0) * *self.i(1) * *self.i(2) } } @@ -1045,9 +1045,9 @@ impl Neg> for Vec3 { /// Returns the vector with each component negated. #[inline] pub fn neg(&self) -> Vec3 { - Vec3::new(-*self.index(0), - -*self.index(1), - -*self.index(2)) + Vec3::new(-*self.i(0), + -*self.i(1), + -*self.i(2)) } } @@ -1116,142 +1116,142 @@ impl FloatVec for Vec3 { impl OrdVec> for Vec3 { #[inline] pub fn lt_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) < value, - *self.index(1) < value, - *self.index(2) < value) + Vec3::new(*self.i(0) < value, + *self.i(1) < value, + *self.i(2) < value) } #[inline] pub fn le_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) <= value, - *self.index(1) <= value, - *self.index(2) <= value) + Vec3::new(*self.i(0) <= value, + *self.i(1) <= value, + *self.i(2) <= value) } #[inline] pub fn ge_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) >= value, - *self.index(1) >= value, - *self.index(2) >= value) + Vec3::new(*self.i(0) >= value, + *self.i(1) >= value, + *self.i(2) >= value) } #[inline] pub fn gt_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) > value, - *self.index(1) > value, - *self.index(2) > value) + Vec3::new(*self.i(0) > value, + *self.i(1) > value, + *self.i(2) > value) } #[inline] pub fn lt_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) < *other.index(0), - *self.index(1) < *other.index(1), - *self.index(2) < *other.index(2)) + Vec3::new(*self.i(0) < *other.i(0), + *self.i(1) < *other.i(1), + *self.i(2) < *other.i(2)) } #[inline] pub fn le_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) <= *other.index(0), - *self.index(1) <= *other.index(1), - *self.index(2) <= *other.index(2)) + Vec3::new(*self.i(0) <= *other.i(0), + *self.i(1) <= *other.i(1), + *self.i(2) <= *other.i(2)) } #[inline] pub fn ge_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) >= *other.index(0), - *self.index(1) >= *other.index(1), - *self.index(2) >= *other.index(2)) + Vec3::new(*self.i(0) >= *other.i(0), + *self.i(1) >= *other.i(1), + *self.i(2) >= *other.i(2)) } #[inline] pub fn gt_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) > *other.index(0), - *self.index(1) > *other.index(1), - *self.index(2) > *other.index(2)) + Vec3::new(*self.i(0) > *other.i(0), + *self.i(1) > *other.i(1), + *self.i(2) > *other.i(2)) } #[inline] pub fn min_s(&self, value: T) -> Vec3 { - Vec3::new(self.index(0).min(&value), - self.index(1).min(&value), - self.index(2).min(&value)) + Vec3::new(self.i(0).min(&value), + self.i(1).min(&value), + self.i(2).min(&value)) } #[inline] pub fn max_s(&self, value: T) -> Vec3 { - Vec3::new(self.index(0).max(&value), - self.index(1).max(&value), - self.index(2).max(&value)) + Vec3::new(self.i(0).max(&value), + self.i(1).max(&value), + self.i(2).max(&value)) } #[inline] pub fn clamp_s(&self, mn: T, mx: T) -> Vec3 { - Vec3::new(self.index(0).clamp(&mn, &mx), - self.index(1).clamp(&mn, &mx), - self.index(2).clamp(&mn, &mx)) + Vec3::new(self.i(0).clamp(&mn, &mx), + self.i(1).clamp(&mn, &mx), + self.i(2).clamp(&mn, &mx)) } #[inline] pub fn min_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(self.index(0).min(other.index(0)), - self.index(1).min(other.index(1)), - self.index(2).min(other.index(2))) + Vec3::new(self.i(0).min(other.i(0)), + self.i(1).min(other.i(1)), + self.i(2).min(other.i(2))) } #[inline] pub fn max_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(self.index(0).max(other.index(0)), - self.index(1).max(other.index(1)), - self.index(2).max(other.index(2))) + Vec3::new(self.i(0).max(other.i(0)), + self.i(1).max(other.i(1)), + self.i(2).max(other.i(2))) } #[inline] pub fn clamp_v(&self, mn: &Vec3, mx: &Vec3) -> Vec3 { - Vec3::new(self.index(0).clamp(mn.index(0), mx.index(0)), - self.index(1).clamp(mn.index(1), mx.index(1)), - self.index(2).clamp(mn.index(2), mx.index(2))) + Vec3::new(self.i(0).clamp(mn.i(0), mx.i(0)), + self.i(1).clamp(mn.i(1), mx.i(1)), + self.i(2).clamp(mn.i(2), mx.i(2))) } /// Returns the smallest component of the vector. #[inline] pub fn comp_min(&self) -> T { - self.index(0).min(self.index(1)).min(self.index(2)) + self.i(0).min(self.i(1)).min(self.i(2)) } /// Returns the largest component of the vector. #[inline] pub fn comp_max(&self) -> T { - self.index(0).max(self.index(1)).max(self.index(2)) + self.i(0).max(self.i(1)).max(self.i(2)) } } impl EqVec> for Vec3 { #[inline] pub fn eq_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) == value, - *self.index(1) == value, - *self.index(2) == value) + Vec3::new(*self.i(0) == value, + *self.i(1) == value, + *self.i(2) == value) } #[inline] pub fn ne_s(&self, value: T) -> Vec3 { - Vec3::new(*self.index(0) != value, - *self.index(1) != value, - *self.index(2) != value) + Vec3::new(*self.i(0) != value, + *self.i(1) != value, + *self.i(2) != value) } #[inline] pub fn eq_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) == *other.index(0), - *self.index(1) == *other.index(1), - *self.index(2) == *other.index(2)) + Vec3::new(*self.i(0) == *other.i(0), + *self.i(1) == *other.i(1), + *self.i(2) == *other.i(2)) } #[inline] pub fn ne_v(&self, other: &Vec3) -> Vec3 { - Vec3::new(*self.index(0) != *other.index(0), - *self.index(1) != *other.index(1), - *self.index(2) != *other.index(2)) + Vec3::new(*self.i(0) != *other.i(0), + *self.i(1) != *other.i(1), + *self.i(2) != *other.i(2)) } } @@ -1260,22 +1260,22 @@ impl BoolVec<[bool,..3]> for Vec3 { /// `true`, otherwise `false`. #[inline] pub fn any(&self) -> bool { - *self.index(0) || *self.index(1) || *self.index(2) + *self.i(0) || *self.i(1) || *self.i(2) } /// Returns `true` if _all_ of the components of the vector are equal to /// `true`, otherwise `false`. #[inline] pub fn all(&self) -> bool { - *self.index(0) && *self.index(1) && *self.index(2) + *self.i(0) && *self.i(1) && *self.i(2) } } impl> Not> for Vec3 { pub fn not(&self) -> Vec3 { - Vec3::new(!*self.index(0), - !*self.index(1), - !*self.index(2)) + Vec3::new(!*self.i(0), + !*self.i(1), + !*self.i(2)) } } @@ -1293,13 +1293,13 @@ mod vec3_tests{ let mut mut_a = A; mut_a.swap(0, 2); - assert_eq!(*mut_a.index(0), *A.index(2)); - assert_eq!(*mut_a.index(2), *A.index(0)); + assert_eq!(*mut_a.i(0), *A.i(2)); + assert_eq!(*mut_a.i(2), *A.i(0)); mut_a = A; mut_a.swap(1, 2); - assert_eq!(*mut_a.index(1), *A.index(2)); - assert_eq!(*mut_a.index(2), *A.index(1)); + assert_eq!(*mut_a.i(1), *A.i(2)); + assert_eq!(*mut_a.i(2), *A.i(1)); } #[test] @@ -1547,203 +1547,203 @@ impl NumVec for Vec4 { /// Returns a new vector with `value` added to each component. #[inline] pub fn add_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) + value, - *self.index(1) + value, - *self.index(2) + value, - *self.index(3) + value) + Vec4::new(*self.i(0) + value, + *self.i(1) + value, + *self.i(2) + value, + *self.i(3) + value) } /// Returns a new vector with `value` subtracted from each component. #[inline] pub fn sub_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) - value, - *self.index(1) - value, - *self.index(2) - value, - *self.index(3) - value) + Vec4::new(*self.i(0) - value, + *self.i(1) - value, + *self.i(2) - value, + *self.i(3) - value) } /// Returns the scalar multiplication of the vector with `value`. #[inline] pub fn mul_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) * value, - *self.index(1) * value, - *self.index(2) * value, - *self.index(3) * value) + Vec4::new(*self.i(0) * value, + *self.i(1) * value, + *self.i(2) * value, + *self.i(3) * value) } /// Returns a new vector with each component divided by `value`. #[inline] pub fn div_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) / value, - *self.index(1) / value, - *self.index(2) / value, - *self.index(3) / value) + Vec4::new(*self.i(0) / value, + *self.i(1) / value, + *self.i(2) / value, + *self.i(3) / value) } /// Returns the remainder of each component divided by `value`. #[inline] pub fn rem_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) % value, - *self.index(1) % value, - *self.index(2) % value, - *self.index(3) % value) + Vec4::new(*self.i(0) % value, + *self.i(1) % value, + *self.i(2) % value, + *self.i(3) % value) } /// Returns the sum of the two vectors. #[inline] pub fn add_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) + *other.index(0), - *self.index(1) + *other.index(1), - *self.index(2) + *other.index(2), - *self.index(3) + *other.index(3)) + Vec4::new(*self.i(0) + *other.i(0), + *self.i(1) + *other.i(1), + *self.i(2) + *other.i(2), + *self.i(3) + *other.i(3)) } /// Ruturns the result of subtrating `other` from the vector. #[inline] pub fn sub_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) - *other.index(0), - *self.index(1) - *other.index(1), - *self.index(2) - *other.index(2), - *self.index(3) - *other.index(3)) + Vec4::new(*self.i(0) - *other.i(0), + *self.i(1) - *other.i(1), + *self.i(2) - *other.i(2), + *self.i(3) - *other.i(3)) } /// Returns the component-wise product of the vector and `other`. #[inline] pub fn mul_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) * *other.index(0), - *self.index(1) * *other.index(1), - *self.index(2) * *other.index(2), - *self.index(3) * *other.index(3)) + Vec4::new(*self.i(0) * *other.i(0), + *self.i(1) * *other.i(1), + *self.i(2) * *other.i(2), + *self.i(3) * *other.i(3)) } /// Returns the component-wise quotient of the vectors. #[inline] pub fn div_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) / *other.index(0), - *self.index(1) / *other.index(1), - *self.index(2) / *other.index(2), - *self.index(3) / *other.index(3)) + Vec4::new(*self.i(0) / *other.i(0), + *self.i(1) / *other.i(1), + *self.i(2) / *other.i(2), + *self.i(3) / *other.i(3)) } /// Returns the component-wise remainder of the vector divided by `other`. #[inline] pub fn rem_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) % *other.index(0), - *self.index(1) % *other.index(1), - *self.index(2) % *other.index(2), - *self.index(3) % *other.index(3)) + Vec4::new(*self.i(0) % *other.i(0), + *self.i(1) % *other.i(1), + *self.i(2) % *other.i(2), + *self.i(3) % *other.i(3)) } /// Negates each component of the vector. #[inline] pub fn neg_self(&mut self) { - *self.index_mut(0) = -*self.index(0); - *self.index_mut(1) = -*self.index(1); - *self.index_mut(2) = -*self.index(2); - *self.index_mut(3) = -*self.index(3); + *self.mut_i(0) = -*self.i(0); + *self.mut_i(1) = -*self.i(1); + *self.mut_i(2) = -*self.i(2); + *self.mut_i(3) = -*self.i(3); } /// Adds `value` to each component of the vector. #[inline] pub fn add_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) + value; - *self.index_mut(1) = *self.index(1) + value; - *self.index_mut(2) = *self.index(2) + value; - *self.index_mut(3) = *self.index(3) + value; + *self.mut_i(0) = *self.i(0) + value; + *self.mut_i(1) = *self.i(1) + value; + *self.mut_i(2) = *self.i(2) + value; + *self.mut_i(3) = *self.i(3) + value; } /// Subtracts `value` from each component of the vector. #[inline] pub fn sub_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) - value; - *self.index_mut(1) = *self.index(1) - value; - *self.index_mut(2) = *self.index(2) - value; - *self.index_mut(3) = *self.index(3) - value; + *self.mut_i(0) = *self.i(0) - value; + *self.mut_i(1) = *self.i(1) - value; + *self.mut_i(2) = *self.i(2) - value; + *self.mut_i(3) = *self.i(3) - value; } #[inline] pub fn mul_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) * value; - *self.index_mut(1) = *self.index(1) * value; - *self.index_mut(2) = *self.index(2) * value; - *self.index_mut(3) = *self.index(3) * value; + *self.mut_i(0) = *self.i(0) * value; + *self.mut_i(1) = *self.i(1) * value; + *self.mut_i(2) = *self.i(2) * value; + *self.mut_i(3) = *self.i(3) * value; } #[inline] pub fn div_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) / value; - *self.index_mut(1) = *self.index(1) / value; - *self.index_mut(2) = *self.index(2) / value; - *self.index_mut(3) = *self.index(3) / value; + *self.mut_i(0) = *self.i(0) / value; + *self.mut_i(1) = *self.i(1) / value; + *self.mut_i(2) = *self.i(2) / value; + *self.mut_i(3) = *self.i(3) / value; } #[inline] pub fn rem_self_s(&mut self, value: T) { - *self.index_mut(0) = *self.index(0) % value; - *self.index_mut(1) = *self.index(1) % value; - *self.index_mut(2) = *self.index(2) % value; - *self.index_mut(3) = *self.index(3) % value; + *self.mut_i(0) = *self.i(0) % value; + *self.mut_i(1) = *self.i(1) % value; + *self.mut_i(2) = *self.i(2) % value; + *self.mut_i(3) = *self.i(3) % value; } #[inline] pub fn add_self_v(&mut self, other: &Vec4) { - *self.index_mut(0) = *self.index(0) + *other.index(0); - *self.index_mut(1) = *self.index(1) + *other.index(1); - *self.index_mut(2) = *self.index(2) + *other.index(2); - *self.index_mut(3) = *self.index(3) + *other.index(3); + *self.mut_i(0) = *self.i(0) + *other.i(0); + *self.mut_i(1) = *self.i(1) + *other.i(1); + *self.mut_i(2) = *self.i(2) + *other.i(2); + *self.mut_i(3) = *self.i(3) + *other.i(3); } #[inline] pub fn sub_self_v(&mut self, other: &Vec4) { - *self.index_mut(0) = *self.index(0) - *other.index(0); - *self.index_mut(1) = *self.index(1) - *other.index(1); - *self.index_mut(2) = *self.index(2) - *other.index(2); - *self.index_mut(3) = *self.index(3) - *other.index(3); + *self.mut_i(0) = *self.i(0) - *other.i(0); + *self.mut_i(1) = *self.i(1) - *other.i(1); + *self.mut_i(2) = *self.i(2) - *other.i(2); + *self.mut_i(3) = *self.i(3) - *other.i(3); } #[inline] pub fn mul_self_v(&mut self, other: &Vec4) { - *self.index_mut(0) = *self.index(0) * *other.index(0); - *self.index_mut(1) = *self.index(1) * *other.index(1); - *self.index_mut(2) = *self.index(2) * *other.index(2); - *self.index_mut(3) = *self.index(3) * *other.index(3); + *self.mut_i(0) = *self.i(0) * *other.i(0); + *self.mut_i(1) = *self.i(1) * *other.i(1); + *self.mut_i(2) = *self.i(2) * *other.i(2); + *self.mut_i(3) = *self.i(3) * *other.i(3); } #[inline] pub fn div_self_v(&mut self, other: &Vec4) { - *self.index_mut(0) = *self.index(0) / *other.index(0); - *self.index_mut(1) = *self.index(1) / *other.index(1); - *self.index_mut(2) = *self.index(2) / *other.index(2); - *self.index_mut(3) = *self.index(3) / *other.index(3); + *self.mut_i(0) = *self.i(0) / *other.i(0); + *self.mut_i(1) = *self.i(1) / *other.i(1); + *self.mut_i(2) = *self.i(2) / *other.i(2); + *self.mut_i(3) = *self.i(3) / *other.i(3); } #[inline] pub fn rem_self_v(&mut self, other: &Vec4) { - *self.index_mut(0) = *self.index(0) % *other.index(0); - *self.index_mut(1) = *self.index(1) % *other.index(1); - *self.index_mut(2) = *self.index(2) % *other.index(2); - *self.index_mut(3) = *self.index(3) % *other.index(3); + *self.mut_i(0) = *self.i(0) % *other.i(0); + *self.mut_i(1) = *self.i(1) % *other.i(1); + *self.mut_i(2) = *self.i(2) % *other.i(2); + *self.mut_i(3) = *self.i(3) % *other.i(3); } /// Returns the dot product of the vector and `other`. #[inline] pub fn dot(&self, other: &Vec4) -> T { - *self.index(0) * *other.index(0) + - *self.index(1) * *other.index(1) + - *self.index(2) * *other.index(2) + - *self.index(3) * *other.index(3) + *self.i(0) * *other.i(0) + + *self.i(1) * *other.i(1) + + *self.i(2) * *other.i(2) + + *self.i(3) * *other.i(3) } /// Returns the sum of the vector's components. #[inline] pub fn comp_add(&self) -> T { - *self.index(0) + *self.index(1) + *self.index(2) + *self.index(3) + *self.i(0) + *self.i(1) + *self.i(2) + *self.i(3) } /// Returns the product of the vector's components. #[inline] pub fn comp_mul(&self) -> T { - *self.index(0) * *self.index(1) * *self.index(2) * *self.index(3) + *self.i(0) * *self.i(1) * *self.i(2) * *self.i(3) } } @@ -1751,10 +1751,10 @@ impl Neg> for Vec4 { /// Returns the vector with each component negated. #[inline] pub fn neg(&self) -> Vec4 { - Vec4::new(-*self.index(0), - -*self.index(1), - -*self.index(2), - -*self.index(3)) + Vec4::new(-*self.i(0), + -*self.i(1), + -*self.i(2), + -*self.i(3)) } } @@ -1823,160 +1823,160 @@ impl FloatVec for Vec4 { impl OrdVec> for Vec4 { #[inline] pub fn lt_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) < value, - *self.index(1) < value, - *self.index(2) < value, - *self.index(3) < value) + Vec4::new(*self.i(0) < value, + *self.i(1) < value, + *self.i(2) < value, + *self.i(3) < value) } #[inline] pub fn le_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) <= value, - *self.index(1) <= value, - *self.index(2) <= value, - *self.index(3) <= value) + Vec4::new(*self.i(0) <= value, + *self.i(1) <= value, + *self.i(2) <= value, + *self.i(3) <= value) } #[inline] pub fn ge_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) >= value, - *self.index(1) >= value, - *self.index(2) >= value, - *self.index(3) >= value) + Vec4::new(*self.i(0) >= value, + *self.i(1) >= value, + *self.i(2) >= value, + *self.i(3) >= value) } #[inline] pub fn gt_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) > value, - *self.index(1) > value, - *self.index(2) > value, - *self.index(3) > value) + Vec4::new(*self.i(0) > value, + *self.i(1) > value, + *self.i(2) > value, + *self.i(3) > value) } #[inline] pub fn lt_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) < *other.index(0), - *self.index(1) < *other.index(1), - *self.index(2) < *other.index(2), - *self.index(3) < *other.index(3)) + Vec4::new(*self.i(0) < *other.i(0), + *self.i(1) < *other.i(1), + *self.i(2) < *other.i(2), + *self.i(3) < *other.i(3)) } #[inline] pub fn le_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) <= *other.index(0), - *self.index(1) <= *other.index(1), - *self.index(2) <= *other.index(2), - *self.index(3) <= *other.index(3)) + Vec4::new(*self.i(0) <= *other.i(0), + *self.i(1) <= *other.i(1), + *self.i(2) <= *other.i(2), + *self.i(3) <= *other.i(3)) } #[inline] pub fn ge_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) >= *other.index(0), - *self.index(1) >= *other.index(1), - *self.index(2) >= *other.index(2), - *self.index(3) >= *other.index(3)) + Vec4::new(*self.i(0) >= *other.i(0), + *self.i(1) >= *other.i(1), + *self.i(2) >= *other.i(2), + *self.i(3) >= *other.i(3)) } #[inline] pub fn gt_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) > *other.index(0), - *self.index(1) > *other.index(1), - *self.index(2) > *other.index(2), - *self.index(3) > *other.index(3)) + Vec4::new(*self.i(0) > *other.i(0), + *self.i(1) > *other.i(1), + *self.i(2) > *other.i(2), + *self.i(3) > *other.i(3)) } #[inline] pub fn min_s(&self, value: T) -> Vec4 { - Vec4::new(self.index(0).min(&value), - self.index(1).min(&value), - self.index(2).min(&value), - self.index(3).min(&value)) + Vec4::new(self.i(0).min(&value), + self.i(1).min(&value), + self.i(2).min(&value), + self.i(3).min(&value)) } #[inline] pub fn max_s(&self, value: T) -> Vec4 { - Vec4::new(self.index(0).max(&value), - self.index(1).max(&value), - self.index(2).max(&value), - self.index(3).max(&value)) + Vec4::new(self.i(0).max(&value), + self.i(1).max(&value), + self.i(2).max(&value), + self.i(3).max(&value)) } #[inline] pub fn clamp_s(&self, mn: T, mx: T) -> Vec4 { - Vec4::new(self.index(0).clamp(&mn, &mx), - self.index(1).clamp(&mn, &mx), - self.index(2).clamp(&mn, &mx), - self.index(3).clamp(&mn, &mx)) + Vec4::new(self.i(0).clamp(&mn, &mx), + self.i(1).clamp(&mn, &mx), + self.i(2).clamp(&mn, &mx), + self.i(3).clamp(&mn, &mx)) } #[inline] pub fn min_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(self.index(0).min(other.index(0)), - self.index(1).min(other.index(1)), - self.index(2).min(other.index(2)), - self.index(3).min(other.index(3))) + Vec4::new(self.i(0).min(other.i(0)), + self.i(1).min(other.i(1)), + self.i(2).min(other.i(2)), + self.i(3).min(other.i(3))) } #[inline] pub fn max_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(self.index(0).max(other.index(0)), - self.index(1).max(other.index(1)), - self.index(2).max(other.index(2)), - self.index(3).max(other.index(3))) + Vec4::new(self.i(0).max(other.i(0)), + self.i(1).max(other.i(1)), + self.i(2).max(other.i(2)), + self.i(3).max(other.i(3))) } #[inline] pub fn clamp_v(&self, mn: &Vec4, mx: &Vec4) -> Vec4 { - Vec4::new(self.index(0).clamp(mn.index(0), mx.index(0)), - self.index(1).clamp(mn.index(1), mx.index(1)), - self.index(2).clamp(mn.index(2), mx.index(2)), - self.index(3).clamp(mn.index(3), mx.index(3))) + Vec4::new(self.i(0).clamp(mn.i(0), mx.i(0)), + self.i(1).clamp(mn.i(1), mx.i(1)), + self.i(2).clamp(mn.i(2), mx.i(2)), + self.i(3).clamp(mn.i(3), mx.i(3))) } /// Returns the smallest component of the vector. #[inline] pub fn comp_min(&self) -> T { - self.index(0).min(self.index(1)).min(self.index(2)).min(self.index(3)) + self.i(0).min(self.i(1)).min(self.i(2)).min(self.i(3)) } /// Returns the largest component of the vector. #[inline] pub fn comp_max(&self) -> T { - self.index(0).max(self.index(1)).max(self.index(2)).max(self.index(3)) + self.i(0).max(self.i(1)).max(self.i(2)).max(self.i(3)) } } impl EqVec> for Vec4 { #[inline] pub fn eq_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) == value, - *self.index(1) == value, - *self.index(2) == value, - *self.index(3) == value) + Vec4::new(*self.i(0) == value, + *self.i(1) == value, + *self.i(2) == value, + *self.i(3) == value) } #[inline] pub fn ne_s(&self, value: T) -> Vec4 { - Vec4::new(*self.index(0) != value, - *self.index(1) != value, - *self.index(2) != value, - *self.index(3) != value) + Vec4::new(*self.i(0) != value, + *self.i(1) != value, + *self.i(2) != value, + *self.i(3) != value) } #[inline] pub fn eq_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) == *other.index(0), - *self.index(1) == *other.index(1), - *self.index(2) == *other.index(2), - *self.index(3) == *other.index(3)) + Vec4::new(*self.i(0) == *other.i(0), + *self.i(1) == *other.i(1), + *self.i(2) == *other.i(2), + *self.i(3) == *other.i(3)) } #[inline] pub fn ne_v(&self, other: &Vec4) -> Vec4 { - Vec4::new(*self.index(0) != *other.index(0), - *self.index(1) != *other.index(1), - *self.index(2) != *other.index(2), - *self.index(3) != *other.index(3)) + Vec4::new(*self.i(0) != *other.i(0), + *self.i(1) != *other.i(1), + *self.i(2) != *other.i(2), + *self.i(3) != *other.i(3)) } } @@ -1985,23 +1985,23 @@ impl BoolVec<[bool,..4]> for Vec4 { /// `true`, otherwise `false`. #[inline] pub fn any(&self) -> bool { - *self.index(0) || *self.index(1) || *self.index(2) || *self.index(3) + *self.i(0) || *self.i(1) || *self.i(2) || *self.i(3) } /// Returns `true` if _all_ of the components of the vector are equal to /// `true`, otherwise `false`. #[inline] pub fn all(&self) -> bool { - *self.index(0) && *self.index(1) && *self.index(2) && *self.index(3) + *self.i(0) && *self.i(1) && *self.i(2) && *self.i(3) } } impl> Not> for Vec4 { pub fn not(&self) -> Vec4 { - Vec4::new(!*self.index(0), - !*self.index(1), - !*self.index(2), - !*self.index(3)) + Vec4::new(!*self.i(0), + !*self.i(1), + !*self.i(2), + !*self.i(3)) } } @@ -2019,13 +2019,13 @@ mod vec4_tests { let mut mut_a = A; mut_a.swap(0, 3); - assert_eq!(*mut_a.index(0), *A.index(3)); - assert_eq!(*mut_a.index(3), *A.index(0)); + assert_eq!(*mut_a.i(0), *A.i(3)); + assert_eq!(*mut_a.i(3), *A.i(0)); mut_a = A; mut_a.swap(1, 2); - assert_eq!(*mut_a.index(1), *A.index(2)); - assert_eq!(*mut_a.index(2), *A.index(1)); + assert_eq!(*mut_a.i(1), *A.i(2)); + assert_eq!(*mut_a.i(2), *A.i(1)); } #[test]