Specialized Mul, RMul, and LMul for Mat2 and Mat3.
This commit is contained in:
parent
1a08262f50
commit
06c7293e83
4
Makefile
4
Makefile
|
@ -3,7 +3,7 @@ nalgebra_lib_path=lib
|
|||
nalgebra_doc_path=doc
|
||||
all:
|
||||
mkdir -p $(nalgebra_lib_path)
|
||||
rust build src/lib.rs --out-dir $(nalgebra_lib_path) --opt-level 2
|
||||
rust build src/lib.rs --out-dir $(nalgebra_lib_path) --opt-level 3
|
||||
|
||||
test:
|
||||
mkdir -p $(nalgebra_lib_path)
|
||||
|
@ -11,7 +11,7 @@ test:
|
|||
rm libtest~
|
||||
|
||||
bench:
|
||||
rustc --test src/lib.rs --opt-level 2 -o bench~ && ./bench~ --bench
|
||||
rustc --test src/lib.rs --opt-level 3 -o bench~ && ./bench~ --bench
|
||||
rm bench~
|
||||
|
||||
doc:
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#[deny(non_uppercase_statics)];
|
||||
#[deny(unnecessary_qualification)];
|
||||
#[deny(missing_doc)];
|
||||
#[deny(warnings)];
|
||||
|
||||
extern mod std;
|
||||
extern mod extra;
|
||||
|
|
12
src/mat.rs
12
src/mat.rs
|
@ -115,9 +115,9 @@ iterable_mut_impl!(Mat2, 2)
|
|||
dim_impl!(Mat2, 2)
|
||||
indexable_impl!(Mat2, 2)
|
||||
at_fast_impl!(Mat2, 2)
|
||||
mul_impl!(Mat2, 2)
|
||||
rmul_impl!(Mat2, Vec2, 2)
|
||||
lmul_impl!(Mat2, Vec2, 2)
|
||||
// (specialized) mul_impl!(Mat2, 2)
|
||||
// (specialized) rmul_impl!(Mat2, Vec2, 2)
|
||||
// (specialized) lmul_impl!(Mat2, Vec2, 2)
|
||||
transform_impl!(Mat2, Vec2)
|
||||
// (specialized) inv_impl!(Mat2, 2)
|
||||
transpose_impl!(Mat2, 2)
|
||||
|
@ -172,9 +172,9 @@ iterable_mut_impl!(Mat3, 3)
|
|||
dim_impl!(Mat3, 3)
|
||||
indexable_impl!(Mat3, 3)
|
||||
at_fast_impl!(Mat3, 3)
|
||||
mul_impl!(Mat3, 3)
|
||||
rmul_impl!(Mat3, Vec3, 3)
|
||||
lmul_impl!(Mat3, Vec3, 3)
|
||||
// (specialized) mul_impl!(Mat3, 3)
|
||||
// (specialized) rmul_impl!(Mat3, Vec3, 3)
|
||||
// (specialized) lmul_impl!(Mat3, Vec3, 3)
|
||||
transform_impl!(Mat3, Vec3)
|
||||
// (specialized) inv_impl!(Mat3, 3)
|
||||
transpose_impl!(Mat3, 3)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::num::{Zero, One};
|
||||
use vec::Vec3;
|
||||
use mat::{Mat1, Mat2, Mat3, Inv, Row, Col};
|
||||
use vec::{Vec2, Vec3};
|
||||
use mat::{Mat1, Mat2, Mat3, Inv, Row, Col, RMul, LMul};
|
||||
use mat;
|
||||
|
||||
// some specializations:
|
||||
|
@ -189,6 +189,80 @@ impl<N: Clone> Col<Vec3<N>> for Mat3<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> Mul<Mat3<N>, Mat3<N>> for Mat3<N> {
|
||||
#[inline]
|
||||
fn mul(&self, other: &Mat3<N>) -> Mat3<N> {
|
||||
Mat3::new(
|
||||
self.m11 * other.m11 + self.m12 * other.m21 + self.m13 * other.m31,
|
||||
self.m11 * other.m12 + self.m12 * other.m22 + self.m13 * other.m32,
|
||||
self.m11 * other.m13 + self.m12 * other.m23 + self.m13 * other.m33,
|
||||
|
||||
self.m21 * other.m11 + self.m22 * other.m21 + self.m23 * other.m31,
|
||||
self.m21 * other.m12 + self.m22 * other.m22 + self.m23 * other.m32,
|
||||
self.m21 * other.m13 + self.m22 * other.m23 + self.m23 * other.m33,
|
||||
|
||||
self.m31 * other.m11 + self.m32 * other.m21 + self.m33 * other.m31,
|
||||
self.m31 * other.m12 + self.m32 * other.m22 + self.m33 * other.m32,
|
||||
self.m31 * other.m13 + self.m32 * other.m23 + self.m33 * other.m33
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> Mul<Mat2<N>, Mat2<N>> for Mat2<N> {
|
||||
#[inline(always)]
|
||||
fn mul(&self, other: &Mat2<N>) -> Mat2<N> {
|
||||
Mat2::new(
|
||||
self.m11 * other.m11 + self.m12 * other.m21,
|
||||
self.m11 * other.m12 + self.m12 * other.m22,
|
||||
|
||||
self.m21 * other.m11 + self.m22 * other.m21,
|
||||
self.m21 * other.m12 + self.m22 * other.m22
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> RMul<Vec3<N>> for Mat3<N> {
|
||||
#[inline(always)]
|
||||
fn rmul(&self, v: &Vec3<N>) -> Vec3<N> {
|
||||
Vec3::new(
|
||||
self.m11 * v.x + self.m12 * v.y + self.m13 * v.z,
|
||||
self.m21 * v.x + self.m22 * v.y + self.m23 * v.z,
|
||||
self.m31 * v.x + self.m32 * v.y + self.m33 * v.z
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> LMul<Vec3<N>> for Mat3<N> {
|
||||
#[inline(always)]
|
||||
fn lmul(&self, v: &Vec3<N>) -> Vec3<N> {
|
||||
Vec3::new(
|
||||
self.m11 * v.x + self.m21 * v.y + self.m31 * v.z,
|
||||
self.m12 * v.x + self.m22 * v.y + self.m32 * v.z,
|
||||
self.m13 * v.x + self.m23 * v.y + self.m33 * v.z
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> RMul<Vec2<N>> for Mat2<N> {
|
||||
#[inline(always)]
|
||||
fn rmul(&self, v: &Vec2<N>) -> Vec2<N> {
|
||||
Vec2::new(
|
||||
self.m11 * v.x + self.m12 * v.y,
|
||||
self.m21 * v.x + self.m22 * v.y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Mul<N, N> + Add<N, N>> LMul<Vec2<N>> for Mat2<N> {
|
||||
#[inline(always)]
|
||||
fn lmul(&self, v: &Vec2<N>) -> Vec2<N> {
|
||||
Vec2::new(
|
||||
self.m11 * v.x + self.m21 * v.y,
|
||||
self.m12 * v.x + self.m22 * v.y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: move this to another file?
|
||||
impl<N: Real + NumCast + Zero + One> mat::Mat4<N> {
|
||||
/// Computes a projection matrix given the frustrum near plane width, height, the field of
|
||||
|
|
|
@ -219,7 +219,9 @@ macro_rules! basis_impl(
|
|||
for i in range(0u, $dim) {
|
||||
let mut basis_element : $t<N> = Zero::zero();
|
||||
|
||||
basis_element.set(i, One::one());
|
||||
unsafe {
|
||||
basis_element.set_fast(i, One::one());
|
||||
}
|
||||
|
||||
if !f(basis_element) { return }
|
||||
}
|
||||
|
@ -234,7 +236,9 @@ macro_rules! basis_impl(
|
|||
for i in range(0u, $dim) {
|
||||
let mut basis_element : $t<N> = Zero::zero();
|
||||
|
||||
basis_element.set(i, One::one());
|
||||
unsafe {
|
||||
basis_element.set_fast(i, One::one());
|
||||
}
|
||||
|
||||
if basis.len() == $dim - 1 {
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue