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<S> trait.

This means you may access the field `x` on a VectorN with vector[0]
syntax.

Signed-off-by: Aaron Jacobs <atheriel@gmail.com>
This commit is contained in:
Aaron Jacobs 2014-07-28 22:37:49 -07:00
parent 7e81b258a9
commit fddb3a7903

View file

@ -215,6 +215,18 @@ macro_rules! vec(
#[inline] fn one() -> $Self<S> { $Self::from_value(one()) }
}
impl<S: BaseNum> Index<uint, S> for $Self<S> {
#[inline]
fn index<'a>(&'a self, index: &uint) -> &'a S {
let slice: &[S, ..$n] = unsafe { mem::transmute(self) };
&slice[*index]
}
}
impl<S: BaseNum> IndexMut<uint, S> for $Self<S> {
#[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut S { self.mut_i(*index) }
}
impl<S: BaseFloat> ApproxEq<S> for $Self<S> {
#[inline]
fn approx_eq_eps(&self, other: &$Self<S>, epsilon: &S) -> bool {