De-moded functions and methods
This commit is contained in:
parent
782b3aaca1
commit
08748ad78b
5 changed files with 231 additions and 235 deletions
202
src/mat.rs
202
src/mat.rs
|
@ -14,19 +14,19 @@ pub trait Matrix<T, V> {
|
|||
pure fn cols() -> uint;
|
||||
pure fn is_col_major() -> bool;
|
||||
|
||||
pure fn row(&&i:uint) -> V;
|
||||
pure fn col(&&i:uint) -> V;
|
||||
pure fn row(i: uint) -> V;
|
||||
pure fn col(i: uint) -> V;
|
||||
|
||||
pure fn mul_f(&&value:T) -> self;
|
||||
pure fn mul_v(&&other:V) -> V;
|
||||
pure fn add_m(&&other:self) -> self;
|
||||
pure fn sub_m(&&other:self) -> self;
|
||||
pure fn mul_m(&&other:self) -> self;
|
||||
pure fn mul_f(value: T) -> self;
|
||||
pure fn mul_v(other: &V) -> V;
|
||||
pure fn add_m(other: &self) -> self;
|
||||
pure fn sub_m(other: &self) -> self;
|
||||
pure fn mul_m(other: &self) -> self;
|
||||
|
||||
// pure fn invert(&&other:self) -> self;
|
||||
// pure fn invert(other: &self) -> self;
|
||||
pure fn transpose() -> self;
|
||||
|
||||
pure fn exact_eq(&&other:self) -> bool;
|
||||
pure fn exact_eq(other: &self) -> bool;
|
||||
|
||||
pure fn is_identity() -> bool;
|
||||
pure fn is_symmetric() -> bool;
|
||||
|
@ -38,7 +38,7 @@ pub trait Matrix<T, V> {
|
|||
// 3x3 Matrix
|
||||
//
|
||||
pub trait Matrix3<V3> {
|
||||
pure fn scale(&&vec:V3) -> self;
|
||||
pure fn scale(vec: &V3) -> self;
|
||||
pure fn to_Mat4() -> Mat4;
|
||||
pure fn to_Quat() -> Quat;
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ pub trait Matrix3<V3> {
|
|||
// 4x4 Matrix
|
||||
//
|
||||
pub trait Matrix4<V3, V4> {
|
||||
pure fn scale(&&vec:V3) -> self; // I don't like the use of `Vec3` here
|
||||
pure fn translate(&&vec:V3) -> self;
|
||||
pure fn scale(vec: &V3) -> self; // I don't like the use of `Vec3` here
|
||||
pure fn translate(vec: &V3) -> self;
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,8 +80,8 @@ pub pure fn Mat2(m00:float, m01:float,
|
|||
// Conpub struct Mat2 from column vectors
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Mat2_v(col0:Vec2, col1:Vec2) -> Mat2 {
|
||||
Mat2 { data: [ col0, col1 ] }
|
||||
pub pure fn Mat2_v(col0: &Vec2, col1: &Vec2) -> Mat2 {
|
||||
Mat2 { data: [ *col0, *col1 ] }
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -98,42 +98,42 @@ pub impl Mat2: Matrix<float, Vec2> {
|
|||
pure fn is_col_major() -> bool { true }
|
||||
|
||||
#[inline]
|
||||
pure fn row(&&i:uint) -> Vec2 {
|
||||
pure fn row(i: uint) -> Vec2 {
|
||||
Vec2(self[0][i],
|
||||
self[1][i])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn col(&&i:uint) -> Vec2 {
|
||||
pure fn col(i: uint) -> Vec2 {
|
||||
self.data[i]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Mat2 {
|
||||
Mat2_v(self[0].mul_f(value),
|
||||
self[1].mul_f(value))
|
||||
pure fn mul_f(value: float) -> Mat2 {
|
||||
Mat2_v(&self[0].mul_f(value),
|
||||
&self[1].mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_v(&&other:Vec2) -> Vec2 {
|
||||
pure fn mul_v(other: &Vec2) -> Vec2 {
|
||||
Vec2(self[0][0]*other[0] + self[1][0]*other[1],
|
||||
self[0][1]*other[0] + self[1][1]*other[1])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_m(&&other:Mat2) -> Mat2 {
|
||||
Mat2_v(self[0].add_v(other[0]),
|
||||
self[1].add_v(other[1]))
|
||||
pure fn add_m(other: &Mat2) -> Mat2 {
|
||||
Mat2_v(&self[0].add_v(&other[0]),
|
||||
&self[1].add_v(&other[1]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_m(&&other:Mat2) -> Mat2 {
|
||||
Mat2_v(self[0].sub_v(other[0]),
|
||||
self[1].sub_v(other[1]))
|
||||
pure fn sub_m(other: &Mat2) -> Mat2 {
|
||||
Mat2_v(&self[0].sub_v(&other[0]),
|
||||
&self[1].sub_v(&other[1]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_m(&&other:Mat2) -> Mat2 {
|
||||
pure fn mul_m(other: &Mat2) -> Mat2 {
|
||||
Mat2(self[0][0]*other[0][0] + self[1][0]*other[0][1],
|
||||
self[0][1]*other[0][0] + self[1][1]*other[0][1],
|
||||
|
||||
|
@ -143,7 +143,7 @@ pub impl Mat2: Matrix<float, Vec2> {
|
|||
|
||||
// TODO - inversion is harrrd D:
|
||||
// #[inline]
|
||||
// pure fn invert(&&other:Mat2) -> Mat2 {}
|
||||
// pure fn invert(other: &Mat2) -> Mat2 {}
|
||||
|
||||
#[inline]
|
||||
pure fn transpose() -> Mat2 {
|
||||
|
@ -152,9 +152,9 @@ pub impl Mat2: Matrix<float, Vec2> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Mat2) -> bool {
|
||||
self[0].exact_eq(other[0]) &&
|
||||
self[1].exact_eq(other[1])
|
||||
pure fn exact_eq(other: &Mat2) -> bool {
|
||||
self[0].exact_eq(&other[0]) &&
|
||||
self[1].exact_eq(&other[1])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -190,7 +190,7 @@ pub impl Mat2: Index<uint, Vec2> {
|
|||
pub impl Mat2: Neg<Mat2> {
|
||||
#[inline]
|
||||
pure fn neg() -> Mat2 {
|
||||
Mat2_v(-self[0], -self[1])
|
||||
Mat2_v(&-self[0], &-self[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,8 +247,8 @@ pub pure fn Mat3(m00:float, m01:float, m02:float,
|
|||
// Conpub struct Mat3 from column vectors
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Mat3_v(col0:Vec3, col1:Vec3, col2:Vec3) -> Mat3 {
|
||||
Mat3 { data: [ col0, col1, col2 ] }
|
||||
pub pure fn Mat3_v(col0: &Vec3, col1: &Vec3, col2: &Vec3) -> Mat3 {
|
||||
Mat3 { data: [ *col0, *col1, *col2 ] }
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -265,47 +265,47 @@ pub impl Mat3: Matrix<float, Vec3> {
|
|||
pure fn is_col_major() -> bool { true }
|
||||
|
||||
#[inline]
|
||||
pure fn row(&&i:uint) -> Vec3 {
|
||||
pure fn row(i: uint) -> Vec3 {
|
||||
Vec3(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn col(&&i:uint) -> Vec3 {
|
||||
pure fn col(i: uint) -> Vec3 {
|
||||
self.data[i]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Mat3 {
|
||||
Mat3_v(self[0].mul_f(value),
|
||||
self[1].mul_f(value),
|
||||
self[2].mul_f(value))
|
||||
pure fn mul_f(value: float) -> Mat3 {
|
||||
Mat3_v(&self[0].mul_f(value),
|
||||
&self[1].mul_f(value),
|
||||
&self[2].mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_v(&&other:Vec3) -> Vec3 {
|
||||
pure fn mul_v(other: &Vec3) -> Vec3 {
|
||||
Vec3(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2],
|
||||
self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2],
|
||||
self[0][2]*other[0] + self[1][2]*other[1] + self[2][2]*other[2])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_m(&&other:Mat3) -> Mat3 {
|
||||
Mat3_v(self[0].add_v(other[0]),
|
||||
self[1].add_v(other[1]),
|
||||
self[2].add_v(other[2]))
|
||||
pure fn add_m(other: &Mat3) -> Mat3 {
|
||||
Mat3_v(&self[0].add_v(&other[0]),
|
||||
&self[1].add_v(&other[1]),
|
||||
&self[2].add_v(&other[2]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_m(&&other:Mat3) -> Mat3 {
|
||||
Mat3_v(self[0].sub_v(other[0]),
|
||||
self[1].sub_v(other[1]),
|
||||
self[2].sub_v(other[2]))
|
||||
pure fn sub_m(other: &Mat3) -> Mat3 {
|
||||
Mat3_v(&self[0].sub_v(&other[0]),
|
||||
&self[1].sub_v(&other[1]),
|
||||
&self[2].sub_v(&other[2]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_m(&&other:Mat3) -> Mat3 {
|
||||
pure fn mul_m(other: &Mat3) -> Mat3 {
|
||||
Mat3(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2],
|
||||
self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2],
|
||||
self[0][2]*other[0][0] + self[1][2]*other[0][1] + self[2][2]*other[0][2],
|
||||
|
@ -321,7 +321,7 @@ pub impl Mat3: Matrix<float, Vec3> {
|
|||
|
||||
// TODO - inversion is harrrd D:
|
||||
// #[inline]
|
||||
// pure fn invert(&&other:Mat3) -> Mat3 {}
|
||||
// pure fn invert(other: &Mat3) -> Mat3 {}
|
||||
|
||||
#[inline]
|
||||
pure fn transpose() -> Mat3 {
|
||||
|
@ -331,10 +331,10 @@ pub impl Mat3: Matrix<float, Vec3> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Mat3) -> bool {
|
||||
self[0].exact_eq(other[0]) &&
|
||||
self[1].exact_eq(other[1]) &&
|
||||
self[2].exact_eq(other[2])
|
||||
pure fn exact_eq(other: &Mat3) -> bool {
|
||||
self[0].exact_eq(&other[0]) &&
|
||||
self[1].exact_eq(&other[1]) &&
|
||||
self[2].exact_eq(&other[2])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -374,10 +374,10 @@ pub impl Mat3: Matrix<float, Vec3> {
|
|||
|
||||
pub impl Mat3: Matrix3<Vec3> {
|
||||
#[inline]
|
||||
pure fn scale(&&vec:Vec3) -> Mat3 {
|
||||
self.mul_m(Mat3(vec.x(), 0f, 0f,
|
||||
0f, vec.y(), 0f,
|
||||
0f, 0f, vec.z()))
|
||||
pure fn scale(vec: &Vec3) -> Mat3 {
|
||||
self.mul_m(&Mat3(vec.x(), 0f, 0f,
|
||||
0f, vec.y(), 0f,
|
||||
0f, 0f, vec.z()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -439,7 +439,7 @@ pub impl Mat3: Index<uint, Vec3> {
|
|||
pub impl Mat3: Neg<Mat3> {
|
||||
#[inline]
|
||||
pure fn neg() -> Mat3 {
|
||||
Mat3_v(-self[0], -self[1], -self[2])
|
||||
Mat3_v(&-self[0], &-self[1], &-self[2])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -501,8 +501,8 @@ pub pure fn Mat4(m00:float, m01:float, m02:float, m03:float,
|
|||
// Conpub struct Mat4 from column vectors
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Mat4_v(col0:Vec4, col1:Vec4, col2:Vec4, col3:Vec4) -> Mat4 {
|
||||
Mat4 { data: [ col0, col1, col2, col3 ] }
|
||||
pub pure fn Mat4_v(col0: &Vec4, col1: &Vec4, col2: &Vec4, col3: &Vec4) -> Mat4 {
|
||||
Mat4 { data: [ *col0, *col1, *col2, *col3 ] }
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -519,7 +519,7 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
pure fn is_col_major() -> bool { true }
|
||||
|
||||
#[inline]
|
||||
pure fn row(&&i:uint) -> Vec4 {
|
||||
pure fn row(i: uint) -> Vec4 {
|
||||
Vec4(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i],
|
||||
|
@ -527,20 +527,20 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn col(&&i:uint) -> Vec4 {
|
||||
pure fn col(i: uint) -> Vec4 {
|
||||
self.data[i]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Mat4 {
|
||||
Mat4_v(self[0].mul_f(value),
|
||||
self[1].mul_f(value),
|
||||
self[2].mul_f(value),
|
||||
self[3].mul_f(value))
|
||||
pure fn mul_f(value: float) -> Mat4 {
|
||||
Mat4_v(&self[0].mul_f(value),
|
||||
&self[1].mul_f(value),
|
||||
&self[2].mul_f(value),
|
||||
&self[3].mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_v(&&other:Vec4) -> Vec4 {
|
||||
pure fn mul_v(other: &Vec4) -> Vec4 {
|
||||
Vec4(self[0][0]*other[0] + self[1][0]*other[1] + self[2][0]*other[2] + self[3][0]*other[3],
|
||||
self[0][1]*other[0] + self[1][1]*other[1] + self[2][1]*other[2] + self[3][1]*other[3],
|
||||
self[0][2]*other[0] + self[1][2]*other[1] + self[2][2]*other[2] + self[3][2]*other[3],
|
||||
|
@ -548,23 +548,23 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_m(&&other:Mat4) -> Mat4 {
|
||||
Mat4_v(self[0].add_v(other[0]),
|
||||
self[1].add_v(other[1]),
|
||||
self[2].add_v(other[2]),
|
||||
self[3].add_v(other[3]))
|
||||
pure fn add_m(other: &Mat4) -> Mat4 {
|
||||
Mat4_v(&self[0].add_v(&other[0]),
|
||||
&self[1].add_v(&other[1]),
|
||||
&self[2].add_v(&other[2]),
|
||||
&self[3].add_v(&other[3]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_m(&&other:Mat4) -> Mat4 {
|
||||
Mat4_v(self[0].sub_v(other[0]),
|
||||
self[1].sub_v(other[1]),
|
||||
self[2].sub_v(other[2]),
|
||||
self[3].sub_v(other[3]))
|
||||
pure fn sub_m(other: &Mat4) -> Mat4 {
|
||||
Mat4_v(&self[0].sub_v(&other[0]),
|
||||
&self[1].sub_v(&other[1]),
|
||||
&self[2].sub_v(&other[2]),
|
||||
&self[3].sub_v(&other[3]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_m(&&other:Mat4) -> Mat4 {
|
||||
pure fn mul_m(other: &Mat4) -> Mat4 {
|
||||
Mat4(self[0][0]*other[0][0] + self[1][0]*other[0][1] + self[2][0]*other[0][2] + self[3][0]*other[0][3],
|
||||
self[0][1]*other[0][0] + self[1][1]*other[0][1] + self[2][1]*other[0][2] + self[3][1]*other[0][3],
|
||||
self[0][2]*other[0][0] + self[1][2]*other[0][1] + self[2][2]*other[0][2] + self[3][2]*other[0][3],
|
||||
|
@ -588,7 +588,7 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
|
||||
// TODO - inversion is harrrd D:
|
||||
// #[inline]
|
||||
// pure fn invert(&&other:Mat4) -> Mat4 {}
|
||||
// pure fn invert(other: &Mat4) -> Mat4 {}
|
||||
|
||||
#[inline]
|
||||
pure fn transpose() -> Mat4 {
|
||||
|
@ -599,11 +599,11 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Mat4) -> bool {
|
||||
self[0].exact_eq(other[0]) &&
|
||||
self[1].exact_eq(other[1]) &&
|
||||
self[2].exact_eq(other[2]) &&
|
||||
self[3].exact_eq(other[3])
|
||||
pure fn exact_eq(other: &Mat4) -> bool {
|
||||
self[0].exact_eq(&other[0]) &&
|
||||
self[1].exact_eq(&other[1]) &&
|
||||
self[2].exact_eq(&other[2]) &&
|
||||
self[3].exact_eq(&other[3])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -657,22 +657,22 @@ pub impl Mat4: Matrix<float, Vec4> {
|
|||
|
||||
pub impl Mat4: Matrix4<Vec3, Vec4> {
|
||||
#[inline]
|
||||
pure fn scale(&&vec:Vec3) -> Mat4 {
|
||||
self.mul_m(Mat4(vec.x(), 0f, 0f, 0f,
|
||||
0f, vec.y(), 0f, 0f,
|
||||
0f, 0f, vec.z(), 0f,
|
||||
0f, 0f, 0f, 1f))
|
||||
pure fn scale(vec: &Vec3) -> Mat4 {
|
||||
self.mul_m(&Mat4(vec.x(), 0f, 0f, 0f,
|
||||
0f, vec.y(), 0f, 0f,
|
||||
0f, 0f, vec.z(), 0f,
|
||||
0f, 0f, 0f, 1f))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn translate(&&vec:Vec3) -> Mat4 {
|
||||
Mat4_v(self[0],
|
||||
self[1],
|
||||
self[2],
|
||||
Vec4(self[3][0] + vec.x(),
|
||||
self[3][1] + vec.y(),
|
||||
self[3][2] + vec.z(),
|
||||
self[3][3]))
|
||||
pure fn translate(vec: &Vec3) -> Mat4 {
|
||||
Mat4_v(&self[0],
|
||||
&self[1],
|
||||
&self[2],
|
||||
&Vec4(self[3][0] + vec.x(),
|
||||
self[3][1] + vec.y(),
|
||||
self[3][2] + vec.z(),
|
||||
self[3][3]))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -686,7 +686,7 @@ pub impl Mat4: Index<uint, Vec4> {
|
|||
pub impl Mat4: Neg<Mat4> {
|
||||
#[inline]
|
||||
pure fn neg() -> Mat4 {
|
||||
Mat4_v(-self[0], -self[1], -self[2], -self[3])
|
||||
Mat4_v(&-self[0], &-self[1], &-self[2], &-self[3])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
32
src/quat.rs
32
src/quat.rs
|
@ -19,20 +19,16 @@ pub trait Quaternion<T> {
|
|||
pure fn y() -> T;
|
||||
pure fn z() -> T;
|
||||
|
||||
// pure fn neg() -> self;
|
||||
pure fn mul_f(value: T) -> self;
|
||||
pure fn div_f(value: T) -> self;
|
||||
|
||||
pure fn mul_f(&&value:T) -> self;
|
||||
pure fn div_f(&&value:T) -> self;
|
||||
// pure fn mul_v(other: &Vec3) -> Vec3;
|
||||
|
||||
// pure fn mul_v(&&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(&&other:self) -> self;
|
||||
pure fn sub_q(&&other:self) -> self;
|
||||
pure fn mul_q(&&other:self) -> self;
|
||||
|
||||
pure fn exact_eq(&&other:self) -> bool;
|
||||
// pure fn fuzzy_eq(&&other:self) -> bool;
|
||||
// pure fn eq(&&other:self) -> bool;
|
||||
pure fn exact_eq(other: &self) -> bool;
|
||||
|
||||
pure fn conjugate() -> self;
|
||||
pure fn inverse() -> self;
|
||||
|
@ -60,7 +56,7 @@ pub const quat_identity :Quat = Quat { data: [ 1f, 0f, 0f, 0f ] };
|
|||
// Quat Constructor
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Quat(w:float, x:float, y:float, z:float) -> Quat {
|
||||
pub pure fn Quat(w: float, x: float, y: float, z: float) -> Quat {
|
||||
Quat { data: [ w, x, y, z ] }
|
||||
}
|
||||
|
||||
|
@ -77,7 +73,7 @@ pub impl Quat: Quaternion<float> {
|
|||
#[inline] pure fn z() -> float { self.data[3] }
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Quat {
|
||||
pure fn mul_f(value: float) -> Quat {
|
||||
Quat(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -85,7 +81,7 @@ pub impl Quat: Quaternion<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn div_f(&&value:float) -> Quat {
|
||||
pure fn div_f(value: float) -> Quat {
|
||||
Quat(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -93,7 +89,7 @@ pub impl Quat: Quaternion<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_q(&&other:Quat) -> Quat{
|
||||
pure fn add_q(other: &Quat) -> Quat{
|
||||
Quat(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -101,7 +97,7 @@ pub impl Quat: Quaternion<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_q(&&other:Quat) -> Quat{
|
||||
pure fn sub_q(other: &Quat) -> Quat{
|
||||
Quat(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -109,7 +105,7 @@ pub impl Quat: Quaternion<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_q(&&other:Quat) -> Quat {
|
||||
pure fn mul_q(other: &Quat) -> Quat {
|
||||
Quat(self.w()*other.w() - self.x()*other.x() - self.y()*other.y() - self.z()*other.z(),
|
||||
self.w()*other.x() + self.x()*other.w() + self.y()*other.z() - self.z()*other.y(),
|
||||
self.w()*other.y() + self.y()*other.w() + self.z()*other.x() - self.x()*other.z(),
|
||||
|
@ -117,7 +113,7 @@ pub impl Quat: Quaternion<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Quat) -> bool {
|
||||
pure fn exact_eq(other: &Quat) -> bool {
|
||||
self[0] == other[0] &&
|
||||
self[1] == other[1] &&
|
||||
self[2] == other[2] &&
|
||||
|
|
116
src/vec.rs
116
src/vec.rs
|
@ -10,26 +10,26 @@ use to_str::ToStr;
|
|||
pub trait Vector<T> {
|
||||
static pure fn dim() -> uint;
|
||||
|
||||
pure fn add_f(&&value:T) -> self;
|
||||
pure fn sub_f(&&value:T) -> self;
|
||||
pure fn mul_f(&&value:T) -> self;
|
||||
pure fn div_f(&&value:T) -> self;
|
||||
pure fn add_f(value: T) -> self;
|
||||
pure fn sub_f(value: T) -> self;
|
||||
pure fn mul_f(value: T) -> self;
|
||||
pure fn div_f(value: T) -> self;
|
||||
|
||||
pure fn add_v(&&other: self) -> self;
|
||||
pure fn sub_v(&&other: self) -> self;
|
||||
pure fn add_v(other: &self) -> self;
|
||||
pure fn sub_v(other: &self) -> self;
|
||||
|
||||
pure fn dot(&&other: self) -> T;
|
||||
pure fn dot(other: &self) -> T;
|
||||
|
||||
pure fn exact_eq(&&other:self) -> bool;
|
||||
pure fn exact_eq(other:&self) -> bool;
|
||||
|
||||
pure fn magnitude2() -> T;
|
||||
pure fn magnitude() -> T;
|
||||
pure fn normalize() -> self;
|
||||
|
||||
pure fn lerp(&&other:self, &&value:T) -> self;
|
||||
pure fn lerp(other: &self, value: T) -> self;
|
||||
pure fn abs() -> self;
|
||||
pure fn min(&&other:self) -> self;
|
||||
pure fn max(&&other:self) -> self;
|
||||
pure fn min(other: &self) -> self;
|
||||
pure fn max(other: &self) -> self;
|
||||
|
||||
static pure fn zero() -> self;
|
||||
static pure fn identity() -> self;
|
||||
|
@ -42,7 +42,7 @@ pub trait Vector<T> {
|
|||
|
||||
|
||||
pub trait Vector2<T> {
|
||||
// static pure fn _new(x:float, y:float) -> self;
|
||||
// static pure fn _new(x: float, y: float) -> self;
|
||||
|
||||
// This is where I wish rust had properties ;)
|
||||
pure fn x() -> T;
|
||||
|
@ -54,7 +54,7 @@ pub trait Vector2<T> {
|
|||
|
||||
pub trait Vector3<T> {
|
||||
// error: duplicate function definition
|
||||
// static pure fn _new(x:float, y:float, z:float) -> self;
|
||||
// static pure fn _new(x: float, y: float, z: float) -> self;
|
||||
|
||||
pure fn x() -> T;
|
||||
pure fn y() -> T;
|
||||
|
@ -64,12 +64,12 @@ pub trait Vector3<T> {
|
|||
// static pure fn unit_y() -> self;
|
||||
// static pure fn unit_z() -> self;
|
||||
|
||||
fn cross(&&other:self) -> self;
|
||||
fn cross(other: &self) -> self;
|
||||
}
|
||||
|
||||
pub trait Vector4<T> {
|
||||
// error: duplicate function definition
|
||||
// static pure fn _new(x:float, y:float, z:float, w:float) -> self;
|
||||
// static pure fn _new(x: float, y: float, z: float, w: float) -> self;
|
||||
|
||||
pure fn x() -> T;
|
||||
pure fn y() -> T;
|
||||
|
@ -101,13 +101,13 @@ pub const vec2_identity :Vec2 = Vec2 { data: [ 1f, 1f ] };
|
|||
// Constructor
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Vec2(x:float, y:float) -> Vec2 {
|
||||
pub pure fn Vec2(x: float, y: float) -> Vec2 {
|
||||
Vec2 { data: [ x, y ] }
|
||||
}
|
||||
|
||||
pub impl Vec2: Vector2<float> {
|
||||
// #[inline]
|
||||
// static pure fn _new(x:float, y:float) -> Vec2 {
|
||||
// static pure fn _new(x: float, y: float) -> Vec2 {
|
||||
// Vec2 { data: [ x, y ] }
|
||||
// }
|
||||
|
||||
|
@ -124,49 +124,49 @@ pub impl Vec2: Vector<float> {
|
|||
static pure fn dim() -> uint { 2 }
|
||||
|
||||
#[inline]
|
||||
pure fn add_f(&&value:float) -> Vec2 {
|
||||
pure fn add_f(value: float) -> Vec2 {
|
||||
Vec2(self[0] + value,
|
||||
self[1] + value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_f(&&value:float) -> Vec2 {
|
||||
pure fn sub_f(value: float) -> Vec2 {
|
||||
Vec2(self[0] - value,
|
||||
self[1] - value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Vec2 {
|
||||
pure fn mul_f(value: float) -> Vec2 {
|
||||
Vec2(self[0] * value,
|
||||
self[1] * value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn div_f(&&value:float) -> Vec2 {
|
||||
pure fn div_f(value: float) -> Vec2 {
|
||||
Vec2(self[0] / value,
|
||||
self[1] / value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_v(&&other: Vec2) -> Vec2{
|
||||
pure fn add_v(other: &Vec2) -> Vec2{
|
||||
Vec2(self[0] + other[0],
|
||||
self[1] + other[1])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_v(&&other: Vec2) -> Vec2{
|
||||
pure fn sub_v(other: &Vec2) -> Vec2{
|
||||
Vec2(self[0] - other[0],
|
||||
self[1] - other[1])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn dot(&&other: Vec2) -> float {
|
||||
pure fn dot(other: &Vec2) -> float {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Vec2) -> bool {
|
||||
pure fn exact_eq(other: &Vec2) -> bool {
|
||||
self[0] == other[0] &&
|
||||
self[1] == other[1]
|
||||
}
|
||||
|
@ -189,8 +189,8 @@ pub impl Vec2: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn lerp(&&other:Vec2, &&value:float) -> Vec2 {
|
||||
self.add_v((other.sub_v(self)).mul_f(value))
|
||||
pure fn lerp(other: &Vec2, value: float) -> Vec2 {
|
||||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -200,13 +200,13 @@ pub impl Vec2: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(&&other:Vec2) -> Vec2 {
|
||||
pure fn min(other: &Vec2) -> Vec2 {
|
||||
Vec2(min(self[0], other[0]),
|
||||
min(self[1], other[1]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn max(&&other:Vec2) -> Vec2 {
|
||||
pure fn max(other: &Vec2) -> Vec2 {
|
||||
Vec2(max(self[0], other[0]),
|
||||
max(self[1], other[1]))
|
||||
}
|
||||
|
@ -275,13 +275,13 @@ pub const vec3_identity :Vec3 = Vec3 { data: [ 1f, 1f, 1f ] };
|
|||
// Constructor
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Vec3(x:float, y:float, z:float) -> Vec3 {
|
||||
pub pure fn Vec3(x: float, y: float, z: float) -> Vec3 {
|
||||
Vec3 { data: [ x, y, z ] }
|
||||
}
|
||||
|
||||
pub impl Vec3: Vector3<float> {
|
||||
// #[inline]
|
||||
// static pure fn _new(x:float, y:float, z:float) -> Vec3 {
|
||||
// static pure fn _new(x: float, y: float, z: float) -> Vec3 {
|
||||
// Vec2 { data: [ x, y, z ] }
|
||||
// }
|
||||
|
||||
|
@ -290,7 +290,7 @@ pub impl Vec3: Vector3<float> {
|
|||
#[inline] pure fn z() -> float { self.data[2] }
|
||||
|
||||
#[inline]
|
||||
fn cross(&&other:Vec3) -> Vec3 {
|
||||
fn cross(other: &Vec3) -> Vec3 {
|
||||
Vec3((self[1] * other[2]) - (self[2] * other[1]),
|
||||
(self[2] * other[0]) - (self[0] * other[2]),
|
||||
(self[0] * other[1]) - (self[1] * other[0]))
|
||||
|
@ -306,56 +306,56 @@ pub impl Vec3: Vector<float> {
|
|||
static pure fn dim() -> uint { 3 }
|
||||
|
||||
#[inline]
|
||||
pure fn add_f(&&value:float) -> Vec3 {
|
||||
pure fn add_f(value: float) -> Vec3 {
|
||||
Vec3(self[0] + value,
|
||||
self[1] + value,
|
||||
self[2] + value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_f(&&value:float) -> Vec3 {
|
||||
pure fn sub_f(value: float) -> Vec3 {
|
||||
Vec3(self[0] - value,
|
||||
self[1] - value,
|
||||
self[2] - value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Vec3 {
|
||||
pure fn mul_f(value: float) -> Vec3 {
|
||||
Vec3(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn div_f(&&value:float) -> Vec3 {
|
||||
pure fn div_f(value: float) -> Vec3 {
|
||||
Vec3(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_v(&&other: Vec3) -> Vec3{
|
||||
pure fn add_v(other: &Vec3) -> Vec3{
|
||||
Vec3(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_v(&&other: Vec3) -> Vec3{
|
||||
pure fn sub_v(other: &Vec3) -> Vec3{
|
||||
Vec3(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn dot(&&other: Vec3) -> float {
|
||||
pure fn dot(other: &Vec3) -> float {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Vec3) -> bool {
|
||||
pure fn exact_eq(other: &Vec3) -> bool {
|
||||
self[0] == other[0] &&
|
||||
self[1] == other[1] &&
|
||||
self[2] == other[2]
|
||||
|
@ -380,8 +380,8 @@ pub impl Vec3: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn lerp(&&other:Vec3, &&value:float) -> Vec3 {
|
||||
self.add_v((other.sub_v(self)).mul_f(value))
|
||||
pure fn lerp(other: &Vec3, value: float) -> Vec3 {
|
||||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -392,14 +392,14 @@ pub impl Vec3: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(&&other:Vec3) -> Vec3 {
|
||||
pure fn min(other: &Vec3) -> Vec3 {
|
||||
Vec3(min(self[0], other[0]),
|
||||
min(self[1], other[1]),
|
||||
min(self[2], other[2]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pure fn max(&&other:Vec3) -> Vec3 {
|
||||
pure fn max(other: &Vec3) -> Vec3 {
|
||||
Vec3(max(self[0], other[0]),
|
||||
max(self[1], other[1]),
|
||||
max(self[2], other[2]))
|
||||
|
@ -471,13 +471,13 @@ pub const vec4_identity :Vec4 = Vec4 { data: [ 1f, 1f, 1f, 1f ] };
|
|||
// Constructor
|
||||
//
|
||||
#[inline]
|
||||
pub pure fn Vec4(x:float, y:float, z:float, w:float) -> Vec4 {
|
||||
pub pure fn Vec4(x: float, y: float, z: float, w: float) -> Vec4 {
|
||||
Vec4 { data: [ x, y, z, w ] }
|
||||
}
|
||||
|
||||
pub impl Vec4: Vector4<float> {
|
||||
// #[inline]
|
||||
// static pure fn _new(x:float, y:float, z:float, w:float) -> Vec3 {
|
||||
// static pure fn _new(x: float, y: float, z: float, w: float) -> Vec3 {
|
||||
// Vec2 { data: [ x, y, z, w ] }
|
||||
// }
|
||||
|
||||
|
@ -497,7 +497,7 @@ pub impl Vec4: Vector<float> {
|
|||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline]
|
||||
pure fn add_f(&&value:float) -> Vec4 {
|
||||
pure fn add_f(value: float) -> Vec4 {
|
||||
Vec4(self[0] + value,
|
||||
self[1] + value,
|
||||
self[2] + value,
|
||||
|
@ -505,7 +505,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_f(&&value:float) -> Vec4 {
|
||||
pure fn sub_f(value: float) -> Vec4 {
|
||||
Vec4(self[0] - value,
|
||||
self[1] - value,
|
||||
self[2] - value,
|
||||
|
@ -513,7 +513,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn mul_f(&&value:float) -> Vec4 {
|
||||
pure fn mul_f(value: float) -> Vec4 {
|
||||
Vec4(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -521,7 +521,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn div_f(&&value:float) -> Vec4 {
|
||||
pure fn div_f(value: float) -> Vec4 {
|
||||
Vec4(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -529,7 +529,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn add_v(&&other: Vec4) -> Vec4{
|
||||
pure fn add_v(other: &Vec4) -> Vec4{
|
||||
Vec4(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -537,7 +537,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn sub_v(&&other: Vec4) -> Vec4{
|
||||
pure fn sub_v(other: &Vec4) -> Vec4{
|
||||
Vec4(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -545,7 +545,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn dot(&&other:Vec4) -> float {
|
||||
pure fn dot(other: &Vec4) -> float {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2] +
|
||||
|
@ -553,7 +553,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn exact_eq(&&other:Vec4) -> bool {
|
||||
pure fn exact_eq(other: &Vec4) -> bool {
|
||||
self[0] == other[0] &&
|
||||
self[1] == other[1] &&
|
||||
self[2] == other[2] &&
|
||||
|
@ -580,8 +580,8 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn lerp(&&other:Vec4, &&value:float) -> Vec4 {
|
||||
self.add_v((other.sub_v(self)).mul_f(value))
|
||||
pure fn lerp(other: &Vec4, value: float) -> Vec4 {
|
||||
self.add_v(&other.sub_v(&self).mul_f(value))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -593,7 +593,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn min(&&other:Vec4) -> Vec4 {
|
||||
pure fn min(other: &Vec4) -> Vec4 {
|
||||
Vec4(min(self[0], other[0]),
|
||||
min(self[1], other[1]),
|
||||
min(self[2], other[2]),
|
||||
|
@ -601,7 +601,7 @@ pub impl Vec4: Vector<float> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pure fn max(&&other:Vec4) -> Vec4 {
|
||||
pure fn max(other: &Vec4) -> Vec4 {
|
||||
Vec4(max(self[0], other[0]),
|
||||
max(self[1], other[1]),
|
||||
max(self[2], other[2]),
|
||||
|
|
|
@ -15,8 +15,8 @@ fn test_Mat2() {
|
|||
assert a == Mat2(1f, 3f,
|
||||
2f, 4f);
|
||||
|
||||
assert a == Mat2_v(Vec2(1f, 3f),
|
||||
Vec2(2f, 4f));
|
||||
assert a == Mat2_v(&Vec2(1f, 3f),
|
||||
&Vec2(2f, 4f));
|
||||
|
||||
assert a[0] == Vec2(1f, 3f);
|
||||
assert a[1] == Vec2(2f, 4f);
|
||||
|
@ -33,14 +33,14 @@ fn test_Mat2() {
|
|||
|
||||
assert a.mul_f(f1) == Mat2(0.5f, 1.5f,
|
||||
1.0f, 2.0f);
|
||||
assert a.mul_v(v1) == Vec2(5f, 11f);
|
||||
assert a.mul_v(&v1) == Vec2(5f, 11f);
|
||||
|
||||
assert a.add_m(b) == Mat2(3f, 7f,
|
||||
5f, 9f);
|
||||
assert a.sub_m(b) == Mat2(-1f, -1f,
|
||||
-1f, -1f);
|
||||
assert a.mul_m(b) == Mat2(10.0, 22.0,
|
||||
13.0, 29.0);
|
||||
assert a.add_m(&b) == Mat2(3f, 7f,
|
||||
5f, 9f);
|
||||
assert a.sub_m(&b) == Mat2(-1f, -1f,
|
||||
-1f, -1f);
|
||||
assert a.mul_m(&b) == Mat2(10.0, 22.0,
|
||||
13.0, 29.0);
|
||||
|
||||
assert a.transpose() == Mat2(1f, 2f,
|
||||
3f, 4f);
|
||||
|
@ -82,9 +82,9 @@ fn test_Mat3() {
|
|||
2f, 5f, 8f,
|
||||
3f, 6f, 9f);
|
||||
|
||||
assert a == Mat3_v(Vec3(1f, 4f, 7f),
|
||||
Vec3(2f, 5f, 8f),
|
||||
Vec3(3f, 6f, 9f));
|
||||
assert a == Mat3_v(&Vec3(1f, 4f, 7f),
|
||||
&Vec3(2f, 5f, 8f),
|
||||
&Vec3(3f, 6f, 9f));
|
||||
|
||||
assert a[0] == Vec3(1f, 4f, 7f);
|
||||
assert a[1] == Vec3(2f, 5f, 8f);
|
||||
|
@ -106,17 +106,17 @@ fn test_Mat3() {
|
|||
assert a.mul_f(f1) == Mat3(0.5f, 2.0f, 3.5f,
|
||||
1.0f, 2.5f, 4.0f,
|
||||
1.5f, 3.0f, 4.5f);
|
||||
assert a.mul_v(v1) == Vec3(14f, 32f, 50f);
|
||||
assert a.mul_v(&v1) == Vec3(14f, 32f, 50f);
|
||||
|
||||
assert a.add_m(b) == Mat3(3f, 9f, 15f,
|
||||
5f, 11f, 17f,
|
||||
7f, 13f, 19f);
|
||||
assert a.sub_m(b) == Mat3(-1f, -1f, -1f,
|
||||
-1f, -1f, -1f,
|
||||
-1f, -1f, -1f);
|
||||
assert a.mul_m(b) == Mat3(36f, 81f, 126f,
|
||||
42f, 96f, 150f,
|
||||
48f, 111f, 174f);
|
||||
assert a.add_m(&b) == Mat3(3f, 9f, 15f,
|
||||
5f, 11f, 17f,
|
||||
7f, 13f, 19f);
|
||||
assert a.sub_m(&b) == Mat3(-1f, -1f, -1f,
|
||||
-1f, -1f, -1f,
|
||||
-1f, -1f, -1f);
|
||||
assert a.mul_m(&b) == Mat3(36f, 81f, 126f,
|
||||
42f, 96f, 150f,
|
||||
48f, 111f, 174f);
|
||||
|
||||
assert a.transpose() == Mat3(1f, 2f, 3f,
|
||||
4f, 5f, 6f,
|
||||
|
@ -170,10 +170,10 @@ fn test_Mat4() {
|
|||
3f, 7f, 11f, 15f,
|
||||
4f, 8f, 12f, 16f);
|
||||
|
||||
assert a == Mat4_v(Vec4(1f, 5f, 9f, 13f),
|
||||
Vec4(2f, 6f, 10f, 14f),
|
||||
Vec4(3f, 7f, 11f, 15f),
|
||||
Vec4(4f, 8f, 12f, 16f));
|
||||
assert a == Mat4_v(&Vec4(1f, 5f, 9f, 13f),
|
||||
&Vec4(2f, 6f, 10f, 14f),
|
||||
&Vec4(3f, 7f, 11f, 15f),
|
||||
&Vec4(4f, 8f, 12f, 16f));
|
||||
|
||||
assert a[0] == Vec4(1f, 5f, 9f, 13f);
|
||||
assert a[1] == Vec4(2f, 6f, 10f, 14f);
|
||||
|
@ -200,20 +200,20 @@ fn test_Mat4() {
|
|||
1.0f, 3.0f, 5.0f, 7.0f,
|
||||
1.5f, 3.5f, 5.5f, 7.5f,
|
||||
2.0f, 4.0f, 6.0f, 8.0f);
|
||||
assert a.mul_v(v1) == Vec4(30.0, 70.0, 110.0, 150.0);
|
||||
assert a.mul_v(&v1) == Vec4(30.0, 70.0, 110.0, 150.0);
|
||||
|
||||
assert a.add_m(b) == Mat4(3f, 11f, 19f, 27f,
|
||||
5f, 13f, 21f, 29f,
|
||||
7f, 15f, 23f, 31f,
|
||||
9f, 17f, 25f, 33f);
|
||||
assert a.sub_m(b) == Mat4(-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f);
|
||||
assert a.mul_m(b) == Mat4(100f, 228f, 356f, 484f,
|
||||
110f, 254f, 398f, 542f,
|
||||
120f, 280f, 440f, 600f,
|
||||
130f, 306f, 482f, 658f);
|
||||
assert a.add_m(&b) == Mat4(3f, 11f, 19f, 27f,
|
||||
5f, 13f, 21f, 29f,
|
||||
7f, 15f, 23f, 31f,
|
||||
9f, 17f, 25f, 33f);
|
||||
assert a.sub_m(&b) == Mat4(-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f,
|
||||
-1f, -1f, -1f, -1f);
|
||||
assert a.mul_m(&b) == Mat4(100f, 228f, 356f, 484f,
|
||||
110f, 254f, 398f, 542f,
|
||||
120f, 280f, 440f, 600f,
|
||||
130f, 306f, 482f, 658f);
|
||||
|
||||
assert a.transpose() == Mat4( 1f, 2f, 3f, 4f,
|
||||
5f, 6f, 7f, 8f,
|
||||
|
|
|
@ -32,8 +32,8 @@ fn test_Vec2() {
|
|||
assert a.mul_f(f1) == Vec2( 1.5f, 3.0f);
|
||||
assert a.div_f(f2) == Vec2( 2.0f, 4.0f);
|
||||
|
||||
assert a.add_v(b) == Vec2( 4f, 6f);
|
||||
assert a.sub_v(b) == Vec2(-2f, -2f);
|
||||
assert a.add_v(&b) == Vec2( 4f, 6f);
|
||||
assert a.sub_v(&b) == Vec2(-2f, -2f);
|
||||
|
||||
// exact_eq
|
||||
// fuzzy_eq
|
||||
|
@ -46,10 +46,10 @@ fn test_Vec2() {
|
|||
let d = Vec2( 1.0f, 0.0f);
|
||||
let f3 = 0.75f;
|
||||
|
||||
assert c.lerp(d, f3) == Vec2(0.250f, -0.250f);
|
||||
assert c.lerp(&d, f3) == Vec2(0.250f, -0.250f);
|
||||
assert c.abs() == Vec2( 2.0f, 1.0f);
|
||||
assert c.min(d) == Vec2(-2.0f, -1.0f);
|
||||
assert c.max(d) == Vec2( 1.0f, 0.0f);
|
||||
assert c.min(&d) == Vec2(-2.0f, -1.0f);
|
||||
assert c.max(&d) == Vec2( 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -76,7 +76,7 @@ fn test_Vec3() {
|
|||
assert a.y() == 2f;
|
||||
assert a.z() == 3f;
|
||||
|
||||
assert a.cross(b) == Vec3(-3f, 6f, -3f);
|
||||
assert a.cross(&b) == Vec3(-3f, 6f, -3f);
|
||||
|
||||
assert -a == Vec3(-1f, -2f, -3f);
|
||||
assert a.neg() == Vec3(-1f, -2f, -3f);
|
||||
|
@ -86,8 +86,8 @@ fn test_Vec3() {
|
|||
assert a.mul_f(f1) == Vec3( 1.5f, 3.0f, 4.5f);
|
||||
assert a.div_f(f2) == Vec3( 2.0f, 4.0f, 6.0f);
|
||||
|
||||
assert a.add_v(b) == Vec3( 5f, 7f, 9f);
|
||||
assert a.sub_v(b) == Vec3(-3f, -3f, -3f);
|
||||
assert a.add_v(&b) == Vec3( 5f, 7f, 9f);
|
||||
assert a.sub_v(&b) == Vec3(-3f, -3f, -3f);
|
||||
|
||||
// exact_eq
|
||||
// fuzzy_eq
|
||||
|
@ -100,10 +100,10 @@ fn test_Vec3() {
|
|||
let d = Vec3( 1.0f, 0.0f, 0.5f);
|
||||
let f3 = 0.75f;
|
||||
|
||||
assert c.lerp(d, f3) == Vec3(0.250f, -0.250f, 0.625f);
|
||||
assert c.abs() == Vec3( 2.0f, 1.0f, 1.0f);
|
||||
assert c.min(d) == Vec3(-2.0f, -1.0f, 0.5f);
|
||||
assert c.max(d) == Vec3( 1.0f, 0.0f, 1.0f);
|
||||
assert c.lerp(&d, f3) == Vec3(0.250f, -0.250f, 0.625f);
|
||||
assert c.abs() == Vec3( 2.0f, 1.0f, 1.0f);
|
||||
assert c.min(&d) == Vec3(-2.0f, -1.0f, 0.5f);
|
||||
assert c.max(&d) == Vec3( 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -141,10 +141,10 @@ fn test_Vec4() {
|
|||
assert a.mul_f(f1) == Vec4( 1.5f, 3.0f, 4.5f, 6.0f);
|
||||
assert a.div_f(f2) == Vec4( 2.0f, 4.0f, 6.0f, 8.0f);
|
||||
|
||||
assert a.add_v(b) == Vec4( 6f, 8f, 10f, 12f);
|
||||
assert a.sub_v(b) == Vec4(-4f, -4f, -4f, -4f);
|
||||
assert a.add_v(&b) == Vec4( 6f, 8f, 10f, 12f);
|
||||
assert a.sub_v(&b) == Vec4(-4f, -4f, -4f, -4f);
|
||||
|
||||
assert a.dot(b) == 70f;
|
||||
assert a.dot(&b) == 70f;
|
||||
|
||||
// exact_eq
|
||||
// fuzzy_eq
|
||||
|
@ -157,8 +157,8 @@ fn test_Vec4() {
|
|||
let d = Vec4( 1.0f, 0.0f, 0.5f, 1.0f);
|
||||
let f3 = 0.75f;
|
||||
|
||||
assert c.lerp(d, f3) == Vec4(0.250f, -0.250f, 0.625f, 1.250f);
|
||||
assert c.abs() == Vec4( 2.0f, 1.0f, 1.0f, 2.0f);
|
||||
assert c.min(d) == Vec4(-2.0f, -1.0f, 0.5f, 1.0f);
|
||||
assert c.max(d) == Vec4( 1.0f, 0.0f, 1.0f, 2.0f);
|
||||
assert c.lerp(&d, f3) == Vec4(0.250f, -0.250f, 0.625f, 1.250f);
|
||||
assert c.abs() == Vec4( 2.0f, 1.0f, 1.0f, 2.0f);
|
||||
assert c.min(&d) == Vec4(-2.0f, -1.0f, 0.5f, 1.0f);
|
||||
assert c.max(&d) == Vec4( 1.0f, 0.0f, 1.0f, 2.0f);
|
||||
}
|
Loading…
Reference in a new issue