Add DeltaTransformVector tait and fix transformation.

This commit is contained in:
Sébastien Crozet 2013-06-13 14:44:15 +00:00
parent fb20ffdf8b
commit 4cc5b178c8
4 changed files with 28 additions and 9 deletions

View File

@ -2,7 +2,7 @@ nalgebra_lib_path=lib
nalgebra_doc_path=doc
all:
mkdir -p $(nalgebra_lib_path)
rust build src/nalgebra.rc --out-dir $(nalgebra_lib_path)
rust build src/nalgebra.rc --out-dir $(nalgebra_lib_path) --opt-level 3
test:
mkdir -p $(nalgebra_lib_path)

View File

@ -6,7 +6,7 @@ use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
use traits::rotation::Rotation;
use traits::delta_transform::DeltaTransform;
use traits::delta_transform::{DeltaTransform, DeltaTransformVector};
use dim1::vec1::Vec1;
use dim2::mat2::Mat2;
use dim3::mat3::Mat3;
@ -141,6 +141,12 @@ impl<M: Copy> DeltaTransform<M> for Rotmat<M>
{ self.submat }
}
impl<M: RMul<V> + Copy, V: Copy> DeltaTransformVector<V> for Rotmat<M>
{
fn delta_transform_vector(&self, v: &V) -> V
{ self.submat.rmul(v) }
}
impl<M: Copy + Transpose> Inv for Rotmat<M>
{
fn invert(&mut self)

View File

@ -6,7 +6,7 @@ use traits::inv::Inv;
use traits::rotation::Rotation;
use traits::translation::Translation;
use traits::transpose::Transpose;
use traits::delta_transform::DeltaTransform;
use traits::delta_transform::{DeltaTransform, DeltaTransformVector};
use traits::workarounds::rlmul::{RMul, LMul};
#[deriving(Eq, ToStr)]
@ -51,16 +51,16 @@ Mul<Transform<M, V>, Transform<M, V>> for Transform<M, V>
}
}
impl<M: RMul<V>, V> RMul<V> for Transform<M, V>
impl<M: RMul<V>, V: Add<V, V>> RMul<V> for Transform<M, V>
{
fn rmul(&self, other: &V) -> V
{ self.submat.rmul(other) }
{ self.submat.rmul(other) + self.subtrans }
}
impl<M: LMul<V>, V> LMul<V> for Transform<M, V>
impl<M: LMul<V>, V: Add<V, V>> LMul<V> for Transform<M, V>
{
fn lmul(&self, other: &V) -> V
{ self.submat.lmul(other) }
{ self.submat.lmul(other) + self.subtrans }
}
impl<M: Copy, V: Copy + Translation<V>> Translation<V> for Transform<M, V>
@ -104,6 +104,12 @@ impl<M: Copy, V> DeltaTransform<M> for Transform<M, V>
{ self.submat }
}
impl<M: RMul<V> + Copy, V> DeltaTransformVector<V> for Transform<M, V>
{
fn delta_transform_vector(&self, v: &V) -> V
{ self.submat.rmul(v) }
}
impl<M:Copy + Transpose + Inv + RMul<V>, V:Copy + Neg<V>>
Inv for Transform<M, V>
{

View File

@ -7,6 +7,13 @@ pub trait DeltaTransform<DT>
{
/// Extracts the delta transformation associated with this transformation.
fn delta_transform(&self) -> DT;
// FIXME: add functions to apply the delta-transform to a vector without
// explicit computation of the transform (does this avoid some matrix copy?)
}
/**
* Trait of delta-transformations on vectors.
*/
pub trait DeltaTransformVector<V>
{
/// Applies a delta-transform to a vector.
fn delta_transform_vector(&self, &V) -> V;
}