Simplify trait bounds

Requires the latest version of numeric
This commit is contained in:
Brendan Zabarauskas 2013-04-15 07:09:43 +10:00
parent aad2d62f37
commit a6acab93c3
4 changed files with 35 additions and 41 deletions

View file

@ -1,4 +1,3 @@
use core::num::{Zero, One};
use core::num::Zero::zero;
use core::num::One::one;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -313,7 +312,7 @@ pub trait BaseMat4<T,V>: BaseMat<T,V> {
#[deriving(Eq)]
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec2<T>> for Mat2<T> {
impl<T:Copy + Float> BaseMat<T, Vec2<T>> for Mat2<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec2<T> { self[i] }
@ -538,7 +537,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat2<T, Vec2<T>> for Mat2<T> {
impl<T:Copy + Float> BaseMat2<T, Vec2<T>> for Mat2<T> {
/**
* Construct a 2 x 2 matrix
*
@ -645,14 +644,14 @@ impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat2<T>> for Mat2<T> {
impl<T:Copy + Float> Neg<Mat2<T>> for Mat2<T> {
#[inline(always)]
fn neg(&self) -> Mat2<T> {
BaseMat2::from_cols(-self[0], -self[1])
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
impl<T:Copy + Float> FuzzyEq<T> for Mat2<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
@ -723,7 +722,7 @@ mat2_type!(Mat2f64<f64,Vec2f64>)
#[deriving(Eq)]
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec3<T>> for Mat3<T> {
impl<T:Copy + Float> BaseMat<T, Vec3<T>> for Mat3<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec3<T> { self[i] }
@ -997,7 +996,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat3<T, Vec3<T>> for Mat3<T> {
impl<T:Copy + Float> BaseMat3<T, Vec3<T>> for Mat3<T> {
/**
* Construct a 3 x 3 matrix
*
@ -1229,14 +1228,14 @@ impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat3<T>> for Mat3<T> {
impl<T:Copy + Float> Neg<Mat3<T>> for Mat3<T> {
#[inline(always)]
fn neg(&self) -> Mat3<T> {
BaseMat3::from_cols(-self[0], -self[1], -self[2])
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> FuzzyEq<T> for Mat3<T> {
impl<T:Copy + Float> FuzzyEq<T> for Mat3<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
@ -1312,7 +1311,7 @@ mat3_type!(Mat3f64<f64,Vec3f64>)
#[deriving(Eq)]
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec4<T>> for Mat4<T> {
impl<T:Copy + Float> BaseMat<T, Vec4<T>> for Mat4<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec4<T> { self[i] }
@ -1685,7 +1684,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat4<T, Vec4<T>> for Mat4<T> {
impl<T:Copy + Float> BaseMat4<T, Vec4<T>> for Mat4<T> {
/**
* Construct a 4 x 4 matrix
*
@ -1749,7 +1748,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat4<T>> for Mat4<T> {
impl<T:Copy + Float> Neg<Mat4<T>> for Mat4<T> {
#[inline(always)]
fn neg(&self) -> Mat4<T> {
BaseMat4::from_cols(-self[0], -self[1], -self[2], -self[3])
@ -1763,7 +1762,7 @@ impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
impl<T:Copy + Float> FuzzyEq<T> for Mat4<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))

View file

@ -1,8 +1,5 @@
use core::num::{Zero, One};
use numeric::*;
use std::cmp::FuzzyEq;
use mat::{Mat4, BaseMat4};
/**
@ -14,7 +11,7 @@ use mat::{Mat4, BaseMat4};
* can be found [here](http://www.opengl.org/wiki/GluPerspective_code).
*/
#[inline(always)]
pub fn perspective<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
pub fn perspective<T:Copy + Float>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
let _2: T = num::cast(2);
let ymax = near * tan(radians(fovy / _2));
@ -30,7 +27,7 @@ pub fn perspective<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T
* (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function.
*/
#[inline(always)]
pub fn frustum<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
pub fn frustum<T:Copy + Float>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
let _0: T = num::cast(0);
let _1: T = num::cast(1);
let _2: T = num::cast(2);
@ -68,7 +65,7 @@ pub fn frustum<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> +
* (http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) function.
*/
#[inline(always)]
pub fn ortho<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
pub fn ortho<T:Copy + Float>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
let _0: T = num::cast(0);
let _1: T = num::cast(1);
let _2: T = num::cast(2);

View file

@ -7,7 +7,6 @@
* Sir William Hamilton
*/
use core::num::{Zero, One};
use core::num::Zero::zero;
use core::num::One::one;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -32,7 +31,7 @@ use vec::{vec3, dvec3, Vec3f, Vec3f32, Vec3f64};
#[deriving(Eq)]
pub struct Quat<T> { s: T, v: Vec3<T> }
pub impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Quat<T> {
pub impl<T:Copy + Float> Quat<T> {
/**
* Construct the quaternion from one scalar component and three
* imaginary components
@ -377,14 +376,14 @@ impl<T:Copy> Index<uint, T> for Quat<T> {
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Quat<T>> for Quat<T> {
impl<T:Copy + Float> Neg<Quat<T>> for Quat<T> {
#[inline(always)]
fn neg(&self) -> Quat<T> {
Quat::new(-self[0], -self[1], -self[2], -self[3])
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
impl<T:Copy + Float> FuzzyEq<T> for Quat<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))

View file

@ -1,4 +1,3 @@
use core::num::{Zero, One};
use core::num::Zero::zero;
use core::num::One::one;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -562,7 +561,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec2<T> {
impl<T:Copy + Number> NumVec<T> for Vec2<T> {
#[inline(always)]
fn identity() -> Vec2<T> {
BaseVec2::new(one::<T>(), one::<T>())
@ -652,14 +651,14 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec2<T>> for Vec2<T> {
impl<T:Copy + Number> Neg<Vec2<T>> for Vec2<T> {
#[inline(always)]
fn neg(&self) -> Vec2<T> {
BaseVec2::new(-self[0], -self[1])
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec2<T> for Vec2<T> {
impl<T:Copy + Number> NumVec2<T> for Vec2<T> {
#[inline(always)]
fn unit_x() -> Vec2<T> {
BaseVec2::new(one::<T>(), zero::<T>())
@ -676,14 +675,14 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
}
}
impl<T:Copy + Number + Zero> ToHomogeneous<Vec3<T>> for Vec2<T> {
impl<T:Copy + Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
#[inline(always)]
fn to_homogeneous(&self) -> Vec3<T> {
BaseVec3::new(self.x, self.y, zero())
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec2<T> {
impl<T:Copy + Float> AffineVec<T> for Vec2<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -742,7 +741,7 @@ impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
@ -941,7 +940,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec3<T> {
impl<T:Copy + Number> NumVec<T> for Vec3<T> {
#[inline(always)]
fn identity() -> Vec3<T> {
BaseVec3::new(one::<T>(), one::<T>(), one::<T>())
@ -1034,14 +1033,14 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec3<T>> for Vec3<T> {
impl<T:Copy + Number> Neg<Vec3<T>> for Vec3<T> {
#[inline(always)]
fn neg(&self) -> Vec3<T> {
BaseVec3::new(-self[0], -self[1], -self[2])
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec3<T> for Vec3<T> {
impl<T:Copy + Number> NumVec3<T> for Vec3<T> {
#[inline(always)]
fn unit_x() -> Vec3<T> {
BaseVec3::new(one::<T>(), zero::<T>(), zero::<T>())
@ -1070,14 +1069,14 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> ToHomogeneous<Vec4<T>> for Vec3<T> {
impl<T:Copy + Number> ToHomogeneous<Vec4<T>> for Vec3<T> {
#[inline(always)]
fn to_homogeneous(&self) -> Vec4<T> {
BaseVec4::new(self.x, self.y, self.z, zero())
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec3<T> {
impl<T:Copy + Float> AffineVec<T> for Vec3<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -1136,7 +1135,7 @@ impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
@ -1339,7 +1338,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec4<T> {
impl<T:Copy + Number> NumVec<T> for Vec4<T> {
#[inline(always)]
fn identity() -> Vec4<T> {
BaseVec4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
@ -1435,14 +1434,14 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec4<T>> for Vec4<T> {
impl<T:Copy + Number> Neg<Vec4<T>> for Vec4<T> {
#[inline(always)]
fn neg(&self) -> Vec4<T> {
BaseVec4::new(-self[0], -self[1], -self[2], -self[3])
}
}
impl<T:Copy + Number + Zero + One> NumVec4<T> for Vec4<T> {
impl<T:Copy + Number> NumVec4<T> for Vec4<T> {
#[inline(always)]
fn unit_x() -> Vec4<T> {
BaseVec4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
@ -1464,7 +1463,7 @@ impl<T:Copy + Number + Zero + One> NumVec4<T> for Vec4<T> {
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec4<T> {
impl<T:Copy + Float> AffineVec<T> for Vec4<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -1523,7 +1522,7 @@ impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
#[inline(always)]
fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))