Merge pull request #457 from alexheretic/approx-0.2

Update approx -> 0.2
This commit is contained in:
Brendan Zabarauskas 2018-05-24 12:25:59 +10:00 committed by GitHub
commit 1c5fb672a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 248 additions and 97 deletions

View file

@ -21,7 +21,7 @@ unstable = []
swizzle = [] swizzle = []
[dependencies] [dependencies]
approx = "0.1" approx = "0.2"
mint = { version = "0.5", optional = true } mint = { version = "0.5", optional = true }
num-traits = "0.2" num-traits = "0.2"
rand = "0.4" rand = "0.4"

View file

@ -26,7 +26,7 @@ use num_traits::{cast, Bounded};
use structure::*; use structure::*;
use approx::ApproxEq; use approx;
use num::BaseFloat; use num::BaseFloat;
/// An angle, in radians. /// An angle, in radians.
@ -170,7 +170,7 @@ macro_rules! impl_angle {
fn div_assign(&mut self, scalar) { self.0 /= scalar; } fn div_assign(&mut self, scalar) { self.0 /= scalar; }
}); });
impl<S: BaseFloat> ApproxEq for $Angle<S> { impl<S: BaseFloat> approx::AbsDiffEq for $Angle<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -178,20 +178,29 @@ macro_rules! impl_angle {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
S::abs_diff_eq(&self.0, &other.0, epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for $Angle<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
S::relative_eq(&self.0, &other.0, epsilon, max_relative) S::relative_eq(&self.0, &other.0, epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for $Angle<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {

View file

@ -19,7 +19,7 @@ use num_traits::cast;
use structure::*; use structure::*;
use angle::Rad; use angle::Rad;
use approx::ApproxEq; use approx;
use quaternion::Quaternion; use quaternion::Quaternion;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
use mint; use mint;
@ -141,7 +141,7 @@ impl<S: BaseFloat> From<Quaternion<S>> for Euler<Rad<S>> {
} }
} }
impl<A: Angle> ApproxEq for Euler<A> { impl<A: Angle> approx::AbsDiffEq for Euler<A> {
type Epsilon = A::Epsilon; type Epsilon = A::Epsilon;
#[inline] #[inline]
@ -149,22 +149,33 @@ impl<A: Angle> ApproxEq for Euler<A> {
A::default_epsilon() A::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: A::Epsilon) -> bool {
A::abs_diff_eq(&self.x, &other.x, epsilon)
&& A::abs_diff_eq(&self.y, &other.y, epsilon)
&& A::abs_diff_eq(&self.z, &other.z, epsilon)
}
}
impl<A: Angle> approx::RelativeEq for Euler<A> {
#[inline] #[inline]
fn default_max_relative() -> A::Epsilon { fn default_max_relative() -> A::Epsilon {
A::default_max_relative() A::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
A::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: A::Epsilon, max_relative: A::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: A::Epsilon, max_relative: A::Epsilon) -> bool {
A::relative_eq(&self.x, &other.x, epsilon, max_relative) A::relative_eq(&self.x, &other.x, epsilon, max_relative)
&& A::relative_eq(&self.y, &other.y, epsilon, max_relative) && A::relative_eq(&self.y, &other.y, epsilon, max_relative)
&& A::relative_eq(&self.z, &other.z, epsilon, max_relative) && A::relative_eq(&self.z, &other.z, epsilon, max_relative)
} }
}
impl<A: Angle> approx::UlpsEq for Euler<A> {
#[inline]
fn default_max_ulps() -> u32 {
A::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: A::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: A::Epsilon, max_ulps: u32) -> bool {

View file

@ -24,7 +24,7 @@ use std::ptr;
use structure::*; use structure::*;
use angle::Rad; use angle::Rad;
use approx::ApproxEq; use approx;
use euler::Euler; use euler::Euler;
use num::BaseFloat; use num::BaseFloat;
use point::{Point2, Point3}; use point::{Point2, Point3};
@ -831,7 +831,7 @@ impl<S: BaseFloat> SquareMatrix for Matrix4<S> {
} }
} }
impl<S: BaseFloat> ApproxEq for Matrix2<S> { impl<S: BaseFloat> approx::AbsDiffEq for Matrix2<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -839,21 +839,31 @@ impl<S: BaseFloat> ApproxEq for Matrix2<S> {
cast(1.0e-6f64).unwrap() cast(1.0e-6f64).unwrap()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
Vector2::abs_diff_eq(&self[0], &other[0], epsilon)
&& Vector2::abs_diff_eq(&self[1], &other[1], epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Matrix2<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
Vector2::relative_eq(&self[0], &other[0], epsilon, max_relative) Vector2::relative_eq(&self[0], &other[0], epsilon, max_relative)
&& Vector2::relative_eq(&self[1], &other[1], epsilon, max_relative) && Vector2::relative_eq(&self[1], &other[1], epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Matrix2<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {
@ -862,7 +872,7 @@ impl<S: BaseFloat> ApproxEq for Matrix2<S> {
} }
} }
impl<S: BaseFloat> ApproxEq for Matrix3<S> { impl<S: BaseFloat> approx::AbsDiffEq for Matrix3<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -870,22 +880,33 @@ impl<S: BaseFloat> ApproxEq for Matrix3<S> {
cast(1.0e-6f64).unwrap() cast(1.0e-6f64).unwrap()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
Vector3::abs_diff_eq(&self[0], &other[0], epsilon)
&& Vector3::abs_diff_eq(&self[1], &other[1], epsilon)
&& Vector3::abs_diff_eq(&self[2], &other[2], epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Matrix3<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
Vector3::relative_eq(&self[0], &other[0], epsilon, max_relative) Vector3::relative_eq(&self[0], &other[0], epsilon, max_relative)
&& Vector3::relative_eq(&self[1], &other[1], epsilon, max_relative) && Vector3::relative_eq(&self[1], &other[1], epsilon, max_relative)
&& Vector3::relative_eq(&self[2], &other[2], epsilon, max_relative) && Vector3::relative_eq(&self[2], &other[2], epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Matrix3<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {
@ -895,7 +916,7 @@ impl<S: BaseFloat> ApproxEq for Matrix3<S> {
} }
} }
impl<S: BaseFloat> ApproxEq for Matrix4<S> { impl<S: BaseFloat> approx::AbsDiffEq for Matrix4<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -903,16 +924,21 @@ impl<S: BaseFloat> ApproxEq for Matrix4<S> {
cast(1.0e-6f64).unwrap() cast(1.0e-6f64).unwrap()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
Vector4::abs_diff_eq(&self[0], &other[0], epsilon)
&& Vector4::abs_diff_eq(&self[1], &other[1], epsilon)
&& Vector4::abs_diff_eq(&self[2], &other[2], epsilon)
&& Vector4::abs_diff_eq(&self[3], &other[3], epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Matrix4<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
Vector4::relative_eq(&self[0], &other[0], epsilon, max_relative) Vector4::relative_eq(&self[0], &other[0], epsilon, max_relative)
@ -920,6 +946,13 @@ impl<S: BaseFloat> ApproxEq for Matrix4<S> {
&& Vector4::relative_eq(&self[2], &other[2], epsilon, max_relative) && Vector4::relative_eq(&self[2], &other[2], epsilon, max_relative)
&& Vector4::relative_eq(&self[3], &other[3], epsilon, max_relative) && Vector4::relative_eq(&self[3], &other[3], epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Matrix4<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {

View file

@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use approx::ApproxEq; use approx;
use std::fmt; use std::fmt;
use std::ops::*; use std::ops::*;
@ -21,8 +21,8 @@ use std::ops::*;
use num_traits::{Float, Num, NumCast}; use num_traits::{Float, Num, NumCast};
/// Base numeric types with partial ordering /// Base numeric types with partial ordering
pub trait BaseNum pub trait BaseNum:
: Copy Copy
+ Clone + Clone
+ fmt::Debug + fmt::Debug
+ Num + Num
@ -32,7 +32,8 @@ pub trait BaseNum
+ SubAssign + SubAssign
+ MulAssign + MulAssign
+ DivAssign + DivAssign
+ RemAssign { + RemAssign
{
} }
impl<T> BaseNum for T impl<T> BaseNum for T
@ -52,10 +53,21 @@ where
} }
/// Base floating point types /// Base floating point types
pub trait BaseFloat: BaseNum + Float + ApproxEq<Epsilon = Self> {} pub trait BaseFloat:
BaseNum
+ Float
+ approx::AbsDiffEq<Epsilon = Self>
+ approx::RelativeEq<Epsilon = Self>
+ approx::UlpsEq<Epsilon = Self>
{
}
impl<T> BaseFloat for T impl<T> BaseFloat for T
where where
T: BaseNum + Float + ApproxEq<Epsilon = Self>, T: BaseNum
+ Float
+ approx::AbsDiffEq<Epsilon = Self>
+ approx::RelativeEq<Epsilon = Self>
+ approx::UlpsEq<Epsilon = Self>,
{ {
} }

View file

@ -24,7 +24,7 @@ use std::ops::*;
use structure::*; use structure::*;
use approx::ApproxEq; use approx;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
use vector::{Vector1, Vector2, Vector3, Vector4}; use vector::{Vector1, Vector2, Vector3, Vector4};
@ -172,7 +172,7 @@ macro_rules! impl_point {
} }
} }
impl<S: BaseFloat> ApproxEq for $PointN<S> { impl<S: BaseFloat> approx::AbsDiffEq for $PointN<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -180,20 +180,31 @@ macro_rules! impl_point {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon)
-> bool
{
$(S::abs_diff_eq(&self.$field, &other.$field, epsilon))&&+
}
}
impl<S: BaseFloat> approx::RelativeEq for $PointN<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
$(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+ $(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+
} }
}
impl<S: BaseFloat> approx::UlpsEq for $PointN<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {

View file

@ -23,7 +23,7 @@ use num_traits::{cast, NumCast};
use structure::*; use structure::*;
use angle::Rad; use angle::Rad;
use approx::ApproxEq; use approx;
use euler::Euler; use euler::Euler;
use matrix::{Matrix3, Matrix4}; use matrix::{Matrix3, Matrix4};
use num::BaseFloat; use num::BaseFloat;
@ -587,7 +587,7 @@ impl_scalar_mul!(f64);
impl_scalar_div!(f32); impl_scalar_div!(f32);
impl_scalar_div!(f64); impl_scalar_div!(f64);
impl<S: BaseFloat> ApproxEq for Quaternion<S> { impl<S: BaseFloat> approx::AbsDiffEq for Quaternion<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -595,21 +595,31 @@ impl<S: BaseFloat> ApproxEq for Quaternion<S> {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
S::abs_diff_eq(&self.s, &other.s, epsilon)
&& Vector3::abs_diff_eq(&self.v, &other.v, epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Quaternion<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
S::relative_eq(&self.s, &other.s, epsilon, max_relative) S::relative_eq(&self.s, &other.s, epsilon, max_relative)
&& Vector3::relative_eq(&self.v, &other.v, epsilon, max_relative) && Vector3::relative_eq(&self.v, &other.v, epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Quaternion<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {

View file

@ -20,7 +20,7 @@ use std::ops::*;
use structure::*; use structure::*;
use angle::Rad; use angle::Rad;
use approx::ApproxEq; use approx;
use euler::Euler; use euler::Euler;
use matrix::{Matrix2, Matrix3}; use matrix::{Matrix2, Matrix3};
use num::BaseFloat; use num::BaseFloat;
@ -33,7 +33,9 @@ use vector::{Vector2, Vector3};
pub trait Rotation<P: EuclideanSpace>: Sized + Copy + One pub trait Rotation<P: EuclideanSpace>: Sized + Copy + One
where where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: ApproxEq<Epsilon = P::Scalar>, Self: approx::AbsDiffEq<Epsilon = P::Scalar>,
Self: approx::RelativeEq<Epsilon = P::Scalar>,
Self: approx::UlpsEq<Epsilon = P::Scalar>,
P::Scalar: BaseFloat, P::Scalar: BaseFloat,
Self: iter::Product<Self>, Self: iter::Product<Self>,
{ {
@ -113,7 +115,7 @@ pub trait Rotation3<S: BaseFloat>
/// use cgmath::Vector2; /// use cgmath::Vector2;
/// use cgmath::{Matrix, Matrix2}; /// use cgmath::{Matrix, Matrix2};
/// use cgmath::{Rotation, Rotation2, Basis2}; /// use cgmath::{Rotation, Rotation2, Basis2};
/// use cgmath::ApproxEq; /// use cgmath::UlpsEq;
/// use std::f64; /// use std::f64;
/// ///
/// // For simplicity, we will rotate the unit x vector to the unit y vector -- /// // For simplicity, we will rotate the unit x vector to the unit y vector --
@ -213,7 +215,7 @@ impl_operator!(<S: BaseFloat> Mul<Basis2<S> > for Basis2<S> {
fn mul(lhs, rhs) -> Basis2<S> { Basis2 { mat: lhs.mat * rhs.mat } } fn mul(lhs, rhs) -> Basis2<S> { Basis2 { mat: lhs.mat * rhs.mat } }
}); });
impl<S: BaseFloat> ApproxEq for Basis2<S> { impl<S: BaseFloat> approx::AbsDiffEq for Basis2<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -221,20 +223,29 @@ impl<S: BaseFloat> ApproxEq for Basis2<S> {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
Matrix2::abs_diff_eq(&self.mat, &other.mat, epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Basis2<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
Matrix2::relative_eq(&self.mat, &other.mat, epsilon, max_relative) Matrix2::relative_eq(&self.mat, &other.mat, epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Basis2<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {
@ -356,7 +367,7 @@ impl_operator!(<S: BaseFloat> Mul<Basis3<S> > for Basis3<S> {
fn mul(lhs, rhs) -> Basis3<S> { Basis3 { mat: lhs.mat * rhs.mat } } fn mul(lhs, rhs) -> Basis3<S> { Basis3 { mat: lhs.mat * rhs.mat } }
}); });
impl<S: BaseFloat> ApproxEq for Basis3<S> { impl<S: BaseFloat> approx::AbsDiffEq for Basis3<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -364,20 +375,29 @@ impl<S: BaseFloat> ApproxEq for Basis3<S> {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
Matrix3::abs_diff_eq(&self.mat, &other.mat, epsilon)
}
}
impl<S: BaseFloat> approx::RelativeEq for Basis3<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
Matrix3::relative_eq(&self.mat, &other.mat, epsilon, max_relative) Matrix3::relative_eq(&self.mat, &other.mat, epsilon, max_relative)
} }
}
impl<S: BaseFloat> approx::UlpsEq for Basis3<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {

View file

@ -20,7 +20,7 @@ use std::cmp;
use std::iter; use std::iter;
use std::ops::*; use std::ops::*;
use approx::ApproxEq; use approx;
use angle::Rad; use angle::Rad;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
@ -215,7 +215,9 @@ where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
<Self as VectorSpace>::Scalar: BaseFloat, <Self as VectorSpace>::Scalar: BaseFloat,
Self: MetricSpace<Metric = <Self as VectorSpace>::Scalar>, Self: MetricSpace<Metric = <Self as VectorSpace>::Scalar>,
Self: ApproxEq<Epsilon = <Self as VectorSpace>::Scalar>, // Self: approx::AbsDiffEq<Epsilon = <Self as VectorSpace>::Scalar>,
// Self: approx::RelativeEq<Epsilon = <Self as VectorSpace>::Scalar>,
Self: approx::UlpsEq<Epsilon = <Self as VectorSpace>::Scalar>,
{ {
/// Vector dot (or inner) product. /// Vector dot (or inner) product.
fn dot(self, other: Self) -> Self::Scalar; fn dot(self, other: Self) -> Self::Scalar;
@ -430,7 +432,9 @@ where
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: Index<usize, Output = <Self as Matrix>::Column>, Self: Index<usize, Output = <Self as Matrix>::Column>,
Self: IndexMut<usize, Output = <Self as Matrix>::Column>, Self: IndexMut<usize, Output = <Self as Matrix>::Column>,
Self: ApproxEq<Epsilon = <Self as VectorSpace>::Scalar>, Self: approx::AbsDiffEq<Epsilon = <Self as VectorSpace>::Scalar>,
Self: approx::RelativeEq<Epsilon = <Self as VectorSpace>::Scalar>,
Self: approx::UlpsEq<Epsilon = <Self as VectorSpace>::Scalar>,
{ {
/// The row vector of the matrix. /// The row vector of the matrix.
type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>; type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>;
@ -570,7 +574,9 @@ where
Self: Copy + Clone, Self: Copy + Clone,
Self: PartialEq + cmp::PartialOrd, Self: PartialEq + cmp::PartialOrd,
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092 // FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
Self: ApproxEq<Epsilon = <Self as Angle>::Unitless>, Self: approx::AbsDiffEq<Epsilon = <Self as Angle>::Unitless>,
Self: approx::RelativeEq<Epsilon = <Self as Angle>::Unitless>,
Self: approx::UlpsEq<Epsilon = <Self as Angle>::Unitless>,
Self: Zero, Self: Zero,

View file

@ -15,7 +15,7 @@
use structure::*; use structure::*;
use approx::ApproxEq; use approx;
use matrix::{Matrix2, Matrix3, Matrix4}; use matrix::{Matrix2, Matrix3, Matrix4};
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
use point::{Point2, Point3}; use point::{Point2, Point3};
@ -62,7 +62,7 @@ pub trait Transform<P: EuclideanSpace>: Sized {
/// A generic transformation consisting of a rotation, /// A generic transformation consisting of a rotation,
/// displacement vector and scale amount. /// displacement vector and scale amount.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq)]
pub struct Decomposed<V: VectorSpace, R> { pub struct Decomposed<V: VectorSpace, R> {
pub scale: V::Scalar, pub scale: V::Scalar,
pub rot: R, pub rot: R,
@ -163,11 +163,11 @@ impl<S: BaseFloat, R: Rotation2<S>> Transform2<S> for Decomposed<Vector2<S>, R>
impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<Vector3<S>, R> {} impl<S: BaseFloat, R: Rotation3<S>> Transform3<S> for Decomposed<Vector3<S>, R> {}
impl<S: VectorSpace, R, E: BaseFloat> ApproxEq for Decomposed<S, R> impl<S: VectorSpace, R, E: BaseFloat> approx::AbsDiffEq for Decomposed<S, R>
where where
S: ApproxEq<Epsilon = E>, S: approx::AbsDiffEq<Epsilon = E>,
S::Scalar: ApproxEq<Epsilon = E>, S::Scalar: approx::AbsDiffEq<Epsilon = E>,
R: ApproxEq<Epsilon = E>, R: approx::AbsDiffEq<Epsilon = E>,
{ {
type Epsilon = E; type Epsilon = E;
@ -176,22 +176,43 @@ where
E::default_epsilon() E::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: E) -> bool {
S::Scalar::abs_diff_eq(&self.scale, &other.scale, epsilon)
&& R::abs_diff_eq(&self.rot, &other.rot, epsilon)
&& S::abs_diff_eq(&self.disp, &other.disp, epsilon)
}
}
impl<S: VectorSpace, R, E: BaseFloat> approx::RelativeEq for Decomposed<S, R>
where
S: approx::RelativeEq<Epsilon = E>,
S::Scalar: approx::RelativeEq<Epsilon = E>,
R: approx::RelativeEq<Epsilon = E>,
{
#[inline] #[inline]
fn default_max_relative() -> E { fn default_max_relative() -> E {
E::default_max_relative() E::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
E::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: E, max_relative: E) -> bool { fn relative_eq(&self, other: &Self, epsilon: E, max_relative: E) -> bool {
S::Scalar::relative_eq(&self.scale, &other.scale, epsilon, max_relative) S::Scalar::relative_eq(&self.scale, &other.scale, epsilon, max_relative)
&& R::relative_eq(&self.rot, &other.rot, epsilon, max_relative) && R::relative_eq(&self.rot, &other.rot, epsilon, max_relative)
&& S::relative_eq(&self.disp, &other.disp, epsilon, max_relative) && S::relative_eq(&self.disp, &other.disp, epsilon, max_relative)
} }
}
impl<S: VectorSpace, R, E: BaseFloat> approx::UlpsEq for Decomposed<S, R>
where
S: approx::UlpsEq<Epsilon = E>,
S::Scalar: approx::UlpsEq<Epsilon = E>,
R: approx::UlpsEq<Epsilon = E>,
{
#[inline]
fn default_max_ulps() -> u32 {
E::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: E, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: E, max_ulps: u32) -> bool {

View file

@ -23,7 +23,7 @@ use std::ops::*;
use structure::*; use structure::*;
use angle::Rad; use angle::Rad;
use approx::ApproxEq; use approx;
use num::{BaseFloat, BaseNum}; use num::{BaseFloat, BaseNum};
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
@ -206,7 +206,7 @@ macro_rules! impl_vector {
fn neg(self) -> $VectorN<S> { $VectorN::new($(-self.$field),+) } fn neg(self) -> $VectorN<S> { $VectorN::new($(-self.$field),+) }
} }
impl<S: BaseFloat> ApproxEq for $VectorN<S> { impl<S: BaseFloat> approx::AbsDiffEq for $VectorN<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -214,20 +214,29 @@ macro_rules! impl_vector {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
$(S::abs_diff_eq(&self.$field, &other.$field, epsilon))&&+
}
}
impl<S: BaseFloat> approx::RelativeEq for $VectorN<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
$(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+ $(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+
} }
}
impl<S: BaseFloat> approx::UlpsEq for $VectorN<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {
@ -452,7 +461,7 @@ macro_rules! impl_vector_default {
default fn neg(self) -> $VectorN<S> { $VectorN::new($(-self.$field),+) } default fn neg(self) -> $VectorN<S> { $VectorN::new($(-self.$field),+) }
} }
impl<S: BaseFloat> ApproxEq for $VectorN<S> { impl<S: BaseFloat> approx::AbsDiffEq for $VectorN<S> {
type Epsilon = S::Epsilon; type Epsilon = S::Epsilon;
#[inline] #[inline]
@ -460,20 +469,29 @@ macro_rules! impl_vector_default {
S::default_epsilon() S::default_epsilon()
} }
#[inline]
fn abs_diff_eq(&self, other: &Self, epsilon: S::Epsilon) -> bool {
$(S::abs_diff_eq(&self.$field, &other.$field, epsilon))&&+
}
}
impl<S: BaseFloat> approx::RelativeEq for $VectorN<S> {
#[inline] #[inline]
fn default_max_relative() -> S::Epsilon { fn default_max_relative() -> S::Epsilon {
S::default_max_relative() S::default_max_relative()
} }
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool { fn relative_eq(&self, other: &Self, epsilon: S::Epsilon, max_relative: S::Epsilon) -> bool {
$(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+ $(S::relative_eq(&self.$field, &other.$field, epsilon, max_relative))&&+
} }
}
impl<S: BaseFloat> approx::UlpsEq for $VectorN<S> {
#[inline]
fn default_max_ulps() -> u32 {
S::default_max_ulps()
}
#[inline] #[inline]
fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool { fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool {