diff --git a/src/core/dim_macros.rs b/src/core/dim_macros.rs index eb46ea1..9f463d3 100644 --- a/src/core/dim_macros.rs +++ b/src/core/dim_macros.rs @@ -55,66 +55,3 @@ macro_rules! impl_swap( } ) ) - -macro_rules! impl_approx( - ($Self:ident, 2) => ( - impl> ApproxEq for $Self { - #[inline] - pub fn approx_epsilon() -> T { - ApproxEq::approx_epsilon::() - } - - #[inline] - pub fn approx_eq(&self, other: &$Self) -> bool { - self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) - } - - #[inline] - pub fn approx_eq_eps(&self, other: &$Self, 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> ApproxEq for $Self { - #[inline] - pub fn approx_epsilon() -> T { - ApproxEq::approx_epsilon::() - } - - #[inline] - pub fn approx_eq(&self, other: &$Self) -> bool { - self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) - } - - #[inline] - pub fn approx_eq_eps(&self, other: &$Self, 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> ApproxEq for $Self { - #[inline] - pub fn approx_epsilon() -> T { - ApproxEq::approx_epsilon::() - } - - #[inline] - pub fn approx_eq(&self, other: &$Self) -> bool { - self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) - } - - #[inline] - pub fn approx_eq_eps(&self, other: &$Self, 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) - } - } - ) -) diff --git a/src/core/mat.rs b/src/core/mat.rs index 2291319..27b063d 100644 --- a/src/core/mat.rs +++ b/src/core/mat.rs @@ -126,8 +126,6 @@ pub type Mat2f32 = Mat2; pub type Mat2f64 = Mat2; impl_dimensional!(Mat2, Vec2, 2) -impl_approx!(Mat2, 2) - impl_mat!(Mat2, Vec2) impl_mat_swap!(Mat2, Vec2) @@ -334,6 +332,24 @@ impl> Mat2 { } } +impl> ApproxEq for Mat2 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Mat2) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Mat2, 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)] mod mat2_tests{ use core::mat::*; @@ -539,8 +555,6 @@ pub type Mat3f32 = Mat3; pub type Mat3f64 = Mat3; impl_dimensional!(Mat3, Vec3, 3) -impl_approx!(Mat3, 3) - impl_mat!(Mat3, Vec3) impl_mat_swap!(Mat3, Vec3) @@ -898,6 +912,25 @@ impl> Mat3 { } } +impl> ApproxEq for Mat3 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Mat3) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Mat3, 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)] mod mat3_tests{ use core::mat::*; @@ -1128,8 +1161,6 @@ pub type Mat4f32 = Mat4; pub type Mat4f64 = Mat4; impl_dimensional!(Mat4, Vec4, 4) -impl_approx!(Mat4, 4) - impl_mat!(Mat4, Vec4) impl_mat_swap!(Mat4, Vec4) @@ -1427,6 +1458,26 @@ impl> Mat4 { } } +impl> ApproxEq for Mat4 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Mat4) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Mat4, 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)] mod mat4_tests { use core::mat::*; diff --git a/src/core/quat.rs b/src/core/quat.rs index 5695ddc..c7ef793 100644 --- a/src/core/quat.rs +++ b/src/core/quat.rs @@ -37,7 +37,6 @@ pub type Quatf64 = Quat; pub struct Quat { s: T, v: Vec3 } impl_dimensional!(Quat, T, 4) -impl_approx!(Quat, 4) impl_swap!(Quat) pub trait ToQuat { @@ -308,6 +307,24 @@ impl Quat { } } +impl> ApproxEq for Quat { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Quat) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Quat, epsilon: &T) -> bool { + self.s.approx_eq_eps(&other.s, epsilon) && + self.v.approx_eq_eps(&other.v, epsilon) + } +} + #[cfg(test)] mod tests { use core::mat::*; diff --git a/src/core/vec.rs b/src/core/vec.rs index 9f15a71..9d0f2bc 100644 --- a/src/core/vec.rs +++ b/src/core/vec.rs @@ -51,7 +51,6 @@ pub type Vec2u64 = Vec2; pub type Vec2b = Vec2; impl_dimensional!(Vec2, T, 2) -impl_approx!(Vec2, 2) impl_swap!(Vec2) impl Vec2 { @@ -414,6 +413,24 @@ impl Vec2 { } } +impl> ApproxEq for Vec2 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Vec2) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Vec2, 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)] mod vec2_tests { use core::vec::*; @@ -574,7 +591,6 @@ pub type Vec3u64 = Vec3; pub type Vec3b = Vec3; impl_dimensional!(Vec3, T, 3) -impl_approx!(Vec3, 3) impl_swap!(Vec3) impl Vec3 { @@ -986,6 +1002,25 @@ impl Vec3 { } } +impl> ApproxEq for Vec3 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Vec3) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Vec3, 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)] mod vec3_tests{ use core::vec::*; @@ -1161,7 +1196,6 @@ pub type Vec4u64 = Vec4; pub type Vec4b = Vec4; impl_dimensional!(Vec4, T, 4) -impl_approx!(Vec4, 4) impl_swap!(Vec4) impl Vec4 { @@ -1586,6 +1620,26 @@ impl Vec4 { } } +impl> ApproxEq for Vec4 { + #[inline] + pub fn approx_epsilon() -> T { + ApproxEq::approx_epsilon::() + } + + #[inline] + pub fn approx_eq(&self, other: &Vec4) -> bool { + self.approx_eq_eps(other, &ApproxEq::approx_epsilon::()) + } + + #[inline] + pub fn approx_eq_eps(&self, other: &Vec4, 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)] mod vec4_tests { use core::vec::*;