From 7e81b258a93abaf55c096e388e9109763e1f96be Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 28 Jul 2014 22:21:58 -0700 Subject: [PATCH 1/2] Implements division and remainder operators for vectors. This might have been an oversight at one point. Although the `rem_v` and `div_v` methods are available for vectors, the actual operators were not. Signed-off-by: Aaron Jacobs --- src/vector.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/vector.rs b/src/vector.rs index 6a1d2d1..f5987eb 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -203,6 +203,14 @@ macro_rules! vec( #[inline] fn mul(&self, v: &$Self) -> $Self { self.mul_v(v) } } + impl Div<$Self, $Self> for $Self { + #[inline] fn div(&self, v: &$Self) -> $Self { self.div_v(v) } + } + + impl Rem<$Self, $Self> for $Self { + #[inline] fn rem(&self, v: &$Self) -> $Self { self.rem_v(v) } + } + impl One for $Self { #[inline] fn one() -> $Self { $Self::from_value(one()) } } From fddb3a79030aff8008dee05484e1d25dc78ac43c Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 28 Jul 2014 22:37:49 -0700 Subject: [PATCH 2/2] Implements the (mutable) index operator for vectors. Again, this is possibly an oversight. The operators simply use the mut_i() and i() methods which are demanded by the Array1 trait. This means you may access the field `x` on a VectorN with vector[0] syntax. Signed-off-by: Aaron Jacobs --- src/vector.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vector.rs b/src/vector.rs index f5987eb..36f3e4b 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -215,6 +215,18 @@ macro_rules! vec( #[inline] fn one() -> $Self { $Self::from_value(one()) } } + impl Index for $Self { + #[inline] + fn index<'a>(&'a self, index: &uint) -> &'a S { + let slice: &[S, ..$n] = unsafe { mem::transmute(self) }; + &slice[*index] + } + } + + impl IndexMut for $Self { + #[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut S { self.mut_i(*index) } + } + impl ApproxEq for $Self { #[inline] fn approx_eq_eps(&self, other: &$Self, epsilon: &S) -> bool {