Add `Round` impl for vectors.
This commit is contained in:
parent
a69f43bccd
commit
5187a1a73f
|
@ -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.
|
/// components.
|
||||||
pub trait VecCast<V> {
|
pub trait VecCast<V> {
|
||||||
/// Converts `v` to have the type `V`.
|
/// Converts `v` to have the type `V`.
|
||||||
|
|
|
@ -60,6 +60,7 @@ translation_impl!(Vec1)
|
||||||
translatable_impl!(Vec1)
|
translatable_impl!(Vec1)
|
||||||
norm_impl!(Vec1)
|
norm_impl!(Vec1)
|
||||||
approx_eq_impl!(Vec1, x)
|
approx_eq_impl!(Vec1, x)
|
||||||
|
round_impl!(Vec1, x)
|
||||||
one_impl!(Vec1)
|
one_impl!(Vec1)
|
||||||
from_iterator_impl!(Vec1, iterator)
|
from_iterator_impl!(Vec1, iterator)
|
||||||
bounded_impl!(Vec1)
|
bounded_impl!(Vec1)
|
||||||
|
@ -99,6 +100,7 @@ translation_impl!(Vec2)
|
||||||
translatable_impl!(Vec2)
|
translatable_impl!(Vec2)
|
||||||
norm_impl!(Vec2)
|
norm_impl!(Vec2)
|
||||||
approx_eq_impl!(Vec2, x, y)
|
approx_eq_impl!(Vec2, x, y)
|
||||||
|
round_impl!(Vec2, x, y)
|
||||||
one_impl!(Vec2)
|
one_impl!(Vec2)
|
||||||
from_iterator_impl!(Vec2, iterator, iterator)
|
from_iterator_impl!(Vec2, iterator, iterator)
|
||||||
bounded_impl!(Vec2)
|
bounded_impl!(Vec2)
|
||||||
|
@ -140,6 +142,7 @@ translation_impl!(Vec3)
|
||||||
translatable_impl!(Vec3)
|
translatable_impl!(Vec3)
|
||||||
norm_impl!(Vec3)
|
norm_impl!(Vec3)
|
||||||
approx_eq_impl!(Vec3, x, y, z)
|
approx_eq_impl!(Vec3, x, y, z)
|
||||||
|
round_impl!(Vec3, x, y, z)
|
||||||
one_impl!(Vec3)
|
one_impl!(Vec3)
|
||||||
from_iterator_impl!(Vec3, iterator, iterator, iterator)
|
from_iterator_impl!(Vec3, iterator, iterator, iterator)
|
||||||
bounded_impl!(Vec3)
|
bounded_impl!(Vec3)
|
||||||
|
@ -183,6 +186,7 @@ translation_impl!(Vec4)
|
||||||
translatable_impl!(Vec4)
|
translatable_impl!(Vec4)
|
||||||
norm_impl!(Vec4)
|
norm_impl!(Vec4)
|
||||||
approx_eq_impl!(Vec4, x, y, z, w)
|
approx_eq_impl!(Vec4, x, y, z, w)
|
||||||
|
round_impl!(Vec4, x, y, z, w)
|
||||||
one_impl!(Vec4)
|
one_impl!(Vec4)
|
||||||
from_iterator_impl!(Vec4, iterator, iterator, iterator, iterator)
|
from_iterator_impl!(Vec4, iterator, iterator, iterator, iterator)
|
||||||
bounded_impl!(Vec4)
|
bounded_impl!(Vec4)
|
||||||
|
@ -228,6 +232,7 @@ translation_impl!(Vec5)
|
||||||
translatable_impl!(Vec5)
|
translatable_impl!(Vec5)
|
||||||
norm_impl!(Vec5)
|
norm_impl!(Vec5)
|
||||||
approx_eq_impl!(Vec5, x, y, z, w, a)
|
approx_eq_impl!(Vec5, x, y, z, w, a)
|
||||||
|
round_impl!(Vec5, x, y, z, w, a)
|
||||||
one_impl!(Vec5)
|
one_impl!(Vec5)
|
||||||
from_iterator_impl!(Vec5, iterator, iterator, iterator, iterator, iterator)
|
from_iterator_impl!(Vec5, iterator, iterator, iterator, iterator, iterator)
|
||||||
bounded_impl!(Vec5)
|
bounded_impl!(Vec5)
|
||||||
|
@ -275,6 +280,7 @@ translation_impl!(Vec6)
|
||||||
translatable_impl!(Vec6)
|
translatable_impl!(Vec6)
|
||||||
norm_impl!(Vec6)
|
norm_impl!(Vec6)
|
||||||
approx_eq_impl!(Vec6, x, y, z, w, a, b)
|
approx_eq_impl!(Vec6, x, y, z, w, a, b)
|
||||||
|
round_impl!(Vec6, x, y, z, w, a, b)
|
||||||
one_impl!(Vec6)
|
one_impl!(Vec6)
|
||||||
from_iterator_impl!(Vec6, iterator, iterator, iterator, iterator, iterator, iterator)
|
from_iterator_impl!(Vec6, iterator, iterator, iterator, iterator, iterator, iterator)
|
||||||
bounded_impl!(Vec6)
|
bounded_impl!(Vec6)
|
||||||
|
|
|
@ -420,6 +420,32 @@ macro_rules! norm_impl(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
macro_rules! round_impl(
|
||||||
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
|
impl<N: Round> Round for $t<N> {
|
||||||
|
fn floor(&self) -> $t<N> {
|
||||||
|
$t::new(self.$comp0.floor() $(, self.$compN.floor())*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ceil(&self) -> $t<N> {
|
||||||
|
$t::new(self.$comp0.ceil() $(, self.$compN.ceil())*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn round(&self) -> $t<N> {
|
||||||
|
$t::new(self.$comp0.round() $(, self.$compN.round())*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trunc(&self) -> $t<N> {
|
||||||
|
$t::new(self.$comp0.trunc() $(, self.$compN.trunc())*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fract(&self) -> $t<N> {
|
||||||
|
$t::new(self.$comp0.fract() $(, self.$compN.fract())*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
macro_rules! approx_eq_impl(
|
macro_rules! approx_eq_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
||||||
|
|
Loading…
Reference in New Issue