Adapted assertions with last rust zero-testing api.

This commit is contained in:
Sébastien Crozet 2013-05-16 21:44:05 +00:00
parent e11cbb0963
commit 699e4c5bb7
4 changed files with 17 additions and 8 deletions

View File

@ -87,7 +87,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec2<T>> for Mat2<T>
} }
} }
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T> + Eq + Zero> impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T> + Zero>
Inv for Mat2<T> Inv for Mat2<T>
{ {
fn inverse(&self) -> Mat2<T> fn inverse(&self) -> Mat2<T>
@ -103,7 +103,7 @@ Inv for Mat2<T>
{ {
let det = self.m11 * self.m22 - self.m21 * self.m12; let det = self.m11 * self.m22 - self.m21 * self.m12;
assert!(det != Zero::zero()); assert!(!det.is_zero());
*self = Mat2(self.m22 / det , -self.m12 / det, *self = Mat2(self.m22 / det , -self.m12 / det,
-self.m21 / det, self.m11 / det) -self.m21 / det, self.m11 / det)

View File

@ -2,6 +2,7 @@ use core::num::{Zero, Algebraic};
use traits::dot::Dot; use traits::dot::Dot;
use traits::dim::Dim; use traits::dim::Dim;
use traits::cross::Cross; use traits::cross::Cross;
use dim1::vec1::Vec1;
#[deriving(Eq)] #[deriving(Eq)]
pub struct Vec2<T> pub struct Vec2<T>
@ -43,10 +44,10 @@ impl<T:Copy + Mul<T, T> + Add<T, T> + Algebraic> Dot<T> for Vec2<T>
{ self.sqnorm().sqrt() } { self.sqnorm().sqrt() }
} }
impl<T:Copy + Mul<T, T> + Sub<T, T>> Cross<T> for Vec2<T> impl<T:Copy + Mul<T, T> + Sub<T, T>> Cross<Vec1<T>> for Vec2<T>
{ {
fn cross(&self, other : &Vec2<T>) -> T fn cross(&self, other : &Vec2<T>) -> Vec1<T>
{ self.x * other.y - self.y * other.x } { Vec1(self.x * other.y - self.y * other.x) }
} }
impl<T:Copy + Neg<T>> Neg<Vec2<T>> for Vec2<T> impl<T:Copy + Neg<T>> Neg<Vec2<T>> for Vec2<T>

View File

@ -104,8 +104,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec3<T>> for Mat3<T>
} }
} }
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Add<T, T> + Neg<T> impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Add<T, T> + Neg<T> + Zero>
+ Eq + Zero>
Inv for Mat3<T> Inv for Mat3<T>
{ {
fn inverse(&self) -> Mat3<T> fn inverse(&self) -> Mat3<T>
@ -127,7 +126,7 @@ Inv for Mat3<T>
- self.m12 * minor_m21_m33 - self.m12 * minor_m21_m33
+ self.m13 * minor_m21_m32; + self.m13 * minor_m21_m32;
assert!(det != Zero::zero()); assert!(det.is_zero());
*self = Mat3( *self = Mat3(
(minor_m22_m33 / det), (minor_m22_m33 / det),

View File

@ -13,6 +13,9 @@ pub use dim3::mat3::Mat3;
pub use dim2::vec2::Vec2; pub use dim2::vec2::Vec2;
pub use dim2::mat2::Mat2; pub use dim2::mat2::Mat2;
pub use dim1::vec1::Vec1;
pub use dim1::mat1::Mat1;
pub use ndim::nvec::NVec; pub use ndim::nvec::NVec;
pub use ndim::nmat::NMat; pub use ndim::nmat::NMat;
@ -34,6 +37,12 @@ mod dim2
mod mat2; mod mat2;
} }
mod dim1
{
mod vec1;
mod mat1;
}
mod dim3 mod dim3
{ {
mod vec3; mod vec3;