From 819c09232129775770388ff537c5c1c660bb6ca1 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 30 Oct 2012 12:55:20 +1000 Subject: [PATCH] Change inline attributes to inline(always) --- src/math.rs | 53 ++++++++-------- src/matrix.rs | 152 +++++++++++++++++++++++----------------------- src/projection.rs | 2 + src/quaternion.rs | 38 ++++++------ src/vector.rs | 146 ++++++++++++++++++++++---------------------- 5 files changed, 197 insertions(+), 194 deletions(-) diff --git a/src/math.rs b/src/math.rs index ecf6331..9f3c9a4 100644 --- a/src/math.rs +++ b/src/math.rs @@ -8,7 +8,7 @@ pub trait ExactEq { // // Min // -#[inline] +#[inline(always)] pure fn min(a: &T, b: &T) -> T { if a < b { *a } else { *b } @@ -17,14 +17,15 @@ pure fn min(a: &T, b: &T) -> T { // // Max // -#[inline] +#[inline(always)] pure fn max(a: &T, b: &T) -> T { if a > b { *a } else { *b } } +// #[inline(always)] // pure fn abs(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; } -#[inline] +#[inline(always)] pure fn abs(x: &T) -> T { x.abs() } impl i8: Abs { - #[inline] + #[inline(always)] pure fn abs() -> i8 { if self >= 0 { self } else {-self } @@ -48,7 +49,7 @@ impl i8: Abs { } impl i16: Abs { - #[inline] + #[inline(always)] pure fn abs() -> i16 { if self >= 0 { self } else {-self } @@ -56,7 +57,7 @@ impl i16: Abs { } impl i32: Abs { - #[inline] + #[inline(always)] pure fn abs() -> i32 { if self >= 0 { self } else {-self } @@ -64,7 +65,7 @@ impl i32: Abs { } impl i64: Abs { - #[inline] + #[inline(always)] pure fn abs() -> i64 { if self >= 0 { self } else {-self } @@ -72,7 +73,7 @@ impl i64: Abs { } impl int: Abs { - #[inline] + #[inline(always)] pure fn abs() -> int { if self >= 0 { self } else {-self } @@ -80,7 +81,7 @@ impl int: Abs { } impl float: Abs { - #[inline] + #[inline(always)] pure fn abs() -> float { if self >= 0f { self } else {-self } @@ -88,7 +89,7 @@ impl float: Abs { } impl f32: Abs { - #[inline] + #[inline(always)] pure fn abs() -> f32 { if self >= 0f32 { self } else {-self } @@ -96,7 +97,7 @@ impl f32: Abs { } impl f64: Abs { - #[inline] + #[inline(always)] pure fn abs() -> f64 { if self >= 0f64 { self } else {-self } @@ -110,97 +111,97 @@ trait Sqrt { pure fn sqrt() -> self; } -#[inline] +#[inline(always)] pure fn sqrt(x: T) -> T { x.sqrt() } impl u8: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> u8 { (self as float).sqrt() as u8 } } impl u16: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> u16 { (self as float).sqrt() as u16 } } impl u32: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> u32 { (self as float).sqrt() as u32 } } impl u64: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> u64 { (self as float).sqrt() as u64 } } impl uint: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> uint { (self as float).sqrt() as uint } } impl i8: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> i8 { (self as float).sqrt() as i8 } } impl i16: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> i16 { (self as float).sqrt() as i16 } } impl i32: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> i32 { (self as float).sqrt() as i32 } } impl i64: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> i64 { (self as float).sqrt() as i64 } } impl int: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> int { (self as float).sqrt() as int } } impl float: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> float { float::sqrt(self) } } impl f32: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> f32 { f32::sqrt(self) } } impl f64: Sqrt { - #[inline] + #[inline(always)] pure fn sqrt() -> f64 { f64::sqrt(self) } diff --git a/src/matrix.rs b/src/matrix.rs index f3cdece..952d639 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -65,7 +65,7 @@ pub const mat2_identity :Mat2 = Mat2 { data: [ Vec2::unit_x, // // Mat2 Constructor // -#[inline] +#[inline(always)] pub pure fn Mat2(m00:float, m01:float, m10:float, m11:float) -> Mat2 { Mat2 { data: [ Vec2(m00, m01), @@ -75,7 +75,7 @@ pub pure fn Mat2(m00:float, m01:float, // // Construct Mat2 from column vectors // -#[inline] +#[inline(always)] pub pure fn Mat2_v(col0: &Vec2, col1: &Vec2) -> Mat2 { Mat2 { data: [ *col0, *col1 ] } } @@ -91,51 +91,51 @@ pub mod Mat2 { // Matrix2x2 Implementation // pub impl Mat2: Matrix { - #[inline] + #[inline(always)] pure fn rows() -> uint { 2 } - #[inline] + #[inline(always)] pure fn cols() -> uint { 2 } - #[inline] + #[inline(always)] pure fn is_col_major() -> bool { true } - #[inline] + #[inline(always)] pure fn row(i: uint) -> Vec2 { Vec2(self[0][i], self[1][i]) } - #[inline] + #[inline(always)] pure fn col(i: uint) -> Vec2 { self.data[i] } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Mat2 { Mat2_v(&self[0].mul_f(value), &self[1].mul_f(value)) } - #[inline] + #[inline(always)] pure fn mul_v(other: &Vec2) -> Vec2 { Vec2(self[0][0]*other[0] + self[1][0]*other[1], self[0][1]*other[0] + self[1][1]*other[1]) } - #[inline] + #[inline(always)] pure fn add_m(other: &Mat2) -> Mat2 { Mat2_v(&self[0].add_v(&other[0]), &self[1].add_v(&other[1])) } - #[inline] + #[inline(always)] pure fn sub_m(other: &Mat2) -> Mat2 { Mat2_v(&self[0].sub_v(&other[0]), &self[1].sub_v(&other[1])) } - #[inline] + #[inline(always)] pure fn mul_m(other: &Mat2) -> Mat2 { 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], @@ -145,66 +145,66 @@ pub impl Mat2: Matrix { } // TODO - inversion is harrrd D: - // #[inline] + // #[inline(always)] // pure fn invert(other: &Mat2) -> Mat2 {} - #[inline] + #[inline(always)] pure fn transpose() -> Mat2 { Mat2(self[0][0], self[1][0], self[0][1], self[1][1]) } - #[inline] + #[inline(always)] pure fn is_identity() -> bool { self.fuzzy_eq(&Mat2::identity) } - #[inline] + #[inline(always)] pure fn is_symmetric() -> bool { self[0][1].fuzzy_eq(&self[1][0]) && self[1][0].fuzzy_eq(&self[0][1]) } - #[inline] + #[inline(always)] pure fn is_diagonal() -> bool { self[0][1].fuzzy_eq(&0f) && self[1][0].fuzzy_eq(&0f) } - #[inline] + #[inline(always)] pure fn is_rotated() -> bool { !self.fuzzy_eq(&Mat2::identity) } } pub impl Mat2: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> Vec2 { self.data[i] } } pub impl Mat2: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Mat2 { Mat2_v(&-self[0], &-self[1]) } } pub impl Mat2: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Mat2) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Mat2) -> bool { !(self == *other) } } impl Mat2: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Mat2) -> bool { self[0].exact_eq(&other[0]) && self[1].exact_eq(&other[1]) @@ -212,7 +212,7 @@ impl Mat2: ExactEq { } pub impl Mat2: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Mat2) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) @@ -232,7 +232,7 @@ pub struct Mat3 { data:[Vec3 * 3] } // // Mat3 Constructor // -#[inline] +#[inline(always)] pub pure fn Mat3(m00:float, m01:float, m02:float, m10:float, m11:float, m12:float, 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 // -#[inline] +#[inline(always)] pub pure fn Mat3_v(col0: &Vec3, col1: &Vec3, col2: &Vec3) -> Mat3 { Mat3 { data: [ *col0, *col1, *col2 ] } } @@ -262,56 +262,56 @@ pub mod Mat3 { // Matrix3x3 Implementation // pub impl Mat3: Matrix { - #[inline] + #[inline(always)] pure fn rows() -> uint { 3 } - #[inline] + #[inline(always)] pure fn cols() -> uint { 3 } - #[inline] + #[inline(always)] pure fn is_col_major() -> bool { true } - #[inline] + #[inline(always)] pure fn row(i: uint) -> Vec3 { Vec3(self[0][i], self[1][i], self[2][i]) } - #[inline] + #[inline(always)] pure fn col(i: uint) -> Vec3 { self.data[i] } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Mat3 { Mat3_v(&self[0].mul_f(value), &self[1].mul_f(value), &self[2].mul_f(value)) } - #[inline] + #[inline(always)] pure fn mul_v(other: &Vec3) -> Vec3 { 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][2]*other[0] + self[1][2]*other[1] + self[2][2]*other[2]) } - #[inline] + #[inline(always)] pure fn add_m(other: &Mat3) -> Mat3 { Mat3_v(&self[0].add_v(&other[0]), &self[1].add_v(&other[1]), &self[2].add_v(&other[2])) } - #[inline] + #[inline(always)] pure fn sub_m(other: &Mat3) -> Mat3 { Mat3_v(&self[0].sub_v(&other[0]), &self[1].sub_v(&other[1]), &self[2].sub_v(&other[2])) } - #[inline] + #[inline(always)] 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], 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 { } // TODO - inversion is harrrd D: - // #[inline] + // #[inline(always)] // pure fn invert(other: &Mat3) -> Mat3 {} - #[inline] + #[inline(always)] pure fn transpose() -> Mat3 { Mat3(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] + #[inline(always)] pure fn is_identity() -> bool { self.fuzzy_eq(&Mat3::identity) } - #[inline] + #[inline(always)] pure fn is_symmetric() -> bool { self[0][1].fuzzy_eq(&self[1][0]) && self[0][2].fuzzy_eq(&self[2][0]) && @@ -354,7 +354,7 @@ pub impl Mat3: Matrix { self[2][1].fuzzy_eq(&self[1][2]) } - #[inline] + #[inline(always)] pure fn is_diagonal() -> bool { self[0][1].fuzzy_eq(&0f) && self[0][2].fuzzy_eq(&0f) && @@ -366,21 +366,21 @@ pub impl Mat3: Matrix { self[2][1].fuzzy_eq(&0f) } - #[inline] + #[inline(always)] pure fn is_rotated() -> bool { !self.fuzzy_eq(&Mat3::identity) } } pub impl Mat3: Matrix3 { - #[inline] + #[inline(always)] pure fn scale(vec: &Vec3) -> Mat3 { self.mul_m(&Mat3(vec.x, 0f, 0f, 0f, vec.y, 0f, 0f, 0f, vec.z)) } - #[inline] + #[inline(always)] pure fn to_Mat4() -> Mat4 { Mat4(self[0][0], self[0][1], self[0][2], 0f, self[1][0], self[1][1], self[1][2], 0f, @@ -430,33 +430,33 @@ pub impl Mat3: Matrix3 { } pub impl Mat3: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> Vec3 { self.data[i] } } pub impl Mat3: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Mat3 { Mat3_v(&-self[0], &-self[1], &-self[2]) } } pub impl Mat3: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Mat3) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Mat3) -> bool { !(self == *other) } } impl Mat3: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Mat3) -> bool { self[0].exact_eq(&other[0]) && self[1].exact_eq(&other[1]) && @@ -465,7 +465,7 @@ impl Mat3: ExactEq { } pub impl Mat3: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Mat3) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) && @@ -486,7 +486,7 @@ pub struct Mat4 { data:[Vec4 * 4] } // // Mat4 Constructor // -#[inline] +#[inline(always)] pub pure fn Mat4(m00:float, m01:float, m02:float, m03:float, m10:float, m11:float, m12:float, m13: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 // -#[inline] +#[inline(always)] pub pure fn Mat4_v(col0: &Vec4, col1: &Vec4, col2: &Vec4, col3: &Vec4) -> Mat4 { Mat4 { data: [ *col0, *col1, *col2, *col3 ] } } @@ -520,16 +520,16 @@ pub mod Mat4 { // Matrix4x4 Implementation // pub impl Mat4: Matrix { - #[inline] + #[inline(always)] pure fn rows() -> uint { 4 } - #[inline] + #[inline(always)] pure fn cols() -> uint { 4 } - #[inline] + #[inline(always)] pure fn is_col_major() -> bool { true } - #[inline] + #[inline(always)] pure fn row(i: uint) -> Vec4 { Vec4(self[0][i], self[1][i], @@ -537,12 +537,12 @@ pub impl Mat4: Matrix { self[3][i]) } - #[inline] + #[inline(always)] pure fn col(i: uint) -> Vec4 { self.data[i] } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Mat4 { Mat4_v(&self[0].mul_f(value), &self[1].mul_f(value), @@ -550,7 +550,7 @@ pub impl Mat4: Matrix { &self[3].mul_f(value)) } - #[inline] + #[inline(always)] 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], 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 { 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 { Mat4_v(&self[0].add_v(&other[0]), &self[1].add_v(&other[1]), @@ -566,7 +566,7 @@ pub impl Mat4: Matrix { &self[3].add_v(&other[3])) } - #[inline] + #[inline(always)] pure fn sub_m(other: &Mat4) -> Mat4 { Mat4_v(&self[0].sub_v(&other[0]), &self[1].sub_v(&other[1]), @@ -574,7 +574,7 @@ pub impl Mat4: Matrix { &self[3].sub_v(&other[3])) } - #[inline] + #[inline(always)] 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], 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 { } // TODO - inversion is harrrd D: - // #[inline] + // #[inline(always)] // pure fn invert(other: &Mat4) -> Mat4 {} - #[inline] + #[inline(always)] pure fn transpose() -> Mat4 { 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], @@ -609,12 +609,12 @@ pub impl Mat4: Matrix { self[0][3], self[1][3], self[2][3], self[3][3]) } - #[inline] + #[inline(always)] pure fn is_identity() -> bool { self.fuzzy_eq(&Mat4::identity) } - #[inline] + #[inline(always)] pure fn is_symmetric() -> bool { self[0][1].fuzzy_eq(&self[1][0]) && self[0][2].fuzzy_eq(&self[2][0]) && @@ -633,7 +633,7 @@ pub impl Mat4: Matrix { self[3][2].fuzzy_eq(&self[2][3]) } - #[inline] + #[inline(always)] pure fn is_diagonal() -> bool { self[0][1].fuzzy_eq(&0f) && self[0][2].fuzzy_eq(&0f) && @@ -652,14 +652,14 @@ pub impl Mat4: Matrix { self[3][2].fuzzy_eq(&0f) } - #[inline] + #[inline(always)] pure fn is_rotated() -> bool { !self.fuzzy_eq(&Mat4::identity) } } pub impl Mat4: Matrix4 { - #[inline] + #[inline(always)] pure fn scale(vec: &Vec3) -> Mat4 { self.mul_m(&Mat4(vec.x, 0f, 0f, 0f, 0f, vec.y, 0f, 0f, @@ -667,7 +667,7 @@ pub impl Mat4: Matrix4 { 0f, 0f, 0f, 1f)) } - #[inline] + #[inline(always)] pure fn translate(vec: &Vec3) -> Mat4 { Mat4_v(&self[0], &self[1], @@ -680,33 +680,33 @@ pub impl Mat4: Matrix4 { } pub impl Mat4: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> Vec4 { self.data[i] } } pub impl Mat4: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Mat4 { Mat4_v(&-self[0], &-self[1], &-self[2], &-self[3]) } } pub impl Mat4: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Mat4) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Mat4) -> bool { !(self == *other) } } impl Mat4: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Mat4) -> bool { self[0].exact_eq(&other[0]) && self[1].exact_eq(&other[1]) && @@ -716,7 +716,7 @@ impl Mat4: ExactEq { } pub impl Mat4: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Mat4) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) && diff --git a/src/projection.rs b/src/projection.rs index 9a17a55..5aa5e49 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -8,6 +8,7 @@ use matrix::Mat4; // fov is in degrees // http://www.opengl.org/wiki/GluPerspective_code // +#[inline(always)] pure fn perspective(fovy:float, aspectRatio:float, near:float, far:float) -> Mat4 { let ymax = near * tan(fovy * pi / 360f); let xmax = ymax * aspectRatio; @@ -21,6 +22,7 @@ pure fn perspective(fovy:float, aspectRatio:float, near:float, far:float) -> Mat // // TODO: double check algorithm // +#[inline(always)] pure fn frustum(left:float, right:float, bottom:float, top:float, near:float, far:float) -> Mat4 { let m00 = (2f * near) / (right - left); let m01 = 0f; diff --git a/src/quaternion.rs b/src/quaternion.rs index 21e9ec6..c57bcbd 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -44,7 +44,7 @@ pub struct Quat { w: float, x: float, y: float, z: float } // // Quat Constructor // -#[inline] +#[inline(always)] pub pure fn Quat(w: float, x: float, y: float, z: float) -> Quat { Quat { w: w, x: x, y: y, z: z } } @@ -58,10 +58,10 @@ pub mod Quat { // Quaternion Implementation // pub impl Quat: Quaternion { - #[inline] + #[inline(always)] pure fn dim() -> uint { 4 } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Quat { Quat(self[0] * value, self[1] * value, @@ -69,7 +69,7 @@ pub impl Quat: Quaternion { self[3] * value) } - #[inline] + #[inline(always)] pure fn div_f(value: float) -> Quat { Quat(self[0] / value, self[1] / value, @@ -77,7 +77,7 @@ pub impl Quat: Quaternion { self[3] / value) } - #[inline] + #[inline(always)] pure fn add_q(other: &Quat) -> Quat{ Quat(self[0] + other[0], self[1] + other[1], @@ -85,7 +85,7 @@ pub impl Quat: Quaternion { self[3] + other[3]) } - #[inline] + #[inline(always)] pure fn sub_q(other: &Quat) -> Quat{ Quat(self[0] - other[0], self[1] - other[1], @@ -93,7 +93,7 @@ pub impl Quat: Quaternion { self[3] - other[3]) } - #[inline] + #[inline(always)] pure fn mul_q(other: &Quat) -> Quat { 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, @@ -101,17 +101,17 @@ pub impl Quat: Quaternion { self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x) } - #[inline] + #[inline(always)] pure fn conjugate() -> Quat { Quat(self.w, -self.x, -self.y, -self.z) } - #[inline] + #[inline(always)] pure fn inverse() -> Quat { self.conjugate().mul_f((1f / self.magnitude2())) } - #[inline] + #[inline(always)] pure fn magnitude2() -> float { self.w * self.w + self.x * self.x + @@ -119,12 +119,12 @@ pub impl Quat: Quaternion { self.z * self.z } - #[inline] + #[inline(always)] pure fn magnitude() -> float { self.magnitude2().sqrt() } - #[inline] + #[inline(always)] pure fn to_Mat3() -> Mat3 { let x2 = self.x + self.x; let y2 = self.y + self.y; @@ -147,14 +147,14 @@ pub impl Quat: Quaternion { xz2 - wy2, yz2 + wx2, 1f - xx2 - yy2); } - #[inline] + #[inline(always)] pure fn to_Mat4() -> Mat4 { self.to_Mat3().to_Mat4() } } pub impl Quat: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> float { unsafe { do buf_as_slice( @@ -165,26 +165,26 @@ pub impl Quat: Index { } pub impl Quat: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Quat { Quat(-self[0], -self[1], -self[2], -self[3]) } } pub impl Quat: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Quat) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Quat) -> bool { !(self == *other) } } impl Quat: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Quat) -> bool { self[0] == other[0] && self[1] == other[1] && @@ -194,7 +194,7 @@ impl Quat: ExactEq { } pub impl Quat: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Quat) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) && diff --git a/src/vector.rs b/src/vector.rs index e0b6161..9803deb 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -51,7 +51,7 @@ pub struct Vec2 { x: float, y: float } // // Constructor // -#[inline] +#[inline(always)] pub pure fn Vec2(x: float, y: float) -> Vec2 { Vec2 { x: x, y: y } } @@ -64,91 +64,91 @@ pub mod Vec2 { } pub impl Vec2: Vector { - #[inline] + #[inline(always)] static pure fn dim() -> uint { 2 } - #[inline] + #[inline(always)] pure fn add_f(value: float) -> Vec2 { Vec2(self[0] + value, self[1] + value) } - #[inline] + #[inline(always)] pure fn sub_f(value: float) -> Vec2 { Vec2(self[0] - value, self[1] - value) } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Vec2 { Vec2(self[0] * value, self[1] * value) } - #[inline] + #[inline(always)] pure fn div_f(value: float) -> Vec2 { Vec2(self[0] / value, self[1] / value) } - #[inline] + #[inline(always)] pure fn add_v(other: &Vec2) -> Vec2{ Vec2(self[0] + other[0], self[1] + other[1]) } - #[inline] + #[inline(always)] pure fn sub_v(other: &Vec2) -> Vec2{ Vec2(self[0] - other[0], self[1] - other[1]) } - #[inline] + #[inline(always)] pure fn dot(other: &Vec2) -> float { self[0] * other[0] + self[1] * other[1] } - #[inline] + #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] + self[1] * self[1] } - #[inline] + #[inline(always)] pure fn magnitude() -> float { self.magnitude2().sqrt() } - #[inline] + #[inline(always)] pure fn normalize() -> Vec2 { let n = 1f / self.magnitude(); return self.mul_f(n); } - #[inline] + #[inline(always)] pure fn lerp(other: &Vec2, value: float) -> Vec2 { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] + #[inline(always)] pure fn min(other: &Vec2) -> Vec2 { Vec2(min(&self[0], &other[0]), min(&self[1], &other[1])) } - #[inline] + #[inline(always)] pure fn max(other: &Vec2) -> Vec2 { Vec2(max(&self[0], &other[0]), max(&self[1], &other[1])) } - #[inline] static pure fn zero() -> Vec2 { Vec2(0f, 0f) } - #[inline] static pure fn identity() -> Vec2 { Vec2(1f, 1f) } + #[inline(always)] static pure fn zero() -> Vec2 { Vec2(0f, 0f) } + #[inline(always)] static pure fn identity() -> Vec2 { Vec2(1f, 1f) } } pub impl Vec2: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> float { unsafe { do buf_as_slice( @@ -159,7 +159,7 @@ pub impl Vec2: Index { } pub impl Vec2: Abs { - #[inline] + #[inline(always)] pure fn abs() -> Vec2 { Vec2(abs(&self[0]), abs(&self[1])) @@ -167,26 +167,26 @@ pub impl Vec2: Abs { } pub impl Vec2: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Vec2 { Vec2(-self[0], -self[1]) } } pub impl Vec2: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Vec2) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Vec2) -> bool { !(self == *other) } } impl Vec2: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Vec2) -> bool { self[0] == other[0] && self[1] == other[1] @@ -194,7 +194,7 @@ impl Vec2: ExactEq { } pub impl Vec2: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Vec2) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) @@ -220,7 +220,7 @@ pub struct Vec3 { x: float, y: float, z: float } // // Constructor // -#[inline] +#[inline(always)] pub pure fn Vec3(x: float, y: float, z: float) -> Vec3 { Vec3 { x: x, y: y, z: z } } @@ -234,7 +234,7 @@ pub mod Vec3 { } pub impl Vec3: Vector3 { - #[inline] + #[inline(always)] fn cross(other: &Vec3) -> Vec3 { Vec3((self[1] * other[2]) - (self[2] * other[1]), (self[2] * other[0]) - (self[0] * other[2]), @@ -243,101 +243,101 @@ pub impl Vec3: Vector3 { } pub impl Vec3: Vector { - #[inline] + #[inline(always)] static pure fn dim() -> uint { 3 } - #[inline] + #[inline(always)] pure fn add_f(value: float) -> Vec3 { Vec3(self[0] + value, self[1] + value, self[2] + value) } - #[inline] + #[inline(always)] pure fn sub_f(value: float) -> Vec3 { Vec3(self[0] - value, self[1] - value, self[2] - value) } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Vec3 { Vec3(self[0] * value, self[1] * value, self[2] * value) } - #[inline] + #[inline(always)] pure fn div_f(value: float) -> Vec3 { Vec3(self[0] / value, self[1] / value, self[2] / value) } - #[inline] + #[inline(always)] pure fn add_v(other: &Vec3) -> Vec3{ Vec3(self[0] + other[0], self[1] + other[1], self[2] + other[2]) } - #[inline] + #[inline(always)] pure fn sub_v(other: &Vec3) -> Vec3{ Vec3(self[0] - other[0], self[1] - other[1], self[2] - other[2]) } - #[inline] + #[inline(always)] pure fn dot(other: &Vec3) -> float { self[0] * other[0] + self[1] * other[1] + self[2] * other[2] } - #[inline] + #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] + self[1] * self[1] + self[2] * self[2] } - #[inline] + #[inline(always)] pure fn magnitude() -> float { self.magnitude2().sqrt() } - #[inline] + #[inline(always)] pure fn normalize() -> Vec3 { let n = 1f / self.magnitude(); return self.mul_f(n); } - #[inline] + #[inline(always)] pure fn lerp(other: &Vec3, value: float) -> Vec3 { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] + #[inline(always)] pure fn min(other: &Vec3) -> Vec3 { Vec3(min(&self[0], &other[0]), min(&self[1], &other[1]), min(&self[2], &other[2])) } - #[inline] + #[inline(always)] pure fn max(other: &Vec3) -> Vec3 { Vec3(max(&self[0], &other[0]), max(&self[1], &other[1]), max(&self[2], &other[2])) } - #[inline] static pure fn zero() -> Vec3 { Vec3(0f, 0f, 0f) } - #[inline] static pure fn identity() -> Vec3 { Vec3(1f, 1f, 1f) } + #[inline(always)] static pure fn zero() -> Vec3 { Vec3(0f, 0f, 0f) } + #[inline(always)] static pure fn identity() -> Vec3 { Vec3(1f, 1f, 1f) } } pub impl Vec3: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> float { unsafe { do buf_as_slice( transmute::<*Vec3, *float>( @@ -347,7 +347,7 @@ pub impl Vec3: Index { } pub impl Vec3: Abs { - #[inline] + #[inline(always)] pure fn abs() -> Vec3 { Vec3(abs(&self[0]), abs(&self[1]), @@ -356,26 +356,26 @@ pub impl Vec3: Abs { } pub impl Vec3: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Vec3 { Vec3(-self[0], -self[1], -self[2]) } } pub impl Vec3: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Vec3) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Vec3) -> bool { !(self == *other) } } impl Vec3: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Vec3) -> bool { self[0] == other[0] && self[1] == other[1] && @@ -384,7 +384,7 @@ impl Vec3: ExactEq { } pub impl Vec3: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Vec3) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) && @@ -420,16 +420,16 @@ pub mod Vec4 { // // Constructor // -#[inline] +#[inline(always)] pub pure fn Vec4(x: float, y: float, z: float, w: float) -> Vec4 { Vec4 { x: x, y: y, z: z, w: w } } pub impl Vec4: Vector { - #[inline] + #[inline(always)] static pure fn dim() -> uint { 4 } - #[inline] + #[inline(always)] pure fn add_f(value: float) -> Vec4 { Vec4(self[0] + value, self[1] + value, @@ -437,7 +437,7 @@ pub impl Vec4: Vector { self[3] + value) } - #[inline] + #[inline(always)] pure fn sub_f(value: float) -> Vec4 { Vec4(self[0] - value, self[1] - value, @@ -445,7 +445,7 @@ pub impl Vec4: Vector { self[3] - value) } - #[inline] + #[inline(always)] pure fn mul_f(value: float) -> Vec4 { Vec4(self[0] * value, self[1] * value, @@ -453,7 +453,7 @@ pub impl Vec4: Vector { self[3] * value) } - #[inline] + #[inline(always)] pure fn div_f(value: float) -> Vec4 { Vec4(self[0] / value, self[1] / value, @@ -461,7 +461,7 @@ pub impl Vec4: Vector { self[3] / value) } - #[inline] + #[inline(always)] pure fn add_v(other: &Vec4) -> Vec4{ Vec4(self[0] + other[0], self[1] + other[1], @@ -469,7 +469,7 @@ pub impl Vec4: Vector { self[3] + other[3]) } - #[inline] + #[inline(always)] pure fn sub_v(other: &Vec4) -> Vec4{ Vec4(self[0] - other[0], self[1] - other[1], @@ -477,7 +477,7 @@ pub impl Vec4: Vector { self[3] - other[3]) } - #[inline] + #[inline(always)] pure fn dot(other: &Vec4) -> float { self[0] * other[0] + self[1] * other[1] + @@ -485,7 +485,7 @@ pub impl Vec4: Vector { self[3] * other[3] } - #[inline] + #[inline(always)] pure fn magnitude2() -> float { self[0] * self[0] + self[1] * self[1] + @@ -493,23 +493,23 @@ pub impl Vec4: Vector { self[3] * self[3] } - #[inline] + #[inline(always)] pure fn magnitude() -> float { self.magnitude2().sqrt() } - #[inline] + #[inline(always)] pure fn normalize() -> Vec4 { let n = 1f / self.magnitude(); return self.mul_f(n); } - #[inline] + #[inline(always)] pure fn lerp(other: &Vec4, value: float) -> Vec4 { self.add_v(&other.sub_v(&self).mul_f(value)) } - #[inline] + #[inline(always)] pure fn min(other: &Vec4) -> Vec4 { Vec4(min(&self[0], &other[0]), min(&self[1], &other[1]), @@ -517,7 +517,7 @@ pub impl Vec4: Vector { min(&self[3], &other[3])) } - #[inline] + #[inline(always)] pure fn max(other: &Vec4) -> Vec4 { Vec4(max(&self[0], &other[0]), max(&self[1], &other[1]), @@ -525,12 +525,12 @@ pub impl Vec4: Vector { max(&self[3], &other[3])) } - #[inline] 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 zero() -> Vec4 { Vec4(0f, 0f, 0f, 0f) } + #[inline(always)] static pure fn identity() -> Vec4 { Vec4(1f, 1f, 1f, 1f) } } pub impl Vec4: Index { - #[inline] + #[inline(always)] pure fn index(i: uint) -> float { unsafe { do buf_as_slice( @@ -541,7 +541,7 @@ pub impl Vec4: Index { } pub impl Vec4: Abs { - #[inline] + #[inline(always)] pure fn abs() -> Vec4 { Vec4(abs(&self[0]), abs(&self[1]), @@ -551,26 +551,26 @@ pub impl Vec4: Abs { } pub impl Vec4: Neg { - #[inline] + #[inline(always)] pure fn neg() -> Vec4 { Vec4(-self[0], -self[1], -self[2], -self[3]) } } pub impl Vec4: Eq { - #[inline] + #[inline(always)] pure fn eq(other: &Vec4) -> bool { self.fuzzy_eq(other) } - #[inline] + #[inline(always)] pure fn ne(other: &Vec4) -> bool { !(self == *other) } } impl Vec4: ExactEq { - #[inline] + #[inline(always)] pure fn exact_eq(other: &Vec4) -> bool { self[0] == other[0] && self[1] == other[1] && @@ -580,7 +580,7 @@ impl Vec4: ExactEq { } pub impl Vec4: FuzzyEq { - #[inline] + #[inline(always)] pure fn fuzzy_eq(other: &Vec4) -> bool { self[0].fuzzy_eq(&other[0]) && self[1].fuzzy_eq(&other[1]) &&