diff --git a/src/vec.rs b/src/vec.rs index d591a3a3..a6bde482 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -145,6 +145,60 @@ translate_impl!(Vec3) rotate_impl!(Vec3) transform_impl!(Vec3) + +/// Vector of dimension 3 with an extra component for padding. +#[deriving(Eq, Encodable, Decodable, Clone, DeepClone, IterBytes, Rand, Zero, ToStr)] +pub struct PVec3 { + /// First component of the vector. + x: N, + /// Second component of the vector. + y: N, + /// Third component of the vector. + z: N, + // Unused component, for padding + priv _unused: N +} + +impl PVec3 { + /// Creates a new 3d vector. + pub fn new(x: N, y: N, z: N) -> PVec3 { + PVec3 { x: x.clone(), y: y, z: z, _unused: x } + } +} + +ord_impl!(PVec3, x, y, z) +orderable_impl!(PVec3, x, y, z) +vec_axis_impl!(PVec3, x, y, z) +vec_cast_impl!(PVec3, x, y, z) +indexable_impl!(PVec3, 3) +new_repeat_impl!(PVec3, val, x, y, z, _unused) +dim_impl!(PVec3, 3) +// (specialized) basis_impl!(PVec3, 1) +add_impl!(PVec3, x, y, z) +sub_impl!(PVec3, x, y, z) +neg_impl!(PVec3, x, y, z) +dot_impl!(PVec3, x, y, z) +scalar_mul_impl!(PVec3, x, y, z) +scalar_div_impl!(PVec3, x, y, z) +scalar_add_impl!(PVec3, x, y, z) +scalar_sub_impl!(PVec3, x, y, z) +translation_impl!(PVec3) +norm_impl!(PVec3) +approx_eq_impl!(PVec3, x, y, z) +round_impl!(PVec3, x, y, z) +one_impl!(PVec3) +from_iterator_impl!(PVec3, iterator, iterator, iterator) +bounded_impl!(PVec3) +iterable_impl!(PVec3, 3) +iterable_mut_impl!(PVec3, 3) +to_homogeneous_impl!(PVec3, Vec4, w, x, y, z) +from_homogeneous_impl!(PVec3, Vec4, w, x, y, z) +translate_impl!(PVec3) +rotate_impl!(PVec3) +transform_impl!(PVec3) + + + /// Vector of dimension 4. #[deriving(Eq, Encodable, Decodable, Clone, DeepClone, IterBytes, Rand, Zero, ToStr)] pub struct Vec4 { diff --git a/src/vec_macros.rs b/src/vec_macros.rs index ba462ebb..c79a5b4d 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -43,7 +43,7 @@ macro_rules! ord_impl( macro_rules! orderable_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl Orderable for $t { + impl Orderable for $t { #[inline] fn max(&self, other: &$t) -> $t { $t::new(self.$comp0.max(&other.$comp0) $(, self.$compN.max(&other.$compN))*) @@ -93,7 +93,7 @@ macro_rules! vec_axis_impl( macro_rules! vec_cast_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl VecCast<$t> for $t { + impl VecCast<$t> for $t { #[inline] fn from(v: $t) -> $t { $t::new(NumCast::from(v.$comp0.clone()) $(, NumCast::from(v.$compN.clone()))*) @@ -233,7 +233,7 @@ macro_rules! basis_impl( macro_rules! add_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Add<$t, $t> for $t { + impl> Add<$t, $t> for $t { #[inline] fn add(&self, other: &$t) -> $t { $t::new(self.$comp0 + other.$comp0 $(, self.$compN + other.$compN)*) @@ -244,7 +244,7 @@ macro_rules! add_impl( macro_rules! sub_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Sub<$t, $t> for $t { + impl> Sub<$t, $t> for $t { #[inline] fn sub(&self, other: &$t) -> $t { $t::new(self.$comp0 - other.$comp0 $(, self.$compN - other.$compN)*) @@ -255,7 +255,7 @@ macro_rules! sub_impl( macro_rules! neg_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Neg<$t> for $t { + impl> Neg<$t> for $t { #[inline] fn neg(&self) -> $t { $t::new(-self.$comp0 $(, -self.$compN )*) @@ -282,7 +282,7 @@ macro_rules! dot_impl( macro_rules! scalar_mul_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Mul> for $t { + impl> Mul> for $t { #[inline] fn mul(&self, s: &N) -> $t { $t::new(self.$comp0 * *s $(, self.$compN * *s)*) @@ -293,7 +293,7 @@ macro_rules! scalar_mul_impl( macro_rules! scalar_div_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> Div> for $t { + impl> Div> for $t { #[inline] fn div(&self, s: &N) -> $t { $t::new(self.$comp0 / *s $(, self.$compN / *s)*) @@ -304,7 +304,7 @@ macro_rules! scalar_div_impl( macro_rules! scalar_add_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> ScalarAdd for $t { + impl> ScalarAdd for $t { #[inline] fn scalar_add(&self, s: &N) -> $t { $t::new(self.$comp0 + *s $(, self.$compN + *s)*) @@ -321,7 +321,7 @@ macro_rules! scalar_add_impl( macro_rules! scalar_sub_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl> ScalarSub for $t { + impl> ScalarSub for $t { #[inline] fn scalar_sub(&self, s: &N) -> $t { $t::new(self.$comp0 - *s $(, self.$compN - *s)*) @@ -398,7 +398,7 @@ macro_rules! norm_impl( macro_rules! round_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( - impl Round for $t { + impl Round for $t { fn floor(&self) -> $t { $t::new(self.$comp0.floor() $(, self.$compN.floor())*) } @@ -457,7 +457,7 @@ macro_rules! one_impl( macro_rules! from_iterator_impl( ($t: ident, $param0: ident $(, $paramN: ident)*) => ( - impl FromIterator for $t { + impl FromIterator for $t { #[inline] fn from_iterator>($param0: &mut I) -> $t { $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) @@ -516,7 +516,7 @@ macro_rules! from_homogeneous_impl( macro_rules! translate_impl( ($t: ident) => ( - impl + Sub> Translate<$t> for $t { + impl + Sub> Translate<$t> for $t { fn translate(&self, other: &$t) -> $t { *other + *self } @@ -544,7 +544,7 @@ macro_rules! rotate_impl( macro_rules! transform_impl( ($t: ident) => ( - impl + Sub> Transform<$t> for $t { + impl + Sub> Transform<$t> for $t { fn transform(&self, other: &$t) -> $t { self.translate(other) } diff --git a/src/vec_spec.rs b/src/vec_spec.rs index e2995857..043d2c3a 100644 --- a/src/vec_spec.rs +++ b/src/vec_spec.rs @@ -185,7 +185,7 @@ static SAMPLES_3_F64: [Vec3, ..42] = [ Vec3 { x: 0.162456 , y: 0.499995 , z: 0.850654 } ]; -impl UniformSphereSample for Vec2 { +impl UniformSphereSample for Vec2 { #[inline(always)] fn sample(f: &fn(Vec2)) { for sample in SAMPLES_2_F64.iter() { @@ -194,7 +194,7 @@ impl UniformSphereSample for Vec2 { } } -impl UniformSphereSample for Vec3 { +impl UniformSphereSample for Vec3 { #[inline(always)] fn sample(f: &fn(Vec3)) { for sample in SAMPLES_3_F64.iter() {