Add fuzzy_eq implementation for everything.
This commit is contained in:
parent
7a58f2c66a
commit
53131731b3
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero}; // , Trigonometric};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::workarounds::rlmul::{RMul, LMul};
|
||||
use traits::workarounds::trigonometric::Trigonometric;
|
||||
use traits::dim::Dim;
|
||||
|
@ -105,6 +106,15 @@ Transpose for Rotmat<M>
|
|||
{ self.submat.transpose() }
|
||||
}
|
||||
|
||||
impl<T, M:FuzzyEq<T>> FuzzyEq<T> for Rotmat<M>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Rotmat<M>) -> bool
|
||||
{ self.submat.fuzzy_eq(&other.submat) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Rotmat<M>, epsilon: &T) -> bool
|
||||
{ self.submat.fuzzy_eq_eps(&other.submat, epsilon) }
|
||||
}
|
||||
|
||||
impl<M:ToStr> ToStr for Rotmat<M>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
use traits::transpose::Transpose;
|
||||
|
@ -75,6 +76,21 @@ Inv for Transform<M, V>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, M:FuzzyEq<T>, V:FuzzyEq<T>> FuzzyEq<T> for Transform<M, V>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Transform<M, V>) -> bool
|
||||
{
|
||||
self.submat.fuzzy_eq(&other.submat) &&
|
||||
self.subtrans.fuzzy_eq(&other.subtrans)
|
||||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Transform<M, V>, epsilon: &T) -> bool
|
||||
{
|
||||
self.submat.fuzzy_eq_eps(&other.submat, epsilon) &&
|
||||
self.subtrans.fuzzy_eq_eps(&other.subtrans, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M:ToStr, V:ToStr> ToStr for Transform<M, V>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
use traits::transpose::Transpose;
|
||||
|
@ -83,6 +84,15 @@ impl<T:Copy> Transpose for Mat1<T>
|
|||
{ }
|
||||
}
|
||||
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat1<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Mat1<T>) -> bool
|
||||
{ self.m11.fuzzy_eq(&other.m11) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Mat1<T>, epsilon: &T) -> bool
|
||||
{ self.m11.fuzzy_eq_eps(&other.m11, epsilon) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat1<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{Zero, Algebraic};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dot::Dot;
|
||||
use traits::dim::Dim;
|
||||
|
||||
|
@ -57,6 +58,15 @@ impl<T:Copy + Zero> Zero for Vec1<T>
|
|||
{ self.x.is_zero() }
|
||||
}
|
||||
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec1<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Vec1<T>) -> bool
|
||||
{ self.x.fuzzy_eq(&other.x) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Vec1<T>, epsilon: &T) -> bool
|
||||
{ self.x.fuzzy_eq_eps(&other.x, epsilon) }
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec1<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
use traits::transpose::Transpose;
|
||||
|
@ -122,6 +123,27 @@ impl<T:Copy> Transpose for Mat2<T>
|
|||
{ self.m21 <-> self.m12; }
|
||||
}
|
||||
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat2<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Mat2<T>) -> bool
|
||||
{
|
||||
self.m11.fuzzy_eq(&other.m11) &&
|
||||
self.m12.fuzzy_eq(&other.m12) &&
|
||||
|
||||
self.m21.fuzzy_eq(&other.m21) &&
|
||||
self.m22.fuzzy_eq(&other.m22)
|
||||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool
|
||||
{
|
||||
self.m11.fuzzy_eq_eps(&other.m11, epsilon) &&
|
||||
self.m12.fuzzy_eq_eps(&other.m12, epsilon) &&
|
||||
|
||||
self.m21.fuzzy_eq_eps(&other.m21, epsilon) &&
|
||||
self.m22.fuzzy_eq_eps(&other.m22, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat2<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{Zero, Algebraic};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dot::Dot;
|
||||
use traits::dim::Dim;
|
||||
use traits::cross::Cross;
|
||||
|
@ -68,6 +69,18 @@ impl<T:Copy + Zero> Zero for Vec2<T>
|
|||
{ self.x.is_zero() && self.y.is_zero() }
|
||||
}
|
||||
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec2<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Vec2<T>) -> bool
|
||||
{ self.x.fuzzy_eq(&other.x) && self.y.fuzzy_eq(&other.y) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool
|
||||
{
|
||||
self.x.fuzzy_eq_eps(&other.x, epsilon) &&
|
||||
self.y.fuzzy_eq_eps(&other.y, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec2<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{One, Zero};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
use traits::transpose::Transpose;
|
||||
|
@ -161,18 +162,38 @@ impl<T:Copy> Transpose for Mat3<T>
|
|||
}
|
||||
}
|
||||
|
||||
// impl<T:Rand> Rand for Mat3<T>
|
||||
// {
|
||||
// fn rand<R:Rng>(rng: &mut R) -> Mat3<T>
|
||||
// {
|
||||
// Mat3
|
||||
// {
|
||||
// m11: rng.next(), m12: rng.next(), m13: rng.next(),
|
||||
// m21: rng.next(), m22: rng.next(), m23: rng.next(),
|
||||
// m31: rng.next(), m32: rng.next(), m33: rng.next()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat3<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Mat3<T>) -> bool
|
||||
{
|
||||
self.m11.fuzzy_eq(&other.m11) &&
|
||||
self.m12.fuzzy_eq(&other.m12) &&
|
||||
self.m13.fuzzy_eq(&other.m13) &&
|
||||
|
||||
self.m21.fuzzy_eq(&other.m21) &&
|
||||
self.m22.fuzzy_eq(&other.m22) &&
|
||||
self.m23.fuzzy_eq(&other.m23) &&
|
||||
|
||||
self.m31.fuzzy_eq(&other.m31) &&
|
||||
self.m32.fuzzy_eq(&other.m32) &&
|
||||
self.m33.fuzzy_eq(&other.m33)
|
||||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool
|
||||
{
|
||||
self.m11.fuzzy_eq_eps(&other.m11, epsilon) &&
|
||||
self.m12.fuzzy_eq_eps(&other.m12, epsilon) &&
|
||||
self.m13.fuzzy_eq_eps(&other.m13, epsilon) &&
|
||||
|
||||
self.m21.fuzzy_eq_eps(&other.m21, epsilon) &&
|
||||
self.m22.fuzzy_eq_eps(&other.m22, epsilon) &&
|
||||
self.m23.fuzzy_eq_eps(&other.m23, epsilon) &&
|
||||
|
||||
self.m31.fuzzy_eq_eps(&other.m31, epsilon) &&
|
||||
self.m32.fuzzy_eq_eps(&other.m32, epsilon) &&
|
||||
self.m33.fuzzy_eq_eps(&other.m33, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Mat3<T>
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::num::{Zero, Algebraic};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::dot::Dot;
|
||||
use traits::cross::Cross;
|
||||
|
@ -74,6 +75,23 @@ impl<T:Copy + Zero> Zero for Vec3<T>
|
|||
{ self.x.is_zero() && self.y.is_zero() && self.z.is_zero() }
|
||||
}
|
||||
|
||||
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec3<T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &Vec3<T>) -> bool
|
||||
{
|
||||
self.x.fuzzy_eq(&other.x) &&
|
||||
self.y.fuzzy_eq(&other.y) &&
|
||||
self.z.fuzzy_eq(&other.z)
|
||||
}
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool
|
||||
{
|
||||
self.x.fuzzy_eq_eps(&other.x, epsilon) &&
|
||||
self.y.fuzzy_eq_eps(&other.y, epsilon) &&
|
||||
self.z.fuzzy_eq_eps(&other.z, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:ToStr> ToStr for Vec3<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use core::num::{One, Zero};
|
||||
use core::vec::{from_elem, swap, all};
|
||||
use core::vec::{from_elem, swap, all, all2};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::inv::Inv;
|
||||
use traits::transpose::Transpose;
|
||||
|
@ -240,6 +241,15 @@ impl<D: Dim, T:Copy> Transpose for NMat<D, T>
|
|||
}
|
||||
}
|
||||
|
||||
impl<D, T:FuzzyEq<T>> FuzzyEq<T> for NMat<D, T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &NMat<D, T>) -> bool
|
||||
{ all2(self.mij, other.mij, |a, b| a.fuzzy_eq(b)) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &NMat<D, T>, epsilon: &T) -> bool
|
||||
{ all2(self.mij, other.mij, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
|
||||
}
|
||||
|
||||
impl<D: Dim, T:ToStr> ToStr for NMat<D, T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use core::vec::{map_zip, from_elem, map, all};
|
||||
use core::vec::{map_zip, from_elem, map, all, all2};
|
||||
use core::num::{Zero, Algebraic};
|
||||
use std::cmp::FuzzyEq;
|
||||
use traits::dim::Dim;
|
||||
use traits::dot::Dot;
|
||||
|
||||
|
@ -83,6 +84,15 @@ impl<D: Dim, T:Copy + Zero> Zero for NVec<D, T>
|
|||
}
|
||||
}
|
||||
|
||||
impl<D, T:FuzzyEq<T>> FuzzyEq<T> for NVec<D, T>
|
||||
{
|
||||
fn fuzzy_eq(&self, other: &NVec<D, T>) -> bool
|
||||
{ all2(self.at, other.at, |a, b| a.fuzzy_eq(b)) }
|
||||
|
||||
fn fuzzy_eq_eps(&self, other: &NVec<D, T>, epsilon: &T) -> bool
|
||||
{ all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
|
||||
}
|
||||
|
||||
impl<D: Dim, T:ToStr> ToStr for NVec<D, T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
|
|
Loading…
Reference in New Issue