Implement explicit self in trait methods
This commit is contained in:
parent
ea074faef5
commit
6d3620c9d7
9 changed files with 646 additions and 629 deletions
22
src/angle.rs
22
src/angle.rs
|
@ -23,9 +23,9 @@ pub trait Angle<T>: Add<self,self>
|
|||
static pure fn sextant() -> self;
|
||||
static pure fn octant() -> self;
|
||||
|
||||
pure fn to_radians() -> Radians<T>;
|
||||
pure fn to_degrees() -> Degrees<T>;
|
||||
pure fn wrap() -> self;
|
||||
pure fn to_radians(&self) -> Radians<T>;
|
||||
pure fn to_degrees(&self) -> Degrees<T>;
|
||||
pure fn wrap(&self) -> self;
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,11 +41,11 @@ pub impl<T:Copy Num NumCast> Radians<T>: Angle<T> {
|
|||
#[inline(always)] static pure fn sextant() -> Radians<T> { Radians(move cast(pi / 3.0)) }
|
||||
#[inline(always)] static pure fn octant() -> Radians<T> { Radians(move cast(pi / 4.0)) }
|
||||
|
||||
#[inline(always)] pure fn to_radians() -> Radians<T> { self }
|
||||
#[inline(always)] pure fn to_degrees() -> Degrees<T> { Degrees(*self * cast(180.0 / pi)) }
|
||||
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { *self }
|
||||
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { Degrees(**self * cast(180.0 / pi)) }
|
||||
|
||||
#[inline(always)] pure fn wrap() -> Radians<T> {
|
||||
self % cast(2.0 * pi) // TODO: keep in the domain of 0 to two_pi
|
||||
#[inline(always)] pure fn wrap(&self) -> Radians<T> {
|
||||
(*self) % cast(2.0 * pi) // TODO: keep in the domain of 0 to two_pi
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,11 +120,11 @@ pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> {
|
|||
#[inline(always)] static pure fn sextant() -> Degrees<T> { Degrees(move cast(60.0)) }
|
||||
#[inline(always)] static pure fn octant() -> Degrees<T> { Degrees(move cast(45.0)) }
|
||||
|
||||
#[inline(always)] pure fn to_radians() -> Radians<T> { Radians(*self * cast(pi / 180.0)) }
|
||||
#[inline(always)] pure fn to_degrees() -> Degrees<T> { self }
|
||||
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { Radians(**self * cast(pi / 180.0)) }
|
||||
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { *self }
|
||||
|
||||
#[inline(always)] pure fn wrap() -> Degrees<T> {
|
||||
self % cast(360) // TODO: keep in the domain of 0 to 360
|
||||
#[inline(always)] pure fn wrap(&self) -> Degrees<T> {
|
||||
(*self) % cast(360) // TODO: keep in the domain of 0 to 360
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub trait Dimensional<T>: Index<uint, T> {
|
||||
static pure fn dim() -> uint; // dim and size_of are pretty useless at the moment due to
|
||||
static pure fn size_of() -> uint; // how Rust's static methods are currently implemented
|
||||
pure fn to_ptr() -> *T;
|
||||
pure fn to_ptr(&self) -> *T;
|
||||
}
|
|
@ -10,75 +10,75 @@ use angle::{Radians, Degrees};
|
|||
use vec::{Vec2, Vec3, Vec4};
|
||||
|
||||
pub trait Sign {
|
||||
pure fn abs() -> self;
|
||||
pure fn sign() -> self;
|
||||
pure fn abs(&self) -> self;
|
||||
pure fn sign(&self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn abs<T:Sign>(x: &T) -> T { x.abs() }
|
||||
#[inline(always)] pub pure fn sign<T:Sign>(x: &T) -> T { x.sign() }
|
||||
|
||||
pub impl i8: Sign {
|
||||
#[inline(always)] pure fn abs() -> i8 { if self >= 0 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> i8 { if self > 0 { 1 } else if self == 0 { 0 } else { -1 } }
|
||||
#[inline(always)] pure fn abs(&self) -> i8 { if (*self) >= 0 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> i8 { if (*self) > 0 { 1 } else if (*self) == 0 { 0 } else { -1 } }
|
||||
}
|
||||
|
||||
pub impl i16: Sign {
|
||||
#[inline(always)] pure fn abs() -> i16 { if self >= 0 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> i16 { if self > 0 { 1 } else if self == 0 { 0 } else { -1 } }
|
||||
#[inline(always)] pure fn abs(&self) -> i16 { if (*self) >= 0 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> i16 { if (*self) > 0 { 1 } else if (*self) == 0 { 0 } else { -1 } }
|
||||
}
|
||||
|
||||
pub impl i32: Sign {
|
||||
#[inline(always)] pure fn abs() -> i32 { if self >= 0 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> i32 { if self > 0 { 1 } else if self == 0 { 0 } else { -1 } }
|
||||
#[inline(always)] pure fn abs(&self) -> i32 { if (*self) >= 0 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> i32 { if (*self) > 0 { 1 } else if (*self) == 0 { 0 } else { -1 } }
|
||||
}
|
||||
|
||||
pub impl i64: Sign {
|
||||
#[inline(always)] pure fn abs() -> i64 { if self >= 0 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> i64 { if self > 0 { 1 } else if self == 0 { 0 } else { -1 } }
|
||||
#[inline(always)] pure fn abs(&self) -> i64 { if (*self) >= 0 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> i64 { if (*self) > 0 { 1 } else if (*self) == 0 { 0 } else { -1 } }
|
||||
}
|
||||
|
||||
pub impl int: Sign {
|
||||
#[inline(always)] pure fn abs() -> int { if self >= 0 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> int { if self > 0 { 1 } else if self == 0 { 0 } else { -1 } }
|
||||
#[inline(always)] pure fn abs(&self) -> int { if (*self) >= 0 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> int { if (*self) > 0 { 1 } else if (*self) == 0 { 0 } else { -1 } }
|
||||
}
|
||||
|
||||
pub impl f32: Sign {
|
||||
#[inline(always)] pure fn abs() -> f32 { if self >= 0f32 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> f32 { if self > 0f32 { 1f32 } else if self == 0f32 { 0f32 } else { -1f32 } }
|
||||
#[inline(always)] pure fn abs(&self) -> f32 { if (*self) >= 0f32 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> f32 { if (*self) > 0f32 { 1f32 } else if (*self) == 0f32 { 0f32 } else { -1f32 } }
|
||||
}
|
||||
|
||||
pub impl f64: Sign {
|
||||
#[inline(always)] pure fn abs() -> f64 { if self >= 0f64 { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> f64 { if self > 0f64 { 1f64 } else if self == 0f64 { 0f64 } else { -1f64 } }
|
||||
#[inline(always)] pure fn abs(&self) -> f64 { if (*self) >= 0f64 { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> f64 { if (*self) > 0f64 { 1f64 } else if (*self) == 0f64 { 0f64 } else { -1f64 } }
|
||||
}
|
||||
|
||||
pub impl float: Sign {
|
||||
#[inline(always)] pure fn abs() -> float { if self >= 0f { self } else {-self } }
|
||||
#[inline(always)] pure fn sign() -> float { if self > 0f { 1f } else if self == 0f { 0f } else { -1f } }
|
||||
#[inline(always)] pure fn abs(&self) -> float { if (*self) >= 0f { (*self) } else { -(*self) } }
|
||||
#[inline(always)] pure fn sign(&self) -> float { if (*self) > 0f { 1f } else if (*self) == 0f { 0f } else { -1f } }
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Sign> Radians<T>: Sign{
|
||||
#[inline(always)] pure fn abs() -> Radians<T> { Radians(abs(&*self)) }
|
||||
#[inline(always)] pure fn sign() -> Radians<T> { Radians(sign(&*self)) }
|
||||
#[inline(always)] pure fn abs(&self) -> Radians<T> { Radians(abs(&**self)) }
|
||||
#[inline(always)] pure fn sign(&self) -> Radians<T> { Radians(sign(&**self)) }
|
||||
}
|
||||
|
||||
pub impl<T:Sign> Degrees<T>: Sign{
|
||||
#[inline(always)] pure fn abs() -> Degrees<T> { Degrees(abs(&*self)) }
|
||||
#[inline(always)] pure fn sign() -> Degrees<T> { Degrees(sign(&*self)) }
|
||||
#[inline(always)] pure fn abs(&self) -> Degrees<T> { Degrees(abs(&**self)) }
|
||||
#[inline(always)] pure fn sign(&self) -> Degrees<T> { Degrees(sign(&**self)) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub impl<T:Copy Sign> Vec2<T>: Sign {
|
||||
#[inline(always)]
|
||||
pure fn abs() -> Vec2<T> {
|
||||
pure fn abs(&self) -> Vec2<T> {
|
||||
Vec2::new(abs(&self[0]),
|
||||
abs(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sign() -> Vec2<T> {
|
||||
pure fn sign(&self) -> Vec2<T> {
|
||||
Vec2::new(sign(&self[0]),
|
||||
sign(&self[1]))
|
||||
}
|
||||
|
@ -86,14 +86,14 @@ pub impl<T:Copy Sign> Vec2<T>: Sign {
|
|||
|
||||
pub impl<T:Copy Sign> Vec3<T>: Sign {
|
||||
#[inline(always)]
|
||||
pure fn abs() -> Vec3<T> {
|
||||
pure fn abs(&self) -> Vec3<T> {
|
||||
Vec3::new(abs(&self[0]),
|
||||
abs(&self[1]),
|
||||
abs(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sign() -> Vec3<T> {
|
||||
pure fn sign(&self) -> Vec3<T> {
|
||||
Vec3::new(sign(&self[0]),
|
||||
sign(&self[1]),
|
||||
sign(&self[2]))
|
||||
|
@ -102,7 +102,7 @@ pub impl<T:Copy Sign> Vec3<T>: Sign {
|
|||
|
||||
pub impl<T:Copy Sign> Vec4<T>: Sign {
|
||||
#[inline(always)]
|
||||
pure fn abs() -> Vec4<T> {
|
||||
pure fn abs(&self) -> Vec4<T> {
|
||||
Vec4::new(abs(&self[0]),
|
||||
abs(&self[1]),
|
||||
abs(&self[2]),
|
||||
|
@ -110,7 +110,7 @@ pub impl<T:Copy Sign> Vec4<T>: Sign {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sign() -> Vec4<T> {
|
||||
pure fn sign(&self) -> Vec4<T> {
|
||||
Vec4::new(sign(&self[0]),
|
||||
sign(&self[1]),
|
||||
sign(&self[2]),
|
||||
|
@ -119,12 +119,12 @@ pub impl<T:Copy Sign> Vec4<T>: Sign {
|
|||
}
|
||||
|
||||
pub trait Approx {
|
||||
pure fn floor() -> self;
|
||||
pure fn trunc() -> self;
|
||||
pure fn round() -> self;
|
||||
// pure fn roundEven() -> self;
|
||||
pure fn ceil() -> self;
|
||||
pure fn fract() -> self;
|
||||
pure fn floor(&self) -> self;
|
||||
pure fn trunc(&self) -> self;
|
||||
pure fn round(&self) -> self;
|
||||
// pure fn roundEven(&self) -> self;
|
||||
pure fn ceil(&self) -> self;
|
||||
pure fn fract(&self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn floor<T:Approx>(x: &T) -> T { x.floor() }
|
||||
|
@ -135,85 +135,85 @@ pub trait Approx {
|
|||
#[inline(always)] pub pure fn fract<T:Approx>(x: &T) -> T { x.fract() }
|
||||
|
||||
pub impl f32: Approx {
|
||||
#[inline(always)] pure fn floor() -> f32 { cast(cmath::c_float_utils::floor(self)) }
|
||||
#[inline(always)] pure fn trunc() -> f32 { cast(cmath::c_float_utils::trunc(self)) }
|
||||
#[inline(always)] pure fn round() -> f32 { cast(cmath::c_float_utils::round(self)) }
|
||||
// #[inline(always)] pure fn roundEven() -> f32 {}
|
||||
#[inline(always)] pure fn ceil() -> f32 { cast(cmath::c_float_utils::ceil(self)) }
|
||||
#[inline(always)] pure fn fract() -> f32 { self - floor(&self) }
|
||||
#[inline(always)] pure fn floor(&self) -> f32 { cast(cmath::c_float_utils::floor(*self)) }
|
||||
#[inline(always)] pure fn trunc(&self) -> f32 { cast(cmath::c_float_utils::trunc(*self)) }
|
||||
#[inline(always)] pure fn round(&self) -> f32 { cast(cmath::c_float_utils::round(*self)) }
|
||||
// #[inline(always)] pure fn roundEven(&self) -> f32 {}
|
||||
#[inline(always)] pure fn ceil(&self) -> f32 { cast(cmath::c_float_utils::ceil(*self)) }
|
||||
#[inline(always)] pure fn fract(&self) -> f32 { (*self) - floor(&*self) }
|
||||
}
|
||||
|
||||
pub impl f64: Approx {
|
||||
#[inline(always)] pure fn floor() -> f64 { cast(cmath::c_double_utils::floor(self)) }
|
||||
#[inline(always)] pure fn trunc() -> f64 { cast(cmath::c_double_utils::trunc(self)) }
|
||||
#[inline(always)] pure fn round() -> f64 { cast(cmath::c_double_utils::round(self)) }
|
||||
// #[inline(always)] pure fn roundEven() -> f64 {}
|
||||
#[inline(always)] pure fn ceil() -> f64 { cast(cmath::c_double_utils::ceil(self)) }
|
||||
#[inline(always)] pure fn fract() -> f64 { self - floor(&self) }
|
||||
#[inline(always)] pure fn floor(&self) -> f64 { cast(cmath::c_double_utils::floor(*self)) }
|
||||
#[inline(always)] pure fn trunc(&self) -> f64 { cast(cmath::c_double_utils::trunc(*self)) }
|
||||
#[inline(always)] pure fn round(&self) -> f64 { cast(cmath::c_double_utils::round(*self)) }
|
||||
// #[inline(always)] pure fn roundEven(&self) -> f64 {}
|
||||
#[inline(always)] pure fn ceil(&self) -> f64 { cast(cmath::c_double_utils::ceil(*self)) }
|
||||
#[inline(always)] pure fn fract(&self) -> f64 { (*self) - floor(&*self) }
|
||||
}
|
||||
|
||||
pub impl float: Approx {
|
||||
#[inline(always)] pure fn floor() -> float { cast(cmath::c_float_utils::floor(cast(self))) }
|
||||
#[inline(always)] pure fn trunc() -> float { cast(cmath::c_float_utils::trunc(cast(self))) }
|
||||
#[inline(always)] pure fn round() -> float { cast(cmath::c_float_utils::round(cast(self))) }
|
||||
// #[inline(always)] pure fn roundEven() -> float {}
|
||||
#[inline(always)] pure fn ceil() -> float { cast(cmath::c_float_utils::ceil(cast(self))) }
|
||||
#[inline(always)] pure fn fract() -> float { self - floor(&self) }
|
||||
#[inline(always)] pure fn floor(&self) -> float { cast(cmath::c_float_utils::floor(cast(*self))) }
|
||||
#[inline(always)] pure fn trunc(&self) -> float { cast(cmath::c_float_utils::trunc(cast(*self))) }
|
||||
#[inline(always)] pure fn round(&self) -> float { cast(cmath::c_float_utils::round(cast(*self))) }
|
||||
// #[inline(always)] pure fn roundEven(&self) -> float {}
|
||||
#[inline(always)] pure fn ceil(&self) -> float { cast(cmath::c_float_utils::ceil(cast(*self))) }
|
||||
#[inline(always)] pure fn fract(&self) -> float { (*self) - floor(&*self) }
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Approx> Radians<T>: Approx{
|
||||
#[inline(always)] pure fn floor() -> Radians<T> { Radians(floor(&*self)) }
|
||||
#[inline(always)] pure fn trunc() -> Radians<T> { Radians(trunc(&*self)) }
|
||||
#[inline(always)] pure fn round() -> Radians<T> { Radians(round(&*self)) }
|
||||
// #[inline(always)] pure fn roundEven() -> Radians<T> { Radians(roundEven(&*self)) }
|
||||
#[inline(always)] pure fn ceil() -> Radians<T> { Radians(ceil(&*self)) }
|
||||
#[inline(always)] pure fn fract() -> Radians<T> { Radians(fract(&*self)) }
|
||||
#[inline(always)] pure fn floor(&self) -> Radians<T> { Radians(floor(&**self)) }
|
||||
#[inline(always)] pure fn trunc(&self) -> Radians<T> { Radians(trunc(&**self)) }
|
||||
#[inline(always)] pure fn round(&self) -> Radians<T> { Radians(round(&**self)) }
|
||||
// #[inline(always)] pure fn roundEven(&self) -> Radians<T> { Radians(roundEven(&**self)) }
|
||||
#[inline(always)] pure fn ceil(&self) -> Radians<T> { Radians(ceil(&**self)) }
|
||||
#[inline(always)] pure fn fract(&self) -> Radians<T> { Radians(fract(&**self)) }
|
||||
}
|
||||
|
||||
pub impl<T:Approx> Degrees<T>: Approx{
|
||||
#[inline(always)] pure fn floor() -> Degrees<T> { Degrees(floor(&*self)) }
|
||||
#[inline(always)] pure fn trunc() -> Degrees<T> { Degrees(trunc(&*self)) }
|
||||
#[inline(always)] pure fn round() -> Degrees<T> { Degrees(round(&*self)) }
|
||||
// #[inline(always)] pure fn roundEven() -> Degrees<T> { Degrees(roundEven(&*self)) }
|
||||
#[inline(always)] pure fn ceil() -> Degrees<T> { Degrees(ceil(&*self)) }
|
||||
#[inline(always)] pure fn fract() -> Degrees<T> { Degrees(fract(&*self)) }
|
||||
#[inline(always)] pure fn floor(&self) -> Degrees<T> { Degrees(floor(&**self)) }
|
||||
#[inline(always)] pure fn trunc(&self) -> Degrees<T> { Degrees(trunc(&**self)) }
|
||||
#[inline(always)] pure fn round(&self) -> Degrees<T> { Degrees(round(&**self)) }
|
||||
// #[inline(always)] pure fn roundEven(&self) -> Degrees<T> { Degrees(roundEven(&**self)) }
|
||||
#[inline(always)] pure fn ceil(&self) -> Degrees<T> { Degrees(ceil(&**self)) }
|
||||
#[inline(always)] pure fn fract(&self) -> Degrees<T> { Degrees(fract(&**self)) }
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Copy Approx> Vec2<T>: Approx {
|
||||
#[inline(always)]
|
||||
pure fn floor() -> Vec2<T> {
|
||||
pure fn floor(&self) -> Vec2<T> {
|
||||
Vec2::new(floor(&self[0]),
|
||||
floor(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn trunc() -> Vec2<T> {
|
||||
pure fn trunc(&self) -> Vec2<T> {
|
||||
Vec2::new(trunc(&self[0]),
|
||||
trunc(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn round() -> Vec2<T> {
|
||||
pure fn round(&self) -> Vec2<T> {
|
||||
Vec2::new(round(&self[0]),
|
||||
round(&self[1]))
|
||||
}
|
||||
|
||||
// #[inline(always)]
|
||||
// pure fn ceil() -> Vec2<T> {
|
||||
// pure fn ceil(&self) -> Vec2<T> {
|
||||
// Vec2::new(roundEven(&self[0]),
|
||||
// roundEven(&self[1]))
|
||||
// }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ceil() -> Vec2<T> {
|
||||
pure fn ceil(&self) -> Vec2<T> {
|
||||
Vec2::new(ceil(&self[0]),
|
||||
ceil(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fract() -> Vec2<T> {
|
||||
pure fn fract(&self) -> Vec2<T> {
|
||||
Vec2::new(fract(&self[0]),
|
||||
fract(&self[1]))
|
||||
}
|
||||
|
@ -222,42 +222,42 @@ pub impl<T:Copy Approx> Vec2<T>: Approx {
|
|||
|
||||
pub impl<T:Copy Approx> Vec3<T>: Approx {
|
||||
#[inline(always)]
|
||||
pure fn floor() -> Vec3<T> {
|
||||
pure fn floor(&self) -> Vec3<T> {
|
||||
Vec3::new(floor(&self[0]),
|
||||
floor(&self[1]),
|
||||
floor(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn trunc() -> Vec3<T> {
|
||||
pure fn trunc(&self) -> Vec3<T> {
|
||||
Vec3::new(trunc(&self[0]),
|
||||
trunc(&self[1]),
|
||||
trunc(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn round() -> Vec3<T> {
|
||||
pure fn round(&self) -> Vec3<T> {
|
||||
Vec3::new(round(&self[0]),
|
||||
round(&self[1]),
|
||||
round(&self[2]))
|
||||
}
|
||||
|
||||
// #[inline(always)]
|
||||
// pure fn ceil() -> Vec3<T> {
|
||||
// pure fn ceil(&self) -> Vec3<T> {
|
||||
// Vec3::new(roundEven(&self[0]),
|
||||
// roundEven(&self[1]),
|
||||
// roundEven(&self[2]))
|
||||
// }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ceil() -> Vec3<T> {
|
||||
pure fn ceil(&self) -> Vec3<T> {
|
||||
Vec3::new(ceil(&self[0]),
|
||||
ceil(&self[1]),
|
||||
ceil(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fract() -> Vec3<T> {
|
||||
pure fn fract(&self) -> Vec3<T> {
|
||||
Vec3::new(fract(&self[0]),
|
||||
fract(&self[1]),
|
||||
fract(&self[2]))
|
||||
|
@ -267,7 +267,7 @@ pub impl<T:Copy Approx> Vec3<T>: Approx {
|
|||
|
||||
pub impl<T:Copy Approx> Vec4<T>: Approx {
|
||||
#[inline(always)]
|
||||
pure fn floor() -> Vec4<T> {
|
||||
pure fn floor(&self) -> Vec4<T> {
|
||||
Vec4::new(floor(&self[0]),
|
||||
floor(&self[1]),
|
||||
floor(&self[2]),
|
||||
|
@ -275,7 +275,7 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn trunc() -> Vec4<T> {
|
||||
pure fn trunc(&self) -> Vec4<T> {
|
||||
Vec4::new(trunc(&self[0]),
|
||||
trunc(&self[1]),
|
||||
trunc(&self[2]),
|
||||
|
@ -283,7 +283,7 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn round() -> Vec4<T> {
|
||||
pure fn round(&self) -> Vec4<T> {
|
||||
Vec4::new(round(&self[0]),
|
||||
round(&self[1]),
|
||||
round(&self[2]),
|
||||
|
@ -291,7 +291,7 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
}
|
||||
|
||||
// #[inline(always)]
|
||||
// pure fn ceil() -> Vec4<T> {
|
||||
// pure fn ceil(&self) -> Vec4<T> {
|
||||
// Vec4::new(roundEven(&self[0]),
|
||||
// roundEven(&self[1]),
|
||||
// roundEven(&self[2]),
|
||||
|
@ -299,7 +299,7 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
// }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ceil() -> Vec4<T> {
|
||||
pure fn ceil(&self) -> Vec4<T> {
|
||||
Vec4::new(ceil(&self[0]),
|
||||
ceil(&self[1]),
|
||||
ceil(&self[2]),
|
||||
|
@ -307,7 +307,7 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fract() -> Vec4<T> {
|
||||
pure fn fract(&self) -> Vec4<T> {
|
||||
Vec4::new(fract(&self[0]),
|
||||
fract(&self[1]),
|
||||
fract(&self[2]),
|
||||
|
@ -317,9 +317,9 @@ pub impl<T:Copy Approx> Vec4<T>: Approx {
|
|||
}
|
||||
|
||||
pub trait Extent {
|
||||
pure fn min(other: &self) -> self;
|
||||
pure fn max(other: &self) -> self;
|
||||
pure fn clamp(mn: &self, mx: &self) -> self;
|
||||
pure fn min(&self, other: &self) -> self;
|
||||
pure fn max(&self, other: &self) -> self;
|
||||
pure fn clamp(&self, mn: &self, mx: &self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn min<T:Extent>(a: &T, b: &T) -> T { a.min(b) }
|
||||
|
@ -328,270 +328,276 @@ pub trait Extent {
|
|||
|
||||
pub impl u8: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &u8) -> u8 { if self < *other { self } else { *other } }
|
||||
#[inline(always)] pure fn max(other: &u8) -> u8 { if self > *other { self } else { *other } }
|
||||
pure fn min(&self, other: &u8) -> u8 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &u8, mx: &u8) -> u8 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn max(&self, other: &u8) -> u8 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(&self, mn: &u8, mx: &u8) -> u8 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl u16: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &u16) -> u16 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &u16) -> u16 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &u16) -> u16 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &u16) -> u16 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &u16, mx: &u16) -> u16 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &u16, mx: &u16) -> u16 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl u32: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &u32) -> u32 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &u32) -> u32 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &u32) -> u32 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &u32) -> u32 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &u32, mx: &u32) -> u32 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &u32, mx: &u32) -> u32 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl u64: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &u64) -> u64 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &u64) -> u64 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &u64) -> u64 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &u64) -> u64 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &u64, mx: &u64) -> u64 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &u64, mx: &u64) -> u64 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl uint: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &uint) -> uint {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &uint) -> uint {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &uint) -> uint {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &uint) -> uint {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &uint, mx: &uint) -> uint {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &uint, mx: &uint) -> uint {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl i8: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &i8) -> i8 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &i8) -> i8 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &i8) -> i8 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &i8) -> i8 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &i8, mx: &i8) -> i8 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &i8, mx: &i8) -> i8 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl i16: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &i16) -> i16 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &i16) -> i16 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &i16) -> i16 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &i16) -> i16 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &i16, mx: &i16) -> i16 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &i16, mx: &i16) -> i16 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl i32: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &i32) -> i32 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &i32) -> i32 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &i32) -> i32 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &i32) -> i32 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &i32, mx: &i32) -> i32 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &i32, mx: &i32) -> i32 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl i64: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &i64) -> i64 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &i64) -> i64 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &i64) -> i64 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &i64) -> i64 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &i64, mx: &i64) -> i64 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &i64, mx: &i64) -> i64 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl int: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &int) -> int {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &int) -> int {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &int) -> int {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &int) -> int {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &int, mx: &int) -> int {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &int, mx: &int) -> int {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl f32: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &f32) -> f32 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &f32) -> f32 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &f32) -> f32 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &f32) -> f32 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &f32, mx: &f32) -> f32 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl f64: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &f64) -> f64 {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &f64) -> f64 {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &f64) -> f64 {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &f64) -> f64 {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &f64, mx: &f64) -> f64 {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl float: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &float) -> float {
|
||||
if self < *other { self } else { *other }
|
||||
pure fn min(&self, other: &float) -> float {
|
||||
if (*self) < (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &float) -> float {
|
||||
if self > *other { self } else { *other }
|
||||
pure fn max(&self, other: &float) -> float {
|
||||
if (*self) > (*other) { (*self) } else { (*other) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &float, mx: &float) -> float {
|
||||
min(&max(&self, mn), mx)
|
||||
pure fn clamp(&self, mn: &float, mx: &float) -> float {
|
||||
min(&max(self, mn), mx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Copy Extent> Radians<T>: Extent{
|
||||
#[inline(always)]
|
||||
pure fn min(other: &Radians<T>) -> Radians<T> {
|
||||
Radians(min(&*self, &**other))
|
||||
pure fn min(&self, other: &Radians<T>) -> Radians<T> {
|
||||
Radians(min(&**self, &**other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &Radians<T>) -> Radians<T> {
|
||||
Radians(max(&*self, &**other))
|
||||
pure fn max(&self, other: &Radians<T>) -> Radians<T> {
|
||||
Radians(max(&**self, &**other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &Radians<T>, mx: &Radians<T>) -> Radians<T> {
|
||||
Radians((*self).clamp(&**mn, &**mx))
|
||||
pure fn clamp(&self, mn: &Radians<T>, mx: &Radians<T>) -> Radians<T> {
|
||||
Radians((**self).clamp(&**mn, &**mx))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Extent> Degrees<T>: Extent{
|
||||
#[inline(always)]
|
||||
pure fn min(other: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees(min(&*self, &**other))
|
||||
pure fn min(&self, other: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees(min(&**self, &**other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees(max(&*self, &**other))
|
||||
pure fn max(&self, other: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees(max(&**self, &**other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &Degrees<T>, mx: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees((*self).clamp(&**mn, &**mx))
|
||||
pure fn clamp(&self, mn: &Degrees<T>, mx: &Degrees<T>) -> Degrees<T> {
|
||||
Degrees((**self).clamp(&**mn, &**mx))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Copy Extent> Vec2<T>: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn min(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(min(&self[0], &other[0]),
|
||||
min(&self[1], &other[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn max(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(max(&self[0], &other[0]),
|
||||
max(&self[1], &other[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &Vec2<T>, mx: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn clamp(&self, mn: &Vec2<T>, mx: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0].clamp(&mn[0], &mx[0]),
|
||||
self[1].clamp(&mn[1], &mx[1]))
|
||||
}
|
||||
|
@ -599,21 +605,21 @@ pub impl<T:Copy Extent> Vec2<T>: Extent {
|
|||
|
||||
pub impl<T:Copy Extent> Vec3<T>: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn min(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(min(&self[0], &other[0]),
|
||||
min(&self[1], &other[1]),
|
||||
min(&self[2], &other[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn max(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(max(&self[0], &other[0]),
|
||||
max(&self[1], &other[1]),
|
||||
max(&self[2], &other[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &Vec3<T>, mx: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn clamp(&self, mn: &Vec3<T>, mx: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(self[0].clamp(&mn[0], &mx[0]),
|
||||
self[1].clamp(&mn[1], &mx[1]),
|
||||
self[2].clamp(&mn[2], &mx[2]))
|
||||
|
@ -622,7 +628,7 @@ pub impl<T:Copy Extent> Vec3<T>: Extent {
|
|||
|
||||
pub impl<T:Copy Extent> Vec4<T>: Extent {
|
||||
#[inline(always)]
|
||||
pure fn min(other: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn min(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(min(&self[0], &other[0]),
|
||||
min(&self[1], &other[1]),
|
||||
min(&self[2], &other[2]),
|
||||
|
@ -630,7 +636,7 @@ pub impl<T:Copy Extent> Vec4<T>: Extent {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn max(other: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn max(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(max(&self[0], &other[0]),
|
||||
max(&self[1], &other[1]),
|
||||
max(&self[2], &other[2]),
|
||||
|
@ -638,7 +644,7 @@ pub impl<T:Copy Extent> Vec4<T>: Extent {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn clamp(mn: &Vec4<T>, mx: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn clamp(&self, mn: &Vec4<T>, mx: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0].clamp(&mn[0], &mx[0]),
|
||||
self[1].clamp(&mn[1], &mx[1]),
|
||||
self[2].clamp(&mn[2], &mx[2]),
|
||||
|
@ -648,9 +654,9 @@ pub impl<T:Copy Extent> Vec4<T>: Extent {
|
|||
|
||||
|
||||
pub trait Mix {
|
||||
pure fn mix(other: &self, value: &self) -> self;
|
||||
pure fn smooth_step(edge0: &self, edge1: &self) -> self;
|
||||
pure fn step(edge: &self) -> self;
|
||||
pure fn mix(&self, other: &self, value: &self) -> self;
|
||||
pure fn smooth_step(&self, edge0: &self, edge1: &self) -> self;
|
||||
pure fn step(&self, edge: &self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn mix<T:Mix>(a: &T, b: &T, value: &T) -> T { a.mix(b, value) }
|
||||
|
@ -659,92 +665,94 @@ pub trait Mix {
|
|||
|
||||
pub impl f32: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &f32, value: &f32) -> f32 {
|
||||
self * (1.0 - (*value)) + (*other) * (*value)
|
||||
pure fn mix(&self, other: &f32, value: &f32) -> f32 {
|
||||
(*self) * (1.0 - (*value)) + (*other) * (*value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &f32, edge1: &f32) -> f32 {
|
||||
let t = clamp(&((self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
pure fn smooth_step(&self, edge0: &f32, edge1: &f32) -> f32 {
|
||||
let t = clamp(&((*self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &f32) -> f32 {
|
||||
if self < *edge { 0.0 } else { 1.0 }
|
||||
pure fn step(&self, edge: &f32) -> f32 {
|
||||
if (*self) < (*edge) { 0.0 } else { 1.0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl f64: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &f64, value: &f64) -> f64 {
|
||||
self * (1.0 - (*value)) + (*other) * (*value)
|
||||
pure fn mix(&self, other: &f64, value: &f64) -> f64 {
|
||||
(*self) * (1.0 - (*value)) + (*other) * (*value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &f64, edge1: &f64) -> f64 {
|
||||
let t = clamp(&((self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
pure fn smooth_step(&self, edge0: &f64, edge1: &f64) -> f64 {
|
||||
let t = clamp(&((*self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &f64) -> f64 {
|
||||
if self < *edge { 0.0 } else { 1.0 }
|
||||
pure fn step(&self, edge: &f64) -> f64 {
|
||||
if (*self) < (*edge) { 0.0 } else { 1.0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl float: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &float, value: &float) -> float {
|
||||
self * (1.0 - (*value)) + (*other) * (*value)
|
||||
pure fn mix(&self, other: &float, value: &float) -> float {
|
||||
(*self) * (1.0 - (*value)) + (*other) * (*value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &float, edge1: &float) -> float {
|
||||
let t = clamp(&((self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
pure fn smooth_step(&self, edge0: &float, edge1: &float) -> float {
|
||||
let t = clamp(&((*self - *edge0) / (*edge1 - *edge0)), &0.0, &1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &float) -> float {
|
||||
if self < *edge { 0.0 } else { 1.0 }
|
||||
pure fn step(&self, edge: &float) -> float {
|
||||
if (*self) < (*edge) { 0.0 } else { 1.0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIXME: ICE!!
|
||||
|
||||
pub impl<T:Mix> Radians<T>: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &Radians<T>, value: &Radians<T>) -> Radians<T> {
|
||||
Radians((*self).mix(&**other, &**value))
|
||||
pure fn mix(&self, other: &Radians<T>, value: &Radians<T>) -> Radians<T> {
|
||||
Radians((**self).mix(&**other, &**value))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &Radians<T>, edge1: &Radians<T>) -> Radians<T> {
|
||||
Radians((*self).smooth_step(&**edge0, &**edge1))
|
||||
pure fn smooth_step(&self, edge0: &Radians<T>, edge1: &Radians<T>) -> Radians<T> {
|
||||
Radians((**self).smooth_step(&**edge0, &**edge1))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &Radians<T>) -> Radians<T> {
|
||||
Radians((*self).step(&**edge))
|
||||
pure fn step(&self, edge: &Radians<T>) -> Radians<T> {
|
||||
Radians((**self).step(&**edge))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub impl<T:Copy Mix> Vec2<T>: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &Vec2<T>, value: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn mix(&self, other: &Vec2<T>, value: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0].mix(&other[0], &value[0]),
|
||||
self[1].mix(&other[1], &value[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &Vec2<T>, edge1: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn smooth_step(&self, edge0: &Vec2<T>, edge1: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0].smooth_step(&edge0[0], &edge1[0]),
|
||||
self[1].smooth_step(&edge0[1], &edge1[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn step(&self, edge: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0].step(&edge[0]),
|
||||
self[1].step(&edge[1]))
|
||||
}
|
||||
|
@ -752,21 +760,21 @@ pub impl<T:Copy Mix> Vec2<T>: Mix {
|
|||
|
||||
pub impl<T:Copy Mix> Vec3<T>: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &Vec3<T>, value: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn mix(&self, other: &Vec3<T>, value: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(self[0].mix(&other[0], &value[0]),
|
||||
self[1].mix(&other[1], &value[1]),
|
||||
self[2].mix(&other[2], &value[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &Vec3<T>, edge1: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn smooth_step(&self, edge0: &Vec3<T>, edge1: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(self[0].smooth_step(&edge0[0], &edge1[0]),
|
||||
self[1].smooth_step(&edge0[1], &edge1[1]),
|
||||
self[2].smooth_step(&edge0[2], &edge1[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn step(&self, edge: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(self[0].step(&edge[0]),
|
||||
self[1].step(&edge[1]),
|
||||
self[2].step(&edge[2]))
|
||||
|
@ -775,7 +783,7 @@ pub impl<T:Copy Mix> Vec3<T>: Mix {
|
|||
|
||||
pub impl<T:Copy Mix> Vec4<T>: Mix {
|
||||
#[inline(always)]
|
||||
pure fn mix(other: &Vec4<T>, value: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn mix(&self, other: &Vec4<T>, value: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0].mix(&other[0], &value[0]),
|
||||
self[1].mix(&other[1], &value[1]),
|
||||
self[2].mix(&other[2], &value[2]),
|
||||
|
@ -783,7 +791,7 @@ pub impl<T:Copy Mix> Vec4<T>: Mix {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn smooth_step(edge0: &Vec4<T>, edge1: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn smooth_step(&self, edge0: &Vec4<T>, edge1: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0].smooth_step(&edge0[0], &edge1[0]),
|
||||
self[1].smooth_step(&edge0[1], &edge1[1]),
|
||||
self[2].smooth_step(&edge0[2], &edge1[2]),
|
||||
|
@ -791,7 +799,7 @@ pub impl<T:Copy Mix> Vec4<T>: Mix {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn step(edge: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn step(&self, edge: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0].step(&edge[0]),
|
||||
self[1].step(&edge[1]),
|
||||
self[2].step(&edge[2]),
|
||||
|
|
|
@ -9,13 +9,13 @@ use num::cast::{NumCast, cast};
|
|||
use vec::{Vec2, Vec3, Vec4};
|
||||
|
||||
pub trait Exp {
|
||||
pure fn pow(n: &self) -> self;
|
||||
pure fn exp() -> self;
|
||||
pure fn log_() -> self;
|
||||
pure fn exp2() -> self;
|
||||
pure fn log2() -> self;
|
||||
pure fn sqrt() -> self;
|
||||
pure fn inv_sqrt() -> self;
|
||||
pure fn pow(&self, n: &self) -> self;
|
||||
pure fn exp(&self) -> self;
|
||||
pure fn log_(&self) -> self;
|
||||
pure fn exp2(&self) -> self;
|
||||
pure fn log2(&self) -> self;
|
||||
pure fn sqrt(&self) -> self;
|
||||
pure fn inv_sqrt(&self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn pow<T:Exp>(x: &T, n: &T) -> T { x.pow(n) }
|
||||
|
@ -27,74 +27,74 @@ pub trait Exp {
|
|||
#[inline(always)] pub pure fn inv_sqrt<T:Exp>(x: &T) -> T { x.inv_sqrt() }
|
||||
|
||||
pub impl f32: Exp {
|
||||
#[inline(always)] pure fn pow(n: &f32) -> f32 { cast(cmath::c_float_utils::pow(self, n.cast())) }
|
||||
#[inline(always)] pure fn exp() -> f32 { cast(cmath::c_float_utils::exp(self)) }
|
||||
#[inline(always)] pure fn log_() -> f32 { cast(cmath::c_float_utils::ln(self)) }
|
||||
#[inline(always)] pure fn exp2() -> f32 { cast(cmath::c_float_utils::exp2(self)) }
|
||||
#[inline(always)] pure fn log2() -> f32 { cast(cmath::c_float_utils::log2(self)) }
|
||||
#[inline(always)] pure fn sqrt() -> f32 { cast(cmath::c_float_utils::sqrt(self)) }
|
||||
#[inline(always)] pure fn inv_sqrt() -> f32 { 1f32 / self.sqrt() } // TODO: optimise? need a wizard
|
||||
#[inline(always)] pure fn pow(&self, n: &f32) -> f32 { cast(cmath::c_float_utils::pow(*self, n.cast())) }
|
||||
#[inline(always)] pure fn exp(&self) -> f32 { cast(cmath::c_float_utils::exp(*self)) }
|
||||
#[inline(always)] pure fn log_(&self) -> f32 { cast(cmath::c_float_utils::ln(*self)) }
|
||||
#[inline(always)] pure fn exp2(&self) -> f32 { cast(cmath::c_float_utils::exp2(*self)) }
|
||||
#[inline(always)] pure fn log2(&self) -> f32 { cast(cmath::c_float_utils::log2(*self)) }
|
||||
#[inline(always)] pure fn sqrt(&self) -> f32 { cast(cmath::c_float_utils::sqrt(*self)) }
|
||||
#[inline(always)] pure fn inv_sqrt(&self) -> f32 { 1f32 / self.sqrt() } // TODO: optimise? need a wizard
|
||||
}
|
||||
|
||||
pub impl f64: Exp {
|
||||
#[inline(always)] pure fn pow(n: &f64) -> f64 { cast(cmath::c_double_utils::pow(self, n.cast())) }
|
||||
#[inline(always)] pure fn exp() -> f64 { cast(cmath::c_double_utils::exp(self)) }
|
||||
#[inline(always)] pure fn log_() -> f64 { cast(cmath::c_double_utils::ln(self)) }
|
||||
#[inline(always)] pure fn exp2() -> f64 { cast(cmath::c_double_utils::exp2(self)) }
|
||||
#[inline(always)] pure fn log2() -> f64 { cast(cmath::c_double_utils::log2(self)) }
|
||||
#[inline(always)] pure fn sqrt() -> f64 { cast(cmath::c_double_utils::sqrt(self)) }
|
||||
#[inline(always)] pure fn inv_sqrt() -> f64 { 1f64 / self.sqrt() } // TODO: optimise? need a wizard
|
||||
#[inline(always)] pure fn pow(&self, n: &f64) -> f64 { cast(cmath::c_double_utils::pow(*self, n.cast())) }
|
||||
#[inline(always)] pure fn exp(&self) -> f64 { cast(cmath::c_double_utils::exp(*self)) }
|
||||
#[inline(always)] pure fn log_(&self) -> f64 { cast(cmath::c_double_utils::ln(*self)) }
|
||||
#[inline(always)] pure fn exp2(&self) -> f64 { cast(cmath::c_double_utils::exp2(*self)) }
|
||||
#[inline(always)] pure fn log2(&self) -> f64 { cast(cmath::c_double_utils::log2(*self)) }
|
||||
#[inline(always)] pure fn sqrt(&self) -> f64 { cast(cmath::c_double_utils::sqrt(*self)) }
|
||||
#[inline(always)] pure fn inv_sqrt(&self) -> f64 { 1f64 / self.sqrt() } // TODO: optimise? need a wizard
|
||||
}
|
||||
|
||||
pub impl float: Exp {
|
||||
#[inline(always)] pure fn pow(n: &float) -> float { cast(cmath::c_float_utils::pow(cast(self), n.cast())) }
|
||||
#[inline(always)] pure fn exp() -> float { cast(cmath::c_float_utils::exp(cast(self))) }
|
||||
#[inline(always)] pure fn log_() -> float { cast(cmath::c_float_utils::ln(cast(self))) }
|
||||
#[inline(always)] pure fn exp2() -> float { cast(cmath::c_float_utils::exp2(cast(self))) }
|
||||
#[inline(always)] pure fn log2() -> float { cast(cmath::c_float_utils::log2(cast(self))) }
|
||||
#[inline(always)] pure fn sqrt() -> float { cast(cmath::c_float_utils::sqrt(cast(self))) }
|
||||
#[inline(always)] pure fn inv_sqrt() -> float { 1f / self.sqrt() } // TODO: optimise? need a wizard
|
||||
#[inline(always)] pure fn pow(&self, n: &float) -> float { cast(cmath::c_float_utils::pow(cast(*self), n.cast())) }
|
||||
#[inline(always)] pure fn exp(&self) -> float { cast(cmath::c_float_utils::exp(cast(*self))) }
|
||||
#[inline(always)] pure fn log_(&self) -> float { cast(cmath::c_float_utils::ln(cast(*self))) }
|
||||
#[inline(always)] pure fn exp2(&self) -> float { cast(cmath::c_float_utils::exp2(cast(*self))) }
|
||||
#[inline(always)] pure fn log2(&self) -> float { cast(cmath::c_float_utils::log2(cast(*self))) }
|
||||
#[inline(always)] pure fn sqrt(&self) -> float { cast(cmath::c_float_utils::sqrt(cast(*self))) }
|
||||
#[inline(always)] pure fn inv_sqrt(&self) -> float { 1f / self.sqrt() } // TODO: optimise? need a wizard
|
||||
}
|
||||
|
||||
pub impl<T:Copy Exp> Vec2<T>: Exp {
|
||||
#[inline(always)]
|
||||
pure fn pow(n: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn pow(&self, n: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(pow(&self[0], &n[0]),
|
||||
pow(&self[1], &n[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp() -> Vec2<T> {
|
||||
pure fn exp(&self) -> Vec2<T> {
|
||||
Vec2::new(exp(&self[0]),
|
||||
exp(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log_() -> Vec2<T> {
|
||||
pure fn log_(&self) -> Vec2<T> {
|
||||
Vec2::new(log_(&self[0]),
|
||||
log_(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp2() -> Vec2<T> {
|
||||
pure fn exp2(&self) -> Vec2<T> {
|
||||
Vec2::new(exp2(&self[0]),
|
||||
exp2(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log2() -> Vec2<T> {
|
||||
pure fn log2(&self) -> Vec2<T> {
|
||||
Vec2::new(log2(&self[0]),
|
||||
log2(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sqrt() -> Vec2<T> {
|
||||
pure fn sqrt(&self) -> Vec2<T> {
|
||||
Vec2::new(sqrt(&self[0]),
|
||||
sqrt(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn inv_sqrt() -> Vec2<T> {
|
||||
pure fn inv_sqrt(&self) -> Vec2<T> {
|
||||
Vec2::new(inv_sqrt(&self[0]),
|
||||
inv_sqrt(&self[1]))
|
||||
}
|
||||
|
@ -102,49 +102,49 @@ pub impl<T:Copy Exp> Vec2<T>: Exp {
|
|||
|
||||
pub impl<T:Copy Exp> Vec3<T>: Exp {
|
||||
#[inline(always)]
|
||||
pure fn pow(n: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn pow(&self, n: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(pow(&self[0], &n[0]),
|
||||
pow(&self[1], &n[1]),
|
||||
pow(&self[2], &n[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp() -> Vec3<T> {
|
||||
pure fn exp(&self) -> Vec3<T> {
|
||||
Vec3::new(exp(&self[0]),
|
||||
exp(&self[1]),
|
||||
exp(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log_() -> Vec3<T> {
|
||||
pure fn log_(&self) -> Vec3<T> {
|
||||
Vec3::new(log_(&self[0]),
|
||||
log_(&self[1]),
|
||||
log_(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp2() -> Vec3<T> {
|
||||
pure fn exp2(&self) -> Vec3<T> {
|
||||
Vec3::new(exp2(&self[0]),
|
||||
exp2(&self[1]),
|
||||
exp2(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log2() -> Vec3<T> {
|
||||
pure fn log2(&self) -> Vec3<T> {
|
||||
Vec3::new(log2(&self[0]),
|
||||
log2(&self[1]),
|
||||
log2(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sqrt() -> Vec3<T> {
|
||||
pure fn sqrt(&self) -> Vec3<T> {
|
||||
Vec3::new(sqrt(&self[0]),
|
||||
sqrt(&self[1]),
|
||||
sqrt(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn inv_sqrt() -> Vec3<T> {
|
||||
pure fn inv_sqrt(&self) -> Vec3<T> {
|
||||
Vec3::new(inv_sqrt(&self[0]),
|
||||
inv_sqrt(&self[1]),
|
||||
inv_sqrt(&self[2]))
|
||||
|
@ -153,7 +153,7 @@ pub impl<T:Copy Exp> Vec3<T>: Exp {
|
|||
|
||||
pub impl<T:Copy Exp> Vec4<T>: Exp {
|
||||
#[inline(always)]
|
||||
pure fn pow(n: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn pow(&self, n: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(pow(&self[0], &n[0]),
|
||||
pow(&self[1], &n[1]),
|
||||
pow(&self[2], &n[2]),
|
||||
|
@ -161,7 +161,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp() -> Vec4<T> {
|
||||
pure fn exp(&self) -> Vec4<T> {
|
||||
Vec4::new(exp(&self[0]),
|
||||
exp(&self[1]),
|
||||
exp(&self[2]),
|
||||
|
@ -169,7 +169,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log_() -> Vec4<T> {
|
||||
pure fn log_(&self) -> Vec4<T> {
|
||||
Vec4::new(log_(&self[0]),
|
||||
log_(&self[1]),
|
||||
log_(&self[2]),
|
||||
|
@ -177,7 +177,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn exp2() -> Vec4<T> {
|
||||
pure fn exp2(&self) -> Vec4<T> {
|
||||
Vec4::new(exp2(&self[0]),
|
||||
exp2(&self[1]),
|
||||
exp2(&self[2]),
|
||||
|
@ -185,7 +185,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn log2() -> Vec4<T> {
|
||||
pure fn log2(&self) -> Vec4<T> {
|
||||
Vec4::new(log2(&self[0]),
|
||||
log2(&self[1]),
|
||||
log2(&self[2]),
|
||||
|
@ -193,7 +193,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sqrt() -> Vec4<T> {
|
||||
pure fn sqrt(&self) -> Vec4<T> {
|
||||
Vec4::new(sqrt(&self[0]),
|
||||
sqrt(&self[1]),
|
||||
sqrt(&self[2]),
|
||||
|
@ -201,7 +201,7 @@ pub impl<T:Copy Exp> Vec4<T>: Exp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn inv_sqrt() -> Vec4<T> {
|
||||
pure fn inv_sqrt(&self) -> Vec4<T> {
|
||||
Vec4::new(inv_sqrt(&self[0]),
|
||||
inv_sqrt(&self[1]),
|
||||
inv_sqrt(&self[2]),
|
||||
|
|
|
@ -9,12 +9,12 @@ use core::cmp::{Eq, Ord};
|
|||
use vec::{Vector, Vec2, Vec3, Vec4};
|
||||
|
||||
pub trait RelVector<BVec> {
|
||||
pure fn less_than(y: &self) -> BVec;
|
||||
pure fn less_than_equal(y: &self) -> BVec;
|
||||
pure fn greater_than(y: &self) -> BVec;
|
||||
pure fn greater_than_equal(y: &self) -> BVec;
|
||||
pure fn equal(y: &self) -> BVec;
|
||||
pure fn not_equal(y: &self) -> BVec;
|
||||
pure fn less_than(&self, other: &self) -> BVec;
|
||||
pure fn less_than_equal(&self, other: &self) -> BVec;
|
||||
pure fn greater_than(&self, other: &self) -> BVec;
|
||||
pure fn greater_than_equal(&self, other: &self) -> BVec;
|
||||
pure fn equal(&self, other: &self) -> BVec;
|
||||
pure fn not_equal(&self, other: &self) -> BVec;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn less_than <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.less_than(y) }
|
||||
|
@ -26,140 +26,140 @@ pub trait RelVector<BVec> {
|
|||
|
||||
pub impl<T:Copy Ord Eq> Vec2<T>: RelVector<Vec2<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] < y[0],
|
||||
self[1] < y[1])
|
||||
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] < other[0],
|
||||
self[1] < other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] <= y[0],
|
||||
self[1] <= y[1])
|
||||
pure fn less_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] <= other[0],
|
||||
self[1] <= other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] > y[0],
|
||||
self[1] > y[1])
|
||||
pure fn greater_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] > other[0],
|
||||
self[1] > other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] >= y[0],
|
||||
self[1] >= y[1])
|
||||
pure fn greater_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] >= other[0],
|
||||
self[1] >= other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] == y[0],
|
||||
self[1] == y[1])
|
||||
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] == other[0],
|
||||
self[1] == other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(y: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] != y[0],
|
||||
self[1] != y[1])
|
||||
pure fn not_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] != other[0],
|
||||
self[1] != other[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> Vec3<T>: RelVector<Vec3<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] < y[0],
|
||||
self[1] < y[1],
|
||||
self[2] < y[2])
|
||||
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] < other[0],
|
||||
self[1] < other[1],
|
||||
self[2] < other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] <= y[0],
|
||||
self[1] <= y[1],
|
||||
self[2] <= y[2])
|
||||
pure fn less_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] <= other[0],
|
||||
self[1] <= other[1],
|
||||
self[2] <= other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] > y[0],
|
||||
self[1] > y[1],
|
||||
self[2] > y[2])
|
||||
pure fn greater_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] > other[0],
|
||||
self[1] > other[1],
|
||||
self[2] > other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] >= y[0],
|
||||
self[1] >= y[1],
|
||||
self[2] >= y[2])
|
||||
pure fn greater_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] == y[0],
|
||||
self[1] == y[1],
|
||||
self[2] == y[2])
|
||||
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] == other[0],
|
||||
self[1] == other[1],
|
||||
self[2] == other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(y: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] != y[0],
|
||||
self[1] != y[1],
|
||||
self[2] != y[2])
|
||||
pure fn not_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> Vec4<T>: RelVector<Vec4<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] < y[0],
|
||||
self[1] < y[1],
|
||||
self[2] < y[2],
|
||||
self[3] < y[3])
|
||||
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] < other[0],
|
||||
self[1] < other[1],
|
||||
self[2] < other[2],
|
||||
self[3] < other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] <= y[0],
|
||||
self[1] <= y[1],
|
||||
self[2] <= y[2],
|
||||
self[3] <= y[3])
|
||||
pure fn less_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] <= other[0],
|
||||
self[1] <= other[1],
|
||||
self[2] <= other[2],
|
||||
self[3] <= other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] > y[0],
|
||||
self[1] > y[1],
|
||||
self[2] > y[2],
|
||||
self[3] > y[3])
|
||||
pure fn greater_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] > other[0],
|
||||
self[1] > other[1],
|
||||
self[2] > other[2],
|
||||
self[3] > other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] >= y[0],
|
||||
self[1] >= y[1],
|
||||
self[2] >= y[2],
|
||||
self[3] >= y[3])
|
||||
pure fn greater_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2],
|
||||
self[3] >= other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] == y[0],
|
||||
self[1] == y[1],
|
||||
self[2] == y[2],
|
||||
self[3] == y[3])
|
||||
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] == other[0],
|
||||
self[1] == other[1],
|
||||
self[2] == other[2],
|
||||
self[3] == other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(y: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] != y[0],
|
||||
self[1] != y[1],
|
||||
self[2] != y[2],
|
||||
self[3] != y[3])
|
||||
pure fn not_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2],
|
||||
self[3] != other[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BooleanVector: Vector<bool> {
|
||||
pure fn any() -> bool;
|
||||
pure fn all() -> bool;
|
||||
pure fn not() -> self;
|
||||
pure fn any(&self) -> bool;
|
||||
pure fn all(&self) -> bool;
|
||||
pure fn not(&self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn any<T:BooleanVector>(x: &T) -> bool { x.any() }
|
||||
|
@ -167,43 +167,52 @@ pub trait BooleanVector: Vector<bool> {
|
|||
#[inline(always)] pub pure fn not<T:BooleanVector>(x: &T) -> T { x.not() }
|
||||
|
||||
pub impl Vec2<bool>: BooleanVector {
|
||||
pure fn any() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1]
|
||||
}
|
||||
|
||||
pure fn all() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1]
|
||||
}
|
||||
|
||||
pure fn not() -> Vec2<bool> {
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec2<bool> {
|
||||
Vec2::new(!self[0], !self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec3<bool>: BooleanVector {
|
||||
pure fn any() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2]
|
||||
}
|
||||
|
||||
pure fn all() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2]
|
||||
}
|
||||
|
||||
pure fn not() -> Vec3<bool> {
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec3<bool> {
|
||||
Vec3::new(!self[0], !self[1], !self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec4<bool>: BooleanVector {
|
||||
pure fn any() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2] || self[3]
|
||||
}
|
||||
|
||||
pure fn all() -> bool {
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2] && self[3]
|
||||
}
|
||||
|
||||
pure fn not() -> Vec4<bool> {
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec4<bool> {
|
||||
Vec4::new(!self[0], !self[1], !self[2], !self[3])
|
||||
}
|
||||
}
|
|
@ -8,15 +8,15 @@ use num::cast::{NumCast, cast};
|
|||
use angle::Radians;
|
||||
use vec::{Vec3, Vec2, Vec4};
|
||||
|
||||
///
|
||||
/// Triganomic functions
|
||||
///
|
||||
/// http://en.wikipedia.org/wiki/Trigonometric_functions
|
||||
///
|
||||
/**
|
||||
* Triganomic functions
|
||||
*
|
||||
* http://en.wikipedia.org/wiki/Trigonometric_functions
|
||||
*/
|
||||
priv trait Trig<T> {
|
||||
pure fn sin() -> T;
|
||||
pure fn cos() -> T;
|
||||
pure fn tan() -> T;
|
||||
pure fn sin(&self) -> T;
|
||||
pure fn cos(&self) -> T;
|
||||
pure fn tan(&self) -> T;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn sin<T:Trig<R>, R>(theta: &T) -> R { theta.sin() }
|
||||
|
@ -24,26 +24,26 @@ priv trait Trig<T> {
|
|||
#[inline(always)] pub pure fn tan<T:Trig<R>, R>(theta: &T) -> R { theta.tan() }
|
||||
|
||||
priv impl<T:Copy Num NumCast> Radians<T>: Trig<T> {
|
||||
#[inline(always)] pure fn sin() -> T { cast(f64::sin(cast(*self))) }
|
||||
#[inline(always)] pure fn cos() -> T { cast(f64::cos(cast(*self))) }
|
||||
#[inline(always)] pure fn tan() -> T { cast(f64::tan(cast(*self))) }
|
||||
#[inline(always)] pure fn sin(&self) -> T { cast(f64::sin(cast(**self))) }
|
||||
#[inline(always)] pure fn cos(&self) -> T { cast(f64::cos(cast(**self))) }
|
||||
#[inline(always)] pure fn tan(&self) -> T { cast(f64::tan(cast(**self))) }
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Vec2<Radians<T>>: Trig<Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn sin() -> Vec2<T> {
|
||||
pure fn sin(&self) -> Vec2<T> {
|
||||
Vec2::new(sin(&self[0]),
|
||||
sin(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cos() -> Vec2<T> {
|
||||
pure fn cos(&self) -> Vec2<T> {
|
||||
Vec2::new(cos(&self[0]),
|
||||
cos(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tan() -> Vec2<T> {
|
||||
pure fn tan(&self) -> Vec2<T> {
|
||||
Vec2::new(tan(&self[0]),
|
||||
tan(&self[1]))
|
||||
}
|
||||
|
@ -51,21 +51,21 @@ pub impl<T:Copy Num NumCast> Vec2<Radians<T>>: Trig<Vec2<T>> {
|
|||
|
||||
pub impl<T:Copy Num NumCast> Vec3<Radians<T>>: Trig<Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn sin() -> Vec3<T> {
|
||||
pure fn sin(&self) -> Vec3<T> {
|
||||
Vec3::new(sin(&self[0]),
|
||||
sin(&self[1]),
|
||||
sin(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cos() -> Vec3<T> {
|
||||
pure fn cos(&self) -> Vec3<T> {
|
||||
Vec3::new(cos(&self[0]),
|
||||
cos(&self[1]),
|
||||
cos(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tan() -> Vec3<T> {
|
||||
pure fn tan(&self) -> Vec3<T> {
|
||||
Vec3::new(tan(&self[0]),
|
||||
tan(&self[1]),
|
||||
tan(&self[2]))
|
||||
|
@ -74,7 +74,7 @@ pub impl<T:Copy Num NumCast> Vec3<Radians<T>>: Trig<Vec3<T>> {
|
|||
|
||||
pub impl<T:Copy Num NumCast> Vec4<Radians<T>>: Trig<Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn sin() -> Vec4<T> {
|
||||
pure fn sin(&self) -> Vec4<T> {
|
||||
Vec4::new(sin(&self[0]),
|
||||
sin(&self[1]),
|
||||
sin(&self[2]),
|
||||
|
@ -82,7 +82,7 @@ pub impl<T:Copy Num NumCast> Vec4<Radians<T>>: Trig<Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cos() -> Vec4<T> {
|
||||
pure fn cos(&self) -> Vec4<T> {
|
||||
Vec4::new(cos(&self[0]),
|
||||
cos(&self[1]),
|
||||
cos(&self[2]),
|
||||
|
@ -90,7 +90,7 @@ pub impl<T:Copy Num NumCast> Vec4<Radians<T>>: Trig<Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tan() -> Vec4<T> {
|
||||
pure fn tan(&self) -> Vec4<T> {
|
||||
Vec4::new(tan(&self[0]),
|
||||
tan(&self[1]),
|
||||
tan(&self[2]),
|
||||
|
@ -98,15 +98,15 @@ pub impl<T:Copy Num NumCast> Vec4<Radians<T>>: Trig<Vec4<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Inverse triganomic functions
|
||||
///
|
||||
/// http://en.wikipedia.org/wiki/Inverse_trigonometric_functions
|
||||
///
|
||||
/**
|
||||
* Inverse triganomic functions
|
||||
*
|
||||
* http://en.wikipedia.org/wiki/Inverse_trigonometric_functions
|
||||
*/
|
||||
pub trait InvTrig {
|
||||
pure fn asin() -> Radians<self>;
|
||||
pure fn acos() -> Radians<self>;
|
||||
pure fn atan() -> Radians<self>;
|
||||
pure fn asin(&self) -> Radians<self>;
|
||||
pure fn acos(&self) -> Radians<self>;
|
||||
pure fn atan(&self) -> Radians<self>;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn asin<T:InvTrig>(x: &T) -> Radians<T> { x.asin() }
|
||||
|
@ -114,45 +114,45 @@ pub trait InvTrig {
|
|||
#[inline(always)] pub pure fn atan<T:InvTrig>(x: &T) -> Radians<T> { x.atan() }
|
||||
|
||||
pub impl f32: InvTrig {
|
||||
#[inline(always)] pure fn asin() -> Radians<f32> { Radians(f32::asin(self)) }
|
||||
#[inline(always)] pure fn acos() -> Radians<f32> { Radians(f32::acos(self)) }
|
||||
#[inline(always)] pure fn atan() -> Radians<f32> { Radians(f32::atan(self)) }
|
||||
#[inline(always)] pure fn asin(&self) -> Radians<f32> { Radians(f32::asin(*self)) }
|
||||
#[inline(always)] pure fn acos(&self) -> Radians<f32> { Radians(f32::acos(*self)) }
|
||||
#[inline(always)] pure fn atan(&self) -> Radians<f32> { Radians(f32::atan(*self)) }
|
||||
}
|
||||
|
||||
pub impl f64: InvTrig {
|
||||
#[inline(always)] pure fn asin() -> Radians<f64> { Radians(f64::asin(self)) }
|
||||
#[inline(always)] pure fn acos() -> Radians<f64> { Radians(f64::acos(self)) }
|
||||
#[inline(always)] pure fn atan() -> Radians<f64> { Radians(f64::atan(self)) }
|
||||
#[inline(always)] pure fn asin(&self) -> Radians<f64> { Radians(f64::asin(*self)) }
|
||||
#[inline(always)] pure fn acos(&self) -> Radians<f64> { Radians(f64::acos(*self)) }
|
||||
#[inline(always)] pure fn atan(&self) -> Radians<f64> { Radians(f64::atan(*self)) }
|
||||
}
|
||||
|
||||
pub impl float: InvTrig {
|
||||
#[inline(always)] pure fn asin() -> Radians<float> { Radians(f64::asin(cast(self)).to_float()) }
|
||||
#[inline(always)] pure fn acos() -> Radians<float> { Radians(f64::acos(cast(self)).to_float()) }
|
||||
#[inline(always)] pure fn atan() -> Radians<float> { Radians(f64::atan(cast(self)).to_float()) }
|
||||
#[inline(always)] pure fn asin(&self) -> Radians<float> { Radians(f64::asin(cast(*self)).to_float()) }
|
||||
#[inline(always)] pure fn acos(&self) -> Radians<float> { Radians(f64::acos(cast(*self)).to_float()) }
|
||||
#[inline(always)] pure fn atan(&self) -> Radians<float> { Radians(f64::atan(cast(*self)).to_float()) }
|
||||
}
|
||||
|
||||
// TODO: figure out how to merge with InvTrig
|
||||
pub trait InvTrigV<T> {
|
||||
pure fn asin() -> T;
|
||||
pure fn acos() -> T;
|
||||
pure fn atan() -> T;
|
||||
pure fn asin(&self) -> T;
|
||||
pure fn acos(&self) -> T;
|
||||
pure fn atan(&self) -> T;
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast InvTrig> Vec2<T>: InvTrigV<Vec2<Radians<T>>> {
|
||||
#[inline(always)]
|
||||
pure fn asin() -> Vec2<Radians<T>> {
|
||||
pure fn asin(&self) -> Vec2<Radians<T>> {
|
||||
Vec2::new(asin(&self[0]),
|
||||
asin(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn acos() -> Vec2<Radians<T>> {
|
||||
pure fn acos(&self) -> Vec2<Radians<T>> {
|
||||
Vec2::new(acos(&self[0]),
|
||||
acos(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn atan() -> Vec2<Radians<T>> {
|
||||
pure fn atan(&self) -> Vec2<Radians<T>> {
|
||||
Vec2::new(atan(&self[0]),
|
||||
atan(&self[1]))
|
||||
}
|
||||
|
@ -160,21 +160,21 @@ pub impl<T:Copy Num NumCast InvTrig> Vec2<T>: InvTrigV<Vec2<Radians<T>>> {
|
|||
|
||||
pub impl<T:Copy Num NumCast InvTrig> Vec3<T>: InvTrigV<Vec3<Radians<T>>> {
|
||||
#[inline(always)]
|
||||
pure fn asin() -> Vec3<Radians<T>> {
|
||||
pure fn asin(&self) -> Vec3<Radians<T>> {
|
||||
Vec3::new(asin(&self[0]),
|
||||
asin(&self[1]),
|
||||
asin(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn acos() -> Vec3<Radians<T>> {
|
||||
pure fn acos(&self) -> Vec3<Radians<T>> {
|
||||
Vec3::new(acos(&self[0]),
|
||||
acos(&self[1]),
|
||||
acos(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn atan() -> Vec3<Radians<T>> {
|
||||
pure fn atan(&self) -> Vec3<Radians<T>> {
|
||||
Vec3::new(atan(&self[0]),
|
||||
atan(&self[1]),
|
||||
atan(&self[2]))
|
||||
|
@ -183,7 +183,7 @@ pub impl<T:Copy Num NumCast InvTrig> Vec3<T>: InvTrigV<Vec3<Radians<T>>> {
|
|||
|
||||
pub impl<T:Copy Num NumCast InvTrig> Vec4<T>: InvTrigV<Vec4<Radians<T>>> {
|
||||
#[inline(always)]
|
||||
pure fn asin() -> Vec4<Radians<T>> {
|
||||
pure fn asin(&self) -> Vec4<Radians<T>> {
|
||||
Vec4::new(asin(&self[0]),
|
||||
asin(&self[1]),
|
||||
asin(&self[2]),
|
||||
|
@ -191,7 +191,7 @@ pub impl<T:Copy Num NumCast InvTrig> Vec4<T>: InvTrigV<Vec4<Radians<T>>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn acos() -> Vec4<Radians<T>> {
|
||||
pure fn acos(&self) -> Vec4<Radians<T>> {
|
||||
Vec4::new(acos(&self[0]),
|
||||
acos(&self[1]),
|
||||
acos(&self[2]),
|
||||
|
@ -199,7 +199,7 @@ pub impl<T:Copy Num NumCast InvTrig> Vec4<T>: InvTrigV<Vec4<Radians<T>>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn atan() -> Vec4<Radians<T>> {
|
||||
pure fn atan(&self) -> Vec4<Radians<T>> {
|
||||
Vec4::new(atan(&self[0]),
|
||||
atan(&self[1]),
|
||||
atan(&self[2]),
|
||||
|
@ -209,15 +209,15 @@ pub impl<T:Copy Num NumCast InvTrig> Vec4<T>: InvTrigV<Vec4<Radians<T>>> {
|
|||
|
||||
|
||||
|
||||
///
|
||||
/// Hyperbolic functions
|
||||
///
|
||||
/// http://en.wikipedia.org/wiki/Hyperbolic_function
|
||||
///
|
||||
/**
|
||||
* Hyperbolic functions
|
||||
*
|
||||
* http://en.wikipedia.org/wiki/Hyperbolic_function
|
||||
*/
|
||||
pub trait Hyp {
|
||||
pure fn sinh() -> self;
|
||||
pure fn cosh() -> self;
|
||||
pure fn tanh() -> self;
|
||||
pure fn sinh(&self) -> self;
|
||||
pure fn cosh(&self) -> self;
|
||||
pure fn tanh(&self) -> self;
|
||||
// pure fn asinh() -> self;
|
||||
// pure fn acosh() -> self;
|
||||
// pure fn atanh() -> self;
|
||||
|
@ -228,38 +228,38 @@ pub trait Hyp {
|
|||
#[inline(always)] pub pure fn tanh<T:Hyp>(x: &T) -> T { x.tanh() }
|
||||
|
||||
pub impl f32: Hyp {
|
||||
#[inline(always)] pure fn sinh() -> f32 { f32::sinh(self) }
|
||||
#[inline(always)] pure fn cosh() -> f32 { f32::cosh(self) }
|
||||
#[inline(always)] pure fn tanh() -> f32 { f32::tanh(self) }
|
||||
#[inline(always)] pure fn sinh(&self) -> f32 { f32::sinh(*self) }
|
||||
#[inline(always)] pure fn cosh(&self) -> f32 { f32::cosh(*self) }
|
||||
#[inline(always)] pure fn tanh(&self) -> f32 { f32::tanh(*self) }
|
||||
}
|
||||
|
||||
pub impl f64: Hyp {
|
||||
#[inline(always)] pure fn sinh() -> f64 { f64::sinh(self) }
|
||||
#[inline(always)] pure fn cosh() -> f64 { f64::cosh(self) }
|
||||
#[inline(always)] pure fn tanh() -> f64 { f64::tanh(self) }
|
||||
#[inline(always)] pure fn sinh(&self) -> f64 { f64::sinh(*self) }
|
||||
#[inline(always)] pure fn cosh(&self) -> f64 { f64::cosh(*self) }
|
||||
#[inline(always)] pure fn tanh(&self) -> f64 { f64::tanh(*self) }
|
||||
}
|
||||
|
||||
pub impl float: Hyp {
|
||||
#[inline(always)] pure fn sinh() -> float { cast(f64::sinh(cast(self))) }
|
||||
#[inline(always)] pure fn cosh() -> float { cast(f64::cosh(cast(self))) }
|
||||
#[inline(always)] pure fn tanh() -> float { cast(f64::tanh(cast(self))) }
|
||||
#[inline(always)] pure fn sinh(&self) -> float { cast(f64::sinh(cast(*self))) }
|
||||
#[inline(always)] pure fn cosh(&self) -> float { cast(f64::cosh(cast(*self))) }
|
||||
#[inline(always)] pure fn tanh(&self) -> float { cast(f64::tanh(cast(*self))) }
|
||||
}
|
||||
|
||||
pub impl <T:Copy Hyp> Vec2<T>: Hyp {
|
||||
#[inline(always)]
|
||||
pure fn sinh() -> Vec2<T> {
|
||||
pure fn sinh(&self) -> Vec2<T> {
|
||||
Vec2::new(sinh(&self[0]),
|
||||
sinh(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cosh() -> Vec2<T> {
|
||||
pure fn cosh(&self) -> Vec2<T> {
|
||||
Vec2::new(cosh(&self[0]),
|
||||
cosh(&self[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tanh() -> Vec2<T> {
|
||||
pure fn tanh(&self) -> Vec2<T> {
|
||||
Vec2::new(tanh(&self[0]),
|
||||
tanh(&self[1]))
|
||||
}
|
||||
|
@ -267,21 +267,21 @@ pub impl <T:Copy Hyp> Vec2<T>: Hyp {
|
|||
|
||||
pub impl <T:Copy Hyp> Vec3<T>: Hyp {
|
||||
#[inline(always)]
|
||||
pure fn sinh() -> Vec3<T> {
|
||||
pure fn sinh(&self) -> Vec3<T> {
|
||||
Vec3::new(sinh(&self[0]),
|
||||
sinh(&self[1]),
|
||||
sinh(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cosh() -> Vec3<T> {
|
||||
pure fn cosh(&self) -> Vec3<T> {
|
||||
Vec3::new(cosh(&self[0]),
|
||||
cosh(&self[1]),
|
||||
cosh(&self[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tanh() -> Vec3<T> {
|
||||
pure fn tanh(&self) -> Vec3<T> {
|
||||
Vec3::new(tanh(&self[0]),
|
||||
tanh(&self[1]),
|
||||
tanh(&self[2]))
|
||||
|
@ -290,7 +290,7 @@ pub impl <T:Copy Hyp> Vec3<T>: Hyp {
|
|||
|
||||
pub impl <T:Copy Hyp> Vec4<T>: Hyp {
|
||||
#[inline(always)]
|
||||
pure fn sinh() -> Vec4<T> {
|
||||
pure fn sinh(&self) -> Vec4<T> {
|
||||
Vec4::new(sinh(&self[0]),
|
||||
sinh(&self[1]),
|
||||
sinh(&self[2]),
|
||||
|
@ -298,7 +298,7 @@ pub impl <T:Copy Hyp> Vec4<T>: Hyp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cosh() -> Vec4<T> {
|
||||
pure fn cosh(&self) -> Vec4<T> {
|
||||
Vec4::new(cosh(&self[0]),
|
||||
cosh(&self[1]),
|
||||
cosh(&self[2]),
|
||||
|
@ -306,7 +306,7 @@ pub impl <T:Copy Hyp> Vec4<T>: Hyp {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn tanh() -> Vec4<T> {
|
||||
pure fn tanh(&self) -> Vec4<T> {
|
||||
Vec4::new(tanh(&self[0]),
|
||||
tanh(&self[1]),
|
||||
tanh(&self[2]),
|
||||
|
|
184
src/mat.rs
184
src/mat.rs
|
@ -18,11 +18,11 @@ use vec::{NumericVector, Vec2, Vec3, Vec4};
|
|||
/// The base Matrix trait
|
||||
///
|
||||
pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq {
|
||||
pure fn rows() -> uint;
|
||||
pure fn cols() -> uint;
|
||||
static pure fn rows() -> uint;
|
||||
static pure fn cols() -> uint;
|
||||
|
||||
pure fn col(i: uint) -> Col;
|
||||
pure fn row(i: uint) -> Row;
|
||||
pure fn col(&self, i: uint) -> Col;
|
||||
pure fn row(&self, i: uint) -> Row;
|
||||
}
|
||||
|
||||
/// A 2 x N matrix
|
||||
|
@ -47,7 +47,7 @@ pub trait Matrix4<T, Col, Row>: Matrix<T, Col, Row> {
|
|||
/// A square matrix
|
||||
///
|
||||
pub trait MatrixNxN<T, ColRow>: Matrix<T, ColRow, ColRow> {
|
||||
pure fn is_symmetric() -> bool;
|
||||
pure fn is_symmetric(&self) -> bool;
|
||||
}
|
||||
|
||||
/// A 2 x 2 square matrix
|
||||
|
@ -83,10 +83,10 @@ pub trait Matrix4x4<T, ColRow>: MatrixNxN<T, ColRow>,
|
|||
pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> {
|
||||
static pure fn zero() -> self;
|
||||
|
||||
pure fn mul_t(value: T) -> self;
|
||||
pure fn mul_v(other: &Col) -> Col;
|
||||
pure fn add_m(other: &self) -> self;
|
||||
pure fn sub_m(other: &self) -> self;
|
||||
pure fn mul_t(&self, value: T) -> self;
|
||||
pure fn mul_v(&self, other: &Col) -> Col;
|
||||
pure fn add_m(&self, other: &self) -> self;
|
||||
pure fn sub_m(&self, other: &self) -> self;
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -98,33 +98,33 @@ pub trait NumericMatrixNxN<T, ColRow>: MatrixNxN<T, ColRow>,
|
|||
|
||||
// static pure fn from_value(value: T) -> self;
|
||||
|
||||
pure fn mul_m(other: &self) -> self;
|
||||
pure fn dot(other: &self) -> T;
|
||||
pure fn mul_m(&self, other: &self) -> self;
|
||||
pure fn dot(&self, other: &self) -> T;
|
||||
|
||||
pure fn det() -> T;
|
||||
pure fn trace() -> T;
|
||||
pure fn det(&self) -> T;
|
||||
pure fn trace(&self) -> T;
|
||||
|
||||
pure fn invert() -> Option<self>;
|
||||
pure fn transpose() -> self;
|
||||
pure fn invert(&self) -> Option<self>;
|
||||
pure fn transpose(&self) -> self;
|
||||
|
||||
pure fn is_identity() -> bool;
|
||||
pure fn is_diagonal() -> bool;
|
||||
pure fn is_rotated() -> bool;
|
||||
pure fn is_invertible() -> bool;
|
||||
pure fn is_identity(&self) -> bool;
|
||||
pure fn is_diagonal(&self) -> bool;
|
||||
pure fn is_rotated(&self) -> bool;
|
||||
pure fn is_invertible(&self) -> bool;
|
||||
}
|
||||
|
||||
/// A 2 x 2 square matrix with numeric elements
|
||||
pub trait NumericMatrix2x2<T, ColRow2>: Matrix2x2<T, ColRow2>,
|
||||
NumericMatrixNxN<T, ColRow2> {
|
||||
|
||||
pure fn to_mat3() -> Mat3<T>;
|
||||
pure fn to_mat4() -> Mat4<T>;
|
||||
pure fn to_mat3(&self) -> Mat3<T>;
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
/// A 3 x 3 square matrix with numeric elements
|
||||
pub trait NumericMatrix3x3<T, ColRow3>: Matrix3x3<T, ColRow3>,
|
||||
NumericMatrixNxN<T, ColRow3> {
|
||||
pure fn to_mat4() -> Mat4<T>;
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
/// A 4 x 4 square matrix with numeric elements
|
||||
|
@ -172,16 +172,16 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
|
|||
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cols() -> uint { 2 }
|
||||
static pure fn cols() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 2 }
|
||||
static pure fn rows() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn col(i: uint) -> Vec2<T> { self[i] }
|
||||
pure fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(i: uint) -> Vec2<T> {
|
||||
pure fn row(&self, i: uint) -> Vec2<T> {
|
||||
Vec2::new(self[0][i],
|
||||
self[1][i])
|
||||
}
|
||||
|
@ -195,14 +195,14 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat2<T>: MatrixNxN<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric() -> bool {
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[1][0].default_eq(&self[0][1])
|
||||
}
|
||||
|
@ -221,25 +221,25 @@ pub impl<T:Copy Num NumCast> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Mat2<T> {
|
||||
pure fn mul_t(&self, value: T) -> Mat2<T> {
|
||||
Mat2::from_cols(self[0].mul_t(value),
|
||||
self[1].mul_t(value))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(other: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn mul_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self.row(0).dot(other),
|
||||
self.row(1).dot(other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(other: &Mat2<T>) -> Mat2<T> {
|
||||
pure fn add_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
Mat2::from_cols(self[0].add_v(&other[0]),
|
||||
self[1].add_v(&other[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(other: &Mat2<T>) -> Mat2<T> {
|
||||
pure fn sub_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
Mat2::from_cols(self[0].sub_v(&other[0]),
|
||||
self[1].sub_v(&other[1]))
|
||||
}
|
||||
|
@ -253,25 +253,25 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(other: &Mat2<T>) -> Mat2<T> {
|
||||
pure fn mul_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
Mat2::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)),
|
||||
self.row(0).dot(&other.col(1)), self.row(1).dot(&other.col(1)))
|
||||
}
|
||||
|
||||
pure fn dot(other: &Mat2<T>) -> T {
|
||||
other.transpose().mul_m(&self).trace()
|
||||
pure fn dot(&self, other: &Mat2<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn det() -> T {
|
||||
pure fn det(&self) -> T {
|
||||
self[0][0] * self[1][1] - self[1][0] * self[0][1]
|
||||
}
|
||||
|
||||
pure fn trace() -> T {
|
||||
pure fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn invert() -> Option<Mat2<T>> {
|
||||
pure fn invert(&self) -> Option<Mat2<T>> {
|
||||
let _0 = cast(0);
|
||||
let d = self.det();
|
||||
if d.default_eq(&_0) {
|
||||
|
@ -283,30 +283,30 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose() -> Mat2<T> {
|
||||
pure fn transpose(&self) -> Mat2<T> {
|
||||
Mat2::new(self[0][0], self[1][0],
|
||||
self[0][1], self[1][1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
pure fn is_identity(&self) -> bool {
|
||||
self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal() -> bool {
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
self[0][1].default_eq(&_0) &&
|
||||
self[1][0].default_eq(&_0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
!self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible() -> bool {
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
!self.det().default_eq(&_0)
|
||||
}
|
||||
|
@ -314,13 +314,13 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
|
||||
pub impl<T:Copy NumCast> Mat2<T>: NumericMatrix2x2<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn to_mat3() -> Mat3<T> {
|
||||
Mat3::from_Mat2(&self)
|
||||
pure fn to_mat3(&self) -> Mat3<T> {
|
||||
Mat3::from_Mat2(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_mat4() -> Mat4<T> {
|
||||
Mat4::from_Mat2(&self)
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
Mat4::from_Mat2(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,16 +406,16 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
|
|||
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cols() -> uint { 3 }
|
||||
static pure fn cols() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 3 }
|
||||
static pure fn rows() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn col(i: uint) -> Vec3<T> { self[i] }
|
||||
pure fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(i: uint) -> Vec3<T> {
|
||||
pure fn row(&self, i: uint) -> Vec3<T> {
|
||||
Vec3::new(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i])
|
||||
|
@ -430,14 +430,14 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat3<T>: MatrixNxN<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric() -> bool {
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
|
||||
|
@ -463,28 +463,28 @@ pub impl<T:Copy Num NumCast> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Mat3<T> {
|
||||
pure fn mul_t(&self, value: T) -> Mat3<T> {
|
||||
Mat3::from_cols(self[0].mul_t(value),
|
||||
self[1].mul_t(value),
|
||||
self[2].mul_t(value))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(other: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn mul_v(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new(self.row(0).dot(other),
|
||||
self.row(1).dot(other),
|
||||
self.row(2).dot(other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(other: &Mat3<T>) -> Mat3<T> {
|
||||
pure fn add_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
Mat3::from_cols(self[0].add_v(&other[0]),
|
||||
self[1].add_v(&other[1]),
|
||||
self[2].add_v(&other[2]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(other: &Mat3<T>) -> Mat3<T> {
|
||||
pure fn sub_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
Mat3::from_cols(self[0].sub_v(&other[0]),
|
||||
self[1].sub_v(&other[1]),
|
||||
self[2].sub_v(&other[2]))
|
||||
|
@ -500,26 +500,26 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(other: &Mat3<T>) -> Mat3<T> {
|
||||
pure fn mul_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
Mat3::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), self.row(2).dot(&other.col(0)),
|
||||
self.row(0).dot(&other.col(1)), self.row(1).dot(&other.col(1)), self.row(2).dot(&other.col(1)),
|
||||
self.row(0).dot(&other.col(2)), self.row(1).dot(&other.col(2)), self.row(2).dot(&other.col(2)))
|
||||
}
|
||||
|
||||
pure fn dot(other: &Mat3<T>) -> T {
|
||||
other.transpose().mul_m(&self).trace()
|
||||
pure fn dot(&self, other: &Mat3<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn det() -> T {
|
||||
pure fn det(&self) -> T {
|
||||
self.col(0).dot(&self.col(1).cross(&self.col(2)))
|
||||
}
|
||||
|
||||
pure fn trace() -> T {
|
||||
pure fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1] + self[2][2]
|
||||
}
|
||||
|
||||
// #[inline(always)]
|
||||
pure fn invert() -> Option<Mat3<T>> {
|
||||
pure fn invert(&self) -> Option<Mat3<T>> {
|
||||
let d = self.det();
|
||||
let _0 = cast(0);
|
||||
if d.default_eq(&_0) {
|
||||
|
@ -533,19 +533,19 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose() -> Mat3<T> {
|
||||
pure fn transpose(&self) -> Mat3<T> {
|
||||
Mat3::new(self[0][0], self[1][0], self[2][0],
|
||||
self[0][1], self[1][1], self[2][1],
|
||||
self[0][2], self[1][2], self[2][2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
pure fn is_identity(&self) -> bool {
|
||||
self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal() -> bool {
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
self[0][1].default_eq(&_0) &&
|
||||
self[0][2].default_eq(&_0) &&
|
||||
|
@ -558,12 +558,12 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
!self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible() -> bool {
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
!self.det().default_eq(&_0)
|
||||
}
|
||||
|
@ -571,8 +571,8 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
|
||||
pub impl<T:Copy NumCast> Mat3<T>: NumericMatrix3x3<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn to_mat4() -> Mat4<T> {
|
||||
Mat4::from_Mat3(&self)
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
Mat4::from_Mat3(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -719,16 +719,16 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
|
|||
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cols() -> uint { 4 }
|
||||
static pure fn cols() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn rows() -> uint { 4 }
|
||||
static pure fn rows() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn col(i: uint) -> Vec4<T> { self[i] }
|
||||
pure fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(i: uint) -> Vec4<T> {
|
||||
pure fn row(&self, i: uint) -> Vec4<T> {
|
||||
Vec4::new(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i],
|
||||
|
@ -744,14 +744,14 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat4<T>: MatrixNxN<T, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric() -> bool {
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
self[0][3].default_eq(&self[3][0]) &&
|
||||
|
@ -785,7 +785,7 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Mat4<T> {
|
||||
pure fn mul_t(&self, value: T) -> Mat4<T> {
|
||||
Mat4::from_cols(self[0].mul_t(value),
|
||||
self[1].mul_t(value),
|
||||
self[2].mul_t(value),
|
||||
|
@ -793,7 +793,7 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(other: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn mul_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self.row(0).dot(other),
|
||||
self.row(1).dot(other),
|
||||
self.row(2).dot(other),
|
||||
|
@ -801,7 +801,7 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(other: &Mat4<T>) -> Mat4<T> {
|
||||
pure fn add_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
Mat4::from_cols(self[0].add_v(&other[0]),
|
||||
self[1].add_v(&other[1]),
|
||||
self[2].add_v(&other[2]),
|
||||
|
@ -809,7 +809,7 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(other: &Mat4<T>) -> Mat4<T> {
|
||||
pure fn sub_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
Mat4::from_cols(self[0].sub_v(&other[0]),
|
||||
self[1].sub_v(&other[1]),
|
||||
self[2].sub_v(&other[2]),
|
||||
|
@ -827,7 +827,7 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(other: &Mat4<T>) -> Mat4<T> {
|
||||
pure fn mul_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
// Surprisingly when building with optimisation turned on this is actually
|
||||
// faster than writing out the matrix multiplication in expanded form.
|
||||
// If you don't believe me, see ./test/performance/matrix_mul.rs
|
||||
|
@ -837,11 +837,11 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
self.row(0).dot(&other.col(3)), self.row(1).dot(&other.col(3)), self.row(2).dot(&other.col(3)), self.row(3).dot(&other.col(3)))
|
||||
}
|
||||
|
||||
pure fn dot(other: &Mat4<T>) -> T {
|
||||
other.transpose().mul_m(&self).trace()
|
||||
pure fn dot(&self, other: &Mat4<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn det() -> T {
|
||||
pure fn det(&self) -> T {
|
||||
self[0][0]*Mat3::new(self[1][1], self[2][1], self[3][1],
|
||||
self[1][2], self[2][2], self[3][2],
|
||||
self[1][3], self[2][3], self[3][3]).det() -
|
||||
|
@ -856,11 +856,11 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
self[0][3], self[1][3], self[2][3]).det()
|
||||
}
|
||||
|
||||
pure fn trace() -> T {
|
||||
pure fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1] + self[2][2] + self[3][3]
|
||||
}
|
||||
|
||||
pure fn invert() -> Option<Mat4<T>> {
|
||||
pure fn invert(&self) -> Option<Mat4<T>> {
|
||||
let d = self.det();
|
||||
let _0 = cast(0);
|
||||
if d.default_eq(&_0) {
|
||||
|
@ -869,7 +869,7 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
|
||||
// Gauss Jordan Elimination with partial pivoting
|
||||
|
||||
let mut a = copy self;
|
||||
let mut a = *self;
|
||||
let mut inv: Mat4<T> = NumericMatrixNxN::identity();
|
||||
|
||||
// Find largest pivot column j among rows j..3
|
||||
|
@ -917,7 +917,7 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose() -> Mat4<T> {
|
||||
pure fn transpose(&self) -> Mat4<T> {
|
||||
Mat4::new(self[0][0], self[1][0], self[2][0], self[3][0],
|
||||
self[0][1], self[1][1], self[2][1], self[3][1],
|
||||
self[0][2], self[1][2], self[2][2], self[3][2],
|
||||
|
@ -925,12 +925,12 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
pure fn is_identity(&self) -> bool {
|
||||
self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal() -> bool {
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
self[0][1].default_eq(&_0) &&
|
||||
self[0][2].default_eq(&_0) &&
|
||||
|
@ -950,12 +950,12 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
!self.default_eq(&NumericMatrixNxN::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible() -> bool {
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
let _0 = cast(0);
|
||||
!self.det().default_eq(&_0)
|
||||
}
|
||||
|
|
64
src/quat.rs
64
src/quat.rs
|
@ -23,28 +23,28 @@ pub trait Quaternion<T>: Dimensional<T>, Eq, DefaultEq, Neg<self> {
|
|||
static pure fn identity() -> self;
|
||||
static pure fn zero() -> self;
|
||||
|
||||
pure fn mul_t(value: T) -> self;
|
||||
pure fn div_t(value: T) -> self;
|
||||
pure fn mul_t(&self, value: T) -> self;
|
||||
pure fn div_t(&self, value: T) -> self;
|
||||
|
||||
pure fn mul_v(vec: &Vec3<T>) -> Vec3<T>;
|
||||
pure fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T>;
|
||||
|
||||
pure fn add_q(other: &self) -> self;
|
||||
pure fn sub_q(other: &self) -> self;
|
||||
pure fn mul_q(other: &self) -> self;
|
||||
pure fn add_q(&self, other: &self) -> self;
|
||||
pure fn sub_q(&self, other: &self) -> self;
|
||||
pure fn mul_q(&self, other: &self) -> self;
|
||||
|
||||
pure fn dot(other: &self) -> T;
|
||||
pure fn dot(&self, other: &self) -> T;
|
||||
|
||||
pure fn conjugate() -> self;
|
||||
pure fn inverse() -> self;
|
||||
pure fn length2() -> T;
|
||||
pure fn length() -> T;
|
||||
pure fn normalize() -> self;
|
||||
pure fn conjugate(&self) -> self;
|
||||
pure fn inverse(&self) -> self;
|
||||
pure fn length2(&self) -> T;
|
||||
pure fn length(&self) -> T;
|
||||
pure fn normalize(&self) -> self;
|
||||
|
||||
pure fn nlerp(other: &self, amount: T) -> self;
|
||||
pure fn slerp(other: &self, amount: T) -> self;
|
||||
pure fn nlerp(&self, other: &self, amount: T) -> self;
|
||||
pure fn slerp(&self, other: &self, amount: T) -> self;
|
||||
|
||||
pure fn to_mat3() -> Mat3<T>;
|
||||
pure fn to_mat4() -> Mat4<T>;
|
||||
pure fn to_mat3(&self) -> Mat3<T>;
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
pub trait ToQuat<T> {
|
||||
|
@ -104,7 +104,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Quat<T> {
|
||||
pure fn mul_t(&self, value: T) -> Quat<T> {
|
||||
Quat::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -112,7 +112,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(value: T) -> Quat<T> {
|
||||
pure fn div_t(&self, value: T) -> Quat<T> {
|
||||
Quat::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -120,13 +120,13 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(vec: &Vec3<T>) -> Vec3<T> {
|
||||
pure 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(cast(2)).add_v(vec)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_q(other: &Quat<T>) -> Quat<T> {
|
||||
pure fn add_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -134,7 +134,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_q(other: &Quat<T>) -> Quat<T> {
|
||||
pure fn sub_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -142,7 +142,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_q(other: &Quat<T>) -> Quat<T> {
|
||||
pure fn mul_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self.s * other.s - self.v.x * other.v.x - self.v.y * other.v.y - self.v.z * other.v.z,
|
||||
self.s * other.v.x + self.v.x * other.s + self.v.y * other.v.z - self.v.z * other.v.y,
|
||||
self.s * other.v.y + self.v.y * other.s + self.v.z * other.v.x - self.v.x * other.v.z,
|
||||
|
@ -150,39 +150,39 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Quat<T>) -> T {
|
||||
pure fn dot(&self, other: &Quat<T>) -> T {
|
||||
self.s * other.s + self.v.dot(&other.v)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn conjugate() -> Quat<T> {
|
||||
pure fn conjugate(&self) -> Quat<T> {
|
||||
Quat::from_sv(self.s, -self.v)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn inverse() -> Quat<T> {
|
||||
pure fn inverse(&self) -> Quat<T> {
|
||||
self.conjugate().div_t(self.length2())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length2() -> T {
|
||||
pure fn length2(&self) -> T {
|
||||
self.s * self.s + self.v.length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length() -> T {
|
||||
pure fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Quat<T> {
|
||||
pure fn normalize(&self) -> Quat<T> {
|
||||
let mut n: T = cast(1);
|
||||
n /= self.length();
|
||||
return self.mul_t(n);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn nlerp(other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
pure fn nlerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
let _1: T = cast(1);
|
||||
self.mul_t(_1 - amount).add_q(&other.mul_t(amount)).normalize()
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
* also provides a good explanation.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn slerp(other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
pure fn slerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
let dot: T = cast(self.dot(other));
|
||||
|
||||
// if quaternions are close together use `nlerp`
|
||||
|
@ -222,7 +222,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_mat3() -> Mat3<T> {
|
||||
pure fn to_mat3(&self) -> Mat3<T> {
|
||||
let x2 = self.v.x + self.v.x;
|
||||
let y2 = self.v.y + self.v.y;
|
||||
let z2 = self.v.z + self.v.z;
|
||||
|
@ -247,7 +247,7 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_mat4() -> Mat4<T> {
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
self.to_mat3().to_mat4()
|
||||
}
|
||||
}
|
||||
|
|
122
src/vec.rs
122
src/vec.rs
|
@ -41,13 +41,13 @@ pub trait NumericVector<T>: Vector<T>, Neg<self>{
|
|||
static pure fn identity() -> self;
|
||||
static pure fn zero() -> self;
|
||||
|
||||
pure fn mul_t(value: T) -> self;
|
||||
pure fn div_t(value: T) -> self;
|
||||
pure fn mul_t(&self, value: T) -> self;
|
||||
pure fn div_t(&self, value: T) -> self;
|
||||
|
||||
pure fn add_v(other: &self) -> self;
|
||||
pure fn sub_v(other: &self) -> self;
|
||||
pure fn add_v(&self, other: &self) -> self;
|
||||
pure fn sub_v(&self, other: &self) -> self;
|
||||
|
||||
pure fn dot(other: &self) -> T;
|
||||
pure fn dot(&self, other: &self) -> T;
|
||||
}
|
||||
|
||||
/// A 2-dimensional vector with numeric components
|
||||
|
@ -61,7 +61,7 @@ pub trait NumericVector3<T>: NumericVector<T> {
|
|||
// static pure fn unit_x() -> self;
|
||||
// static pure fn unit_y() -> self;
|
||||
// static pure fn unit_z() -> self;
|
||||
pure fn cross(other: &self) -> self;
|
||||
pure fn cross(&self, other: &self) -> self;
|
||||
}
|
||||
|
||||
/// A 4-dimensional vector with numeric components
|
||||
|
@ -76,12 +76,12 @@ pub trait NumericVector4<T>: NumericVector<T> {
|
|||
/// A vector with geometric properties
|
||||
///
|
||||
pub trait GeometricVector<T>: NumericVector<T> {
|
||||
pure fn length2() -> T;
|
||||
pure fn length() -> T;
|
||||
pure fn distance2(other: &self) -> T;
|
||||
pure fn distance(other: &self) -> T;
|
||||
pure fn normalize() -> self;
|
||||
pure fn lerp(other: &self, amount: T) -> self;
|
||||
pure fn length2(&self) -> T;
|
||||
pure fn length(&self) -> T;
|
||||
pure fn distance2(&self, other: &self) -> T;
|
||||
pure fn distance(&self, other: &self) -> T;
|
||||
pure fn normalize(&self) -> self;
|
||||
pure fn lerp(&self, other: &self, amount: T) -> self;
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ pub impl<T:Copy> Vec2<T>: Vector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
ptr::to_unsafe_ptr(&self[0])
|
||||
}
|
||||
}
|
||||
|
@ -145,31 +145,31 @@ pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Vec2<T> {
|
||||
pure fn mul_t(&self, value: T) -> Vec2<T> {
|
||||
Vec2::new(self[0] * value,
|
||||
self[1] * value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(value: T) -> Vec2<T> {
|
||||
pure fn div_t(&self, value: T) -> Vec2<T> {
|
||||
Vec2::new(self[0] / value,
|
||||
self[1] / value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(other: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn add_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0] + other[0],
|
||||
self[1] + other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(other: &Vec2<T>) -> Vec2<T> {
|
||||
pure fn sub_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vec2::new(self[0] - other[0],
|
||||
self[1] - other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Vec2<T>) -> T {
|
||||
pure fn dot(&self, other: &Vec2<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1]
|
||||
}
|
||||
|
@ -177,35 +177,35 @@ pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> {
|
|||
|
||||
pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2() -> T {
|
||||
self.dot(&self)
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length() -> T {
|
||||
pure fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec2<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
pure fn distance2(&self, other: &Vec2<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec2<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
pure fn distance(&self, other: &Vec2<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec2<T> {
|
||||
pure fn normalize(&self) -> Vec2<T> {
|
||||
let mut n: T = cast(1);
|
||||
n /= self.length();
|
||||
return self.mul_t(n);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(other: &Vec2<T>, amount: T) -> Vec2<T> {
|
||||
self.add_v(&other.sub_v(&self).mul_t(amount))
|
||||
pure fn lerp(&self, other: &Vec2<T>, amount: T) -> Vec2<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ pub impl<T:Copy> Vec3<T>: Vector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
to_unsafe_ptr(&self[0])
|
||||
}
|
||||
}
|
||||
|
@ -301,35 +301,35 @@ pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Vec3<T> {
|
||||
pure fn mul_t(&self, value: T) -> Vec3<T> {
|
||||
Vec3::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(value: T) -> Vec3<T> {
|
||||
pure fn div_t(&self, value: T) -> Vec3<T> {
|
||||
Vec3::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(other: &Vec3<T>) -> Vec3<T>{
|
||||
pure fn add_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vec3::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(other: &Vec3<T>) -> Vec3<T>{
|
||||
pure fn sub_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vec3::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Vec3<T>) -> T {
|
||||
pure fn dot(&self, other: &Vec3<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2]
|
||||
|
@ -338,7 +338,7 @@ pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> {
|
|||
|
||||
pub impl<T:Copy Num> Vec3<T>: NumericVector3<T> {
|
||||
#[inline(always)]
|
||||
pure fn cross(other: &Vec3<T>) -> Vec3<T> {
|
||||
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new((self[1] * other[2]) - (self[2] * other[1]),
|
||||
(self[2] * other[0]) - (self[0] * other[2]),
|
||||
(self[0] * other[1]) - (self[1] * other[0]))
|
||||
|
@ -347,35 +347,35 @@ pub impl<T:Copy Num> Vec3<T>: NumericVector3<T> {
|
|||
|
||||
pub impl<T:Copy Num NumCast Exp> Vec3<T>: GeometricVector<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2() -> T {
|
||||
self.dot(&self)
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length() -> T {
|
||||
pure fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec3<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
pure fn distance2(&self, other: &Vec3<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec3<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
pure fn distance(&self, other: &Vec3<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec3<T> {
|
||||
pure fn normalize(&self) -> Vec3<T> {
|
||||
let mut n: T = cast(1);
|
||||
n /= self.length();
|
||||
return self.mul_t(n);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(other: &Vec3<T>, amount: T) -> Vec3<T> {
|
||||
self.add_v(&other.sub_v(&self).mul_t(amount))
|
||||
pure fn lerp(&self, other: &Vec3<T>, amount: T) -> Vec3<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ pub impl<T:Copy> Vec4<T>: Vector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr() -> *T {
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
to_unsafe_ptr(&self[0])
|
||||
}
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Vec4<T> {
|
||||
pure fn mul_t(&self, value: T) -> Vec4<T> {
|
||||
Vec4::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -483,7 +483,7 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(value: T) -> Vec4<T> {
|
||||
pure fn div_t(&self, value: T) -> Vec4<T> {
|
||||
Vec4::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -491,7 +491,7 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(other: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn add_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -499,7 +499,7 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(other: &Vec4<T>) -> Vec4<T> {
|
||||
pure fn sub_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -507,7 +507,7 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Vec4<T>) -> T {
|
||||
pure fn dot(&self, other: &Vec4<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2] +
|
||||
|
@ -517,35 +517,35 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
|
|||
|
||||
pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2() -> T {
|
||||
self.dot(&self)
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length() -> T {
|
||||
pure fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(other: &Vec4<T>) -> T {
|
||||
other.sub_v(&self).length2()
|
||||
pure fn distance2(&self, other: &Vec4<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(other: &Vec4<T>) -> T {
|
||||
other.distance2(&self).sqrt()
|
||||
pure fn distance(&self, other: &Vec4<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Vec4<T> {
|
||||
pure fn normalize(&self) -> Vec4<T> {
|
||||
let mut n: T = cast(1);
|
||||
n /= self.length();
|
||||
return self.mul_t(n);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(other: &Vec4<T>, amount: T) -> Vec4<T> {
|
||||
self.add_v(&other.sub_v(&self).mul_t(amount))
|
||||
pure fn lerp(&self, other: &Vec4<T>, amount: T) -> Vec4<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue