updated syntax and added type bounds, scope ownership issues remain
This commit is contained in:
parent
7f0de1b42f
commit
8b94369a38
10 changed files with 538 additions and 539 deletions
|
@ -18,7 +18,7 @@ pub use mat4::{Mat4, mat4, dmat4};
|
|||
* floating point type and have the same number of dimensions as the
|
||||
* number of rows and columns in the matrix.
|
||||
*/
|
||||
pub trait Matrix<T,V>: Index<uint, V> Eq Neg<Self> {
|
||||
pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
|
|
35
src/mat2.rs
35
src/mat2.rs
|
@ -46,7 +46,7 @@ use mat::{
|
|||
#[deriving_eq]
|
||||
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
|
||||
|
@ -208,7 +208,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableMatrix<T, Vec2<T> > for Mat2<T> {
|
||||
#[inline(always)]
|
||||
fn col_mut(&mut self, i: uint) -> &self/mut Vec2<T> {
|
||||
match i {
|
||||
|
@ -220,8 +220,7 @@ pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec2<T>> for Mat2<T> {
|
|||
|
||||
#[inline(always)]
|
||||
fn swap_cols(&mut self, a: uint, b: uint) {
|
||||
swap(self.col_mut(a),
|
||||
self.col_mut(b));
|
||||
swap(&mut self.x, &mut self.y);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -247,20 +246,20 @@ pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec2<T>> for Mat2<T> {
|
|||
|
||||
#[inline(always)]
|
||||
fn mul_self_t(&mut self, value: T) {
|
||||
self.col_mut(0).mul_self_t(&value);
|
||||
self.col_mut(1).mul_self_t(&value);
|
||||
&mut self.x.mul_self_t(&value);
|
||||
&mut self.y.mul_self_t(&value);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn add_self_m(&mut self, other: &Mat2<T>) {
|
||||
self.col_mut(0).add_self_v(&other[0]);
|
||||
self.col_mut(1).add_self_v(&other[1]);
|
||||
&mut self.x.add_self_v(&other[0]);
|
||||
&mut self.y.add_self_v(&other[1]);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn sub_self_m(&mut self, other: &Mat2<T>) {
|
||||
self.col_mut(0).sub_self_v(&other[0]);
|
||||
self.col_mut(1).sub_self_v(&other[1]);
|
||||
&mut self.x.sub_self_v(&other[0]);
|
||||
&mut self.y.sub_self_v(&other[1]);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -273,12 +272,12 @@ pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec2<T>> for Mat2<T> {
|
|||
|
||||
#[inline(always)]
|
||||
fn transpose_self(&mut self) {
|
||||
swap(self.col_mut(0).index_mut(1), self.col_mut(1).index_mut(0));
|
||||
swap(self.col_mut(1).index_mut(0), self.col_mut(0).index_mut(1));
|
||||
&mut swap(&mut self.x.index_mut(1), &mut self.y.index_mut(0));
|
||||
&mut swap(&mut self.y.index_mut(0), &mut self.x.index_mut(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
|
||||
/**
|
||||
* Construct a 2 x 2 matrix
|
||||
*
|
||||
|
@ -379,7 +378,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
||||
impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec2<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -389,14 +388,14 @@ pub impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat2<T>> for Mat2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat2<T> {
|
||||
Matrix2::from_cols(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -417,7 +416,7 @@ pub type dmat2 = Mat2<f64>; // a 2×2 double-precision floating-point matrix
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat2 {
|
||||
impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
|
@ -435,7 +434,7 @@ pub impl mat2 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
||||
}
|
||||
|
||||
pub impl dmat2 {
|
||||
impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
|
|
16
src/mat3.rs
16
src/mat3.rs
|
@ -48,7 +48,7 @@ use mat::{
|
|||
#[deriving_eq]
|
||||
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
|
||||
|
@ -248,7 +248,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
|
||||
/**
|
||||
* Construct a 3 x 3 matrix
|
||||
*
|
||||
|
@ -475,7 +475,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableMatrix<T, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
fn col_mut(&mut self, i: uint) -> &self/mut Vec3<T> {
|
||||
match i {
|
||||
|
@ -556,7 +556,7 @@ pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec3<T>> for Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
||||
impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec3<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -566,14 +566,14 @@ pub impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat3<T>> for Mat3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat3<T> {
|
||||
Matrix3::from_cols(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> FuzzyEq<T> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -595,7 +595,7 @@ pub type dmat3 = Mat3<f64>; // a 3×3 double-precision floating-point matrix
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat3 {
|
||||
impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
|
@ -620,7 +620,7 @@ pub impl mat3 {
|
|||
}
|
||||
|
||||
|
||||
pub impl dmat3 {
|
||||
impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
|
|
16
src/mat4.rs
16
src/mat4.rs
|
@ -45,7 +45,7 @@ use mat::{
|
|||
#[deriving_eq]
|
||||
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
|
||||
|
@ -332,7 +332,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
|
||||
/**
|
||||
* Construct a 4 x 4 matrix
|
||||
*
|
||||
|
@ -399,7 +399,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableMatrix<T, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
fn col_mut(&mut self, i: uint) -> &self/mut Vec4<T> {
|
||||
match i {
|
||||
|
@ -492,14 +492,14 @@ pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec4<T>> for Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat4<T>> for Mat4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat4<T> {
|
||||
Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
||||
impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec4<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -509,7 +509,7 @@ pub impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -532,7 +532,7 @@ pub type dmat4 = Mat4<f64>; // a 4×4 double-precision floating-point matrix
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl mat4 {
|
||||
impl mat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
||||
-> mat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
||||
|
@ -548,7 +548,7 @@ pub impl mat4 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
||||
}
|
||||
|
||||
pub impl dmat4 {
|
||||
impl dmat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
||||
-> dmat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
||||
|
|
|
@ -12,7 +12,7 @@ use mat::{Mat4, Matrix4};
|
|||
* can be found [here](http://www.opengl.org/wiki/GluPerspective_code).
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn perspective<T:Copy Float FuzzyEq<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
|
||||
pub pure fn perspective<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
|
||||
let ymax = near * tan(radians(fovy));
|
||||
let xmax = ymax * aspectRatio;
|
||||
|
||||
|
@ -26,7 +26,7 @@ pub pure fn perspective<T:Copy Float FuzzyEq<T>>(fovy: T, aspectRatio: T, near:
|
|||
* (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn frustum<T:Copy Float FuzzyEq<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
|
||||
pub pure fn frustum<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
|
||||
let _0: T = Number::from(0);
|
||||
let _1: T = Number::from(1);
|
||||
let _2: T = Number::from(2);
|
||||
|
|
12
src/quat.rs
12
src/quat.rs
|
@ -48,7 +48,7 @@ use vec::{
|
|||
#[deriving_eq]
|
||||
pub struct Quat<T> { s: T, v: Vec3<T> }
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Quat<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Quat<T> {
|
||||
/**
|
||||
* Construct the quaternion from one scalar component and three
|
||||
* imaginary components
|
||||
|
@ -390,7 +390,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Quat<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Index<uint, T> for Quat<T> {
|
||||
impl<T:Copy> Index<uint, T> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
|
@ -400,14 +400,14 @@ pub impl<T:Copy> Index<uint, T> for Quat<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> Neg<Quat<T>> for Quat<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Quat<T>> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Quat<T> {
|
||||
Quat::new(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -430,7 +430,7 @@ pub type dquat = Quat<f64>; /// a double-precision floating-point qu
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl quat {
|
||||
impl quat {
|
||||
#[inline(always)] static pure fn new(w: f32, xi: f32, yj: f32, zk: f32) -> quat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static pure fn from_sv(s: f32, v: vec3) -> quat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static pure fn identity() -> quat { Quat::identity() }
|
||||
|
@ -446,7 +446,7 @@ pub impl quat {
|
|||
#[inline(always)] static pure fn look_at(dir: &vec3, up: &vec3) -> quat { Quat::look_at(dir, up) }
|
||||
}
|
||||
|
||||
pub impl dquat {
|
||||
impl dquat {
|
||||
#[inline(always)] static pure fn new(w: f64, xi: f64, yj: f64, zk: f64) -> dquat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static pure fn from_sv(s: f64, v: dvec3) -> dquat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static pure fn identity() -> dquat { Quat::identity() }
|
||||
|
|
|
@ -17,7 +17,7 @@ pub use vec4::{Vec4, vec4, dvec4, bvec4, ivec4, uvec4};
|
|||
* * `T` - The type of the components. This is intended to support boolean,
|
||||
* integer, unsigned integer, and floating point types.
|
||||
*/
|
||||
pub trait Vector<T>: Index<uint, T> Eq {
|
||||
pub trait Vector<T>: Index<uint, T> + Eq {
|
||||
/**
|
||||
* Construct the vector from a single value, copying it to each component
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ pub trait Vector4<T>: Vector<T> {
|
|||
/**
|
||||
* A vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector<T>: Vector<T> Neg<Self> {
|
||||
pub trait NumericVector<T>: Vector<T> + Neg<Self> {
|
||||
/**
|
||||
* The standard basis vector
|
||||
*
|
||||
|
@ -179,7 +179,7 @@ pub trait NumericVector4<T>: NumericVector<T> {
|
|||
/**
|
||||
* A mutable vector with numeric components
|
||||
*/
|
||||
pub trait MutableNumericVector<T>: MutableVector<&self/T>
|
||||
pub trait MutableNumericVector<T>: MutableVector<&self/T> +
|
||||
NumericVector<T> {
|
||||
/**
|
||||
* Negate the vector
|
||||
|
@ -313,7 +313,7 @@ pub trait EuclideanVector<T>: NumericVector<T> {
|
|||
*
|
||||
* * `T` - The type of the components. This should be a floating point type.
|
||||
*/
|
||||
pub trait MutableEuclideanVector<T>: MutableNumericVector<&self/T>
|
||||
pub trait MutableEuclideanVector<T>: MutableNumericVector<&self/T> +
|
||||
EuclideanVector<T> {
|
||||
/**
|
||||
* Normalize the vector
|
||||
|
|
40
src/vec2.rs
40
src/vec2.rs
|
@ -43,7 +43,7 @@ use vec::{
|
|||
#[deriving_eq]
|
||||
pub struct Vec2<T> { x: T, y: T }
|
||||
|
||||
pub impl<T:Copy Eq> Vector<T> for Vec2<T> {
|
||||
impl<T:Copy + Eq> Vector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec2<T> {
|
||||
Vector2::new(value, value)
|
||||
|
@ -59,21 +59,21 @@ pub impl<T:Copy Eq> Vector<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T> Vector2<T> for Vec2<T> {
|
||||
impl<T> Vector2<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T ) -> Vec2<T> {
|
||||
Vec2 { x: x, y: y }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Index<uint, T> for Vec2<T> {
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> MutableVector<T> for Vec2<T> {
|
||||
impl<T:Copy> MutableVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, i: uint) -> &self/mut T {
|
||||
match i {
|
||||
|
@ -90,7 +90,7 @@ pub impl<T:Copy> MutableVector<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector<T> for Vec2<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), one::<T>())
|
||||
|
@ -150,14 +150,14 @@ pub impl<T:Copy Number> NumericVector<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Neg<Vec2<T>> for Vec2<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec2<T>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec2<T> {
|
||||
Vector2::new(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector2<T> for Vec2<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector2<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), zero::<T>())
|
||||
|
@ -174,7 +174,7 @@ pub impl<T:Copy Number> NumericVector2<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec2<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableNumericVector<&self/T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
*self.index_mut(0) = -*self.index_mut(0);
|
||||
|
@ -218,14 +218,14 @@ pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
|
||||
impl<T:Copy + Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_homogeneous(&self) -> Vec3<T> {
|
||||
Vector3::new(self.x, self.y, zero())
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> EuclideanVector<T> for Vec2<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -267,7 +267,7 @@ pub impl<T:Copy Float> EuclideanVector<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec2<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableEuclideanVector<&self/T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
fn normalize_self(&mut self) {
|
||||
let n = one::<T>() / self.length();
|
||||
|
@ -285,7 +285,7 @@ pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -298,7 +298,7 @@ pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] < other[0],
|
||||
|
@ -324,7 +324,7 @@ pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] == other[0],
|
||||
|
@ -338,7 +338,7 @@ pub impl<T:Copy Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl BooleanVector for Vec2<bool> {
|
||||
impl BooleanVector for Vec2<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1]
|
||||
|
@ -366,7 +366,7 @@ pub type uvec2 = Vec2<u32>; // a two-component unsigned integer vector
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec2 {
|
||||
impl vec2 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
||||
|
@ -379,7 +379,7 @@ pub impl vec2 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
||||
}
|
||||
|
||||
pub impl dvec2 {
|
||||
impl dvec2 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
||||
|
@ -392,7 +392,7 @@ pub impl dvec2 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
||||
}
|
||||
|
||||
pub impl bvec2 {
|
||||
impl bvec2 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec2 { Vector::from_value(v) }
|
||||
|
||||
|
@ -400,7 +400,7 @@ pub impl bvec2 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec2>() }
|
||||
}
|
||||
|
||||
pub impl ivec2 {
|
||||
impl ivec2 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
||||
|
@ -413,7 +413,7 @@ pub impl ivec2 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
||||
}
|
||||
|
||||
pub impl uvec2 {
|
||||
impl uvec2 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
||||
|
|
42
src/vec3.rs
42
src/vec3.rs
|
@ -45,7 +45,7 @@ use vec::{
|
|||
#[deriving_eq]
|
||||
pub struct Vec3<T> { x: T, y: T, z: T }
|
||||
|
||||
pub impl<T:Copy Eq> Vector<T> for Vec3<T> {
|
||||
impl<T:Copy + Eq> Vector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec3<T> {
|
||||
Vector3::new(value, value, value)
|
||||
|
@ -61,21 +61,21 @@ pub impl<T:Copy Eq> Vector<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T> Vector3<T> for Vec3<T> {
|
||||
impl<T> Vector3<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T, z: T) -> Vec3<T> {
|
||||
Vec3 { x: x, y: y, z: z }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Index<uint, T> for Vec3<T> {
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> MutableVector<T> for Vec3<T> {
|
||||
impl<T:Copy> MutableVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, i: uint) -> &self/mut T {
|
||||
match i {
|
||||
|
@ -93,7 +93,7 @@ pub impl<T:Copy> MutableVector<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector<T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), one::<T>(), one::<T>())
|
||||
|
@ -161,14 +161,14 @@ pub impl<T:Copy Number> NumericVector<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Neg<Vec3<T>> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec3<T>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec3<T> {
|
||||
Vector3::new(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector3<T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector3<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), zero::<T>(), zero::<T>())
|
||||
|
@ -192,7 +192,7 @@ pub impl<T:Copy Number> NumericVector3<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableNumericVector<&self/T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
*self.index_mut(0) = -*self.index_mut(0);
|
||||
|
@ -243,21 +243,21 @@ pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> MutableNumericVector3<&self/T> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableNumericVector3<&self/T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn cross_self(&mut self, other: &Vec3<T>) {
|
||||
*self = self.cross(other);
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> ToHomogeneous<Vec4<T>> for Vec3<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> ToHomogeneous<Vec4<T>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_homogeneous(&self) -> Vec4<T> {
|
||||
Vector4::new(self.x, self.y, self.z, zero())
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> EuclideanVector<T> for Vec3<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -299,7 +299,7 @@ pub impl<T:Copy Float> EuclideanVector<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec3<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableEuclideanVector<&self/T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
fn normalize_self(&mut self) {
|
||||
let n = one::<T>() / self.length();
|
||||
|
@ -317,7 +317,7 @@ pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -331,7 +331,7 @@ pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] < other[0],
|
||||
|
@ -361,7 +361,7 @@ pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] == other[0],
|
||||
|
@ -377,7 +377,7 @@ pub impl<T:Copy Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl BooleanVector for Vec3<bool> {
|
||||
impl BooleanVector for Vec3<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2]
|
||||
|
@ -405,7 +405,7 @@ pub type uvec3 = Vec3<u32>; // a three-component unsigned integer vector
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec3 {
|
||||
impl vec3 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
||||
|
@ -419,7 +419,7 @@ pub impl vec3 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
||||
}
|
||||
|
||||
pub impl dvec3 {
|
||||
impl dvec3 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
||||
|
@ -433,7 +433,7 @@ pub impl dvec3 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
||||
}
|
||||
|
||||
pub impl bvec3 {
|
||||
impl bvec3 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec3 { Vector::from_value(v) }
|
||||
|
||||
|
@ -441,7 +441,7 @@ pub impl bvec3 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec3>() }
|
||||
}
|
||||
|
||||
pub impl ivec3 {
|
||||
impl ivec3 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
||||
|
@ -455,7 +455,7 @@ pub impl ivec3 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
||||
}
|
||||
|
||||
pub impl uvec3 {
|
||||
impl uvec3 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
||||
|
|
38
src/vec4.rs
38
src/vec4.rs
|
@ -43,7 +43,7 @@ use vec::{
|
|||
#[deriving_eq]
|
||||
pub struct Vec4<T> { x: T, y: T, z: T, w: T }
|
||||
|
||||
pub impl<T:Copy Eq> Vector<T> for Vec4<T> {
|
||||
impl<T:Copy + Eq> Vector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec4<T> {
|
||||
Vector4::new(value, value, value, value)
|
||||
|
@ -59,21 +59,21 @@ pub impl<T:Copy Eq> Vector<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T> Vector4<T> for Vec4<T> {
|
||||
impl<T> Vector4<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T, z: T, w: T) -> Vec4<T> {
|
||||
Vec4 { x: x, y: y, z: z, w: w }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> Index<uint, T> for Vec4<T> {
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> MutableVector<T> for Vec4<T> {
|
||||
impl<T:Copy> MutableVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, i: uint) -> &self/mut T {
|
||||
match i {
|
||||
|
@ -92,7 +92,7 @@ pub impl<T:Copy> MutableVector<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector<T> for Vec4<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
|
||||
|
@ -168,14 +168,14 @@ pub impl<T:Copy Number> NumericVector<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Neg<Vec4<T>> for Vec4<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec4<T>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec4<T> {
|
||||
Vector4::new(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> NumericVector4<T> for Vec4<T> {
|
||||
impl<T:Copy + Number> NumericVector4<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
|
||||
|
@ -197,7 +197,7 @@ pub impl<T:Copy Number> NumericVector4<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec4<T> {
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableNumericVector<&self/T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
*self.index_mut(0) = -*self.index_mut(0);
|
||||
|
@ -255,7 +255,7 @@ pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> EuclideanVector<T> for Vec4<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
|
@ -297,7 +297,7 @@ pub impl<T:Copy Float> EuclideanVector<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec4<T> {
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> MutableEuclideanVector<&self/T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
fn normalize_self(&mut self) {
|
||||
let n = one::<T>() / self.length();
|
||||
|
@ -315,7 +315,7 @@ pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
|
@ -330,7 +330,7 @@ pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] < other[0],
|
||||
|
@ -364,7 +364,7 @@ pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] == other[0],
|
||||
|
@ -382,7 +382,7 @@ pub impl<T:Copy Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl BooleanVector for Vec4<bool> {
|
||||
impl BooleanVector for Vec4<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2] || self[3]
|
||||
|
@ -410,7 +410,7 @@ pub type uvec4 = Vec4<u32>; // a four-component unsigned integer vector
|
|||
|
||||
// Static method wrappers for GLSL-style types
|
||||
|
||||
pub impl vec4 {
|
||||
impl vec4 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
||||
|
@ -425,7 +425,7 @@ pub impl vec4 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
||||
}
|
||||
|
||||
pub impl dvec4 {
|
||||
impl dvec4 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
||||
|
@ -441,7 +441,7 @@ pub impl dvec4 {
|
|||
}
|
||||
|
||||
|
||||
pub impl bvec4 {
|
||||
impl bvec4 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec4 { Vector::from_value(v) }
|
||||
|
||||
|
@ -449,7 +449,7 @@ pub impl bvec4 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec4>() }
|
||||
}
|
||||
|
||||
pub impl ivec4 {
|
||||
impl ivec4 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
||||
|
@ -464,7 +464,7 @@ pub impl ivec4 {
|
|||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
||||
}
|
||||
|
||||
pub impl uvec4 {
|
||||
impl uvec4 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
||||
|
|
Loading…
Reference in a new issue