diff --git a/src/traits/vec_cast.rs b/src/traits/vec_cast.rs index bfa9ec30..18e4a924 100644 --- a/src/traits/vec_cast.rs +++ b/src/traits/vec_cast.rs @@ -1,4 +1,4 @@ -/// Trait of vectors which can be converted to another matrix. Used to change the type of a vector +/// Trait of vectors which can be converted to another vector. Used to change the type of a vector /// components. pub trait VecCast { /// Converts `v` to have the type `V`. diff --git a/src/vec.rs b/src/vec.rs index 4054a763..ca723de0 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -60,6 +60,7 @@ translation_impl!(Vec1) translatable_impl!(Vec1) norm_impl!(Vec1) approx_eq_impl!(Vec1, x) +round_impl!(Vec1, x) one_impl!(Vec1) from_iterator_impl!(Vec1, iterator) bounded_impl!(Vec1) @@ -99,6 +100,7 @@ translation_impl!(Vec2) translatable_impl!(Vec2) norm_impl!(Vec2) approx_eq_impl!(Vec2, x, y) +round_impl!(Vec2, x, y) one_impl!(Vec2) from_iterator_impl!(Vec2, iterator, iterator) bounded_impl!(Vec2) @@ -140,6 +142,7 @@ translation_impl!(Vec3) translatable_impl!(Vec3) norm_impl!(Vec3) approx_eq_impl!(Vec3, x, y, z) +round_impl!(Vec3, x, y, z) one_impl!(Vec3) from_iterator_impl!(Vec3, iterator, iterator, iterator) bounded_impl!(Vec3) @@ -183,6 +186,7 @@ translation_impl!(Vec4) translatable_impl!(Vec4) norm_impl!(Vec4) approx_eq_impl!(Vec4, x, y, z, w) +round_impl!(Vec4, x, y, z, w) one_impl!(Vec4) from_iterator_impl!(Vec4, iterator, iterator, iterator, iterator) bounded_impl!(Vec4) @@ -228,6 +232,7 @@ translation_impl!(Vec5) translatable_impl!(Vec5) norm_impl!(Vec5) approx_eq_impl!(Vec5, x, y, z, w, a) +round_impl!(Vec5, x, y, z, w, a) one_impl!(Vec5) from_iterator_impl!(Vec5, iterator, iterator, iterator, iterator, iterator) bounded_impl!(Vec5) @@ -275,6 +280,7 @@ translation_impl!(Vec6) translatable_impl!(Vec6) norm_impl!(Vec6) approx_eq_impl!(Vec6, x, y, z, w, a, b) +round_impl!(Vec6, x, y, z, w, a, b) one_impl!(Vec6) from_iterator_impl!(Vec6, iterator, iterator, iterator, iterator, iterator, iterator) bounded_impl!(Vec6) diff --git a/src/vec_macros.rs b/src/vec_macros.rs index c602fa7e..4cc92fea 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -420,6 +420,32 @@ macro_rules! norm_impl( ) ) +macro_rules! round_impl( + ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + impl Round for $t { + fn floor(&self) -> $t { + $t::new(self.$comp0.floor() $(, self.$compN.floor())*) + } + + fn ceil(&self) -> $t { + $t::new(self.$comp0.ceil() $(, self.$compN.ceil())*) + } + + fn round(&self) -> $t { + $t::new(self.$comp0.round() $(, self.$compN.round())*) + } + + fn trunc(&self) -> $t { + $t::new(self.$comp0.trunc() $(, self.$compN.trunc())*) + } + + fn fract(&self) -> $t { + $t::new(self.$comp0.fract() $(, self.$compN.fract())*) + } + } + ) +) + macro_rules! approx_eq_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl> ApproxEq for $t {