diff --git a/src/angle.rs b/src/angle.rs index 31dddb8..24e599b 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -23,9 +23,9 @@ pub trait Angle: Add static pure fn sextant() -> self; static pure fn octant() -> self; - pure fn to_radians() -> Radians; - pure fn to_degrees() -> Degrees; - pure fn wrap() -> self; + pure fn to_radians(&self) -> Radians; + pure fn to_degrees(&self) -> Degrees; + pure fn wrap(&self) -> self; } @@ -41,11 +41,11 @@ pub impl Radians: Angle { #[inline(always)] static pure fn sextant() -> Radians { Radians(move cast(pi / 3.0)) } #[inline(always)] static pure fn octant() -> Radians { Radians(move cast(pi / 4.0)) } - #[inline(always)] pure fn to_radians() -> Radians { self } - #[inline(always)] pure fn to_degrees() -> Degrees { Degrees(*self * cast(180.0 / pi)) } + #[inline(always)] pure fn to_radians(&self) -> Radians { *self } + #[inline(always)] pure fn to_degrees(&self) -> Degrees { Degrees(**self * cast(180.0 / pi)) } - #[inline(always)] pure fn wrap() -> Radians { - self % cast(2.0 * pi) // TODO: keep in the domain of 0 to two_pi + #[inline(always)] pure fn wrap(&self) -> Radians { + (*self) % cast(2.0 * pi) // TODO: keep in the domain of 0 to two_pi } } @@ -120,11 +120,11 @@ pub impl Degrees: Angle { #[inline(always)] static pure fn sextant() -> Degrees { Degrees(move cast(60.0)) } #[inline(always)] static pure fn octant() -> Degrees { Degrees(move cast(45.0)) } - #[inline(always)] pure fn to_radians() -> Radians { Radians(*self * cast(pi / 180.0)) } - #[inline(always)] pure fn to_degrees() -> Degrees { self } + #[inline(always)] pure fn to_radians(&self) -> Radians { Radians(**self * cast(pi / 180.0)) } + #[inline(always)] pure fn to_degrees(&self) -> Degrees { *self } - #[inline(always)] pure fn wrap() -> Degrees { - self % cast(360) // TODO: keep in the domain of 0 to 360 + #[inline(always)] pure fn wrap(&self) -> Degrees { + (*self) % cast(360) // TODO: keep in the domain of 0 to 360 } } diff --git a/src/dim.rs b/src/dim.rs index 7cb9f65..a4d315f 100644 --- a/src/dim.rs +++ b/src/dim.rs @@ -1,5 +1,5 @@ pub trait Dimensional: Index { 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; } \ No newline at end of file diff --git a/src/funs/common.rs b/src/funs/common.rs index 3fd1376..57e1089 100644 --- a/src/funs/common.rs +++ b/src/funs/common.rs @@ -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(x: &T) -> T { x.abs() } #[inline(always)] pub pure fn 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 Radians: Sign{ - #[inline(always)] pure fn abs() -> Radians { Radians(abs(&*self)) } - #[inline(always)] pure fn sign() -> Radians { Radians(sign(&*self)) } + #[inline(always)] pure fn abs(&self) -> Radians { Radians(abs(&**self)) } + #[inline(always)] pure fn sign(&self) -> Radians { Radians(sign(&**self)) } } pub impl Degrees: Sign{ - #[inline(always)] pure fn abs() -> Degrees { Degrees(abs(&*self)) } - #[inline(always)] pure fn sign() -> Degrees { Degrees(sign(&*self)) } + #[inline(always)] pure fn abs(&self) -> Degrees { Degrees(abs(&**self)) } + #[inline(always)] pure fn sign(&self) -> Degrees { Degrees(sign(&**self)) } } pub impl Vec2: Sign { #[inline(always)] - pure fn abs() -> Vec2 { + pure fn abs(&self) -> Vec2 { Vec2::new(abs(&self[0]), abs(&self[1])) } #[inline(always)] - pure fn sign() -> Vec2 { + pure fn sign(&self) -> Vec2 { Vec2::new(sign(&self[0]), sign(&self[1])) } @@ -86,14 +86,14 @@ pub impl Vec2: Sign { pub impl Vec3: Sign { #[inline(always)] - pure fn abs() -> Vec3 { + pure fn abs(&self) -> Vec3 { Vec3::new(abs(&self[0]), abs(&self[1]), abs(&self[2])) } #[inline(always)] - pure fn sign() -> Vec3 { + pure fn sign(&self) -> Vec3 { Vec3::new(sign(&self[0]), sign(&self[1]), sign(&self[2])) @@ -102,7 +102,7 @@ pub impl Vec3: Sign { pub impl Vec4: Sign { #[inline(always)] - pure fn abs() -> Vec4 { + pure fn abs(&self) -> Vec4 { Vec4::new(abs(&self[0]), abs(&self[1]), abs(&self[2]), @@ -110,7 +110,7 @@ pub impl Vec4: Sign { } #[inline(always)] - pure fn sign() -> Vec4 { + pure fn sign(&self) -> Vec4 { Vec4::new(sign(&self[0]), sign(&self[1]), sign(&self[2]), @@ -119,12 +119,12 @@ pub impl Vec4: 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(x: &T) -> T { x.floor() } @@ -135,85 +135,85 @@ pub trait Approx { #[inline(always)] pub pure fn fract(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 Radians: Approx{ - #[inline(always)] pure fn floor() -> Radians { Radians(floor(&*self)) } - #[inline(always)] pure fn trunc() -> Radians { Radians(trunc(&*self)) } - #[inline(always)] pure fn round() -> Radians { Radians(round(&*self)) } - // #[inline(always)] pure fn roundEven() -> Radians { Radians(roundEven(&*self)) } - #[inline(always)] pure fn ceil() -> Radians { Radians(ceil(&*self)) } - #[inline(always)] pure fn fract() -> Radians { Radians(fract(&*self)) } + #[inline(always)] pure fn floor(&self) -> Radians { Radians(floor(&**self)) } + #[inline(always)] pure fn trunc(&self) -> Radians { Radians(trunc(&**self)) } + #[inline(always)] pure fn round(&self) -> Radians { Radians(round(&**self)) } + // #[inline(always)] pure fn roundEven(&self) -> Radians { Radians(roundEven(&**self)) } + #[inline(always)] pure fn ceil(&self) -> Radians { Radians(ceil(&**self)) } + #[inline(always)] pure fn fract(&self) -> Radians { Radians(fract(&**self)) } } pub impl Degrees: Approx{ - #[inline(always)] pure fn floor() -> Degrees { Degrees(floor(&*self)) } - #[inline(always)] pure fn trunc() -> Degrees { Degrees(trunc(&*self)) } - #[inline(always)] pure fn round() -> Degrees { Degrees(round(&*self)) } - // #[inline(always)] pure fn roundEven() -> Degrees { Degrees(roundEven(&*self)) } - #[inline(always)] pure fn ceil() -> Degrees { Degrees(ceil(&*self)) } - #[inline(always)] pure fn fract() -> Degrees { Degrees(fract(&*self)) } + #[inline(always)] pure fn floor(&self) -> Degrees { Degrees(floor(&**self)) } + #[inline(always)] pure fn trunc(&self) -> Degrees { Degrees(trunc(&**self)) } + #[inline(always)] pure fn round(&self) -> Degrees { Degrees(round(&**self)) } + // #[inline(always)] pure fn roundEven(&self) -> Degrees { Degrees(roundEven(&**self)) } + #[inline(always)] pure fn ceil(&self) -> Degrees { Degrees(ceil(&**self)) } + #[inline(always)] pure fn fract(&self) -> Degrees { Degrees(fract(&**self)) } } pub impl Vec2: Approx { #[inline(always)] - pure fn floor() -> Vec2 { + pure fn floor(&self) -> Vec2 { Vec2::new(floor(&self[0]), floor(&self[1])) } #[inline(always)] - pure fn trunc() -> Vec2 { + pure fn trunc(&self) -> Vec2 { Vec2::new(trunc(&self[0]), trunc(&self[1])) } #[inline(always)] - pure fn round() -> Vec2 { + pure fn round(&self) -> Vec2 { Vec2::new(round(&self[0]), round(&self[1])) } // #[inline(always)] - // pure fn ceil() -> Vec2 { + // pure fn ceil(&self) -> Vec2 { // Vec2::new(roundEven(&self[0]), // roundEven(&self[1])) // } #[inline(always)] - pure fn ceil() -> Vec2 { + pure fn ceil(&self) -> Vec2 { Vec2::new(ceil(&self[0]), ceil(&self[1])) } #[inline(always)] - pure fn fract() -> Vec2 { + pure fn fract(&self) -> Vec2 { Vec2::new(fract(&self[0]), fract(&self[1])) } @@ -222,42 +222,42 @@ pub impl Vec2: Approx { pub impl Vec3: Approx { #[inline(always)] - pure fn floor() -> Vec3 { + pure fn floor(&self) -> Vec3 { Vec3::new(floor(&self[0]), floor(&self[1]), floor(&self[2])) } #[inline(always)] - pure fn trunc() -> Vec3 { + pure fn trunc(&self) -> Vec3 { Vec3::new(trunc(&self[0]), trunc(&self[1]), trunc(&self[2])) } #[inline(always)] - pure fn round() -> Vec3 { + pure fn round(&self) -> Vec3 { Vec3::new(round(&self[0]), round(&self[1]), round(&self[2])) } // #[inline(always)] - // pure fn ceil() -> Vec3 { + // pure fn ceil(&self) -> Vec3 { // Vec3::new(roundEven(&self[0]), // roundEven(&self[1]), // roundEven(&self[2])) // } #[inline(always)] - pure fn ceil() -> Vec3 { + pure fn ceil(&self) -> Vec3 { Vec3::new(ceil(&self[0]), ceil(&self[1]), ceil(&self[2])) } #[inline(always)] - pure fn fract() -> Vec3 { + pure fn fract(&self) -> Vec3 { Vec3::new(fract(&self[0]), fract(&self[1]), fract(&self[2])) @@ -267,7 +267,7 @@ pub impl Vec3: Approx { pub impl Vec4: Approx { #[inline(always)] - pure fn floor() -> Vec4 { + pure fn floor(&self) -> Vec4 { Vec4::new(floor(&self[0]), floor(&self[1]), floor(&self[2]), @@ -275,7 +275,7 @@ pub impl Vec4: Approx { } #[inline(always)] - pure fn trunc() -> Vec4 { + pure fn trunc(&self) -> Vec4 { Vec4::new(trunc(&self[0]), trunc(&self[1]), trunc(&self[2]), @@ -283,7 +283,7 @@ pub impl Vec4: Approx { } #[inline(always)] - pure fn round() -> Vec4 { + pure fn round(&self) -> Vec4 { Vec4::new(round(&self[0]), round(&self[1]), round(&self[2]), @@ -291,7 +291,7 @@ pub impl Vec4: Approx { } // #[inline(always)] - // pure fn ceil() -> Vec4 { + // pure fn ceil(&self) -> Vec4 { // Vec4::new(roundEven(&self[0]), // roundEven(&self[1]), // roundEven(&self[2]), @@ -299,7 +299,7 @@ pub impl Vec4: Approx { // } #[inline(always)] - pure fn ceil() -> Vec4 { + pure fn ceil(&self) -> Vec4 { Vec4::new(ceil(&self[0]), ceil(&self[1]), ceil(&self[2]), @@ -307,7 +307,7 @@ pub impl Vec4: Approx { } #[inline(always)] - pure fn fract() -> Vec4 { + pure fn fract(&self) -> Vec4 { Vec4::new(fract(&self[0]), fract(&self[1]), fract(&self[2]), @@ -317,9 +317,9 @@ pub impl Vec4: 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(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 Radians: Extent{ #[inline(always)] - pure fn min(other: &Radians) -> Radians { - Radians(min(&*self, &**other)) + pure fn min(&self, other: &Radians) -> Radians { + Radians(min(&**self, &**other)) } #[inline(always)] - pure fn max(other: &Radians) -> Radians { - Radians(max(&*self, &**other)) + pure fn max(&self, other: &Radians) -> Radians { + Radians(max(&**self, &**other)) } #[inline(always)] - pure fn clamp(mn: &Radians, mx: &Radians) -> Radians { - Radians((*self).clamp(&**mn, &**mx)) + pure fn clamp(&self, mn: &Radians, mx: &Radians) -> Radians { + Radians((**self).clamp(&**mn, &**mx)) } } pub impl Degrees: Extent{ #[inline(always)] - pure fn min(other: &Degrees) -> Degrees { - Degrees(min(&*self, &**other)) + pure fn min(&self, other: &Degrees) -> Degrees { + Degrees(min(&**self, &**other)) } #[inline(always)] - pure fn max(other: &Degrees) -> Degrees { - Degrees(max(&*self, &**other)) + pure fn max(&self, other: &Degrees) -> Degrees { + Degrees(max(&**self, &**other)) } #[inline(always)] - pure fn clamp(mn: &Degrees, mx: &Degrees) -> Degrees { - Degrees((*self).clamp(&**mn, &**mx)) + pure fn clamp(&self, mn: &Degrees, mx: &Degrees) -> Degrees { + Degrees((**self).clamp(&**mn, &**mx)) } } pub impl Vec2: Extent { #[inline(always)] - pure fn min(other: &Vec2) -> Vec2 { + pure fn min(&self, other: &Vec2) -> Vec2 { Vec2::new(min(&self[0], &other[0]), min(&self[1], &other[1])) } #[inline(always)] - pure fn max(other: &Vec2) -> Vec2 { + pure fn max(&self, other: &Vec2) -> Vec2 { Vec2::new(max(&self[0], &other[0]), max(&self[1], &other[1])) } #[inline(always)] - pure fn clamp(mn: &Vec2, mx: &Vec2) -> Vec2 { + pure fn clamp(&self, mn: &Vec2, mx: &Vec2) -> Vec2 { Vec2::new(self[0].clamp(&mn[0], &mx[0]), self[1].clamp(&mn[1], &mx[1])) } @@ -599,21 +605,21 @@ pub impl Vec2: Extent { pub impl Vec3: Extent { #[inline(always)] - pure fn min(other: &Vec3) -> Vec3 { + pure fn min(&self, other: &Vec3) -> Vec3 { Vec3::new(min(&self[0], &other[0]), min(&self[1], &other[1]), min(&self[2], &other[2])) } #[inline(always)] - pure fn max(other: &Vec3) -> Vec3 { + pure fn max(&self, other: &Vec3) -> Vec3 { Vec3::new(max(&self[0], &other[0]), max(&self[1], &other[1]), max(&self[2], &other[2])) } #[inline(always)] - pure fn clamp(mn: &Vec3, mx: &Vec3) -> Vec3 { + pure fn clamp(&self, mn: &Vec3, mx: &Vec3) -> Vec3 { 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 Vec3: Extent { pub impl Vec4: Extent { #[inline(always)] - pure fn min(other: &Vec4) -> Vec4 { + pure fn min(&self, other: &Vec4) -> Vec4 { Vec4::new(min(&self[0], &other[0]), min(&self[1], &other[1]), min(&self[2], &other[2]), @@ -630,7 +636,7 @@ pub impl Vec4: Extent { } #[inline(always)] - pure fn max(other: &Vec4) -> Vec4 { + pure fn max(&self, other: &Vec4) -> Vec4 { Vec4::new(max(&self[0], &other[0]), max(&self[1], &other[1]), max(&self[2], &other[2]), @@ -638,7 +644,7 @@ pub impl Vec4: Extent { } #[inline(always)] - pure fn clamp(mn: &Vec4, mx: &Vec4) -> Vec4 { + pure fn clamp(&self, mn: &Vec4, mx: &Vec4) -> Vec4 { 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 Vec4: 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(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 Radians: Mix { #[inline(always)] - pure fn mix(other: &Radians, value: &Radians) -> Radians { - Radians((*self).mix(&**other, &**value)) + pure fn mix(&self, other: &Radians, value: &Radians) -> Radians { + Radians((**self).mix(&**other, &**value)) } #[inline(always)] - pure fn smooth_step(edge0: &Radians, edge1: &Radians) -> Radians { - Radians((*self).smooth_step(&**edge0, &**edge1)) + pure fn smooth_step(&self, edge0: &Radians, edge1: &Radians) -> Radians { + Radians((**self).smooth_step(&**edge0, &**edge1)) } #[inline(always)] - pure fn step(edge: &Radians) -> Radians { - Radians((*self).step(&**edge)) + pure fn step(&self, edge: &Radians) -> Radians { + Radians((**self).step(&**edge)) } } pub impl Vec2: Mix { #[inline(always)] - pure fn mix(other: &Vec2, value: &Vec2) -> Vec2 { + pure fn mix(&self, other: &Vec2, value: &Vec2) -> Vec2 { Vec2::new(self[0].mix(&other[0], &value[0]), self[1].mix(&other[1], &value[1])) } #[inline(always)] - pure fn smooth_step(edge0: &Vec2, edge1: &Vec2) -> Vec2 { + pure fn smooth_step(&self, edge0: &Vec2, edge1: &Vec2) -> Vec2 { 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) -> Vec2 { + pure fn step(&self, edge: &Vec2) -> Vec2 { Vec2::new(self[0].step(&edge[0]), self[1].step(&edge[1])) } @@ -752,21 +760,21 @@ pub impl Vec2: Mix { pub impl Vec3: Mix { #[inline(always)] - pure fn mix(other: &Vec3, value: &Vec3) -> Vec3 { + pure fn mix(&self, other: &Vec3, value: &Vec3) -> Vec3 { 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, edge1: &Vec3) -> Vec3 { + pure fn smooth_step(&self, edge0: &Vec3, edge1: &Vec3) -> Vec3 { 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) -> Vec3 { + pure fn step(&self, edge: &Vec3) -> Vec3 { Vec3::new(self[0].step(&edge[0]), self[1].step(&edge[1]), self[2].step(&edge[2])) @@ -775,7 +783,7 @@ pub impl Vec3: Mix { pub impl Vec4: Mix { #[inline(always)] - pure fn mix(other: &Vec4, value: &Vec4) -> Vec4 { + pure fn mix(&self, other: &Vec4, value: &Vec4) -> Vec4 { 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 Vec4: Mix { } #[inline(always)] - pure fn smooth_step(edge0: &Vec4, edge1: &Vec4) -> Vec4 { + pure fn smooth_step(&self, edge0: &Vec4, edge1: &Vec4) -> Vec4 { 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 Vec4: Mix { } #[inline(always)] - pure fn step(edge: &Vec4) -> Vec4 { + pure fn step(&self, edge: &Vec4) -> Vec4 { Vec4::new(self[0].step(&edge[0]), self[1].step(&edge[1]), self[2].step(&edge[2]), diff --git a/src/funs/exponential.rs b/src/funs/exponential.rs index e1643ef..ba548c3 100644 --- a/src/funs/exponential.rs +++ b/src/funs/exponential.rs @@ -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(x: &T, n: &T) -> T { x.pow(n) } @@ -27,74 +27,74 @@ pub trait Exp { #[inline(always)] pub pure fn inv_sqrt(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 Vec2: Exp { #[inline(always)] - pure fn pow(n: &Vec2) -> Vec2 { + pure fn pow(&self, n: &Vec2) -> Vec2 { Vec2::new(pow(&self[0], &n[0]), pow(&self[1], &n[1])) } #[inline(always)] - pure fn exp() -> Vec2 { + pure fn exp(&self) -> Vec2 { Vec2::new(exp(&self[0]), exp(&self[1])) } #[inline(always)] - pure fn log_() -> Vec2 { + pure fn log_(&self) -> Vec2 { Vec2::new(log_(&self[0]), log_(&self[1])) } #[inline(always)] - pure fn exp2() -> Vec2 { + pure fn exp2(&self) -> Vec2 { Vec2::new(exp2(&self[0]), exp2(&self[1])) } #[inline(always)] - pure fn log2() -> Vec2 { + pure fn log2(&self) -> Vec2 { Vec2::new(log2(&self[0]), log2(&self[1])) } #[inline(always)] - pure fn sqrt() -> Vec2 { + pure fn sqrt(&self) -> Vec2 { Vec2::new(sqrt(&self[0]), sqrt(&self[1])) } #[inline(always)] - pure fn inv_sqrt() -> Vec2 { + pure fn inv_sqrt(&self) -> Vec2 { Vec2::new(inv_sqrt(&self[0]), inv_sqrt(&self[1])) } @@ -102,49 +102,49 @@ pub impl Vec2: Exp { pub impl Vec3: Exp { #[inline(always)] - pure fn pow(n: &Vec3) -> Vec3 { + pure fn pow(&self, n: &Vec3) -> Vec3 { Vec3::new(pow(&self[0], &n[0]), pow(&self[1], &n[1]), pow(&self[2], &n[2])) } #[inline(always)] - pure fn exp() -> Vec3 { + pure fn exp(&self) -> Vec3 { Vec3::new(exp(&self[0]), exp(&self[1]), exp(&self[2])) } #[inline(always)] - pure fn log_() -> Vec3 { + pure fn log_(&self) -> Vec3 { Vec3::new(log_(&self[0]), log_(&self[1]), log_(&self[2])) } #[inline(always)] - pure fn exp2() -> Vec3 { + pure fn exp2(&self) -> Vec3 { Vec3::new(exp2(&self[0]), exp2(&self[1]), exp2(&self[2])) } #[inline(always)] - pure fn log2() -> Vec3 { + pure fn log2(&self) -> Vec3 { Vec3::new(log2(&self[0]), log2(&self[1]), log2(&self[2])) } #[inline(always)] - pure fn sqrt() -> Vec3 { + pure fn sqrt(&self) -> Vec3 { Vec3::new(sqrt(&self[0]), sqrt(&self[1]), sqrt(&self[2])) } #[inline(always)] - pure fn inv_sqrt() -> Vec3 { + pure fn inv_sqrt(&self) -> Vec3 { Vec3::new(inv_sqrt(&self[0]), inv_sqrt(&self[1]), inv_sqrt(&self[2])) @@ -153,7 +153,7 @@ pub impl Vec3: Exp { pub impl Vec4: Exp { #[inline(always)] - pure fn pow(n: &Vec4) -> Vec4 { + pure fn pow(&self, n: &Vec4) -> Vec4 { Vec4::new(pow(&self[0], &n[0]), pow(&self[1], &n[1]), pow(&self[2], &n[2]), @@ -161,7 +161,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn exp() -> Vec4 { + pure fn exp(&self) -> Vec4 { Vec4::new(exp(&self[0]), exp(&self[1]), exp(&self[2]), @@ -169,7 +169,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn log_() -> Vec4 { + pure fn log_(&self) -> Vec4 { Vec4::new(log_(&self[0]), log_(&self[1]), log_(&self[2]), @@ -177,7 +177,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn exp2() -> Vec4 { + pure fn exp2(&self) -> Vec4 { Vec4::new(exp2(&self[0]), exp2(&self[1]), exp2(&self[2]), @@ -185,7 +185,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn log2() -> Vec4 { + pure fn log2(&self) -> Vec4 { Vec4::new(log2(&self[0]), log2(&self[1]), log2(&self[2]), @@ -193,7 +193,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn sqrt() -> Vec4 { + pure fn sqrt(&self) -> Vec4 { Vec4::new(sqrt(&self[0]), sqrt(&self[1]), sqrt(&self[2]), @@ -201,7 +201,7 @@ pub impl Vec4: Exp { } #[inline(always)] - pure fn inv_sqrt() -> Vec4 { + pure fn inv_sqrt(&self) -> Vec4 { Vec4::new(inv_sqrt(&self[0]), inv_sqrt(&self[1]), inv_sqrt(&self[2]), diff --git a/src/funs/relational.rs b/src/funs/relational.rs index c43bc39..64616bc 100644 --- a/src/funs/relational.rs +++ b/src/funs/relational.rs @@ -9,12 +9,12 @@ use core::cmp::{Eq, Ord}; use vec::{Vector, Vec2, Vec3, Vec4}; pub trait RelVector { - 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 , BV>(x: &T, y: &T) -> BV { x.less_than(y) } @@ -26,140 +26,140 @@ pub trait RelVector { pub impl Vec2: RelVector> { #[inline(always)] - pure fn less_than(y: &Vec2) -> Vec2 { - Vec2::new(self[0] < y[0], - self[1] < y[1]) + pure fn less_than(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] < other[0], + self[1] < other[1]) } #[inline(always)] - pure fn less_than_equal(y: &Vec2) -> Vec2 { - Vec2::new(self[0] <= y[0], - self[1] <= y[1]) + pure fn less_than_equal(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] <= other[0], + self[1] <= other[1]) } #[inline(always)] - pure fn greater_than(y: &Vec2) -> Vec2 { - Vec2::new(self[0] > y[0], - self[1] > y[1]) + pure fn greater_than(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] > other[0], + self[1] > other[1]) } #[inline(always)] - pure fn greater_than_equal(y: &Vec2) -> Vec2 { - Vec2::new(self[0] >= y[0], - self[1] >= y[1]) + pure fn greater_than_equal(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] >= other[0], + self[1] >= other[1]) } #[inline(always)] - pure fn equal(y: &Vec2) -> Vec2 { - Vec2::new(self[0] == y[0], - self[1] == y[1]) + pure fn equal(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] == other[0], + self[1] == other[1]) } #[inline(always)] - pure fn not_equal(y: &Vec2) -> Vec2 { - Vec2::new(self[0] != y[0], - self[1] != y[1]) + pure fn not_equal(&self, other: &Vec2) -> Vec2 { + Vec2::new(self[0] != other[0], + self[1] != other[1]) } } pub impl Vec3: RelVector> { #[inline(always)] - pure fn less_than(y: &Vec3) -> Vec3 { - Vec3::new(self[0] < y[0], - self[1] < y[1], - self[2] < y[2]) + pure fn less_than(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] < other[0], + self[1] < other[1], + self[2] < other[2]) } #[inline(always)] - pure fn less_than_equal(y: &Vec3) -> Vec3 { - Vec3::new(self[0] <= y[0], - self[1] <= y[1], - self[2] <= y[2]) + pure fn less_than_equal(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] <= other[0], + self[1] <= other[1], + self[2] <= other[2]) } #[inline(always)] - pure fn greater_than(y: &Vec3) -> Vec3 { - Vec3::new(self[0] > y[0], - self[1] > y[1], - self[2] > y[2]) + pure fn greater_than(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] > other[0], + self[1] > other[1], + self[2] > other[2]) } #[inline(always)] - pure fn greater_than_equal(y: &Vec3) -> Vec3 { - Vec3::new(self[0] >= y[0], - self[1] >= y[1], - self[2] >= y[2]) + pure fn greater_than_equal(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] >= other[0], + self[1] >= other[1], + self[2] >= other[2]) } #[inline(always)] - pure fn equal(y: &Vec3) -> Vec3 { - Vec3::new(self[0] == y[0], - self[1] == y[1], - self[2] == y[2]) + pure fn equal(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] == other[0], + self[1] == other[1], + self[2] == other[2]) } #[inline(always)] - pure fn not_equal(y: &Vec3) -> Vec3 { - Vec3::new(self[0] != y[0], - self[1] != y[1], - self[2] != y[2]) + pure fn not_equal(&self, other: &Vec3) -> Vec3 { + Vec3::new(self[0] != other[0], + self[1] != other[1], + self[2] != other[2]) } } pub impl Vec4: RelVector> { #[inline(always)] - pure fn less_than(y: &Vec4) -> Vec4 { - 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) -> Vec4 { + 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) -> Vec4 { - 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) -> Vec4 { + 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) -> Vec4 { - 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) -> Vec4 { + 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) -> Vec4 { - 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) -> Vec4 { + 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) -> Vec4 { - Vec4::new(self[0] == y[0], - self[1] == y[1], - self[2] == y[2], - self[3] == y[3]) + pure fn equal(&self, other: &Vec4) -> Vec4 { + 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) -> Vec4 { - 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) -> Vec4 { + Vec4::new(self[0] != other[0], + self[1] != other[1], + self[2] != other[2], + self[3] != other[3]) } } pub trait BooleanVector: Vector { - 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(x: &T) -> bool { x.any() } @@ -167,43 +167,52 @@ pub trait BooleanVector: Vector { #[inline(always)] pub pure fn not(x: &T) -> T { x.not() } pub impl Vec2: 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 { + #[inline(always)] + pure fn not(&self) -> Vec2 { Vec2::new(!self[0], !self[1]) } } pub impl Vec3: 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 { + #[inline(always)] + pure fn not(&self) -> Vec3 { Vec3::new(!self[0], !self[1], !self[2]) } } pub impl Vec4: 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 { + #[inline(always)] + pure fn not(&self) -> Vec4 { Vec4::new(!self[0], !self[1], !self[2], !self[3]) } } \ No newline at end of file diff --git a/src/funs/triganomic.rs b/src/funs/triganomic.rs index 48648dc..b14c8c4 100644 --- a/src/funs/triganomic.rs +++ b/src/funs/triganomic.rs @@ -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 { - 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, R>(theta: &T) -> R { theta.sin() } @@ -24,26 +24,26 @@ priv trait Trig { #[inline(always)] pub pure fn tan, R>(theta: &T) -> R { theta.tan() } priv impl Radians: Trig { - #[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 Vec2>: Trig> { #[inline(always)] - pure fn sin() -> Vec2 { + pure fn sin(&self) -> Vec2 { Vec2::new(sin(&self[0]), sin(&self[1])) } #[inline(always)] - pure fn cos() -> Vec2 { + pure fn cos(&self) -> Vec2 { Vec2::new(cos(&self[0]), cos(&self[1])) } #[inline(always)] - pure fn tan() -> Vec2 { + pure fn tan(&self) -> Vec2 { Vec2::new(tan(&self[0]), tan(&self[1])) } @@ -51,21 +51,21 @@ pub impl Vec2>: Trig> { pub impl Vec3>: Trig> { #[inline(always)] - pure fn sin() -> Vec3 { + pure fn sin(&self) -> Vec3 { Vec3::new(sin(&self[0]), sin(&self[1]), sin(&self[2])) } #[inline(always)] - pure fn cos() -> Vec3 { + pure fn cos(&self) -> Vec3 { Vec3::new(cos(&self[0]), cos(&self[1]), cos(&self[2])) } #[inline(always)] - pure fn tan() -> Vec3 { + pure fn tan(&self) -> Vec3 { Vec3::new(tan(&self[0]), tan(&self[1]), tan(&self[2])) @@ -74,7 +74,7 @@ pub impl Vec3>: Trig> { pub impl Vec4>: Trig> { #[inline(always)] - pure fn sin() -> Vec4 { + pure fn sin(&self) -> Vec4 { Vec4::new(sin(&self[0]), sin(&self[1]), sin(&self[2]), @@ -82,7 +82,7 @@ pub impl Vec4>: Trig> { } #[inline(always)] - pure fn cos() -> Vec4 { + pure fn cos(&self) -> Vec4 { Vec4::new(cos(&self[0]), cos(&self[1]), cos(&self[2]), @@ -90,7 +90,7 @@ pub impl Vec4>: Trig> { } #[inline(always)] - pure fn tan() -> Vec4 { + pure fn tan(&self) -> Vec4 { Vec4::new(tan(&self[0]), tan(&self[1]), tan(&self[2]), @@ -98,15 +98,15 @@ pub impl Vec4>: Trig> { } } -/// -/// 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; - pure fn acos() -> Radians; - pure fn atan() -> Radians; + pure fn asin(&self) -> Radians; + pure fn acos(&self) -> Radians; + pure fn atan(&self) -> Radians; } #[inline(always)] pub pure fn asin(x: &T) -> Radians { x.asin() } @@ -114,45 +114,45 @@ pub trait InvTrig { #[inline(always)] pub pure fn atan(x: &T) -> Radians { x.atan() } pub impl f32: InvTrig { - #[inline(always)] pure fn asin() -> Radians { Radians(f32::asin(self)) } - #[inline(always)] pure fn acos() -> Radians { Radians(f32::acos(self)) } - #[inline(always)] pure fn atan() -> Radians { Radians(f32::atan(self)) } + #[inline(always)] pure fn asin(&self) -> Radians { Radians(f32::asin(*self)) } + #[inline(always)] pure fn acos(&self) -> Radians { Radians(f32::acos(*self)) } + #[inline(always)] pure fn atan(&self) -> Radians { Radians(f32::atan(*self)) } } pub impl f64: InvTrig { - #[inline(always)] pure fn asin() -> Radians { Radians(f64::asin(self)) } - #[inline(always)] pure fn acos() -> Radians { Radians(f64::acos(self)) } - #[inline(always)] pure fn atan() -> Radians { Radians(f64::atan(self)) } + #[inline(always)] pure fn asin(&self) -> Radians { Radians(f64::asin(*self)) } + #[inline(always)] pure fn acos(&self) -> Radians { Radians(f64::acos(*self)) } + #[inline(always)] pure fn atan(&self) -> Radians { Radians(f64::atan(*self)) } } pub impl float: InvTrig { - #[inline(always)] pure fn asin() -> Radians { Radians(f64::asin(cast(self)).to_float()) } - #[inline(always)] pure fn acos() -> Radians { Radians(f64::acos(cast(self)).to_float()) } - #[inline(always)] pure fn atan() -> Radians { Radians(f64::atan(cast(self)).to_float()) } + #[inline(always)] pure fn asin(&self) -> Radians { Radians(f64::asin(cast(*self)).to_float()) } + #[inline(always)] pure fn acos(&self) -> Radians { Radians(f64::acos(cast(*self)).to_float()) } + #[inline(always)] pure fn atan(&self) -> Radians { Radians(f64::atan(cast(*self)).to_float()) } } // TODO: figure out how to merge with InvTrig pub trait InvTrigV { - 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 Vec2: InvTrigV>> { #[inline(always)] - pure fn asin() -> Vec2> { + pure fn asin(&self) -> Vec2> { Vec2::new(asin(&self[0]), asin(&self[1])) } #[inline(always)] - pure fn acos() -> Vec2> { + pure fn acos(&self) -> Vec2> { Vec2::new(acos(&self[0]), acos(&self[1])) } #[inline(always)] - pure fn atan() -> Vec2> { + pure fn atan(&self) -> Vec2> { Vec2::new(atan(&self[0]), atan(&self[1])) } @@ -160,21 +160,21 @@ pub impl Vec2: InvTrigV>> { pub impl Vec3: InvTrigV>> { #[inline(always)] - pure fn asin() -> Vec3> { + pure fn asin(&self) -> Vec3> { Vec3::new(asin(&self[0]), asin(&self[1]), asin(&self[2])) } #[inline(always)] - pure fn acos() -> Vec3> { + pure fn acos(&self) -> Vec3> { Vec3::new(acos(&self[0]), acos(&self[1]), acos(&self[2])) } #[inline(always)] - pure fn atan() -> Vec3> { + pure fn atan(&self) -> Vec3> { Vec3::new(atan(&self[0]), atan(&self[1]), atan(&self[2])) @@ -183,7 +183,7 @@ pub impl Vec3: InvTrigV>> { pub impl Vec4: InvTrigV>> { #[inline(always)] - pure fn asin() -> Vec4> { + pure fn asin(&self) -> Vec4> { Vec4::new(asin(&self[0]), asin(&self[1]), asin(&self[2]), @@ -191,7 +191,7 @@ pub impl Vec4: InvTrigV>> { } #[inline(always)] - pure fn acos() -> Vec4> { + pure fn acos(&self) -> Vec4> { Vec4::new(acos(&self[0]), acos(&self[1]), acos(&self[2]), @@ -199,7 +199,7 @@ pub impl Vec4: InvTrigV>> { } #[inline(always)] - pure fn atan() -> Vec4> { + pure fn atan(&self) -> Vec4> { Vec4::new(atan(&self[0]), atan(&self[1]), atan(&self[2]), @@ -209,15 +209,15 @@ pub impl Vec4: InvTrigV>> { -/// -/// 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(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 Vec2: Hyp { #[inline(always)] - pure fn sinh() -> Vec2 { + pure fn sinh(&self) -> Vec2 { Vec2::new(sinh(&self[0]), sinh(&self[1])) } #[inline(always)] - pure fn cosh() -> Vec2 { + pure fn cosh(&self) -> Vec2 { Vec2::new(cosh(&self[0]), cosh(&self[1])) } #[inline(always)] - pure fn tanh() -> Vec2 { + pure fn tanh(&self) -> Vec2 { Vec2::new(tanh(&self[0]), tanh(&self[1])) } @@ -267,21 +267,21 @@ pub impl Vec2: Hyp { pub impl Vec3: Hyp { #[inline(always)] - pure fn sinh() -> Vec3 { + pure fn sinh(&self) -> Vec3 { Vec3::new(sinh(&self[0]), sinh(&self[1]), sinh(&self[2])) } #[inline(always)] - pure fn cosh() -> Vec3 { + pure fn cosh(&self) -> Vec3 { Vec3::new(cosh(&self[0]), cosh(&self[1]), cosh(&self[2])) } #[inline(always)] - pure fn tanh() -> Vec3 { + pure fn tanh(&self) -> Vec3 { Vec3::new(tanh(&self[0]), tanh(&self[1]), tanh(&self[2])) @@ -290,7 +290,7 @@ pub impl Vec3: Hyp { pub impl Vec4: Hyp { #[inline(always)] - pure fn sinh() -> Vec4 { + pure fn sinh(&self) -> Vec4 { Vec4::new(sinh(&self[0]), sinh(&self[1]), sinh(&self[2]), @@ -298,7 +298,7 @@ pub impl Vec4: Hyp { } #[inline(always)] - pure fn cosh() -> Vec4 { + pure fn cosh(&self) -> Vec4 { Vec4::new(cosh(&self[0]), cosh(&self[1]), cosh(&self[2]), @@ -306,7 +306,7 @@ pub impl Vec4: Hyp { } #[inline(always)] - pure fn tanh() -> Vec4 { + pure fn tanh(&self) -> Vec4 { Vec4::new(tanh(&self[0]), tanh(&self[1]), tanh(&self[2]), diff --git a/src/mat.rs b/src/mat.rs index 6e57590..60c3099 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -18,11 +18,11 @@ use vec::{NumericVector, Vec2, Vec3, Vec4}; /// The base Matrix trait /// pub trait Matrix: Dimensional, 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: Matrix { /// A square matrix /// pub trait MatrixNxN: Matrix { - pure fn is_symmetric() -> bool; + pure fn is_symmetric(&self) -> bool; } /// A 2 x 2 square matrix @@ -83,10 +83,10 @@ pub trait Matrix4x4: MatrixNxN, pub trait NumericMatrix: Matrix, Neg { 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: MatrixNxN, // 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; - pure fn transpose() -> self; + pure fn invert(&self) -> Option; + 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: Matrix2x2, NumericMatrixNxN { - pure fn to_mat3() -> Mat3; - pure fn to_mat4() -> Mat4; + pure fn to_mat3(&self) -> Mat3; + pure fn to_mat4(&self) -> Mat4; } /// A 3 x 3 square matrix with numeric elements pub trait NumericMatrix3x3: Matrix3x3, NumericMatrixNxN { - pure fn to_mat4() -> Mat4; + pure fn to_mat4(&self) -> Mat4; } /// A 4 x 4 square matrix with numeric elements @@ -172,16 +172,16 @@ pub impl Mat2: Matrix, Vec2> { static pure fn size_of() -> uint { size_of::>() } #[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 { self[i] } + pure fn col(&self, i: uint) -> Vec2 { self[i] } #[inline(always)] - pure fn row(i: uint) -> Vec2 { + pure fn row(&self, i: uint) -> Vec2 { Vec2::new(self[0][i], self[1][i]) } @@ -195,14 +195,14 @@ pub impl Mat2: Matrix, Vec2> { } #[inline(always)] - pure fn to_ptr() -> *T { + pure fn to_ptr(&self) -> *T { self[0].to_ptr() } } pub impl Mat2: MatrixNxN> { #[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 Mat2: NumericMatrix, Vec2> { } #[inline(always)] - pure fn mul_t(value: T) -> Mat2 { + pure fn mul_t(&self, value: T) -> Mat2 { Mat2::from_cols(self[0].mul_t(value), self[1].mul_t(value)) } #[inline(always)] - pure fn mul_v(other: &Vec2) -> Vec2 { + pure fn mul_v(&self, other: &Vec2) -> Vec2 { Vec2::new(self.row(0).dot(other), self.row(1).dot(other)) } #[inline(always)] - pure fn add_m(other: &Mat2) -> Mat2 { + pure fn add_m(&self, other: &Mat2) -> Mat2 { Mat2::from_cols(self[0].add_v(&other[0]), self[1].add_v(&other[1])) } #[inline(always)] - pure fn sub_m(other: &Mat2) -> Mat2 { + pure fn sub_m(&self, other: &Mat2) -> Mat2 { Mat2::from_cols(self[0].sub_v(&other[0]), self[1].sub_v(&other[1])) } @@ -253,25 +253,25 @@ pub impl Mat2: NumericMatrixNxN> { } #[inline(always)] - pure fn mul_m(other: &Mat2) -> Mat2 { + pure fn mul_m(&self, other: &Mat2) -> Mat2 { 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 { - other.transpose().mul_m(&self).trace() + pure fn dot(&self, other: &Mat2) -> 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> { + pure fn invert(&self) -> Option> { let _0 = cast(0); let d = self.det(); if d.default_eq(&_0) { @@ -283,30 +283,30 @@ pub impl Mat2: NumericMatrixNxN> { } #[inline(always)] - pure fn transpose() -> Mat2 { + pure fn transpose(&self) -> Mat2 { 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 Mat2: NumericMatrixNxN> { pub impl Mat2: NumericMatrix2x2> { #[inline(always)] - pure fn to_mat3() -> Mat3 { - Mat3::from_Mat2(&self) + pure fn to_mat3(&self) -> Mat3 { + Mat3::from_Mat2(self) } #[inline(always)] - pure fn to_mat4() -> Mat4 { - Mat4::from_Mat2(&self) + pure fn to_mat4(&self) -> Mat4 { + Mat4::from_Mat2(self) } } @@ -406,16 +406,16 @@ pub impl Mat3: Matrix, Vec3> { static pure fn size_of() -> uint { size_of::>() } #[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 { self[i] } + pure fn col(&self, i: uint) -> Vec3 { self[i] } #[inline(always)] - pure fn row(i: uint) -> Vec3 { + pure fn row(&self, i: uint) -> Vec3 { Vec3::new(self[0][i], self[1][i], self[2][i]) @@ -430,14 +430,14 @@ pub impl Mat3: Matrix, Vec3> { } #[inline(always)] - pure fn to_ptr() -> *T { + pure fn to_ptr(&self) -> *T { self[0].to_ptr() } } pub impl Mat3: MatrixNxN> { #[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 Mat3: NumericMatrix, Vec3> { } #[inline(always)] - pure fn mul_t(value: T) -> Mat3 { + pure fn mul_t(&self, value: T) -> Mat3 { 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) -> Vec3 { + pure fn mul_v(&self, other: &Vec3) -> Vec3 { 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) -> Mat3 { + pure fn add_m(&self, other: &Mat3) -> Mat3 { 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) -> Mat3 { + pure fn sub_m(&self, other: &Mat3) -> Mat3 { 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 Mat3: NumericMatrixNxN> { } #[inline(always)] - pure fn mul_m(other: &Mat3) -> Mat3 { + pure fn mul_m(&self, other: &Mat3) -> Mat3 { 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 { - other.transpose().mul_m(&self).trace() + pure fn dot(&self, other: &Mat3) -> 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> { + pure fn invert(&self) -> Option> { let d = self.det(); let _0 = cast(0); if d.default_eq(&_0) { @@ -533,19 +533,19 @@ pub impl Mat3: NumericMatrixNxN> { } #[inline(always)] - pure fn transpose() -> Mat3 { + pure fn transpose(&self) -> Mat3 { 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 Mat3: NumericMatrixNxN> { } #[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 Mat3: NumericMatrixNxN> { pub impl Mat3: NumericMatrix3x3> { #[inline(always)] - pure fn to_mat4() -> Mat4 { - Mat4::from_Mat3(&self) + pure fn to_mat4(&self) -> Mat4 { + Mat4::from_Mat3(self) } } @@ -719,16 +719,16 @@ pub impl Mat4: Matrix, Vec4> { static pure fn size_of() -> uint { size_of::>() } #[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 { self[i] } + pure fn col(&self, i: uint) -> Vec4 { self[i] } #[inline(always)] - pure fn row(i: uint) -> Vec4 { + pure fn row(&self, i: uint) -> Vec4 { Vec4::new(self[0][i], self[1][i], self[2][i], @@ -744,14 +744,14 @@ pub impl Mat4: Matrix, Vec4> { } #[inline(always)] - pure fn to_ptr() -> *T { + pure fn to_ptr(&self) -> *T { self[0].to_ptr() } } pub impl Mat4: MatrixNxN> { #[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 Mat4: NumericMatrix, Vec4> { } #[inline(always)] - pure fn mul_t(value: T) -> Mat4 { + pure fn mul_t(&self, value: T) -> Mat4 { Mat4::from_cols(self[0].mul_t(value), self[1].mul_t(value), self[2].mul_t(value), @@ -793,7 +793,7 @@ pub impl Mat4: NumericMatrix, Vec4> { } #[inline(always)] - pure fn mul_v(other: &Vec4) -> Vec4 { + pure fn mul_v(&self, other: &Vec4) -> Vec4 { Vec4::new(self.row(0).dot(other), self.row(1).dot(other), self.row(2).dot(other), @@ -801,7 +801,7 @@ pub impl Mat4: NumericMatrix, Vec4> { } #[inline(always)] - pure fn add_m(other: &Mat4) -> Mat4 { + pure fn add_m(&self, other: &Mat4) -> Mat4 { 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 Mat4: NumericMatrix, Vec4> { } #[inline(always)] - pure fn sub_m(other: &Mat4) -> Mat4 { + pure fn sub_m(&self, other: &Mat4) -> Mat4 { 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 Mat4: NumericMatrixNxN) -> Mat4 { + pure fn mul_m(&self, other: &Mat4) -> Mat4 { // 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 Mat4: NumericMatrixNxN) -> T { - other.transpose().mul_m(&self).trace() + pure fn dot(&self, other: &Mat4) -> 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 Mat4: NumericMatrixNxN T { + pure fn trace(&self) -> T { self[0][0] + self[1][1] + self[2][2] + self[3][3] } - pure fn invert() -> Option> { + pure fn invert(&self) -> Option> { let d = self.det(); let _0 = cast(0); if d.default_eq(&_0) { @@ -869,7 +869,7 @@ pub impl Mat4: NumericMatrixNxN = NumericMatrixNxN::identity(); // Find largest pivot column j among rows j..3 @@ -917,7 +917,7 @@ pub impl Mat4: NumericMatrixNxN Mat4 { + pure fn transpose(&self) -> Mat4 { 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 Mat4: NumericMatrixNxN 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 Mat4: NumericMatrixNxN 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) } diff --git a/src/quat.rs b/src/quat.rs index b6c385a..64f16de 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -23,28 +23,28 @@ pub trait Quaternion: Dimensional, Eq, DefaultEq, Neg { 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) -> Vec3; + pure fn mul_v(&self, vec: &Vec3) -> Vec3; - 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; - pure fn to_mat4() -> Mat4; + pure fn to_mat3(&self) -> Mat3; + pure fn to_mat4(&self) -> Mat4; } pub trait ToQuat { @@ -104,7 +104,7 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn mul_t(value: T) -> Quat { + pure fn mul_t(&self, value: T) -> Quat { Quat::new(self[0] * value, self[1] * value, self[2] * value, @@ -112,7 +112,7 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn div_t(value: T) -> Quat { + pure fn div_t(&self, value: T) -> Quat { Quat::new(self[0] / value, self[1] / value, self[2] / value, @@ -120,13 +120,13 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn mul_v(vec: &Vec3) -> Vec3 { + pure fn mul_v(&self, vec: &Vec3) -> Vec3 { 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) -> Quat { + pure fn add_q(&self, other: &Quat) -> Quat { Quat::new(self[0] + other[0], self[1] + other[1], self[2] + other[2], @@ -134,7 +134,7 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn sub_q(other: &Quat) -> Quat { + pure fn sub_q(&self, other: &Quat) -> Quat { Quat::new(self[0] - other[0], self[1] - other[1], self[2] - other[2], @@ -142,7 +142,7 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn mul_q(other: &Quat) -> Quat { + pure fn mul_q(&self, other: &Quat) -> Quat { 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 Quat: Quaternion { } #[inline(always)] - pure fn dot(other: &Quat) -> T { + pure fn dot(&self, other: &Quat) -> T { self.s * other.s + self.v.dot(&other.v) } #[inline(always)] - pure fn conjugate() -> Quat { + pure fn conjugate(&self) -> Quat { Quat::from_sv(self.s, -self.v) } #[inline(always)] - pure fn inverse() -> Quat { + pure fn inverse(&self) -> Quat { 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 { + pure fn normalize(&self) -> Quat { let mut n: T = cast(1); n /= self.length(); return self.mul_t(n); } #[inline(always)] - pure fn nlerp(other: &Quat, amount: T) -> Quat { + pure fn nlerp(&self, other: &Quat, amount: T) -> Quat { let _1: T = cast(1); self.mul_t(_1 - amount).add_q(&other.mul_t(amount)).normalize() } @@ -204,7 +204,7 @@ pub impl Quat: Quaternion { * also provides a good explanation. */ #[inline(always)] - pure fn slerp(other: &Quat, amount: T) -> Quat { + pure fn slerp(&self, other: &Quat, amount: T) -> Quat { let dot: T = cast(self.dot(other)); // if quaternions are close together use `nlerp` @@ -222,7 +222,7 @@ pub impl Quat: Quaternion { } #[inline(always)] - pure fn to_mat3() -> Mat3 { + pure fn to_mat3(&self) -> Mat3 { 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 Quat: Quaternion { } #[inline(always)] - pure fn to_mat4() -> Mat4 { + pure fn to_mat4(&self) -> Mat4 { self.to_mat3().to_mat4() } } diff --git a/src/vec.rs b/src/vec.rs index 1fa7b92..4954926 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -41,13 +41,13 @@ pub trait NumericVector: Vector, Neg{ 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: NumericVector { // 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: NumericVector { /// A vector with geometric properties /// pub trait GeometricVector: NumericVector { - 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 Vec2: Vector { } #[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 Vec2: NumericVector { } #[inline(always)] - pure fn mul_t(value: T) -> Vec2 { + pure fn mul_t(&self, value: T) -> Vec2 { Vec2::new(self[0] * value, self[1] * value) } #[inline(always)] - pure fn div_t(value: T) -> Vec2 { + pure fn div_t(&self, value: T) -> Vec2 { Vec2::new(self[0] / value, self[1] / value) } #[inline(always)] - pure fn add_v(other: &Vec2) -> Vec2 { + pure fn add_v(&self, other: &Vec2) -> Vec2 { Vec2::new(self[0] + other[0], self[1] + other[1]) } #[inline(always)] - pure fn sub_v(other: &Vec2) -> Vec2 { + pure fn sub_v(&self, other: &Vec2) -> Vec2 { Vec2::new(self[0] - other[0], self[1] - other[1]) } #[inline(always)] - pure fn dot(other: &Vec2) -> T { + pure fn dot(&self, other: &Vec2) -> T { self[0] * other[0] + self[1] * other[1] } @@ -177,35 +177,35 @@ pub impl Vec2: NumericVector { pub impl Vec2: GeometricVector { #[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 { - other.sub_v(&self).length2() + pure fn distance2(&self, other: &Vec2) -> T { + other.sub_v(self).length2() } #[inline(always)] - pure fn distance(other: &Vec2) -> T { - other.distance2(&self).sqrt() + pure fn distance(&self, other: &Vec2) -> T { + other.distance2(self).sqrt() } #[inline(always)] - pure fn normalize() -> Vec2 { + pure fn normalize(&self) -> Vec2 { let mut n: T = cast(1); n /= self.length(); return self.mul_t(n); } #[inline(always)] - pure fn lerp(other: &Vec2, amount: T) -> Vec2 { - self.add_v(&other.sub_v(&self).mul_t(amount)) + pure fn lerp(&self, other: &Vec2, amount: T) -> Vec2 { + self.add_v(&other.sub_v(self).mul_t(amount)) } } @@ -275,7 +275,7 @@ pub impl Vec3: Vector { } #[inline(always)] - pure fn to_ptr() -> *T { + pure fn to_ptr(&self) -> *T { to_unsafe_ptr(&self[0]) } } @@ -301,35 +301,35 @@ pub impl Vec3: NumericVector { } #[inline(always)] - pure fn mul_t(value: T) -> Vec3 { + pure fn mul_t(&self, value: T) -> Vec3 { Vec3::new(self[0] * value, self[1] * value, self[2] * value) } #[inline(always)] - pure fn div_t(value: T) -> Vec3 { + pure fn div_t(&self, value: T) -> Vec3 { Vec3::new(self[0] / value, self[1] / value, self[2] / value) } #[inline(always)] - pure fn add_v(other: &Vec3) -> Vec3{ + pure fn add_v(&self, other: &Vec3) -> Vec3{ Vec3::new(self[0] + other[0], self[1] + other[1], self[2] + other[2]) } #[inline(always)] - pure fn sub_v(other: &Vec3) -> Vec3{ + pure fn sub_v(&self, other: &Vec3) -> Vec3{ Vec3::new(self[0] - other[0], self[1] - other[1], self[2] - other[2]) } #[inline(always)] - pure fn dot(other: &Vec3) -> T { + pure fn dot(&self, other: &Vec3) -> T { self[0] * other[0] + self[1] * other[1] + self[2] * other[2] @@ -338,7 +338,7 @@ pub impl Vec3: NumericVector { pub impl Vec3: NumericVector3 { #[inline(always)] - pure fn cross(other: &Vec3) -> Vec3 { + pure fn cross(&self, other: &Vec3) -> Vec3 { 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 Vec3: NumericVector3 { pub impl Vec3: GeometricVector { #[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 { - other.sub_v(&self).length2() + pure fn distance2(&self, other: &Vec3) -> T { + other.sub_v(self).length2() } #[inline(always)] - pure fn distance(other: &Vec3) -> T { - other.distance2(&self).sqrt() + pure fn distance(&self, other: &Vec3) -> T { + other.distance2(self).sqrt() } #[inline(always)] - pure fn normalize() -> Vec3 { + pure fn normalize(&self) -> Vec3 { let mut n: T = cast(1); n /= self.length(); return self.mul_t(n); } #[inline(always)] - pure fn lerp(other: &Vec3, amount: T) -> Vec3 { - self.add_v(&other.sub_v(&self).mul_t(amount)) + pure fn lerp(&self, other: &Vec3, amount: T) -> Vec3 { + self.add_v(&other.sub_v(self).mul_t(amount)) } } @@ -447,7 +447,7 @@ pub impl Vec4: Vector { } #[inline(always)] - pure fn to_ptr() -> *T { + pure fn to_ptr(&self) -> *T { to_unsafe_ptr(&self[0]) } } @@ -475,7 +475,7 @@ pub impl Vec4: NumericVector { } #[inline(always)] - pure fn mul_t(value: T) -> Vec4 { + pure fn mul_t(&self, value: T) -> Vec4 { Vec4::new(self[0] * value, self[1] * value, self[2] * value, @@ -483,7 +483,7 @@ pub impl Vec4: NumericVector { } #[inline(always)] - pure fn div_t(value: T) -> Vec4 { + pure fn div_t(&self, value: T) -> Vec4 { Vec4::new(self[0] / value, self[1] / value, self[2] / value, @@ -491,7 +491,7 @@ pub impl Vec4: NumericVector { } #[inline(always)] - pure fn add_v(other: &Vec4) -> Vec4 { + pure fn add_v(&self, other: &Vec4) -> Vec4 { Vec4::new(self[0] + other[0], self[1] + other[1], self[2] + other[2], @@ -499,7 +499,7 @@ pub impl Vec4: NumericVector { } #[inline(always)] - pure fn sub_v(other: &Vec4) -> Vec4 { + pure fn sub_v(&self, other: &Vec4) -> Vec4 { Vec4::new(self[0] - other[0], self[1] - other[1], self[2] - other[2], @@ -507,7 +507,7 @@ pub impl Vec4: NumericVector { } #[inline(always)] - pure fn dot(other: &Vec4) -> T { + pure fn dot(&self, other: &Vec4) -> T { self[0] * other[0] + self[1] * other[1] + self[2] * other[2] + @@ -517,35 +517,35 @@ pub impl Vec4: NumericVector { pub impl Vec4: GeometricVector { #[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 { - other.sub_v(&self).length2() + pure fn distance2(&self, other: &Vec4) -> T { + other.sub_v(self).length2() } #[inline(always)] - pure fn distance(other: &Vec4) -> T { - other.distance2(&self).sqrt() + pure fn distance(&self, other: &Vec4) -> T { + other.distance2(self).sqrt() } #[inline(always)] - pure fn normalize() -> Vec4 { + pure fn normalize(&self) -> Vec4 { let mut n: T = cast(1); n /= self.length(); return self.mul_t(n); } #[inline(always)] - pure fn lerp(other: &Vec4, amount: T) -> Vec4 { - self.add_v(&other.sub_v(&self).mul_t(amount)) + pure fn lerp(&self, other: &Vec4, amount: T) -> Vec4 { + self.add_v(&other.sub_v(self).mul_t(amount)) } }