Use GLSL nomenclature

This commit is contained in:
Brendan Zabarauskas 2012-11-05 17:40:31 +10:00
parent d2cf5c9da3
commit c3344b5a6f
3 changed files with 26 additions and 26 deletions

View file

@ -33,8 +33,8 @@ pub trait Quaternion<T> {
pure fn conjugate() -> self;
pure fn inverse() -> self;
pure fn magnitude2() -> T;
pure fn magnitude() -> T;
pure fn length2() -> T;
pure fn length() -> T;
pure fn to_Mat3() -> Mat3<T>;
pure fn to_Mat4() -> Mat4<T>;
@ -128,12 +128,12 @@ pub impl<T:Copy Num NumCast Sqrt FuzzyEq> Quat<T>: Quaternion<T> {
#[inline(always)]
pure fn inverse() -> Quat<T> {
let mut n: T = from_int(1);
n /= self.magnitude2();
n /= self.length2();
self.conjugate().mul_t(n)
}
#[inline(always)]
pure fn magnitude2() -> T {
pure fn length2() -> T {
self.w * self.w +
self.x * self.x +
self.y * self.y +
@ -141,8 +141,8 @@ pub impl<T:Copy Num NumCast Sqrt FuzzyEq> Quat<T>: Quaternion<T> {
}
#[inline(always)]
pure fn magnitude() -> T {
self.magnitude2().sqrt()
pure fn length() -> T {
self.length2().sqrt()
}
#[inline(always)]

View file

@ -40,8 +40,8 @@ fn test_Vec2() {
// fuzzy_eq
// eq
assert a.magnitude2().fuzzy_eq(&5f);
assert a.magnitude().fuzzy_eq(&2.236068f);
assert a.length2().fuzzy_eq(&5f);
assert a.length().fuzzy_eq(&2.236068f);
let c = Vec2::new(-2.0f, -1.0f);
let d = Vec2::new( 1.0f, 0.0f);
@ -111,8 +111,8 @@ fn test_Vec3() {
// fuzzy_eq
// eq
assert a.magnitude2().fuzzy_eq(&14f);
assert a.magnitude().fuzzy_eq(&3.74165738677f);
assert a.length2().fuzzy_eq(&14f);
assert a.length().fuzzy_eq(&3.74165738677f);
let c = Vec3::new(-2.0f, -1.0f, 1.0f);
let d = Vec3::new( 1.0f, 0.0f, 0.5f);
@ -185,8 +185,8 @@ fn test_Vec4() {
// fuzzy_eq
// eq
assert a.magnitude2().fuzzy_eq(&30f);
assert a.magnitude().fuzzy_eq(&5.477226f);
assert a.length2().fuzzy_eq(&30f);
assert a.length().fuzzy_eq(&5.477226f);
let c = Vec4::new(-2.0f, -1.0f, 1.0f, 2.0f);
let d = Vec4::new( 1.0f, 0.0f, 0.5f, 1.0f);

View file

@ -48,8 +48,8 @@ pub trait NumericVector<T> {
}
pub trait GeometricVector<T> {
pure fn magnitude2() -> T;
pure fn magnitude() -> T;
pure fn length2() -> T;
pure fn length() -> T;
pure fn normalize() -> self;
pure fn lerp(other: &self, value: T) -> self;
}
@ -175,20 +175,20 @@ pub impl<T:Copy Num> Vec2<T>: NumericVector<T> {
pub impl<T:Copy Num Sqrt> Vec2<T>: GeometricVector<T> {
#[inline(always)]
pure fn magnitude2() -> T {
pure fn length2() -> T {
self[0] * self[0] +
self[1] * self[1]
}
#[inline(always)]
pure fn magnitude() -> T {
self.magnitude2().sqrt()
pure fn length() -> T {
self.length2().sqrt()
}
#[inline(always)]
pure fn normalize() -> Vec2<T> {
let mut n: T = from_int(1);
n /= self.magnitude();
n /= self.length();
return self.mul_t(n);
}
@ -410,21 +410,21 @@ pub impl<T:Copy Num> Vec3<T>: NumericVector<T> {
pub impl<T:Copy Num Sqrt> Vec3<T>: GeometricVector<T> {
#[inline(always)]
pure fn magnitude2() -> T {
pure fn length2() -> T {
self[0] * self[0] +
self[1] * self[1] +
self[2] * self[2]
}
#[inline(always)]
pure fn magnitude() -> T {
self.magnitude2().sqrt()
pure fn length() -> T {
self.length2().sqrt()
}
#[inline(always)]
pure fn normalize() -> Vec3<T> {
let mut n: T = from_int(1);
n /= self.magnitude();
n /= self.length();
return self.mul_t(n);
}
@ -656,7 +656,7 @@ pub impl<T:Copy Num> Vec4<T>: NumericVector<T> {
pub impl<T:Copy Num Sqrt> Vec4<T>: GeometricVector<T> {
#[inline(always)]
pure fn magnitude2() -> T {
pure fn length2() -> T {
self[0] * self[0] +
self[1] * self[1] +
self[2] * self[2] +
@ -664,14 +664,14 @@ pub impl<T:Copy Num Sqrt> Vec4<T>: GeometricVector<T> {
}
#[inline(always)]
pure fn magnitude() -> T {
self.magnitude2().sqrt()
pure fn length() -> T {
self.length2().sqrt()
}
#[inline(always)]
pure fn normalize() -> Vec4<T> {
let mut n: T = from_int(1);
n /= self.magnitude();
n /= self.length();
return self.mul_t(n);
}