Use core::num::{Zero, One, NumCast} traits for 'zero', 'one' and 'cast' methods
This commit is contained in:
parent
64ab171dc3
commit
449705b760
4 changed files with 63 additions and 58 deletions
39
src/mat.rs
39
src/mat.rs
|
@ -1,7 +1,8 @@
|
|||
use core::num::{Zero, One};
|
||||
use core::num::Zero::zero;
|
||||
use core::num::One::one;
|
||||
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
|
||||
use numeric::*;
|
||||
use numeric::number::Number;
|
||||
use numeric::number::Number::{zero,one};
|
||||
|
||||
use vec::*;
|
||||
use quat::Quat;
|
||||
|
@ -312,7 +313,7 @@ pub trait Matrix4<T,V>: Matrix<T,V> {
|
|||
#[deriving(Eq)]
|
||||
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
|
||||
|
@ -537,7 +538,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
|
||||
/**
|
||||
* Construct a 2 x 2 matrix
|
||||
*
|
||||
|
@ -645,17 +646,17 @@ impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + 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 + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Mat2<T> {
|
||||
Matrix2::from_cols(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -723,7 +724,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 + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
|
||||
|
@ -997,7 +998,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
|
||||
/**
|
||||
* Construct a 3 x 3 matrix
|
||||
*
|
||||
|
@ -1187,8 +1188,8 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
let w, x, y, z;
|
||||
let trace = self.trace();
|
||||
|
||||
let _1: T = Number::from(1.0);
|
||||
let half: T = Number::from(0.5);
|
||||
let _1: T = num::cast(1.0);
|
||||
let half: T = num::cast(0.5);
|
||||
|
||||
if trace >= zero() {
|
||||
s = (_1 + trace).sqrt();
|
||||
|
@ -1231,17 +1232,17 @@ impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + 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 + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Mat3<T> {
|
||||
Matrix3::from_cols(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + 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 + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> FuzzyEq<T> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -1314,7 +1315,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 + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
|
||||
|
@ -1687,7 +1688,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
|
||||
/**
|
||||
* Construct a 4 x 4 matrix
|
||||
*
|
||||
|
@ -1754,7 +1755,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + 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 + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Mat4<T> {
|
||||
Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3])
|
||||
|
@ -1768,10 +1769,10 @@ impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use core::num::{Zero, One};
|
||||
use numeric::*;
|
||||
use numeric::number::Number;
|
||||
|
||||
use std::cmp::FuzzyEq;
|
||||
|
||||
|
@ -12,7 +12,7 @@ use mat::{Mat4, Matrix4};
|
|||
* can be found [here](http://www.opengl.org/wiki/GluPerspective_code).
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn perspective<T:Copy + Float + 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 + NumCast + 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> {
|
||||
let ymax = near * tan(radians(fovy));
|
||||
let xmax = ymax * aspectRatio;
|
||||
|
||||
|
@ -26,10 +26,10 @@ pub fn perspective<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T>
|
|||
* (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn frustum<T:Copy + Float + 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> {
|
||||
let _0: T = Number::from(0);
|
||||
let _1: T = Number::from(1);
|
||||
let _2: T = Number::from(2);
|
||||
pub fn frustum<T:Copy + Float + NumCast + 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> {
|
||||
let _0: T = num::cast(0);
|
||||
let _1: T = num::cast(1);
|
||||
let _2: T = num::cast(2);
|
||||
|
||||
let c0r0 = (_2 * near) / (right - left);
|
||||
let c0r1 = _0;
|
||||
|
|
26
src/quat.rs
26
src/quat.rs
|
@ -7,10 +7,12 @@
|
|||
* Sir William Hamilton
|
||||
*/
|
||||
|
||||
use core::num::{Zero, One};
|
||||
use core::num::Zero::zero;
|
||||
use core::num::One::one;
|
||||
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
|
||||
use numeric::*;
|
||||
use numeric::number::Number;
|
||||
use numeric::number::Number::{zero,one};
|
||||
|
||||
use mat::{Mat3, Matrix3};
|
||||
use vec::{Vec3, Vector3, EuclideanVector};
|
||||
|
@ -32,7 +34,7 @@ use vec::{vec3, dvec3, Vec3f, Vec3f32, Vec3f64};
|
|||
#[deriving(Eq)]
|
||||
pub struct Quat<T> { s: T, v: Vec3<T> }
|
||||
|
||||
pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Quat<T> {
|
||||
pub impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Quat<T> {
|
||||
/**
|
||||
* Construct the quaternion from one scalar component and three
|
||||
* imaginary components
|
||||
|
@ -84,26 +86,26 @@ pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T>
|
|||
|
||||
#[inline(always)]
|
||||
fn from_angle_x(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
let _2 = num::cast(2);
|
||||
Quat::new(cos(radians / _2), sin(radians), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn from_angle_y(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
let _2 = num::cast(2);
|
||||
Quat::new(cos(radians / _2), zero(), sin(radians), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn from_angle_z(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
let _2 = num::cast(2);
|
||||
Quat::new(cos(radians / _2), zero(), zero(), sin(radians))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Quat<T> {
|
||||
// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion
|
||||
let _2 = Number::from(2);
|
||||
let _2 = num::cast(2);
|
||||
let xdiv2 = radians_x / _2;
|
||||
let ydiv2 = radians_y / _2;
|
||||
let zdiv2 = radians_z / _2;
|
||||
|
@ -115,7 +117,7 @@ pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T>
|
|||
|
||||
#[inline(always)]
|
||||
fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Quat<T> {
|
||||
let half = radians / Number::from(2);
|
||||
let half = radians / num::cast(2);
|
||||
Quat::from_sv(cos(half), axis.mul_t(sin(half)))
|
||||
}
|
||||
|
||||
|
@ -167,7 +169,7 @@ pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T>
|
|||
#[inline(always)]
|
||||
fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
||||
let tmp = self.v.cross(vec).add_v(&vec.mul_t(self.s));
|
||||
self.v.cross(&tmp).mul_t(Number::from(2)).add_v(vec)
|
||||
self.v.cross(&tmp).mul_t(num::cast(2)).add_v(vec)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -314,7 +316,7 @@ pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T>
|
|||
fn slerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
let dot = self.dot(other);
|
||||
|
||||
let dot_threshold = Number::from(0.9995);
|
||||
let dot_threshold = num::cast(0.9995);
|
||||
|
||||
if dot > dot_threshold {
|
||||
return self.nlerp(other, amount); // if quaternions are close together use `nlerp`
|
||||
|
@ -377,17 +379,17 @@ impl<T:Copy> Index<uint, T> for Quat<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + 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 + NumCast + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> 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 + FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
44
src/vec.rs
44
src/vec.rs
|
@ -1,7 +1,9 @@
|
|||
use core::num::{Zero, One};
|
||||
use core::num::Zero::zero;
|
||||
use core::num::One::one;
|
||||
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
|
||||
use numeric::*;
|
||||
use numeric::number::Number;
|
||||
use numeric::number::Number::{zero,one};
|
||||
|
||||
/**
|
||||
* The base generic vector trait.
|
||||
|
@ -561,7 +563,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec2<T> {
|
||||
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn identity() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), one::<T>())
|
||||
|
@ -651,14 +653,14 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec2<T>> for Vec2<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> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Vec2<T> {
|
||||
Vector2::new(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector2<T> for Vec2<T> {
|
||||
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector2<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn unit_x() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), zero::<T>())
|
||||
|
@ -675,14 +677,14 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
|
||||
impl<T:Copy + Number + Zero> ToHomogeneous<Vec3<T>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn to_homogeneous(&self) -> Vec3<T> {
|
||||
Vector3::new(self.x, self.y, zero())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec2<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -741,10 +743,10 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Euclid
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -940,7 +942,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn identity() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), one::<T>(), one::<T>())
|
||||
|
@ -1033,14 +1035,14 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec3<T>> for Vec3<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> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Vec3<T> {
|
||||
Vector3::new(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector3<T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector3<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn unit_x() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), zero::<T>(), zero::<T>())
|
||||
|
@ -1069,14 +1071,14 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> ToHomogeneous<Vec4<T>> for Vec3<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> {
|
||||
#[inline(always)]
|
||||
fn to_homogeneous(&self) -> Vec4<T> {
|
||||
Vector4::new(self.x, self.y, self.z, zero())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec3<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -1135,10 +1137,10 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Euclid
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -1338,7 +1340,7 @@ impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec4<T> {
|
||||
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn identity() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
|
||||
|
@ -1434,14 +1436,14 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec4<T>> for Vec4<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> {
|
||||
#[inline(always)]
|
||||
fn neg(&self) -> Vec4<T> {
|
||||
Vector4::new(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number> NumericVector4<T> for Vec4<T> {
|
||||
impl<T:Copy + Number + Zero + One> NumericVector4<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn unit_x() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
|
||||
|
@ -1463,7 +1465,7 @@ impl<T:Copy + Number> NumericVector4<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec4<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -1522,10 +1524,10 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Euclid
|
|||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
||||
impl<T:Copy + Float + NumCast + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
self.fuzzy_eq_eps(other, &num::cast(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
Loading…
Reference in a new issue