diff --git a/README.md b/README.md index 35a8ec3..2d6bdbd 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,6 @@ Lmath is generic linear algebra library for Rust. There is still much to do, unit tests to write, bugs to fix, and performance enhancements to make. Help is much appreciated, so please don't hesitate to send me a pull request. -## Current issues - -Some of the trait bounds are currently very brittle and verbose. For example you may see implementations like the following: - - pub impl Quat: Quaternion { ... } - -Ick! Luckily this will be largely eliminated with trait inheritance which will be coming to Rust in the future. That will mean that the above Quaternion implementation would become something like: - - pub impl Quat: Quaternion { ... } - ## Todo: - ~~Matrix inversion~~ @@ -29,7 +19,7 @@ Ick! Luckily this will be largely eliminated with trait inheritance which will b Dependant on rust/master: -- Implement trait inheritance +- ~~Implement trait inheritance~~ - Make use of static functions for constants and constructors diff --git a/src/angle.rs b/src/angle.rs index b207a31..1733bd4 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -40,7 +40,7 @@ pub trait Angle: Add pub enum Radians = T; // FIXME: not sure why I need the Eq and Ord trait bounds, but Rust complains if I don't include them -pub impl Radians: Angle { +pub impl Radians: Angle { #[inline(always)] static pure fn full_turn() -> Radians { Radians(Float::two_pi()) } #[inline(always)] static pure fn half_turn() -> Radians { Radians(Float::pi()) } #[inline(always)] static pure fn quadrant() -> Radians { Radians(Float::pi_2()) } @@ -69,54 +69,54 @@ pub impl Radians: Angle { } } -pub impl Radians: Add, Radians> { +pub impl Radians: Add, Radians> { #[inline(always)] pure fn add(rhs: &Radians) -> Radians { Radians(*self + **rhs) } } -pub impl Radians: Sub, Radians> { +pub impl Radians: Sub, Radians> { #[inline(always)] pure fn sub(&self, rhs: &Radians) -> Radians { Radians(**self - **rhs) } } -pub impl Radians: Mul> { +pub impl Radians: Mul> { #[inline(always)] pure fn mul(&self, rhs: &T) -> Radians { Radians(**self * *rhs) } } -pub impl Radians: Div> { +pub impl Radians: Div> { #[inline(always)] pure fn div(&self, rhs: &T) -> Radians { Radians(**self / *rhs) } } -pub impl Radians: Modulo> { +pub impl Radians: Modulo> { #[inline(always)] pure fn modulo(&self, rhs: &T) -> Radians { Radians(**self % *rhs) } } -pub impl Radians: Neg> { +pub impl Radians: Neg> { #[inline(always)] pure fn neg(&self) -> Radians { Radians(-**self) } } -pub impl Radians: Eq { +pub impl Radians: Eq { #[inline(always)] pure fn eq(&self, other: &Radians) -> bool { **self == **other } #[inline(always)] pure fn ne(&self, other: &Radians) -> bool { **self != **other } } -pub impl Radians: Ord { +pub impl Radians: Ord { #[inline(always)] pure fn lt(&self, other: &Radians) -> bool { **self < **other } #[inline(always)] pure fn le(&self, other: &Radians) -> bool { **self <= **other } #[inline(always)] pure fn ge(&self, other: &Radians) -> bool { **self >= **other } @@ -134,7 +134,7 @@ pub impl Radians: ToStr { pub enum Degrees = T; // FIXME: not sure why I need the Eq and Ord trait bounds, but Rust complains if I don't include them -pub impl Degrees: Angle { +pub impl Degrees: Angle { #[inline(always)] static pure fn full_turn() -> Degrees { Degrees(cast(360.0)) } #[inline(always)] static pure fn half_turn() -> Degrees { Degrees(cast(180.0)) } #[inline(always)] static pure fn quadrant() -> Degrees { Degrees(cast(90.0)) } @@ -163,54 +163,54 @@ pub impl Degrees: Angle { } } -pub impl Degrees: Add, Degrees> { +pub impl Degrees: Add, Degrees> { #[inline(always)] pure fn add(rhs: &Degrees) -> Degrees { Degrees(*self + **rhs) } } -pub impl Degrees: Sub, Degrees> { +pub impl Degrees: Sub, Degrees> { #[inline(always)] pure fn sub(&self, rhs: &Degrees) -> Degrees { Degrees(**self - **rhs) } } -pub impl Degrees: Mul> { +pub impl Degrees: Mul> { #[inline(always)] pure fn mul(&self, rhs: &T) -> Degrees { Degrees(**self * *rhs) } } -pub impl Degrees: Div> { +pub impl Degrees: Div> { #[inline(always)] pure fn div(&self, rhs: &T) -> Degrees { Degrees(**self / *rhs) } } -pub impl Degrees: Modulo> { +pub impl Degrees: Modulo> { #[inline(always)] pure fn modulo(&self, rhs: &T) -> Degrees { Degrees(**self % *rhs) } } -pub impl Degrees: Neg> { +pub impl Degrees: Neg> { #[inline(always)] pure fn neg(&self) -> Degrees { Degrees(-**self) } } -pub impl Degrees: Eq { +pub impl Degrees: Eq { #[inline(always)] pure fn eq(&self, other: &Degrees) -> bool { **self == **other } #[inline(always)] pure fn ne(&self, other: &Degrees) -> bool { **self != **other } } -pub impl Degrees: Ord { +pub impl Degrees: Ord { #[inline(always)] pure fn lt(&self, other: &Degrees) -> bool { **self < **other } #[inline(always)] pure fn le(&self, other: &Degrees) -> bool { **self <= **other } #[inline(always)] pure fn ge(&self, other: &Degrees) -> bool { **self >= **other } @@ -233,7 +233,7 @@ pub struct Rotation { axis: Vec3, } -pub impl Rotation { +pub impl Rotation { #[inline(always)] static pure fn new(theta: Radians, axis: Vec3) -> Rotation { Rotation { theta: move theta, axis: move axis } diff --git a/src/color/color.rs b/src/color/color.rs index f098342..1670f86 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -9,6 +9,7 @@ use channel::Channel; use dim::{Dimensional, ToPtr}; use funs::common::Sign; use num::cast::{cast, NumCast}; +use num::ext::Float; pub trait Color: Dimensional, ToPtr, Eq { @@ -412,7 +413,7 @@ pub impl HSV: ToPtr { } } -pub impl HSV: Color { +pub impl HSV: Color { #[inline(always)] pure fn inverse(&self) -> HSV { HSV::new(self.h.opposite(), @@ -442,7 +443,7 @@ pub impl HSV: Color { } } -pub impl HSV: Color3 { +pub impl HSV: Color3 { #[inline(always)] pure fn to_rgba_u8(&self, a: u8) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u8(), a) } #[inline(always)] pure fn to_rgba_u16(&self, a: u16) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u16(), a) } #[inline(always)] pure fn to_rgba_u32(&self, a: u32) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u32(), a) } @@ -454,7 +455,7 @@ pub impl HSV: Color3 { #[inline(always)] pure fn to_hsva_f64(&self, a: f64) -> HSVA { HSVA::from_hsv_a(&self.to_hsv_f64(), a) } } -pub impl HSV: Eq { +pub impl HSV: Eq { pure fn eq(&self, other: &HSV) -> bool { self.h == other.h && self.s == other.s && @@ -511,7 +512,7 @@ pub impl HSVA: ToPtr { } } -pub impl HSVA: Color { +pub impl HSVA: Color { #[inline(always)] pure fn inverse(&self) -> HSVA { HSVA::new(self.h.opposite(), @@ -542,7 +543,7 @@ pub impl HSVA: Color { } } -pub impl HSVA: Color4 { +pub impl HSVA: Color4 { #[inline(always)] pure fn to_rgba_u8(&self) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u8(), self.a.to_channel_u8()) } #[inline(always)] pure fn to_rgba_u16(&self) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u16(), self.a.to_channel_u16()) } #[inline(always)] pure fn to_rgba_u32(&self) -> RGBA { RGBA::from_rgb_a(&self.to_rgb_u32(), self.a.to_channel_u32()) } @@ -554,7 +555,7 @@ pub impl HSVA: Color4 { #[inline(always)] pure fn to_hsva_f64(&self) -> HSVA { HSVA::from_hsv_a(&self.to_hsv_f64(), self.a.to_channel_f64()) } } -pub impl HSVA: Eq { +pub impl HSVA: Eq { pure fn eq(&self, other: &HSVA) -> bool { self.h == other.h && self.s == other.s && diff --git a/src/funs/projection.rs b/src/funs/projection.rs index 215ab88..c56e67e 100644 --- a/src/funs/projection.rs +++ b/src/funs/projection.rs @@ -2,6 +2,7 @@ use funs::triganomic::tan; use angle::Angle; use mat::Mat4; use num::cast::{NumCast, cast}; +use num::ext::Float; /** * Create a perspective projection matrix @@ -10,7 +11,7 @@ use num::cast::{NumCast, cast}; * can be found [here](http://www.opengl.org/wiki/GluPerspective_code). */ #[inline(always)] -pub pure fn perspective>(fovy: A, aspectRatio: T, near: T, far: T) -> Mat4 { +pub pure fn perspective>(fovy: A, aspectRatio: T, near: T, far: T) -> Mat4 { let ymax = near * tan(&fovy.to_radians()); let xmax = ymax * aspectRatio; @@ -24,7 +25,7 @@ pub pure fn perspective>(fovy: A, aspectRatio: T, * (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function. */ #[inline(always)] -pub pure fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4 { +pub pure fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4 { let _0: T = cast(0); let _2: T = cast(2); diff --git a/src/funs/test/test_common.rs b/src/funs/test/test_common.rs index 0915679..4e5d02e 100644 --- a/src/funs/test/test_common.rs +++ b/src/funs/test/test_common.rs @@ -122,15 +122,15 @@ fn test_min() { assert min(&2f32, &1f32) == 1f32; assert min(&2f64, &1f64) == 1f64; - assert Radians(1).min(&Radians(2)) == Radians(1); - assert Radians(2).min(&Radians(1)) == Radians(1); - assert min(&Radians(1), &Radians(2)) == Radians(1); - assert min(&Radians(2), &Radians(1)) == Radians(1); + assert Radians(1.0).min(&Radians(2.0)) == Radians(1.0); + assert Radians(2.0).min(&Radians(1.0)) == Radians(1.0); + assert min(&Radians(1.0), &Radians(2.0)) == Radians(1.0); + assert min(&Radians(2.0), &Radians(1.0)) == Radians(1.0); - assert Degrees(1).min(&Degrees(2)) == Degrees(1); - assert Degrees(2).min(&Degrees(1)) == Degrees(1); - assert min(&Degrees(1), &Degrees(2)) == Degrees(1); - assert min(&Degrees(2), &Degrees(1)) == Degrees(1); + assert Degrees(1.0).min(&Degrees(2.0)) == Degrees(1.0); + assert Degrees(2.0).min(&Degrees(1.0)) == Degrees(1.0); + assert min(&Degrees(1.0), &Degrees(2.0)) == Degrees(1.0); + assert min(&Degrees(2.0), &Degrees(1.0)) == Degrees(1.0); assert min(&Vec2::new(1, 2), &Vec2::new(2, 1)) == Vec2::new(1, 1); assert min(&Vec3::new(1, 2, 3), &Vec3::new(3, 2, 1)) == Vec3::new(1, 2, 1); @@ -201,15 +201,15 @@ fn test_max() { assert max(&2f32, &1f32) == 2f32; assert max(&2f64, &1f64) == 2f64; - assert Radians(1).max(&Radians(2)) == Radians(2); - assert Radians(2).max(&Radians(1)) == Radians(2); - assert max(&Radians(1), &Radians(2)) == Radians(2); - assert max(&Radians(2), &Radians(1)) == Radians(2); + assert Radians(1.0).max(&Radians(2.0)) == Radians(2.0); + assert Radians(2.0).max(&Radians(1.0)) == Radians(2.0); + assert max(&Radians(1.0), &Radians(2.0)) == Radians(2.0); + assert max(&Radians(2.0), &Radians(1.0)) == Radians(2.0); - assert Degrees(1).max(&Degrees(2)) == Degrees(2); - assert Degrees(2).max(&Degrees(1)) == Degrees(2); - assert max(&Degrees(1), &Degrees(2)) == Degrees(2); - assert max(&Degrees(2), &Degrees(1)) == Degrees(2); + assert Degrees(1.0).max(&Degrees(2.0)) == Degrees(2.0); + assert Degrees(2.0).max(&Degrees(1.0)) == Degrees(2.0); + assert max(&Degrees(1.0), &Degrees(2.0)) == Degrees(2.0); + assert max(&Degrees(2.0), &Degrees(1.0)) == Degrees(2.0); assert max(&Vec2::new(1, 2), &Vec2::new(2, 1)) == Vec2::new(2, 2); assert max(&Vec3::new(1, 2, 3), &Vec3::new(3, 2, 1)) == Vec3::new(3, 2, 3); diff --git a/src/mat.rs b/src/mat.rs index 8208421..a2e99eb 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -11,6 +11,7 @@ use funs::common::*; use funs::exponential::*; use num::cast::*; use num::default_eq::DefaultEq; +use num::ext::Float; use quat::{Quat, ToQuat}; use vec::{NumericVector, Vec2, Vec3, Vec4}; @@ -70,7 +71,7 @@ pub trait Matrix4: Matrix { */ pub struct Mat2 { x: Vec2, y: Vec2 } -pub impl Mat2 { +pub impl Mat2 { #[inline(always)] static pure fn new(c0r0: T, c0r1: T, c1r0: T, c1r1: T) -> Mat2 { @@ -109,7 +110,7 @@ pub impl Mat2 { } } -pub impl Mat2: Matrix> { +pub impl Mat2: Matrix> { #[inline(always)] pure fn col(&self, i: uint) -> Vec2 { self[i] } @@ -226,7 +227,7 @@ pub impl Mat2: Matrix> { } } -pub impl Mat2: Matrix2> { +pub impl Mat2: Matrix2> { #[inline(always)] pure fn to_mat3(&self) -> Mat3 { Mat3::from_Mat2(self) @@ -263,14 +264,14 @@ pub impl Mat2: ToPtr { } } -pub impl Mat2: Neg> { +pub impl Mat2: Neg> { #[inline(always)] pure fn neg(&self) -> Mat2 { Mat2::from_cols(-self[0], -self[1]) } } -pub impl Mat2: Eq { +pub impl Mat2: Eq { #[inline(always)] pure fn eq(&self, other: &Mat2) -> bool { self[0] == other[0] && @@ -283,7 +284,7 @@ pub impl Mat2: Eq { } } -pub impl Mat2: FuzzyEq { +pub impl Mat2: FuzzyEq { #[inline(always)] pure fn fuzzy_eq(other: &Mat2) -> bool { self[0].fuzzy_eq(&other[0]) && @@ -291,7 +292,7 @@ pub impl Mat2: FuzzyEq { } } -pub impl Mat2: DefaultEq { +pub impl Mat2: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &Mat2) -> bool { self[0].default_eq(&other[0]) && @@ -309,7 +310,7 @@ pub impl Mat2: DefaultEq { */ pub struct Mat3 { x: Vec3, y: Vec3, z: Vec3 } -pub impl Mat3 { +pub impl Mat3 { #[inline(always)] static pure fn new(c0r0:T, c0r1:T, c0r2:T, c1r0:T, c1r1:T, c1r2:T, @@ -363,7 +364,7 @@ pub impl Mat3 { } } -pub impl Mat3: Matrix> { +pub impl Mat3: Matrix> { #[inline(always)] pure fn col(&self, i: uint) -> Vec3 { self[i] } @@ -503,14 +504,14 @@ pub impl Mat3: Matrix> { } } -pub impl Mat3: Matrix3> { +pub impl Mat3: Matrix3> { #[inline(always)] pure fn to_mat4(&self) -> Mat4 { Mat4::from_Mat3(self) } } -pub impl Mat3: ToQuat { +pub impl Mat3: ToQuat { pure fn to_Quat() -> Quat { // Implemented using a mix of ideas from jMonkeyEngine and Ken Shoemake's // paper on Quaternions: http://www.cs.ucr.edu/~vbz/resources/Quatut.pdf @@ -578,14 +579,14 @@ pub impl Mat3: ToPtr { } } -pub impl Mat3: Neg> { +pub impl Mat3: Neg> { #[inline(always)] pure fn neg(&self) -> Mat3 { Mat3::from_cols(-self[0], -self[1], -self[2]) } } -pub impl Mat3: Eq { +pub impl Mat3: Eq { #[inline(always)] pure fn eq(&self, other: &Mat3) -> bool { self[0] == other[0] && @@ -599,7 +600,7 @@ pub impl Mat3: Eq { } } -pub impl Mat3: FuzzyEq { +pub impl Mat3: FuzzyEq { #[inline(always)] pure fn fuzzy_eq(other: &Mat3) -> bool { self[0].fuzzy_eq(&other[0]) && @@ -608,7 +609,7 @@ pub impl Mat3: FuzzyEq { } } -pub impl Mat3: DefaultEq { +pub impl Mat3: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &Mat3) -> bool { self[0].default_eq(&other[0]) && @@ -627,7 +628,7 @@ pub impl Mat3: DefaultEq { */ pub struct Mat4 { x: Vec4, y: Vec4, z: Vec4, w: Vec4 } -pub impl Mat4 { +pub impl Mat4 { #[inline(always)] static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T, c1r0: T, c1r1: T, c1r2: T, c1r3: T, @@ -698,7 +699,7 @@ pub impl Mat4 { } } -pub impl Mat4: Matrix> { +pub impl Mat4: Matrix> { #[inline(always)] pure fn col(&self, i: uint) -> Vec4 { self[i] } @@ -921,7 +922,7 @@ pub impl Mat4: Matrix> { pub impl Mat4: Matrix4> { } -pub impl Mat4: Neg> { +pub impl Mat4: Neg> { #[inline(always)] pure fn neg(&self) -> Mat4 { Mat4::from_cols(-self[0], -self[1], -self[2], -self[3]) @@ -953,7 +954,7 @@ pub impl Mat4: ToPtr { } } -pub impl Mat4: Eq { +pub impl Mat4: Eq { #[inline(always)] pure fn eq(&self, other: &Mat4) -> bool { self[0] == other[0] && @@ -968,7 +969,7 @@ pub impl Mat4: Eq { } } -pub impl Mat4: FuzzyEq { +pub impl Mat4: FuzzyEq { #[inline(always)] pure fn fuzzy_eq(other: &Mat4) -> bool { self[0].fuzzy_eq(&other[0]) && @@ -978,7 +979,7 @@ pub impl Mat4: FuzzyEq { } } -pub impl Mat4: DefaultEq { +pub impl Mat4: DefaultEq { #[inline(always)] pure fn default_eq(&self, other: &Mat4) -> bool { self[0].default_eq(&other[0]) && diff --git a/src/num/ext.rs b/src/num/ext.rs index ce3c0f6..bdfbb88 100644 --- a/src/num/ext.rs +++ b/src/num/ext.rs @@ -1,16 +1,82 @@ use core::cmp::{Eq, Ord}; +use std::cmp::FuzzyEq; -use num::cast::*; -use num::default_eq::*; +use num::cast::NumCast; +use num::default_eq::DefaultEq; -pub trait Number: Copy, Eq, Num, NumCast, Ord { +pub trait Number: DefaultEq, Eq, Num, NumCast, Ord { static pure fn zero() -> self; static pure fn one() -> self; } +pub impl u8: Number { + #[inline(always)] static pure fn zero() -> u8 { 0u8 } + #[inline(always)] static pure fn one() -> u8 { 1u8 } +} -pub trait UnSigned /*:Number*/ {} +pub impl u16: Number { + #[inline(always)] static pure fn zero() -> u16 { 0u16 } + #[inline(always)] static pure fn one() -> u16 { 1u16 } +} + +pub impl u32: Number { + #[inline(always)] static pure fn zero() -> u32 { 0u32 } + #[inline(always)] static pure fn one() -> u32 { 1u32 } +} + +pub impl u64: Number { + #[inline(always)] static pure fn zero() -> u64 { 0u64 } + #[inline(always)] static pure fn one() -> u64 { 1u64 } +} + +pub impl uint: Number { + #[inline(always)] static pure fn zero() -> uint { 0u } + #[inline(always)] static pure fn one() -> uint { 1u } +} + +pub impl i8: Number { + #[inline(always)] static pure fn zero() -> i8 { 0i8 } + #[inline(always)] static pure fn one() -> i8 { 1i8 } +} + +pub impl i16: Number { + #[inline(always)] static pure fn zero() -> i16 { 0i16 } + #[inline(always)] static pure fn one() -> i16 { 1i16 } +} + +pub impl i32: Number { + #[inline(always)] static pure fn zero() -> i32 { 0i32 } + #[inline(always)] static pure fn one() -> i32 { 1i32 } +} + +pub impl i64: Number { + #[inline(always)] static pure fn zero() -> i64 { 0i64 } + #[inline(always)] static pure fn one() -> i64 { 1i64 } +} + +pub impl int: Number { + #[inline(always)] static pure fn zero() -> int { 0 } + #[inline(always)] static pure fn one() -> int { 1 } +} + +pub impl f32: Number { + #[inline(always)] static pure fn zero() -> f32 { 0f32 } + #[inline(always)] static pure fn one() -> f32 { 1f32 } +} + +pub impl f64: Number { + #[inline(always)] static pure fn zero() -> f64 { 0f64 } + #[inline(always)] static pure fn one() -> f64 { 1f64 } +} + +pub impl float: Number { + #[inline(always)] static pure fn zero() -> float { 0f } + #[inline(always)] static pure fn one() -> float { 1f } +} + + +pub trait UnSigned: Number {} pub impl u8: UnSigned {} pub impl u16: UnSigned {} @@ -19,7 +85,7 @@ pub impl u64: UnSigned {} pub impl uint: UnSigned {} -pub trait Signed /*:Number*/ {} +pub trait Signed: Number {} pub impl i8: Signed {} pub impl i16: Signed {} @@ -32,7 +98,7 @@ pub impl f64: Signed {} pub impl float: Signed {} -pub trait Integer /*:Number*/ {} +pub trait Integer: Number {} pub impl u8: Integer {} pub impl u16: Integer {} @@ -47,7 +113,7 @@ pub impl i64: Integer {} pub impl int: Integer {} -pub trait Float /*:Number, FuzzyEq*/ { +pub trait Float: Number, FuzzyEq { pure fn to_float() -> float; static pure fn from_float(n: float) -> self; diff --git a/src/quat.rs b/src/quat.rs index 560104b..b32b0fc 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -13,6 +13,7 @@ use funs::triganomic::*; use mat::{Mat3, Mat4}; use num::cast::*; use num::default_eq::DefaultEq; +use num::ext::Float; use vec::Vec3; @@ -95,7 +96,7 @@ pub impl Quat: ToPtr { } } -pub impl Quat: Quaternion { +pub impl Quat: Quaternion { #[inline(always)] static pure fn identity() -> Quat { Quat::new(NumCast::one(), @@ -301,4 +302,82 @@ pub impl Quat: DefaultEq { self[2].default_eq(&other[2]) && self[3].default_eq(&other[3]) } -} \ No newline at end of file +} + +// // Operator Overloads + +// pub impl> Quat: Add { +// #[inline(always)] +// pure fn add(rhs: &RHS) -> Result { +// rhs.quat_add_rhs(&self) +// } +// } + +// pub impl> Quat: Sub { +// #[inline(always)] +// pure fn sub(&self, rhs: &RHS) -> Result { +// rhs.quat_sub_rhs(self) +// } +// } + +// pub impl> Quat: Mul { +// #[inline(always)] +// pure fn mul(&self, rhs: &RHS) -> Result { +// rhs.quat_mul_rhs(self) +// } +// } + +// pub impl> Quat: Div { +// #[inline(always)] +// pure fn div(&self, rhs: &RHS) -> Result { +// rhs.quat_div_rhs(self) +// } +// } + +// // RHS Traits for Operator overloads +// pub trait QuatAddRHS { pure fn quat_add_rhs(&self, lhs: &Quat) -> Result; } +// pub trait QuatSubRHS { pure fn quat_sub_rhs(&self, lhs: &Quat) -> Result; } +// pub trait QuatMulRHS { pure fn quat_mul_rhs(&self, lhs: &Quat) -> Result; } +// pub trait QuatDivRHS { pure fn quat_div_rhs(&self, lhs: &Quat) -> Result; } + +// // Quat/Scalar Multiplication +// pub impl f32: QuatMulRHS> { #[inline(always)] pure fn quat_mul_rhs(&self, lhs: &Quat) -> Quat { lhs.mul_t(self) } } +// pub impl f64: QuatMulRHS> { #[inline(always)] pure fn quat_mul_rhs(&self, lhs: &Quat) -> Quat { lhs.mul_t(self) } } +// pub impl float: QuatMulRHS> { #[inline(always)] pure fn quat_mul_rhs(&self, lhs: &Quat) -> Quat { lhs.mul_t(self) } } + +// // Quat/Scalar Division +// pub impl f32: QuatDivRHS> { #[inline(always)] pure fn quat_div_rhs(&self, lhs: &Quat) -> Quat { lhs.div_t(self) } } +// pub impl f64: QuatDivRHS> { #[inline(always)] pure fn quat_div_rhs(&self, lhs: &Quat) -> Quat { lhs.div_t(self) } } +// pub impl float: QuatDivRHS> { #[inline(always)] pure fn quat_div_rhs(&self, lhs: &Quat) -> Quat { lhs.div_t(self) } } + +// // Quat/Vector Multiplication +// pub impl Vec3: QuatMulRHS> { +// #[inline(always)] +// pure fn quat_mul_rhs(&self, lhs: &Quat) -> Vec3 { +// lhs.mul_v(self) +// } +// } + +// // // Quat/Quat Addition +// // pub impl Quat: QuatAddRHS, Quat> { +// // #[inline(always)] +// // pure fn quat_add_rhs(&self, lhs: &Quat) -> Quat { +// // lhs.add_q(self) +// // } +// // } + +// // Quat/Quat Subtraction +// pub impl Quat: QuatSubRHS> { +// #[inline(always)] +// pure fn quat_sub_rhs(&self, lhs: &Quat) -> Quat { +// lhs.sub_q(self) +// } +// } + +// // Quat/Quat Multiplication +// pub impl Quat: QuatMulRHS> { +// #[inline(always)] +// pure fn quat_mul_rhs(&self, lhs: &Quat) -> Quat { +// lhs.mul_q(self) +// } +// } \ No newline at end of file diff --git a/src/vec.rs b/src/vec.rs index 25a9c3f..ec7cdbc 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -10,6 +10,7 @@ use dim::{Dimensional, ToPtr}; use funs::exponential::Exp; use num::cast::*; use num::default_eq::DefaultEq; +use num::ext::Number; /// /// The base vector trait @@ -132,7 +133,7 @@ pub impl Vec2: ToPtr { } } -pub impl Vec2: NumericVector { +pub impl Vec2: NumericVector { #[inline(always)] static pure fn identity() -> Vec2 { Vec2::new(NumCast::one(), @@ -176,14 +177,14 @@ pub impl Vec2: NumericVector { } } -pub impl Vec2: Neg> { +pub impl Vec2: Neg> { #[inline(always)] pure fn neg(&self) -> Vec2 { Vec2::new(-self[0], -self[1]) } } -pub impl Vec2: GeometricVector { +pub impl Vec2: GeometricVector { #[inline(always)] pure fn length2(&self) -> T { self.dot(self) @@ -294,7 +295,7 @@ pub impl Vec3: ToPtr { } } -pub impl Vec3: NumericVector { +pub impl Vec3: NumericVector { #[inline(always)] static pure fn identity() -> Vec3 { Vec3::new(NumCast::one(), @@ -345,14 +346,14 @@ pub impl Vec3: NumericVector { } } -pub impl Vec3: Neg> { +pub impl Vec3: Neg> { #[inline(always)] pure fn neg(&self) -> Vec3 { Vec3::new(-self[0], -self[1], -self[2]) } } -pub impl Vec3: NumericVector3 { +pub impl Vec3: NumericVector3 { #[inline(always)] pure fn cross(&self, other: &Vec3) -> Vec3 { Vec3::new((self[1] * other[2]) - (self[2] * other[1]), @@ -361,7 +362,7 @@ pub impl Vec3: NumericVector3 { } } -pub impl Vec3: GeometricVector { +pub impl Vec3: GeometricVector { #[inline(always)] pure fn length2(&self) -> T { self.dot(self) @@ -474,7 +475,7 @@ pub impl Vec4: ToPtr { } } -pub impl Vec4: NumericVector { +pub impl Vec4: NumericVector { #[inline(always)] static pure fn identity() -> Vec4 { Vec4::new(NumCast::one(), @@ -532,14 +533,14 @@ pub impl Vec4: NumericVector { } } -pub impl Vec4: Neg> { +pub impl Vec4: Neg> { #[inline(always)] pure fn neg(&self) -> Vec4 { Vec4::new(-self[0], -self[1], -self[2], -self[3]) } } -pub impl Vec4: GeometricVector { +pub impl Vec4: GeometricVector { #[inline(always)] pure fn length2(&self) -> T { self.dot(self)