diff --git a/src/lib.rs b/src/lib.rs index f93d40bc..e6e16adf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,6 +215,10 @@ pub mod overload { Vec1DivRhs, Vec2DivRhs, Vec3DivRhs, Vec4DivRhs, Vec5DivRhs, Vec6DivRhs, Vec1AddRhs, Vec2AddRhs, Vec3AddRhs, Vec4AddRhs, Vec5AddRhs, Vec6AddRhs, Vec1SubRhs, Vec2SubRhs, Vec3SubRhs, Vec4SubRhs, Vec5SubRhs, Vec6SubRhs, + Pnt1MulRhs, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs, Pnt5MulRhs, Pnt6MulRhs, + Pnt1DivRhs, Pnt2DivRhs, Pnt3DivRhs, Pnt4DivRhs, Pnt5DivRhs, Pnt6DivRhs, + Pnt1AddRhs, Pnt2AddRhs, Pnt3AddRhs, Pnt4AddRhs, Pnt5AddRhs, Pnt6AddRhs, + Pnt1SubRhs, Pnt2SubRhs, Pnt3SubRhs, Pnt4SubRhs, Pnt5SubRhs, Pnt6SubRhs, Mat1MulRhs, Mat2MulRhs, Mat3MulRhs, Mat4MulRhs, Mat5MulRhs, Mat6MulRhs, Mat1DivRhs, Mat2DivRhs, Mat3DivRhs, Mat4DivRhs, Mat5DivRhs, Mat6DivRhs, Mat1AddRhs, Mat2AddRhs, Mat3AddRhs, Mat4AddRhs, Mat5AddRhs, Mat6AddRhs, diff --git a/src/structs/mod.rs b/src/structs/mod.rs index be5f335f..b5402041 100644 --- a/src/structs/mod.rs +++ b/src/structs/mod.rs @@ -12,6 +12,10 @@ pub use self::vec::{Vec1MulRhs, Vec2MulRhs, Vec3MulRhs, Vec4MulRhs, Vec5MulRhs, Vec1DivRhs, Vec2DivRhs, Vec3DivRhs, Vec4DivRhs, Vec5DivRhs, Vec6DivRhs, Vec1AddRhs, Vec2AddRhs, Vec3AddRhs, Vec4AddRhs, Vec5AddRhs, Vec6AddRhs, Vec1SubRhs, Vec2SubRhs, Vec3SubRhs, Vec4SubRhs, Vec5SubRhs, Vec6SubRhs}; +pub use self::pnt::{Pnt1MulRhs, Pnt2MulRhs, Pnt3MulRhs, Pnt4MulRhs, Pnt5MulRhs, Pnt6MulRhs, + Pnt1DivRhs, Pnt2DivRhs, Pnt3DivRhs, Pnt4DivRhs, Pnt5DivRhs, Pnt6DivRhs, + Pnt1AddRhs, Pnt2AddRhs, Pnt3AddRhs, Pnt4AddRhs, Pnt5AddRhs, Pnt6AddRhs, + Pnt1SubRhs, Pnt2SubRhs, Pnt3SubRhs, Pnt4SubRhs, Pnt5SubRhs, Pnt6SubRhs}; pub use self::mat::{Mat1MulRhs, Mat2MulRhs, Mat3MulRhs, Mat4MulRhs, Mat5MulRhs, Mat6MulRhs, Mat1DivRhs, Mat2DivRhs, Mat3DivRhs, Mat4DivRhs, Mat5DivRhs, Mat6DivRhs, Mat1AddRhs, Mat2AddRhs, Mat3AddRhs, Mat4AddRhs, Mat5AddRhs, Mat6AddRhs, diff --git a/src/structs/pnt.rs b/src/structs/pnt.rs index 9820e6b9..9974d625 100644 --- a/src/structs/pnt.rs +++ b/src/structs/pnt.rs @@ -1,6 +1,6 @@ //! Points with dimensions known at compile-time. -#![allow(missing_doc)] // we allow missing to avoid having to document the vector components. +#![allow(missing_doc)] // we allow missing to avoid having to document the point components. use std::mem; use std::num::{Zero, One, Bounded}; @@ -18,13 +18,13 @@ use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6}; pub struct Pnt0; impl Pnt0 { - /// Creates a new vector. + /// Creates a new point. #[inline] pub fn new() -> Pnt0 { Pnt0 } - /// Creates a new vector. The parameter is not taken in account. + /// Creates a new point. The parameter is not taken in account. #[inline] pub fn new_repeat(_: N) -> Pnt0 { Pnt0 @@ -34,7 +34,7 @@ impl Pnt0 { /// Point of dimension 1. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt1 { - /// First component of the vector. + /// First component of the point. pub x: N } @@ -123,9 +123,9 @@ pnt_from_homogeneous_impl!(Pnt1, Pnt2, y, x) /// Point of dimension 2. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt2 { - /// First component of the vector. + /// First component of the point. pub x: N, - /// Second component of the vector. + /// Second component of the point. pub y: N } @@ -214,11 +214,11 @@ pnt_from_homogeneous_impl!(Pnt2, Pnt3, z, x, y) /// Point of dimension 3. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt3 { - /// First component of the vector. + /// First component of the point. pub x: N, - /// Second component of the vector. + /// Second component of the point. pub y: N, - /// Third component of the vector. + /// Third component of the point. pub z: N } @@ -307,13 +307,13 @@ pnt_from_homogeneous_impl!(Pnt3, Pnt4, w, x, y, z) /// Point of dimension 4. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt4 { - /// First component of the vector. + /// First component of the point. pub x: N, - /// Second component of the vector. + /// Second component of the point. pub y: N, - /// Third component of the vector. + /// Third component of the point. pub z: N, - /// Fourth component of the vector. + /// Fourth component of the point. pub w: N } @@ -402,15 +402,15 @@ pnt_from_homogeneous_impl!(Pnt4, Pnt5, a, x, y, z, w) /// Point of dimension 5. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt5 { - /// First component of the vector. + /// First component of the point. pub x: N, - /// Second component of the vector. + /// Second component of the point. pub y: N, - /// Third component of the vector. + /// Third component of the point. pub z: N, - /// Fourth component of the vector. + /// Fourth component of the point. pub w: N, - /// Fifth of the vector. + /// Fifth of the point. pub a: N } @@ -499,17 +499,17 @@ pnt_from_homogeneous_impl!(Pnt5, Pnt6, b, x, y, z, w, a) /// Point of dimension 6. #[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Show)] pub struct Pnt6 { - /// First component of the vector. + /// First component of the point. pub x: N, - /// Second component of the vector. + /// Second component of the point. pub y: N, - /// Third component of the vector. + /// Third component of the point. pub z: N, - /// Fourth component of the vector. + /// Fourth component of the point. pub w: N, - /// Fifth of the vector. + /// Fifth of the point. pub a: N, - /// Sixth component of the vector. + /// Sixth component of the point. pub b: N } diff --git a/src/structs/pnt_macros.rs b/src/structs/pnt_macros.rs index 1d326a9c..5e1b0e93 100644 --- a/src/structs/pnt_macros.rs +++ b/src/structs/pnt_macros.rs @@ -69,6 +69,12 @@ macro_rules! pnt_as_vec_impl( mem::transmute(self) } } + + #[inline] + fn set_coords(&mut self, v: $tv) { + self.$comp0 = v.$comp0; + $(self.$compN = v.$compN;)* + } } impl PntAsVec<$tv> for $t { @@ -81,6 +87,11 @@ macro_rules! pnt_as_vec_impl( fn as_vec<'a>(&'a self) -> &'a $tv { self.as_vec() } + + #[inline] + fn set_coords(&mut self, v: $tv) { + self.set_coords(v) + } } ) ) diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 4468f0a0..df5bd7ae 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -162,8 +162,7 @@ impl Rot3 { /// Reorient this matrix such that its local `z` axis points to a given point. /// /// # Arguments - /// * at - The point to look at. It is also the direction the matrix `y` axis will be aligned - /// with + /// * at - The look direction, that is, direction the matrix `y` axis will be aligned with /// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear /// with `at`. Non-colinearity is not checked. pub fn look_at_z(&mut self, at: &Vec3, up: &Vec3) { diff --git a/src/structs/vec.rs b/src/structs/vec.rs index 25b0a44b..f86838d6 100644 --- a/src/structs/vec.rs +++ b/src/structs/vec.rs @@ -123,8 +123,8 @@ from_iterator_impl!(Vec1, iterator) bounded_impl!(Vec1, x) iterable_impl!(Vec1, 1) iterable_mut_impl!(Vec1, 1) -to_homogeneous_impl!(Vec1, Vec2, y, x) -from_homogeneous_impl!(Vec1, Vec2, y, x) +vec_to_homogeneous_impl!(Vec1, Vec2, y, x) +vec_from_homogeneous_impl!(Vec1, Vec2, y, x) translate_impl!(Vec1, Pnt1) rotate_impl!(Vec1) rotate_impl!(Pnt1) @@ -224,8 +224,8 @@ from_iterator_impl!(Vec2, iterator, iterator) bounded_impl!(Vec2, x, y) iterable_impl!(Vec2, 2) iterable_mut_impl!(Vec2, 2) -to_homogeneous_impl!(Vec2, Vec3, z, x, y) -from_homogeneous_impl!(Vec2, Vec3, z, x, y) +vec_to_homogeneous_impl!(Vec2, Vec3, z, x, y) +vec_from_homogeneous_impl!(Vec2, Vec3, z, x, y) translate_impl!(Vec2, Pnt2) rotate_impl!(Vec2) rotate_impl!(Pnt2) @@ -330,8 +330,8 @@ from_iterator_impl!(Vec3, iterator, iterator, iterator) bounded_impl!(Vec3, x, y, z) iterable_impl!(Vec3, 3) iterable_mut_impl!(Vec3, 3) -to_homogeneous_impl!(Vec3, Vec4, w, x, y, z) -from_homogeneous_impl!(Vec3, Vec4, w, x, y, z) +vec_to_homogeneous_impl!(Vec3, Vec4, w, x, y, z) +vec_from_homogeneous_impl!(Vec3, Vec4, w, x, y, z) translate_impl!(Vec3, Pnt3) rotate_impl!(Vec3) rotate_impl!(Pnt3) @@ -436,8 +436,8 @@ from_iterator_impl!(Vec4, iterator, iterator, iterator, iterator) bounded_impl!(Vec4, x, y, z, w) iterable_impl!(Vec4, 4) iterable_mut_impl!(Vec4, 4) -to_homogeneous_impl!(Vec4, Vec5, a, x, y, z, w) -from_homogeneous_impl!(Vec4, Vec5, a, x, y, z, w) +vec_to_homogeneous_impl!(Vec4, Vec5, a, x, y, z, w) +vec_from_homogeneous_impl!(Vec4, Vec5, a, x, y, z, w) translate_impl!(Vec4, Pnt4) rotate_impl!(Vec4) rotate_impl!(Pnt4) @@ -543,8 +543,8 @@ from_iterator_impl!(Vec5, iterator, iterator, iterator, iterator, iterator) bounded_impl!(Vec5, x, y, z, w, a) iterable_impl!(Vec5, 5) iterable_mut_impl!(Vec5, 5) -to_homogeneous_impl!(Vec5, Vec6, b, x, y, z, w, a) -from_homogeneous_impl!(Vec5, Vec6, b, x, y, z, w, a) +vec_to_homogeneous_impl!(Vec5, Vec6, b, x, y, z, w, a) +vec_from_homogeneous_impl!(Vec5, Vec6, b, x, y, z, w, a) translate_impl!(Vec5, Pnt5) rotate_impl!(Vec5) rotate_impl!(Pnt5) diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index e73ee5c3..d94313b8 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -599,7 +599,7 @@ macro_rules! bounded_impl( ) ) -macro_rules! to_homogeneous_impl( +macro_rules! vec_to_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( impl ToHomogeneous<$t2> for $t { fn to_homogeneous(v: &$t) -> $t2 { @@ -614,7 +614,7 @@ macro_rules! to_homogeneous_impl( ) ) -macro_rules! from_homogeneous_impl( +macro_rules! vec_from_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( impl + One + Zero> FromHomogeneous<$t2> for $t { fn from(v: &$t2) -> $t { diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 34864891..402768a2 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -195,13 +195,19 @@ pub trait PntAsVec { /// Converts a reference to this point to a reference to its associated vector. fn as_vec<'a>(&'a self) -> &'a V; + + // NOTE: this is used in some places to overcome some limitations untill the trait reform is + // done on rustc. + /// Sets the coordinates of this point to match those of a given vector. + fn set_coords(&mut self, coords: V); } /// Trait grouping most common operations on points. // XXX: the vector space element `V` should be an associated type. Though this would prevent V from // having bounds (they are not supported yet). So, for now, we will just use a type parameter. pub trait AnyPnt: - PntAsVec + Dim + Sub + Orig + Neg + PartialEq + Mul + Div { + PntAsVec + Dim + Sub + Orig + Neg + PartialEq + Mul + + Div + Add { // FIXME: + Sub } /// Trait of points with components implementing the `Float` trait. @@ -230,7 +236,7 @@ pub trait PntExt: AnyPnt + Indexable + Iterable + pub trait FloatPntExt> : FloatPnt + PntExt { } -impl + Dim + Sub + Orig + Neg

+ PartialEq + Mul + Div> +impl + Dim + Sub + Add + Orig + Neg

+ PartialEq + Mul + Div> AnyPnt for P { } impl, P: AnyPnt> FloatPnt for P { } impl + Indexable + Iterable + ScalarAdd + ScalarSub + Bounded>