diff --git a/src/vector.rs b/src/vector.rs index 7ec191d..0593b96 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -211,19 +211,19 @@ pub trait Vector: Array1 + Clone // where // Utility macro for generating associated functions for the vectors macro_rules! vec { - ($Self_:ident <$S:ident> { $($field:ident),+ }, $n:expr, $constructor:ident) => { + ($VectorN:ident <$S:ident> { $($field:ident),+ }, $n:expr, $constructor:ident) => { #[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] - pub struct $Self_ { $(pub $field: S),+ } + pub struct $VectorN { $(pub $field: S),+ } - impl<$S> $Self_<$S> { + impl<$S> $VectorN<$S> { /// Construct a new vector, using the provided values. #[inline] - pub fn new($($field: $S),+) -> $Self_<$S> { - $Self_ { $($field: $field),+ } + pub fn new($($field: $S),+) -> $VectorN<$S> { + $VectorN { $($field: $field),+ } } } - impl<$S: Copy + Neg> $Self_<$S> { + impl<$S: Copy + Neg> $VectorN<$S> { /// Negate this vector in-place (multiply by -1). #[inline] pub fn neg_self(&mut self) { @@ -233,34 +233,34 @@ macro_rules! vec { /// The short constructor. #[inline] - pub fn $constructor($($field: S),+) -> $Self_ { - $Self_::new($($field),+) + pub fn $constructor($($field: S),+) -> $VectorN { + $VectorN::new($($field),+) } - impl<$S: NumCast + Copy> $Self_<$S> { + impl<$S: NumCast + Copy> $VectorN<$S> { /// Component-wise casting to another type #[inline] - pub fn cast(&self) -> $Self_ { - $Self_ { $($field: NumCast::from(self.$field).unwrap()),+ } + pub fn cast(&self) -> $VectorN { + $VectorN { $($field: NumCast::from(self.$field).unwrap()),+ } } } - impl<$S: Copy> Array1<$S> for $Self_<$S> {} + impl<$S: Copy> Array1<$S> for $VectorN<$S> {} - impl Vector for $Self_ { - #[inline] fn from_value(s: S) -> $Self_ { $Self_ { $($field: s),+ } } + impl Vector for $VectorN { + #[inline] fn from_value(s: S) -> $VectorN { $VectorN { $($field: s),+ } } - #[inline] fn add_s(&self, s: S) -> $Self_ { self + s } - #[inline] fn sub_s(&self, s: S) -> $Self_ { self - s } - #[inline] fn mul_s(&self, s: S) -> $Self_ { self * s } - #[inline] fn div_s(&self, s: S) -> $Self_ { self / s } - #[inline] fn rem_s(&self, s: S) -> $Self_ { self % s } + #[inline] fn add_s(&self, s: S) -> $VectorN { self + s } + #[inline] fn sub_s(&self, s: S) -> $VectorN { self - s } + #[inline] fn mul_s(&self, s: S) -> $VectorN { self * s } + #[inline] fn div_s(&self, s: S) -> $VectorN { self / s } + #[inline] fn rem_s(&self, s: S) -> $VectorN { self % s } - #[inline] fn add_v(&self, v: &$Self_) -> $Self_ { self + v } - #[inline] fn sub_v(&self, v: &$Self_) -> $Self_ { self - v } - #[inline] fn mul_v(&self, v: &$Self_) -> $Self_ { self * v } - #[inline] fn div_v(&self, v: &$Self_) -> $Self_ { self / v } - #[inline] fn rem_v(&self, v: &$Self_) -> $Self_ { self % v } + #[inline] fn add_v(&self, v: &$VectorN) -> $VectorN { self + v } + #[inline] fn sub_v(&self, v: &$VectorN) -> $VectorN { self - v } + #[inline] fn mul_v(&self, v: &$VectorN) -> $VectorN { self * v } + #[inline] fn div_v(&self, v: &$VectorN) -> $VectorN { self / v } + #[inline] fn rem_v(&self, v: &$VectorN) -> $VectorN { self % v } #[inline] fn add_self_s(&mut self, s: S) { *self = &*self + s; } #[inline] fn sub_self_s(&mut self, s: S) { *self = &*self - s; } @@ -268,11 +268,11 @@ macro_rules! vec { #[inline] fn div_self_s(&mut self, s: S) { *self = &*self / s; } #[inline] fn rem_self_s(&mut self, s: S) { *self = &*self % s; } - #[inline] fn add_self_v(&mut self, v: &$Self_) { *self = &*self + v; } - #[inline] fn sub_self_v(&mut self, v: &$Self_) { *self = &*self - v; } - #[inline] fn mul_self_v(&mut self, v: &$Self_) { *self = &*self * v; } - #[inline] fn div_self_v(&mut self, v: &$Self_) { *self = &*self / v; } - #[inline] fn rem_self_v(&mut self, v: &$Self_) { *self = &*self % v; } + #[inline] fn add_self_v(&mut self, v: &$VectorN) { *self = &*self + v; } + #[inline] fn sub_self_v(&mut self, v: &$VectorN) { *self = &*self - v; } + #[inline] fn mul_self_v(&mut self, v: &$VectorN) { *self = &*self * v; } + #[inline] fn div_self_v(&mut self, v: &$VectorN) { *self = &*self / v; } + #[inline] fn rem_self_v(&mut self, v: &$VectorN) { *self = &*self % v; } #[inline] fn comp_add(&self) -> S { fold!(add, { $(self.$field),+ }) } #[inline] fn comp_mul(&self) -> S { fold!(mul, { $(self.$field),+ }) } @@ -280,24 +280,24 @@ macro_rules! vec { #[inline] fn comp_max(&self) -> S { fold!(partial_max, { $(self.$field),+ }) } } - impl> Neg for $Self_ { - type Output = $Self_; + impl> Neg for $VectorN { + type Output = $VectorN; #[inline] - fn neg(self) -> $Self_ { $Self_::new($(-self.$field),+) } + fn neg(self) -> $VectorN { $VectorN::new($(-self.$field),+) } } - impl ApproxEq for $Self_ { + impl ApproxEq for $VectorN { #[inline] - fn approx_eq_eps(&self, other: &$Self_, epsilon: &S) -> bool { + fn approx_eq_eps(&self, other: &$VectorN, epsilon: &S) -> bool { $(self.$field.approx_eq_eps(&other.$field, epsilon))&&+ } } - impl Rand for $Self_ { + impl Rand for $VectorN { #[inline] - fn rand(rng: &mut R) -> $Self_ { - $Self_ { $($field: rng.gen()),+ } + fn rand(rng: &mut R) -> $VectorN { + $VectorN { $($field: rng.gen()),+ } } } }