Change inline attributes to inline(always)

This commit is contained in:
Brendan Zabarauskas 2012-10-30 12:55:20 +10:00
parent d8f669da75
commit 819c092321
5 changed files with 197 additions and 194 deletions

View file

@ -8,7 +8,7 @@ pub trait ExactEq {
// //
// Min // Min
// //
#[inline] #[inline(always)]
pure fn min<T:Copy Ord>(a: &T, b: &T) -> T { pure fn min<T:Copy Ord>(a: &T, b: &T) -> T {
if a < b { *a } if a < b { *a }
else { *b } else { *b }
@ -17,14 +17,15 @@ pure fn min<T:Copy Ord>(a: &T, b: &T) -> T {
// //
// Max // Max
// //
#[inline] #[inline(always)]
pure fn max<T:Copy Ord>(a: &T, b: &T) -> T { pure fn max<T:Copy Ord>(a: &T, b: &T) -> T {
if a > b { *a } if a > b { *a }
else { *b } else { *b }
} }
// #[inline(always)]
// pure fn abs<T:Copy Num Ord>(x: &T) -> T { // pure fn abs<T:Copy Num Ord>(x: &T) -> T {
// if x >= num::from_int(0) { *x } else {-x } // if x >= &from_int(0) { *x } else {-x }
// } // }
// //
@ -34,13 +35,13 @@ trait Abs {
pure fn abs() -> self; pure fn abs() -> self;
} }
#[inline] #[inline(always)]
pure fn abs<T: Abs>(x: &T) -> T { pure fn abs<T: Abs>(x: &T) -> T {
x.abs() x.abs()
} }
impl i8: Abs { impl i8: Abs {
#[inline] #[inline(always)]
pure fn abs() -> i8 { pure fn abs() -> i8 {
if self >= 0 { self } if self >= 0 { self }
else {-self } else {-self }
@ -48,7 +49,7 @@ impl i8: Abs {
} }
impl i16: Abs { impl i16: Abs {
#[inline] #[inline(always)]
pure fn abs() -> i16 { pure fn abs() -> i16 {
if self >= 0 { self } if self >= 0 { self }
else {-self } else {-self }
@ -56,7 +57,7 @@ impl i16: Abs {
} }
impl i32: Abs { impl i32: Abs {
#[inline] #[inline(always)]
pure fn abs() -> i32 { pure fn abs() -> i32 {
if self >= 0 { self } if self >= 0 { self }
else {-self } else {-self }
@ -64,7 +65,7 @@ impl i32: Abs {
} }
impl i64: Abs { impl i64: Abs {
#[inline] #[inline(always)]
pure fn abs() -> i64 { pure fn abs() -> i64 {
if self >= 0 { self } if self >= 0 { self }
else {-self } else {-self }
@ -72,7 +73,7 @@ impl i64: Abs {
} }
impl int: Abs { impl int: Abs {
#[inline] #[inline(always)]
pure fn abs() -> int { pure fn abs() -> int {
if self >= 0 { self } if self >= 0 { self }
else {-self } else {-self }
@ -80,7 +81,7 @@ impl int: Abs {
} }
impl float: Abs { impl float: Abs {
#[inline] #[inline(always)]
pure fn abs() -> float { pure fn abs() -> float {
if self >= 0f { self } if self >= 0f { self }
else {-self } else {-self }
@ -88,7 +89,7 @@ impl float: Abs {
} }
impl f32: Abs { impl f32: Abs {
#[inline] #[inline(always)]
pure fn abs() -> f32 { pure fn abs() -> f32 {
if self >= 0f32 { self } if self >= 0f32 { self }
else {-self } else {-self }
@ -96,7 +97,7 @@ impl f32: Abs {
} }
impl f64: Abs { impl f64: Abs {
#[inline] #[inline(always)]
pure fn abs() -> f64 { pure fn abs() -> f64 {
if self >= 0f64 { self } if self >= 0f64 { self }
else {-self } else {-self }
@ -110,97 +111,97 @@ trait Sqrt {
pure fn sqrt() -> self; pure fn sqrt() -> self;
} }
#[inline] #[inline(always)]
pure fn sqrt<T: Sqrt>(x: T) -> T { pure fn sqrt<T: Sqrt>(x: T) -> T {
x.sqrt() x.sqrt()
} }
impl u8: Sqrt { impl u8: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> u8 { pure fn sqrt() -> u8 {
(self as float).sqrt() as u8 (self as float).sqrt() as u8
} }
} }
impl u16: Sqrt { impl u16: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> u16 { pure fn sqrt() -> u16 {
(self as float).sqrt() as u16 (self as float).sqrt() as u16
} }
} }
impl u32: Sqrt { impl u32: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> u32 { pure fn sqrt() -> u32 {
(self as float).sqrt() as u32 (self as float).sqrt() as u32
} }
} }
impl u64: Sqrt { impl u64: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> u64 { pure fn sqrt() -> u64 {
(self as float).sqrt() as u64 (self as float).sqrt() as u64
} }
} }
impl uint: Sqrt { impl uint: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> uint { pure fn sqrt() -> uint {
(self as float).sqrt() as uint (self as float).sqrt() as uint
} }
} }
impl i8: Sqrt { impl i8: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> i8 { pure fn sqrt() -> i8 {
(self as float).sqrt() as i8 (self as float).sqrt() as i8
} }
} }
impl i16: Sqrt { impl i16: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> i16 { pure fn sqrt() -> i16 {
(self as float).sqrt() as i16 (self as float).sqrt() as i16
} }
} }
impl i32: Sqrt { impl i32: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> i32 { pure fn sqrt() -> i32 {
(self as float).sqrt() as i32 (self as float).sqrt() as i32
} }
} }
impl i64: Sqrt { impl i64: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> i64 { pure fn sqrt() -> i64 {
(self as float).sqrt() as i64 (self as float).sqrt() as i64
} }
} }
impl int: Sqrt { impl int: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> int { pure fn sqrt() -> int {
(self as float).sqrt() as int (self as float).sqrt() as int
} }
} }
impl float: Sqrt { impl float: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> float { pure fn sqrt() -> float {
float::sqrt(self) float::sqrt(self)
} }
} }
impl f32: Sqrt { impl f32: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> f32 { pure fn sqrt() -> f32 {
f32::sqrt(self) f32::sqrt(self)
} }
} }
impl f64: Sqrt { impl f64: Sqrt {
#[inline] #[inline(always)]
pure fn sqrt() -> f64 { pure fn sqrt() -> f64 {
f64::sqrt(self) f64::sqrt(self)
} }

View file

@ -65,7 +65,7 @@ pub const mat2_identity :Mat2 = Mat2 { data: [ Vec2::unit_x,
// //
// Mat2 Constructor // Mat2 Constructor
// //
#[inline] #[inline(always)]
pub pure fn Mat2(m00:float, m01:float, pub pure fn Mat2(m00:float, m01:float,
m10:float, m11:float) -> Mat2 { m10:float, m11:float) -> Mat2 {
Mat2 { data: [ Vec2(m00, m01), Mat2 { data: [ Vec2(m00, m01),
@ -75,7 +75,7 @@ pub pure fn Mat2(m00:float, m01:float,
// //
// Construct Mat2 from column vectors // Construct Mat2 from column vectors
// //
#[inline] #[inline(always)]
pub pure fn Mat2_v(col0: &Vec2, col1: &Vec2) -> Mat2 { pub pure fn Mat2_v(col0: &Vec2, col1: &Vec2) -> Mat2 {
Mat2 { data: [ *col0, *col1 ] } Mat2 { data: [ *col0, *col1 ] }
} }
@ -91,51 +91,51 @@ pub mod Mat2 {
// Matrix2x2 Implementation // Matrix2x2 Implementation
// //
pub impl Mat2: Matrix<float, Vec2> { pub impl Mat2: Matrix<float, Vec2> {
#[inline] #[inline(always)]
pure fn rows() -> uint { 2 } pure fn rows() -> uint { 2 }
#[inline] #[inline(always)]
pure fn cols() -> uint { 2 } pure fn cols() -> uint { 2 }
#[inline] #[inline(always)]
pure fn is_col_major() -> bool { true } pure fn is_col_major() -> bool { true }
#[inline] #[inline(always)]
pure fn row(i: uint) -> Vec2 { pure fn row(i: uint) -> Vec2 {
Vec2(self[0][i], Vec2(self[0][i],
self[1][i]) self[1][i])
} }
#[inline] #[inline(always)]
pure fn col(i: uint) -> Vec2 { pure fn col(i: uint) -> Vec2 {
self.data[i] self.data[i]
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Mat2 { pure fn mul_f(value: float) -> Mat2 {
Mat2_v(&self[0].mul_f(value), Mat2_v(&self[0].mul_f(value),
&self[1].mul_f(value)) &self[1].mul_f(value))
} }
#[inline] #[inline(always)]
pure fn mul_v(other: &Vec2) -> Vec2 { pure fn mul_v(other: &Vec2) -> Vec2 {
Vec2(self[0][0]*other[0] + self[1][0]*other[1], Vec2(self[0][0]*other[0] + self[1][0]*other[1],
self[0][1]*other[0] + self[1][1]*other[1]) self[0][1]*other[0] + self[1][1]*other[1])
} }
#[inline] #[inline(always)]
pure fn add_m(other: &Mat2) -> Mat2 { pure fn add_m(other: &Mat2) -> Mat2 {
Mat2_v(&self[0].add_v(&other[0]), Mat2_v(&self[0].add_v(&other[0]),
&self[1].add_v(&other[1])) &self[1].add_v(&other[1]))
} }
#[inline] #[inline(always)]
pure fn sub_m(other: &Mat2) -> Mat2 { pure fn sub_m(other: &Mat2) -> Mat2 {
Mat2_v(&self[0].sub_v(&other[0]), Mat2_v(&self[0].sub_v(&other[0]),
&self[1].sub_v(&other[1])) &self[1].sub_v(&other[1]))
} }
#[inline] #[inline(always)]
pure fn mul_m(other: &Mat2) -> Mat2 { pure fn mul_m(other: &Mat2) -> Mat2 {
Mat2(self[0][0]*other[0][0] + self[1][0]*other[0][1], Mat2(self[0][0]*other[0][0] + self[1][0]*other[0][1],
self[0][1]*other[0][0] + self[1][1]*other[0][1], self[0][1]*other[0][0] + self[1][1]*other[0][1],
@ -145,66 +145,66 @@ pub impl Mat2: Matrix<float, Vec2> {
} }
// TODO - inversion is harrrd D: // TODO - inversion is harrrd D:
// #[inline] // #[inline(always)]
// pure fn invert(other: &Mat2) -> Mat2 {} // pure fn invert(other: &Mat2) -> Mat2 {}
#[inline] #[inline(always)]
pure fn transpose() -> Mat2 { pure fn transpose() -> Mat2 {
Mat2(self[0][0], self[1][0], Mat2(self[0][0], self[1][0],
self[0][1], self[1][1]) self[0][1], self[1][1])
} }
#[inline] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat2::identity) self.fuzzy_eq(&Mat2::identity)
} }
#[inline] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].fuzzy_eq(&self[1][0]) &&
self[1][0].fuzzy_eq(&self[0][1]) self[1][0].fuzzy_eq(&self[0][1])
} }
#[inline] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
self[0][1].fuzzy_eq(&0f) && self[0][1].fuzzy_eq(&0f) &&
self[1][0].fuzzy_eq(&0f) self[1][0].fuzzy_eq(&0f)
} }
#[inline] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat2::identity) !self.fuzzy_eq(&Mat2::identity)
} }
} }
pub impl Mat2: Index<uint, Vec2> { pub impl Mat2: Index<uint, Vec2> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> Vec2 { pure fn index(i: uint) -> Vec2 {
self.data[i] self.data[i]
} }
} }
pub impl Mat2: Neg<Mat2> { pub impl Mat2: Neg<Mat2> {
#[inline] #[inline(always)]
pure fn neg() -> Mat2 { pure fn neg() -> Mat2 {
Mat2_v(&-self[0], &-self[1]) Mat2_v(&-self[0], &-self[1])
} }
} }
pub impl Mat2: Eq { pub impl Mat2: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Mat2) -> bool { pure fn eq(other: &Mat2) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Mat2) -> bool { pure fn ne(other: &Mat2) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Mat2: ExactEq { impl Mat2: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Mat2) -> bool { pure fn exact_eq(other: &Mat2) -> bool {
self[0].exact_eq(&other[0]) && self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) self[1].exact_eq(&other[1])
@ -212,7 +212,7 @@ impl Mat2: ExactEq {
} }
pub impl Mat2: FuzzyEq { pub impl Mat2: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Mat2) -> bool { pure fn fuzzy_eq(other: &Mat2) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) self[1].fuzzy_eq(&other[1])
@ -232,7 +232,7 @@ pub struct Mat3 { data:[Vec3 * 3] }
// //
// Mat3 Constructor // Mat3 Constructor
// //
#[inline] #[inline(always)]
pub pure fn Mat3(m00:float, m01:float, m02:float, pub pure fn Mat3(m00:float, m01:float, m02:float,
m10:float, m11:float, m12:float, m10:float, m11:float, m12:float,
m20:float, m21:float, m22:float) -> Mat3 { m20:float, m21:float, m22:float) -> Mat3 {
@ -244,7 +244,7 @@ pub pure fn Mat3(m00:float, m01:float, m02:float,
// //
// Construct Mat3 from column vectors // Construct Mat3 from column vectors
// //
#[inline] #[inline(always)]
pub pure fn Mat3_v(col0: &Vec3, col1: &Vec3, col2: &Vec3) -> Mat3 { pub pure fn Mat3_v(col0: &Vec3, col1: &Vec3, col2: &Vec3) -> Mat3 {
Mat3 { data: [ *col0, *col1, *col2 ] } Mat3 { data: [ *col0, *col1, *col2 ] }
} }
@ -262,56 +262,56 @@ pub mod Mat3 {
// Matrix3x3 Implementation // Matrix3x3 Implementation
// //
pub impl Mat3: Matrix<float, Vec3> { pub impl Mat3: Matrix<float, Vec3> {
#[inline] #[inline(always)]
pure fn rows() -> uint { 3 } pure fn rows() -> uint { 3 }
#[inline] #[inline(always)]
pure fn cols() -> uint { 3 } pure fn cols() -> uint { 3 }
#[inline] #[inline(always)]
pure fn is_col_major() -> bool { true } pure fn is_col_major() -> bool { true }
#[inline] #[inline(always)]
pure fn row(i: uint) -> Vec3 { pure fn row(i: uint) -> Vec3 {
Vec3(self[0][i], Vec3(self[0][i],
self[1][i], self[1][i],
self[2][i]) self[2][i])
} }
#[inline] #[inline(always)]
pure fn col(i: uint) -> Vec3 { pure fn col(i: uint) -> Vec3 {
self.data[i] self.data[i]
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Mat3 { pure fn mul_f(value: float) -> Mat3 {
Mat3_v(&self[0].mul_f(value), Mat3_v(&self[0].mul_f(value),
&self[1].mul_f(value), &self[1].mul_f(value),
&self[2].mul_f(value)) &self[2].mul_f(value))
} }
#[inline] #[inline(always)]
pure fn mul_v(other: &Vec3) -> Vec3 { pure fn mul_v(other: &Vec3) -> Vec3 {
Vec3(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2], Vec3(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2],
self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2], self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2],
self[0][2]*other[0] + self[1][2]*other[1] + self[2][2]*other[2]) self[0][2]*other[0] + self[1][2]*other[1] + self[2][2]*other[2])
} }
#[inline] #[inline(always)]
pure fn add_m(other: &Mat3) -> Mat3 { pure fn add_m(other: &Mat3) -> Mat3 {
Mat3_v(&self[0].add_v(&other[0]), Mat3_v(&self[0].add_v(&other[0]),
&self[1].add_v(&other[1]), &self[1].add_v(&other[1]),
&self[2].add_v(&other[2])) &self[2].add_v(&other[2]))
} }
#[inline] #[inline(always)]
pure fn sub_m(other: &Mat3) -> Mat3 { pure fn sub_m(other: &Mat3) -> Mat3 {
Mat3_v(&self[0].sub_v(&other[0]), Mat3_v(&self[0].sub_v(&other[0]),
&self[1].sub_v(&other[1]), &self[1].sub_v(&other[1]),
&self[2].sub_v(&other[2])) &self[2].sub_v(&other[2]))
} }
#[inline] #[inline(always)]
pure fn mul_m(other: &Mat3) -> Mat3 { pure fn mul_m(other: &Mat3) -> Mat3 {
Mat3(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2], Mat3(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2],
self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2], self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2],
@ -327,22 +327,22 @@ pub impl Mat3: Matrix<float, Vec3> {
} }
// TODO - inversion is harrrd D: // TODO - inversion is harrrd D:
// #[inline] // #[inline(always)]
// pure fn invert(other: &Mat3) -> Mat3 {} // pure fn invert(other: &Mat3) -> Mat3 {}
#[inline] #[inline(always)]
pure fn transpose() -> Mat3 { pure fn transpose() -> Mat3 {
Mat3(self[0][0], self[1][0], self[2][0], Mat3(self[0][0], self[1][0], self[2][0],
self[0][1], self[1][1], self[2][1], self[0][1], self[1][1], self[2][1],
self[0][2], self[1][2], self[2][2]) self[0][2], self[1][2], self[2][2])
} }
#[inline] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat3::identity) self.fuzzy_eq(&Mat3::identity)
} }
#[inline] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].fuzzy_eq(&self[1][0]) &&
self[0][2].fuzzy_eq(&self[2][0]) && self[0][2].fuzzy_eq(&self[2][0]) &&
@ -354,7 +354,7 @@ pub impl Mat3: Matrix<float, Vec3> {
self[2][1].fuzzy_eq(&self[1][2]) self[2][1].fuzzy_eq(&self[1][2])
} }
#[inline] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
self[0][1].fuzzy_eq(&0f) && self[0][1].fuzzy_eq(&0f) &&
self[0][2].fuzzy_eq(&0f) && self[0][2].fuzzy_eq(&0f) &&
@ -366,21 +366,21 @@ pub impl Mat3: Matrix<float, Vec3> {
self[2][1].fuzzy_eq(&0f) self[2][1].fuzzy_eq(&0f)
} }
#[inline] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat3::identity) !self.fuzzy_eq(&Mat3::identity)
} }
} }
pub impl Mat3: Matrix3<Vec3> { pub impl Mat3: Matrix3<Vec3> {
#[inline] #[inline(always)]
pure fn scale(vec: &Vec3) -> Mat3 { pure fn scale(vec: &Vec3) -> Mat3 {
self.mul_m(&Mat3(vec.x, 0f, 0f, self.mul_m(&Mat3(vec.x, 0f, 0f,
0f, vec.y, 0f, 0f, vec.y, 0f,
0f, 0f, vec.z)) 0f, 0f, vec.z))
} }
#[inline] #[inline(always)]
pure fn to_Mat4() -> Mat4 { pure fn to_Mat4() -> Mat4 {
Mat4(self[0][0], self[0][1], self[0][2], 0f, Mat4(self[0][0], self[0][1], self[0][2], 0f,
self[1][0], self[1][1], self[1][2], 0f, self[1][0], self[1][1], self[1][2], 0f,
@ -430,33 +430,33 @@ pub impl Mat3: Matrix3<Vec3> {
} }
pub impl Mat3: Index<uint, Vec3> { pub impl Mat3: Index<uint, Vec3> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> Vec3 { pure fn index(i: uint) -> Vec3 {
self.data[i] self.data[i]
} }
} }
pub impl Mat3: Neg<Mat3> { pub impl Mat3: Neg<Mat3> {
#[inline] #[inline(always)]
pure fn neg() -> Mat3 { pure fn neg() -> Mat3 {
Mat3_v(&-self[0], &-self[1], &-self[2]) Mat3_v(&-self[0], &-self[1], &-self[2])
} }
} }
pub impl Mat3: Eq { pub impl Mat3: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Mat3) -> bool { pure fn eq(other: &Mat3) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Mat3) -> bool { pure fn ne(other: &Mat3) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Mat3: ExactEq { impl Mat3: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Mat3) -> bool { pure fn exact_eq(other: &Mat3) -> bool {
self[0].exact_eq(&other[0]) && self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) && self[1].exact_eq(&other[1]) &&
@ -465,7 +465,7 @@ impl Mat3: ExactEq {
} }
pub impl Mat3: FuzzyEq { pub impl Mat3: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Mat3) -> bool { pure fn fuzzy_eq(other: &Mat3) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) && self[1].fuzzy_eq(&other[1]) &&
@ -486,7 +486,7 @@ pub struct Mat4 { data:[Vec4 * 4] }
// //
// Mat4 Constructor // Mat4 Constructor
// //
#[inline] #[inline(always)]
pub pure fn Mat4(m00:float, m01:float, m02:float, m03:float, pub pure fn Mat4(m00:float, m01:float, m02:float, m03:float,
m10:float, m11:float, m12:float, m13:float, m10:float, m11:float, m12:float, m13:float,
m20:float, m21:float, m22:float, m23:float, m20:float, m21:float, m22:float, m23:float,
@ -500,7 +500,7 @@ pub pure fn Mat4(m00:float, m01:float, m02:float, m03:float,
// //
// Construct Mat4 from column vectors // Construct Mat4 from column vectors
// //
#[inline] #[inline(always)]
pub pure fn Mat4_v(col0: &Vec4, col1: &Vec4, col2: &Vec4, col3: &Vec4) -> Mat4 { pub pure fn Mat4_v(col0: &Vec4, col1: &Vec4, col2: &Vec4, col3: &Vec4) -> Mat4 {
Mat4 { data: [ *col0, *col1, *col2, *col3 ] } Mat4 { data: [ *col0, *col1, *col2, *col3 ] }
} }
@ -520,16 +520,16 @@ pub mod Mat4 {
// Matrix4x4 Implementation // Matrix4x4 Implementation
// //
pub impl Mat4: Matrix<float, Vec4> { pub impl Mat4: Matrix<float, Vec4> {
#[inline] #[inline(always)]
pure fn rows() -> uint { 4 } pure fn rows() -> uint { 4 }
#[inline] #[inline(always)]
pure fn cols() -> uint { 4 } pure fn cols() -> uint { 4 }
#[inline] #[inline(always)]
pure fn is_col_major() -> bool { true } pure fn is_col_major() -> bool { true }
#[inline] #[inline(always)]
pure fn row(i: uint) -> Vec4 { pure fn row(i: uint) -> Vec4 {
Vec4(self[0][i], Vec4(self[0][i],
self[1][i], self[1][i],
@ -537,12 +537,12 @@ pub impl Mat4: Matrix<float, Vec4> {
self[3][i]) self[3][i])
} }
#[inline] #[inline(always)]
pure fn col(i: uint) -> Vec4 { pure fn col(i: uint) -> Vec4 {
self.data[i] self.data[i]
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Mat4 { pure fn mul_f(value: float) -> Mat4 {
Mat4_v(&self[0].mul_f(value), Mat4_v(&self[0].mul_f(value),
&self[1].mul_f(value), &self[1].mul_f(value),
@ -550,7 +550,7 @@ pub impl Mat4: Matrix<float, Vec4> {
&self[3].mul_f(value)) &self[3].mul_f(value))
} }
#[inline] #[inline(always)]
pure fn mul_v(other: &Vec4) -> Vec4 { pure fn mul_v(other: &Vec4) -> Vec4 {
Vec4(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2] + self[3][0]*other[3], Vec4(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2] + self[3][0]*other[3],
self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2] + self[3][1]*other[3], self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2] + self[3][1]*other[3],
@ -558,7 +558,7 @@ pub impl Mat4: Matrix<float, Vec4> {
self[0][3]*other[0] + self[1][3]*other[1] + self[2][3]*other[2] + self[3][3]*other[3]) self[0][3]*other[0] + self[1][3]*other[1] + self[2][3]*other[2] + self[3][3]*other[3])
} }
#[inline] #[inline(always)]
pure fn add_m(other: &Mat4) -> Mat4 { pure fn add_m(other: &Mat4) -> Mat4 {
Mat4_v(&self[0].add_v(&other[0]), Mat4_v(&self[0].add_v(&other[0]),
&self[1].add_v(&other[1]), &self[1].add_v(&other[1]),
@ -566,7 +566,7 @@ pub impl Mat4: Matrix<float, Vec4> {
&self[3].add_v(&other[3])) &self[3].add_v(&other[3]))
} }
#[inline] #[inline(always)]
pure fn sub_m(other: &Mat4) -> Mat4 { pure fn sub_m(other: &Mat4) -> Mat4 {
Mat4_v(&self[0].sub_v(&other[0]), Mat4_v(&self[0].sub_v(&other[0]),
&self[1].sub_v(&other[1]), &self[1].sub_v(&other[1]),
@ -574,7 +574,7 @@ pub impl Mat4: Matrix<float, Vec4> {
&self[3].sub_v(&other[3])) &self[3].sub_v(&other[3]))
} }
#[inline] #[inline(always)]
pure fn mul_m(other: &Mat4) -> Mat4 { pure fn mul_m(other: &Mat4) -> Mat4 {
Mat4(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2] + self[3][0]*other[0][3], Mat4(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2] + self[3][0]*other[0][3],
self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2] + self[3][1]*other[0][3], self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2] + self[3][1]*other[0][3],
@ -598,10 +598,10 @@ pub impl Mat4: Matrix<float, Vec4> {
} }
// TODO - inversion is harrrd D: // TODO - inversion is harrrd D:
// #[inline] // #[inline(always)]
// pure fn invert(other: &Mat4) -> Mat4 {} // pure fn invert(other: &Mat4) -> Mat4 {}
#[inline] #[inline(always)]
pure fn transpose() -> Mat4 { pure fn transpose() -> Mat4 {
Mat4(self[0][0], self[1][0], self[2][0], self[3][0], Mat4(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][1], self[1][1], self[2][1], self[3][1],
@ -609,12 +609,12 @@ pub impl Mat4: Matrix<float, Vec4> {
self[0][3], self[1][3], self[2][3], self[3][3]) self[0][3], self[1][3], self[2][3], self[3][3])
} }
#[inline] #[inline(always)]
pure fn is_identity() -> bool { pure fn is_identity() -> bool {
self.fuzzy_eq(&Mat4::identity) self.fuzzy_eq(&Mat4::identity)
} }
#[inline] #[inline(always)]
pure fn is_symmetric() -> bool { pure fn is_symmetric() -> bool {
self[0][1].fuzzy_eq(&self[1][0]) && self[0][1].fuzzy_eq(&self[1][0]) &&
self[0][2].fuzzy_eq(&self[2][0]) && self[0][2].fuzzy_eq(&self[2][0]) &&
@ -633,7 +633,7 @@ pub impl Mat4: Matrix<float, Vec4> {
self[3][2].fuzzy_eq(&self[2][3]) self[3][2].fuzzy_eq(&self[2][3])
} }
#[inline] #[inline(always)]
pure fn is_diagonal() -> bool { pure fn is_diagonal() -> bool {
self[0][1].fuzzy_eq(&0f) && self[0][1].fuzzy_eq(&0f) &&
self[0][2].fuzzy_eq(&0f) && self[0][2].fuzzy_eq(&0f) &&
@ -652,14 +652,14 @@ pub impl Mat4: Matrix<float, Vec4> {
self[3][2].fuzzy_eq(&0f) self[3][2].fuzzy_eq(&0f)
} }
#[inline] #[inline(always)]
pure fn is_rotated() -> bool { pure fn is_rotated() -> bool {
!self.fuzzy_eq(&Mat4::identity) !self.fuzzy_eq(&Mat4::identity)
} }
} }
pub impl Mat4: Matrix4<Vec3, Vec4> { pub impl Mat4: Matrix4<Vec3, Vec4> {
#[inline] #[inline(always)]
pure fn scale(vec: &Vec3) -> Mat4 { pure fn scale(vec: &Vec3) -> Mat4 {
self.mul_m(&Mat4(vec.x, 0f, 0f, 0f, self.mul_m(&Mat4(vec.x, 0f, 0f, 0f,
0f, vec.y, 0f, 0f, 0f, vec.y, 0f, 0f,
@ -667,7 +667,7 @@ pub impl Mat4: Matrix4<Vec3, Vec4> {
0f, 0f, 0f, 1f)) 0f, 0f, 0f, 1f))
} }
#[inline] #[inline(always)]
pure fn translate(vec: &Vec3) -> Mat4 { pure fn translate(vec: &Vec3) -> Mat4 {
Mat4_v(&self[0], Mat4_v(&self[0],
&self[1], &self[1],
@ -680,33 +680,33 @@ pub impl Mat4: Matrix4<Vec3, Vec4> {
} }
pub impl Mat4: Index<uint, Vec4> { pub impl Mat4: Index<uint, Vec4> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> Vec4 { pure fn index(i: uint) -> Vec4 {
self.data[i] self.data[i]
} }
} }
pub impl Mat4: Neg<Mat4> { pub impl Mat4: Neg<Mat4> {
#[inline] #[inline(always)]
pure fn neg() -> Mat4 { pure fn neg() -> Mat4 {
Mat4_v(&-self[0], &-self[1], &-self[2], &-self[3]) Mat4_v(&-self[0], &-self[1], &-self[2], &-self[3])
} }
} }
pub impl Mat4: Eq { pub impl Mat4: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Mat4) -> bool { pure fn eq(other: &Mat4) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Mat4) -> bool { pure fn ne(other: &Mat4) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Mat4: ExactEq { impl Mat4: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Mat4) -> bool { pure fn exact_eq(other: &Mat4) -> bool {
self[0].exact_eq(&other[0]) && self[0].exact_eq(&other[0]) &&
self[1].exact_eq(&other[1]) && self[1].exact_eq(&other[1]) &&
@ -716,7 +716,7 @@ impl Mat4: ExactEq {
} }
pub impl Mat4: FuzzyEq { pub impl Mat4: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Mat4) -> bool { pure fn fuzzy_eq(other: &Mat4) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) && self[1].fuzzy_eq(&other[1]) &&

View file

@ -8,6 +8,7 @@ use matrix::Mat4;
// fov is in degrees // fov is in degrees
// http://www.opengl.org/wiki/GluPerspective_code // http://www.opengl.org/wiki/GluPerspective_code
// //
#[inline(always)]
pure fn perspective(fovy:float, aspectRatio:float, near:float, far:float) -> Mat4 { pure fn perspective(fovy:float, aspectRatio:float, near:float, far:float) -> Mat4 {
let ymax = near * tan(fovy * pi / 360f); let ymax = near * tan(fovy * pi / 360f);
let xmax = ymax * aspectRatio; let xmax = ymax * aspectRatio;
@ -21,6 +22,7 @@ pure fn perspective(fovy:float, aspectRatio:float, near:float, far:float) -> Mat
// //
// TODO: double check algorithm // TODO: double check algorithm
// //
#[inline(always)]
pure fn frustum(left:float, right:float, bottom:float, top:float, near:float, far:float) -> Mat4 { pure fn frustum(left:float, right:float, bottom:float, top:float, near:float, far:float) -> Mat4 {
let m00 = (2f * near) / (right - left); let m00 = (2f * near) / (right - left);
let m01 = 0f; let m01 = 0f;

View file

@ -44,7 +44,7 @@ pub struct Quat { w: float, x: float, y: float, z: float }
// //
// Quat Constructor // Quat Constructor
// //
#[inline] #[inline(always)]
pub pure fn Quat(w: float, x: float, y: float, z: float) -> Quat { pub pure fn Quat(w: float, x: float, y: float, z: float) -> Quat {
Quat { w: w, x: x, y: y, z: z } Quat { w: w, x: x, y: y, z: z }
} }
@ -58,10 +58,10 @@ pub mod Quat {
// Quaternion Implementation // Quaternion Implementation
// //
pub impl Quat: Quaternion<float> { pub impl Quat: Quaternion<float> {
#[inline] #[inline(always)]
pure fn dim() -> uint { 4 } pure fn dim() -> uint { 4 }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Quat { pure fn mul_f(value: float) -> Quat {
Quat(self[0] * value, Quat(self[0] * value,
self[1] * value, self[1] * value,
@ -69,7 +69,7 @@ pub impl Quat: Quaternion<float> {
self[3] * value) self[3] * value)
} }
#[inline] #[inline(always)]
pure fn div_f(value: float) -> Quat { pure fn div_f(value: float) -> Quat {
Quat(self[0] / value, Quat(self[0] / value,
self[1] / value, self[1] / value,
@ -77,7 +77,7 @@ pub impl Quat: Quaternion<float> {
self[3] / value) self[3] / value)
} }
#[inline] #[inline(always)]
pure fn add_q(other: &Quat) -> Quat{ pure fn add_q(other: &Quat) -> Quat{
Quat(self[0] + other[0], Quat(self[0] + other[0],
self[1] + other[1], self[1] + other[1],
@ -85,7 +85,7 @@ pub impl Quat: Quaternion<float> {
self[3] + other[3]) self[3] + other[3])
} }
#[inline] #[inline(always)]
pure fn sub_q(other: &Quat) -> Quat{ pure fn sub_q(other: &Quat) -> Quat{
Quat(self[0] - other[0], Quat(self[0] - other[0],
self[1] - other[1], self[1] - other[1],
@ -93,7 +93,7 @@ pub impl Quat: Quaternion<float> {
self[3] - other[3]) self[3] - other[3])
} }
#[inline] #[inline(always)]
pure fn mul_q(other: &Quat) -> Quat { pure fn mul_q(other: &Quat) -> Quat {
Quat(self.w * other.w - self.x * other.x - self.y * other.y - self.z * other.z, Quat(self.w * other.w - self.x * other.x - self.y * other.y - self.z * other.z,
self.w * other.x + self.x * other.w + self.y * other.z - self.z * other.y, self.w * other.x + self.x * other.w + self.y * other.z - self.z * other.y,
@ -101,17 +101,17 @@ pub impl Quat: Quaternion<float> {
self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x) self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x)
} }
#[inline] #[inline(always)]
pure fn conjugate() -> Quat { pure fn conjugate() -> Quat {
Quat(self.w, -self.x, -self.y, -self.z) Quat(self.w, -self.x, -self.y, -self.z)
} }
#[inline] #[inline(always)]
pure fn inverse() -> Quat { pure fn inverse() -> Quat {
self.conjugate().mul_f((1f / self.magnitude2())) self.conjugate().mul_f((1f / self.magnitude2()))
} }
#[inline] #[inline(always)]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self.w * self.w + self.w * self.w +
self.x * self.x + self.x * self.x +
@ -119,12 +119,12 @@ pub impl Quat: Quaternion<float> {
self.z * self.z self.z * self.z
} }
#[inline] #[inline(always)]
pure fn magnitude() -> float { pure fn magnitude() -> float {
self.magnitude2().sqrt() self.magnitude2().sqrt()
} }
#[inline] #[inline(always)]
pure fn to_Mat3() -> Mat3 { pure fn to_Mat3() -> Mat3 {
let x2 = self.x + self.x; let x2 = self.x + self.x;
let y2 = self.y + self.y; let y2 = self.y + self.y;
@ -147,14 +147,14 @@ pub impl Quat: Quaternion<float> {
xz2 - wy2, yz2 + wx2, 1f - xx2 - yy2); xz2 - wy2, yz2 + wx2, 1f - xx2 - yy2);
} }
#[inline] #[inline(always)]
pure fn to_Mat4() -> Mat4 { pure fn to_Mat4() -> Mat4 {
self.to_Mat3().to_Mat4() self.to_Mat3().to_Mat4()
} }
} }
pub impl Quat: Index<uint, float> { pub impl Quat: Index<uint, float> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> float { pure fn index(i: uint) -> float {
unsafe { unsafe {
do buf_as_slice( do buf_as_slice(
@ -165,26 +165,26 @@ pub impl Quat: Index<uint, float> {
} }
pub impl Quat: Neg<Quat> { pub impl Quat: Neg<Quat> {
#[inline] #[inline(always)]
pure fn neg() -> Quat { pure fn neg() -> Quat {
Quat(-self[0], -self[1], -self[2], -self[3]) Quat(-self[0], -self[1], -self[2], -self[3])
} }
} }
pub impl Quat: Eq { pub impl Quat: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Quat) -> bool { pure fn eq(other: &Quat) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Quat) -> bool { pure fn ne(other: &Quat) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Quat: ExactEq { impl Quat: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Quat) -> bool { pure fn exact_eq(other: &Quat) -> bool {
self[0] == other[0] && self[0] == other[0] &&
self[1] == other[1] && self[1] == other[1] &&
@ -194,7 +194,7 @@ impl Quat: ExactEq {
} }
pub impl Quat: FuzzyEq { pub impl Quat: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Quat) -> bool { pure fn fuzzy_eq(other: &Quat) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) && self[1].fuzzy_eq(&other[1]) &&

View file

@ -51,7 +51,7 @@ pub struct Vec2 { x: float, y: float }
// //
// Constructor // Constructor
// //
#[inline] #[inline(always)]
pub pure fn Vec2(x: float, y: float) -> Vec2 { pub pure fn Vec2(x: float, y: float) -> Vec2 {
Vec2 { x: x, y: y } Vec2 { x: x, y: y }
} }
@ -64,91 +64,91 @@ pub mod Vec2 {
} }
pub impl Vec2: Vector<float> { pub impl Vec2: Vector<float> {
#[inline] #[inline(always)]
static pure fn dim() -> uint { 2 } static pure fn dim() -> uint { 2 }
#[inline] #[inline(always)]
pure fn add_f(value: float) -> Vec2 { pure fn add_f(value: float) -> Vec2 {
Vec2(self[0] + value, Vec2(self[0] + value,
self[1] + value) self[1] + value)
} }
#[inline] #[inline(always)]
pure fn sub_f(value: float) -> Vec2 { pure fn sub_f(value: float) -> Vec2 {
Vec2(self[0] - value, Vec2(self[0] - value,
self[1] - value) self[1] - value)
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Vec2 { pure fn mul_f(value: float) -> Vec2 {
Vec2(self[0] * value, Vec2(self[0] * value,
self[1] * value) self[1] * value)
} }
#[inline] #[inline(always)]
pure fn div_f(value: float) -> Vec2 { pure fn div_f(value: float) -> Vec2 {
Vec2(self[0] / value, Vec2(self[0] / value,
self[1] / value) self[1] / value)
} }
#[inline] #[inline(always)]
pure fn add_v(other: &Vec2) -> Vec2{ pure fn add_v(other: &Vec2) -> Vec2{
Vec2(self[0] + other[0], Vec2(self[0] + other[0],
self[1] + other[1]) self[1] + other[1])
} }
#[inline] #[inline(always)]
pure fn sub_v(other: &Vec2) -> Vec2{ pure fn sub_v(other: &Vec2) -> Vec2{
Vec2(self[0] - other[0], Vec2(self[0] - other[0],
self[1] - other[1]) self[1] - other[1])
} }
#[inline] #[inline(always)]
pure fn dot(other: &Vec2) -> float { pure fn dot(other: &Vec2) -> float {
self[0] * other[0] + self[0] * other[0] +
self[1] * other[1] self[1] * other[1]
} }
#[inline] #[inline(always)]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
self[1] * self[1] self[1] * self[1]
} }
#[inline] #[inline(always)]
pure fn magnitude() -> float { pure fn magnitude() -> float {
self.magnitude2().sqrt() self.magnitude2().sqrt()
} }
#[inline] #[inline(always)]
pure fn normalize() -> Vec2 { pure fn normalize() -> Vec2 {
let n = 1f / self.magnitude(); let n = 1f / self.magnitude();
return self.mul_f(n); return self.mul_f(n);
} }
#[inline] #[inline(always)]
pure fn lerp(other: &Vec2, value: float) -> Vec2 { pure fn lerp(other: &Vec2, value: float) -> Vec2 {
self.add_v(&other.sub_v(&self).mul_f(value)) self.add_v(&other.sub_v(&self).mul_f(value))
} }
#[inline] #[inline(always)]
pure fn min(other: &Vec2) -> Vec2 { pure fn min(other: &Vec2) -> Vec2 {
Vec2(min(&self[0], &other[0]), Vec2(min(&self[0], &other[0]),
min(&self[1], &other[1])) min(&self[1], &other[1]))
} }
#[inline] #[inline(always)]
pure fn max(other: &Vec2) -> Vec2 { pure fn max(other: &Vec2) -> Vec2 {
Vec2(max(&self[0], &other[0]), Vec2(max(&self[0], &other[0]),
max(&self[1], &other[1])) max(&self[1], &other[1]))
} }
#[inline] static pure fn zero() -> Vec2 { Vec2(0f, 0f) } #[inline(always)] static pure fn zero() -> Vec2 { Vec2(0f, 0f) }
#[inline] static pure fn identity() -> Vec2 { Vec2(1f, 1f) } #[inline(always)] static pure fn identity() -> Vec2 { Vec2(1f, 1f) }
} }
pub impl Vec2: Index<uint, float> { pub impl Vec2: Index<uint, float> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> float { pure fn index(i: uint) -> float {
unsafe { unsafe {
do buf_as_slice( do buf_as_slice(
@ -159,7 +159,7 @@ pub impl Vec2: Index<uint, float> {
} }
pub impl Vec2: Abs { pub impl Vec2: Abs {
#[inline] #[inline(always)]
pure fn abs() -> Vec2 { pure fn abs() -> Vec2 {
Vec2(abs(&self[0]), Vec2(abs(&self[0]),
abs(&self[1])) abs(&self[1]))
@ -167,26 +167,26 @@ pub impl Vec2: Abs {
} }
pub impl Vec2: Neg<Vec2> { pub impl Vec2: Neg<Vec2> {
#[inline] #[inline(always)]
pure fn neg() -> Vec2 { pure fn neg() -> Vec2 {
Vec2(-self[0], -self[1]) Vec2(-self[0], -self[1])
} }
} }
pub impl Vec2: Eq { pub impl Vec2: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Vec2) -> bool { pure fn eq(other: &Vec2) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Vec2) -> bool { pure fn ne(other: &Vec2) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Vec2: ExactEq { impl Vec2: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Vec2) -> bool { pure fn exact_eq(other: &Vec2) -> bool {
self[0] == other[0] && self[0] == other[0] &&
self[1] == other[1] self[1] == other[1]
@ -194,7 +194,7 @@ impl Vec2: ExactEq {
} }
pub impl Vec2: FuzzyEq { pub impl Vec2: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Vec2) -> bool { pure fn fuzzy_eq(other: &Vec2) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) self[1].fuzzy_eq(&other[1])
@ -220,7 +220,7 @@ pub struct Vec3 { x: float, y: float, z: float }
// //
// Constructor // Constructor
// //
#[inline] #[inline(always)]
pub pure fn Vec3(x: float, y: float, z: float) -> Vec3 { pub pure fn Vec3(x: float, y: float, z: float) -> Vec3 {
Vec3 { x: x, y: y, z: z } Vec3 { x: x, y: y, z: z }
} }
@ -234,7 +234,7 @@ pub mod Vec3 {
} }
pub impl Vec3: Vector3<float> { pub impl Vec3: Vector3<float> {
#[inline] #[inline(always)]
fn cross(other: &Vec3) -> Vec3 { fn cross(other: &Vec3) -> Vec3 {
Vec3((self[1] * other[2]) - (self[2] * other[1]), Vec3((self[1] * other[2]) - (self[2] * other[1]),
(self[2] * other[0]) - (self[0] * other[2]), (self[2] * other[0]) - (self[0] * other[2]),
@ -243,101 +243,101 @@ pub impl Vec3: Vector3<float> {
} }
pub impl Vec3: Vector<float> { pub impl Vec3: Vector<float> {
#[inline] #[inline(always)]
static pure fn dim() -> uint { 3 } static pure fn dim() -> uint { 3 }
#[inline] #[inline(always)]
pure fn add_f(value: float) -> Vec3 { pure fn add_f(value: float) -> Vec3 {
Vec3(self[0] + value, Vec3(self[0] + value,
self[1] + value, self[1] + value,
self[2] + value) self[2] + value)
} }
#[inline] #[inline(always)]
pure fn sub_f(value: float) -> Vec3 { pure fn sub_f(value: float) -> Vec3 {
Vec3(self[0] - value, Vec3(self[0] - value,
self[1] - value, self[1] - value,
self[2] - value) self[2] - value)
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Vec3 { pure fn mul_f(value: float) -> Vec3 {
Vec3(self[0] * value, Vec3(self[0] * value,
self[1] * value, self[1] * value,
self[2] * value) self[2] * value)
} }
#[inline] #[inline(always)]
pure fn div_f(value: float) -> Vec3 { pure fn div_f(value: float) -> Vec3 {
Vec3(self[0] / value, Vec3(self[0] / value,
self[1] / value, self[1] / value,
self[2] / value) self[2] / value)
} }
#[inline] #[inline(always)]
pure fn add_v(other: &Vec3) -> Vec3{ pure fn add_v(other: &Vec3) -> Vec3{
Vec3(self[0] + other[0], Vec3(self[0] + other[0],
self[1] + other[1], self[1] + other[1],
self[2] + other[2]) self[2] + other[2])
} }
#[inline] #[inline(always)]
pure fn sub_v(other: &Vec3) -> Vec3{ pure fn sub_v(other: &Vec3) -> Vec3{
Vec3(self[0] - other[0], Vec3(self[0] - other[0],
self[1] - other[1], self[1] - other[1],
self[2] - other[2]) self[2] - other[2])
} }
#[inline] #[inline(always)]
pure fn dot(other: &Vec3) -> float { pure fn dot(other: &Vec3) -> float {
self[0] * other[0] + self[0] * other[0] +
self[1] * other[1] + self[1] * other[1] +
self[2] * other[2] self[2] * other[2]
} }
#[inline] #[inline(always)]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
self[1] * self[1] + self[1] * self[1] +
self[2] * self[2] self[2] * self[2]
} }
#[inline] #[inline(always)]
pure fn magnitude() -> float { pure fn magnitude() -> float {
self.magnitude2().sqrt() self.magnitude2().sqrt()
} }
#[inline] #[inline(always)]
pure fn normalize() -> Vec3 { pure fn normalize() -> Vec3 {
let n = 1f / self.magnitude(); let n = 1f / self.magnitude();
return self.mul_f(n); return self.mul_f(n);
} }
#[inline] #[inline(always)]
pure fn lerp(other: &Vec3, value: float) -> Vec3 { pure fn lerp(other: &Vec3, value: float) -> Vec3 {
self.add_v(&other.sub_v(&self).mul_f(value)) self.add_v(&other.sub_v(&self).mul_f(value))
} }
#[inline] #[inline(always)]
pure fn min(other: &Vec3) -> Vec3 { pure fn min(other: &Vec3) -> Vec3 {
Vec3(min(&self[0], &other[0]), Vec3(min(&self[0], &other[0]),
min(&self[1], &other[1]), min(&self[1], &other[1]),
min(&self[2], &other[2])) min(&self[2], &other[2]))
} }
#[inline] #[inline(always)]
pure fn max(other: &Vec3) -> Vec3 { pure fn max(other: &Vec3) -> Vec3 {
Vec3(max(&self[0], &other[0]), Vec3(max(&self[0], &other[0]),
max(&self[1], &other[1]), max(&self[1], &other[1]),
max(&self[2], &other[2])) max(&self[2], &other[2]))
} }
#[inline] static pure fn zero() -> Vec3 { Vec3(0f, 0f, 0f) } #[inline(always)] static pure fn zero() -> Vec3 { Vec3(0f, 0f, 0f) }
#[inline] static pure fn identity() -> Vec3 { Vec3(1f, 1f, 1f) } #[inline(always)] static pure fn identity() -> Vec3 { Vec3(1f, 1f, 1f) }
} }
pub impl Vec3: Index<uint, float> { pub impl Vec3: Index<uint, float> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> float { pure fn index(i: uint) -> float {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
transmute::<*Vec3, *float>( transmute::<*Vec3, *float>(
@ -347,7 +347,7 @@ pub impl Vec3: Index<uint, float> {
} }
pub impl Vec3: Abs { pub impl Vec3: Abs {
#[inline] #[inline(always)]
pure fn abs() -> Vec3 { pure fn abs() -> Vec3 {
Vec3(abs(&self[0]), Vec3(abs(&self[0]),
abs(&self[1]), abs(&self[1]),
@ -356,26 +356,26 @@ pub impl Vec3: Abs {
} }
pub impl Vec3: Neg<Vec3> { pub impl Vec3: Neg<Vec3> {
#[inline] #[inline(always)]
pure fn neg() -> Vec3 { pure fn neg() -> Vec3 {
Vec3(-self[0], -self[1], -self[2]) Vec3(-self[0], -self[1], -self[2])
} }
} }
pub impl Vec3: Eq { pub impl Vec3: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Vec3) -> bool { pure fn eq(other: &Vec3) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Vec3) -> bool { pure fn ne(other: &Vec3) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Vec3: ExactEq { impl Vec3: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Vec3) -> bool { pure fn exact_eq(other: &Vec3) -> bool {
self[0] == other[0] && self[0] == other[0] &&
self[1] == other[1] && self[1] == other[1] &&
@ -384,7 +384,7 @@ impl Vec3: ExactEq {
} }
pub impl Vec3: FuzzyEq { pub impl Vec3: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Vec3) -> bool { pure fn fuzzy_eq(other: &Vec3) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) && self[1].fuzzy_eq(&other[1]) &&
@ -420,16 +420,16 @@ pub mod Vec4 {
// //
// Constructor // Constructor
// //
#[inline] #[inline(always)]
pub pure fn Vec4(x: float, y: float, z: float, w: float) -> Vec4 { pub pure fn Vec4(x: float, y: float, z: float, w: float) -> Vec4 {
Vec4 { x: x, y: y, z: z, w: w } Vec4 { x: x, y: y, z: z, w: w }
} }
pub impl Vec4: Vector<float> { pub impl Vec4: Vector<float> {
#[inline] #[inline(always)]
static pure fn dim() -> uint { 4 } static pure fn dim() -> uint { 4 }
#[inline] #[inline(always)]
pure fn add_f(value: float) -> Vec4 { pure fn add_f(value: float) -> Vec4 {
Vec4(self[0] + value, Vec4(self[0] + value,
self[1] + value, self[1] + value,
@ -437,7 +437,7 @@ pub impl Vec4: Vector<float> {
self[3] + value) self[3] + value)
} }
#[inline] #[inline(always)]
pure fn sub_f(value: float) -> Vec4 { pure fn sub_f(value: float) -> Vec4 {
Vec4(self[0] - value, Vec4(self[0] - value,
self[1] - value, self[1] - value,
@ -445,7 +445,7 @@ pub impl Vec4: Vector<float> {
self[3] - value) self[3] - value)
} }
#[inline] #[inline(always)]
pure fn mul_f(value: float) -> Vec4 { pure fn mul_f(value: float) -> Vec4 {
Vec4(self[0] * value, Vec4(self[0] * value,
self[1] * value, self[1] * value,
@ -453,7 +453,7 @@ pub impl Vec4: Vector<float> {
self[3] * value) self[3] * value)
} }
#[inline] #[inline(always)]
pure fn div_f(value: float) -> Vec4 { pure fn div_f(value: float) -> Vec4 {
Vec4(self[0] / value, Vec4(self[0] / value,
self[1] / value, self[1] / value,
@ -461,7 +461,7 @@ pub impl Vec4: Vector<float> {
self[3] / value) self[3] / value)
} }
#[inline] #[inline(always)]
pure fn add_v(other: &Vec4) -> Vec4{ pure fn add_v(other: &Vec4) -> Vec4{
Vec4(self[0] + other[0], Vec4(self[0] + other[0],
self[1] + other[1], self[1] + other[1],
@ -469,7 +469,7 @@ pub impl Vec4: Vector<float> {
self[3] + other[3]) self[3] + other[3])
} }
#[inline] #[inline(always)]
pure fn sub_v(other: &Vec4) -> Vec4{ pure fn sub_v(other: &Vec4) -> Vec4{
Vec4(self[0] - other[0], Vec4(self[0] - other[0],
self[1] - other[1], self[1] - other[1],
@ -477,7 +477,7 @@ pub impl Vec4: Vector<float> {
self[3] - other[3]) self[3] - other[3])
} }
#[inline] #[inline(always)]
pure fn dot(other: &Vec4) -> float { pure fn dot(other: &Vec4) -> float {
self[0] * other[0] + self[0] * other[0] +
self[1] * other[1] + self[1] * other[1] +
@ -485,7 +485,7 @@ pub impl Vec4: Vector<float> {
self[3] * other[3] self[3] * other[3]
} }
#[inline] #[inline(always)]
pure fn magnitude2() -> float { pure fn magnitude2() -> float {
self[0] * self[0] + self[0] * self[0] +
self[1] * self[1] + self[1] * self[1] +
@ -493,23 +493,23 @@ pub impl Vec4: Vector<float> {
self[3] * self[3] self[3] * self[3]
} }
#[inline] #[inline(always)]
pure fn magnitude() -> float { pure fn magnitude() -> float {
self.magnitude2().sqrt() self.magnitude2().sqrt()
} }
#[inline] #[inline(always)]
pure fn normalize() -> Vec4 { pure fn normalize() -> Vec4 {
let n = 1f / self.magnitude(); let n = 1f / self.magnitude();
return self.mul_f(n); return self.mul_f(n);
} }
#[inline] #[inline(always)]
pure fn lerp(other: &Vec4, value: float) -> Vec4 { pure fn lerp(other: &Vec4, value: float) -> Vec4 {
self.add_v(&other.sub_v(&self).mul_f(value)) self.add_v(&other.sub_v(&self).mul_f(value))
} }
#[inline] #[inline(always)]
pure fn min(other: &Vec4) -> Vec4 { pure fn min(other: &Vec4) -> Vec4 {
Vec4(min(&self[0], &other[0]), Vec4(min(&self[0], &other[0]),
min(&self[1], &other[1]), min(&self[1], &other[1]),
@ -517,7 +517,7 @@ pub impl Vec4: Vector<float> {
min(&self[3], &other[3])) min(&self[3], &other[3]))
} }
#[inline] #[inline(always)]
pure fn max(other: &Vec4) -> Vec4 { pure fn max(other: &Vec4) -> Vec4 {
Vec4(max(&self[0], &other[0]), Vec4(max(&self[0], &other[0]),
max(&self[1], &other[1]), max(&self[1], &other[1]),
@ -525,12 +525,12 @@ pub impl Vec4: Vector<float> {
max(&self[3], &other[3])) max(&self[3], &other[3]))
} }
#[inline] static pure fn zero() -> Vec4 { Vec4(0f, 0f, 0f, 0f) } #[inline(always)] static pure fn zero() -> Vec4 { Vec4(0f, 0f, 0f, 0f) }
#[inline] static pure fn identity() -> Vec4 { Vec4(1f, 1f, 1f, 1f) } #[inline(always)] static pure fn identity() -> Vec4 { Vec4(1f, 1f, 1f, 1f) }
} }
pub impl Vec4: Index<uint, float> { pub impl Vec4: Index<uint, float> {
#[inline] #[inline(always)]
pure fn index(i: uint) -> float { pure fn index(i: uint) -> float {
unsafe { unsafe {
do buf_as_slice( do buf_as_slice(
@ -541,7 +541,7 @@ pub impl Vec4: Index<uint, float> {
} }
pub impl Vec4: Abs { pub impl Vec4: Abs {
#[inline] #[inline(always)]
pure fn abs() -> Vec4 { pure fn abs() -> Vec4 {
Vec4(abs(&self[0]), Vec4(abs(&self[0]),
abs(&self[1]), abs(&self[1]),
@ -551,26 +551,26 @@ pub impl Vec4: Abs {
} }
pub impl Vec4: Neg<Vec4> { pub impl Vec4: Neg<Vec4> {
#[inline] #[inline(always)]
pure fn neg() -> Vec4 { pure fn neg() -> Vec4 {
Vec4(-self[0], -self[1], -self[2], -self[3]) Vec4(-self[0], -self[1], -self[2], -self[3])
} }
} }
pub impl Vec4: Eq { pub impl Vec4: Eq {
#[inline] #[inline(always)]
pure fn eq(other: &Vec4) -> bool { pure fn eq(other: &Vec4) -> bool {
self.fuzzy_eq(other) self.fuzzy_eq(other)
} }
#[inline] #[inline(always)]
pure fn ne(other: &Vec4) -> bool { pure fn ne(other: &Vec4) -> bool {
!(self == *other) !(self == *other)
} }
} }
impl Vec4: ExactEq { impl Vec4: ExactEq {
#[inline] #[inline(always)]
pure fn exact_eq(other: &Vec4) -> bool { pure fn exact_eq(other: &Vec4) -> bool {
self[0] == other[0] && self[0] == other[0] &&
self[1] == other[1] && self[1] == other[1] &&
@ -580,7 +580,7 @@ impl Vec4: ExactEq {
} }
pub impl Vec4: FuzzyEq { pub impl Vec4: FuzzyEq {
#[inline] #[inline(always)]
pure fn fuzzy_eq(other: &Vec4) -> bool { pure fn fuzzy_eq(other: &Vec4) -> bool {
self[0].fuzzy_eq(&other[0]) && self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) && self[1].fuzzy_eq(&other[1]) &&