Remove impl_approx! macro

This commit is contained in:
Brendan Zabarauskas 2013-07-11 23:54:50 +10:00
parent c4c986c0ef
commit b06785fc89
4 changed files with 132 additions and 73 deletions

View file

@ -55,66 +55,3 @@ macro_rules! impl_swap(
} }
) )
) )
macro_rules! impl_approx(
($Self:ident, 2) => (
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for $Self<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &$Self<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &$Self<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon)
}
}
);
($Self:ident, 3) => (
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for $Self<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &$Self<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &$Self<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon) &&
self.index(2).approx_eq_eps(other.index(2), epsilon)
}
}
);
($Self:ident, 4) => (
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for $Self<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &$Self<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &$Self<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon) &&
self.index(2).approx_eq_eps(other.index(2), epsilon) &&
self.index(3).approx_eq_eps(other.index(3), epsilon)
}
}
)
)

View file

@ -126,8 +126,6 @@ pub type Mat2f32 = Mat2<f32>;
pub type Mat2f64 = Mat2<f64>; pub type Mat2f64 = Mat2<f64>;
impl_dimensional!(Mat2, Vec2<T>, 2) impl_dimensional!(Mat2, Vec2<T>, 2)
impl_approx!(Mat2, 2)
impl_mat!(Mat2, Vec2) impl_mat!(Mat2, Vec2)
impl_mat_swap!(Mat2, Vec2) impl_mat_swap!(Mat2, Vec2)
@ -334,6 +332,24 @@ impl<T:Clone + Real + ApproxEq<T>> Mat2<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Mat2<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Mat2<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool {
self.col(0).approx_eq_eps(other.col(0), epsilon) &&
self.col(1).approx_eq_eps(other.col(1), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod mat2_tests{ mod mat2_tests{
use core::mat::*; use core::mat::*;
@ -539,8 +555,6 @@ pub type Mat3f32 = Mat3<f32>;
pub type Mat3f64 = Mat3<f64>; pub type Mat3f64 = Mat3<f64>;
impl_dimensional!(Mat3, Vec3<T>, 3) impl_dimensional!(Mat3, Vec3<T>, 3)
impl_approx!(Mat3, 3)
impl_mat!(Mat3, Vec3) impl_mat!(Mat3, Vec3)
impl_mat_swap!(Mat3, Vec3) impl_mat_swap!(Mat3, Vec3)
@ -898,6 +912,25 @@ impl<T:Clone + Real + ApproxEq<T>> Mat3<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Mat3<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Mat3<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool {
self.col(0).approx_eq_eps(other.col(0), epsilon) &&
self.col(1).approx_eq_eps(other.col(1), epsilon) &&
self.col(2).approx_eq_eps(other.col(2), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod mat3_tests{ mod mat3_tests{
use core::mat::*; use core::mat::*;
@ -1128,8 +1161,6 @@ pub type Mat4f32 = Mat4<f32>;
pub type Mat4f64 = Mat4<f64>; pub type Mat4f64 = Mat4<f64>;
impl_dimensional!(Mat4, Vec4<T>, 4) impl_dimensional!(Mat4, Vec4<T>, 4)
impl_approx!(Mat4, 4)
impl_mat!(Mat4, Vec4) impl_mat!(Mat4, Vec4)
impl_mat_swap!(Mat4, Vec4) impl_mat_swap!(Mat4, Vec4)
@ -1427,6 +1458,26 @@ impl<T:Clone + Real + ApproxEq<T>> Mat4<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Mat4<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Mat4<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Mat4<T>, epsilon: &T) -> bool {
self.col(0).approx_eq_eps(other.col(0), epsilon) &&
self.col(1).approx_eq_eps(other.col(1), epsilon) &&
self.col(2).approx_eq_eps(other.col(2), epsilon) &&
self.col(3).approx_eq_eps(other.col(3), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod mat4_tests { mod mat4_tests {
use core::mat::*; use core::mat::*;

View file

@ -37,7 +37,6 @@ pub type Quatf64 = Quat<f64>;
pub struct Quat<T> { s: T, v: Vec3<T> } pub struct Quat<T> { s: T, v: Vec3<T> }
impl_dimensional!(Quat, T, 4) impl_dimensional!(Quat, T, 4)
impl_approx!(Quat, 4)
impl_swap!(Quat) impl_swap!(Quat)
pub trait ToQuat<T> { pub trait ToQuat<T> {
@ -308,6 +307,24 @@ impl<T:Clone + Float> Quat<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Quat<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Quat<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Quat<T>, epsilon: &T) -> bool {
self.s.approx_eq_eps(&other.s, epsilon) &&
self.v.approx_eq_eps(&other.v, epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use core::mat::*; use core::mat::*;

View file

@ -51,7 +51,6 @@ pub type Vec2u64 = Vec2<u64>;
pub type Vec2b = Vec2<bool>; pub type Vec2b = Vec2<bool>;
impl_dimensional!(Vec2, T, 2) impl_dimensional!(Vec2, T, 2)
impl_approx!(Vec2, 2)
impl_swap!(Vec2) impl_swap!(Vec2)
impl<T> Vec2<T> { impl<T> Vec2<T> {
@ -414,6 +413,24 @@ impl Vec2<bool> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Vec2<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Vec2<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod vec2_tests { mod vec2_tests {
use core::vec::*; use core::vec::*;
@ -574,7 +591,6 @@ pub type Vec3u64 = Vec3<u64>;
pub type Vec3b = Vec3<bool>; pub type Vec3b = Vec3<bool>;
impl_dimensional!(Vec3, T, 3) impl_dimensional!(Vec3, T, 3)
impl_approx!(Vec3, 3)
impl_swap!(Vec3) impl_swap!(Vec3)
impl<T> Vec3<T> { impl<T> Vec3<T> {
@ -986,6 +1002,25 @@ impl Vec3<bool> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Vec3<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Vec3<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon) &&
self.index(2).approx_eq_eps(other.index(2), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod vec3_tests{ mod vec3_tests{
use core::vec::*; use core::vec::*;
@ -1161,7 +1196,6 @@ pub type Vec4u64 = Vec4<u64>;
pub type Vec4b = Vec4<bool>; pub type Vec4b = Vec4<bool>;
impl_dimensional!(Vec4, T, 4) impl_dimensional!(Vec4, T, 4)
impl_approx!(Vec4, 4)
impl_swap!(Vec4) impl_swap!(Vec4)
impl<T> Vec4<T> { impl<T> Vec4<T> {
@ -1586,6 +1620,26 @@ impl Vec4<bool> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Vec4<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Vec4<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Vec4<T>, epsilon: &T) -> bool {
self.index(0).approx_eq_eps(other.index(0), epsilon) &&
self.index(1).approx_eq_eps(other.index(1), epsilon) &&
self.index(2).approx_eq_eps(other.index(2), epsilon) &&
self.index(3).approx_eq_eps(other.index(3), epsilon)
}
}
#[cfg(test)] #[cfg(test)]
mod vec4_tests { mod vec4_tests {
use core::vec::*; use core::vec::*;