Add comments and adapted to new rust syntax.

This commit is contained in:
Sébastien Crozet 2013-05-21 17:25:01 +02:00
parent 4a44d436d1
commit 3fa933d13f
31 changed files with 400 additions and 215 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
*.swp
doc
*.html
lib

View File

@ -1,4 +1,5 @@
nalgebra_lib_path=lib
nalgebra_doc_path=doc
all:
rust build src/nalgebra.rc --out-dir $(nalgebra_lib_path)
@ -7,6 +8,7 @@ test:
rm nalgebratest~
doc:
rust test src/nalgebra.rc
rust doc src/nalgebra.rc --output-dir $(nalgebra_doc_path)
.PHONY:doc, test
.PHONY:doc
.PHONY:test

View File

@ -1,6 +1,6 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::workarounds::rlmul::{RMul, LMul};
use traits::dim::Dim;
use traits::inv::Inv;
@ -64,7 +64,7 @@ pub fn rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
}
}
impl<T: Quot<T, T> + Trigonometric + Neg<T> + Mul<T, T> + Add<T, T> + Copy>
impl<T: Div<T, T> + Trigonometric + Neg<T> + Mul<T, T> + Add<T, T> + Copy>
Rotation<Vec1<T>> for Rotmat<Mat2<T>>
{
fn rotation(&self) -> Vec1<T>
@ -77,7 +77,7 @@ Rotation<Vec1<T>> for Rotmat<Mat2<T>>
{ *self = self.rotated(rot) }
}
impl<T: Quot<T, T> + Trigonometric + Neg<T> + Mul<T, T> + Add<T, T> + Copy +
impl<T: Div<T, T> + Trigonometric + Neg<T> + Mul<T, T> + Add<T, T> + Copy +
One + Sub<T, T>>
Rotation<(Vec3<T>, T)> for Rotmat<Mat3<T>>
{
@ -93,7 +93,7 @@ Rotation<(Vec3<T>, T)> for Rotmat<Mat3<T>>
impl<T: Copy + Rand + Trigonometric + Neg<T>> Rand for Rotmat<Mat2<T>>
{
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat2<T>>
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat2<T>>
{ rotmat2(rng.gen()) }
}
@ -101,7 +101,7 @@ impl<T: Copy + Rand + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
Mul<T, T>>
Rand for Rotmat<Mat3<T>>
{
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat3<T>>
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat3<T>>
{ rotmat3(&rng.gen(), rng.gen()) }
}
@ -160,13 +160,16 @@ Transpose for Rotmat<M>
{ self.submat.transpose() }
}
impl<T, M: FuzzyEq<T>> FuzzyEq<T> for Rotmat<M>
impl<T: ApproxEq<T>, M: ApproxEq<T>> ApproxEq<T> for Rotmat<M>
{
fn fuzzy_eq(&self, other: &Rotmat<M>) -> bool
{ self.submat.fuzzy_eq(&other.submat) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &Rotmat<M>, epsilon: &T) -> bool
{ self.submat.fuzzy_eq_eps(&other.submat, epsilon) }
fn approx_eq(&self, other: &Rotmat<M>) -> bool
{ self.submat.approx_eq(&other.submat) }
fn approx_eq_eps(&self, other: &Rotmat<M>, epsilon: &T) -> bool
{ self.submat.approx_eq_eps(&other.submat, epsilon) }
}
impl<M: ToStr> ToStr for Rotmat<M>

View File

@ -1,6 +1,6 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::rotation::Rotation;
@ -122,24 +122,28 @@ Inv for Transform<M, V>
}
}
impl<T, M:FuzzyEq<T>, V:FuzzyEq<T>> FuzzyEq<T> for Transform<M, V>
impl<T: ApproxEq<T>, M:ApproxEq<T>, V:ApproxEq<T>>
ApproxEq<T> for Transform<M, V>
{
fn fuzzy_eq(&self, other: &Transform<M, V>) -> bool
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn approx_eq(&self, other: &Transform<M, V>) -> bool
{
self.submat.fuzzy_eq(&other.submat) &&
self.subtrans.fuzzy_eq(&other.subtrans)
self.submat.approx_eq(&other.submat) &&
self.subtrans.approx_eq(&other.subtrans)
}
fn fuzzy_eq_eps(&self, other: &Transform<M, V>, epsilon: &T) -> bool
fn approx_eq_eps(&self, other: &Transform<M, V>, epsilon: &T) -> bool
{
self.submat.fuzzy_eq_eps(&other.submat, epsilon) &&
self.subtrans.fuzzy_eq_eps(&other.subtrans, epsilon)
self.submat.approx_eq_eps(&other.submat, epsilon) &&
self.subtrans.approx_eq_eps(&other.subtrans, epsilon)
}
}
impl<M: Rand + Copy, V: Rand + Copy> Rand for Transform<M, V>
{
fn rand<R: Rng>(rng: &R) -> Transform<M, V>
fn rand<R: Rng>(rng: &mut R) -> Transform<M, V>
{ transform(&rng.gen(), &rng.gen()) }
}

View File

@ -1,6 +1,6 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
@ -56,7 +56,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec1<T>> for Mat1<T>
{ vec1(self.m11 * other.x) }
}
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T> + Zero + One>
impl<T:Copy + Mul<T, T> + Div<T, T> + Sub<T, T> + Neg<T> + Zero + One>
Inv for Mat1<T>
{
fn inverse(&self) -> Mat1<T>
@ -85,18 +85,21 @@ impl<T:Copy> Transpose for Mat1<T>
{ }
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat1<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Mat1<T>
{
fn fuzzy_eq(&self, other: &Mat1<T>) -> bool
{ self.m11.fuzzy_eq(&other.m11) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &Mat1<T>, epsilon: &T) -> bool
{ self.m11.fuzzy_eq_eps(&other.m11, epsilon) }
fn approx_eq(&self, other: &Mat1<T>) -> bool
{ self.m11.approx_eq(&other.m11) }
fn approx_eq_eps(&self, other: &Mat1<T>, epsilon: &T) -> bool
{ self.m11.approx_eq_eps(&other.m11, epsilon) }
}
impl<T:Rand + Copy> Rand for Mat1<T>
{
fn rand<R: Rng>(rng: &R) -> Mat1<T>
fn rand<R: Rng>(rng: &mut R) -> Mat1<T>
{ mat1(rng.gen()) }
}

View File

@ -1,6 +1,6 @@
use core::num::{Zero, One, Algebraic};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::basis::Basis;
use traits::dim::Dim;
use traits::dot::Dot;
@ -44,7 +44,7 @@ ScalarMul<T> for Vec1<T>
}
impl<T: Copy + Quot<T, T>>
impl<T: Copy + Div<T, T>>
ScalarDiv<T> for Vec1<T>
{
fn scalar_div(&self, s: &T) -> Vec1<T>
@ -92,7 +92,7 @@ impl<T:Copy + Mul<T, T> + Add<T, T> + Algebraic> Dot<T> for Vec1<T>
{ self.x * other.x }
}
impl<T:Copy + Mul<T, T> + Add<T, T> + Quot<T, T> + Algebraic>
impl<T:Copy + Mul<T, T> + Add<T, T> + Div<T, T> + Algebraic>
Norm<T> for Vec1<T>
{
fn sqnorm(&self) -> T
@ -141,18 +141,21 @@ impl<T: Copy + One> Basis for Vec1<T>
{ ~[] }
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec1<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Vec1<T>
{
fn fuzzy_eq(&self, other: &Vec1<T>) -> bool
{ self.x.fuzzy_eq(&other.x) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &Vec1<T>, epsilon: &T) -> bool
{ self.x.fuzzy_eq_eps(&other.x, epsilon) }
fn approx_eq(&self, other: &Vec1<T>) -> bool
{ self.x.approx_eq(&other.x) }
fn approx_eq_eps(&self, other: &Vec1<T>, epsilon: &T) -> bool
{ self.x.approx_eq_eps(&other.x, epsilon) }
}
impl<T:Rand + Copy> Rand for Vec1<T>
{
fn rand<R: Rng>(rng: &R) -> Vec1<T>
fn rand<R: Rng>(rng: &mut R) -> Vec1<T>
{ vec1(rng.gen()) }
}

View File

@ -1,6 +1,7 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use core::util::swap;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
@ -89,7 +90,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec2<T>> for Mat2<T>
}
}
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T> + Zero>
impl<T:Copy + Mul<T, T> + Div<T, T> + Sub<T, T> + Neg<T> + Zero>
Inv for Mat2<T>
{
fn inverse(&self) -> Mat2<T>
@ -121,33 +122,36 @@ impl<T:Copy> Transpose for Mat2<T>
}
fn transpose(&mut self)
{ self.m21 <-> self.m12; }
{ swap(&mut self.m21, &mut self.m12); }
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat2<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Mat2<T>
{
fn fuzzy_eq(&self, other: &Mat2<T>) -> bool
{
self.m11.fuzzy_eq(&other.m11) &&
self.m12.fuzzy_eq(&other.m12) &&
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
self.m21.fuzzy_eq(&other.m21) &&
self.m22.fuzzy_eq(&other.m22)
fn approx_eq(&self, other: &Mat2<T>) -> bool
{
self.m11.approx_eq(&other.m11) &&
self.m12.approx_eq(&other.m12) &&
self.m21.approx_eq(&other.m21) &&
self.m22.approx_eq(&other.m22)
}
fn fuzzy_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool
fn approx_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool
{
self.m11.fuzzy_eq_eps(&other.m11, epsilon) &&
self.m12.fuzzy_eq_eps(&other.m12, epsilon) &&
self.m11.approx_eq_eps(&other.m11, epsilon) &&
self.m12.approx_eq_eps(&other.m12, epsilon) &&
self.m21.fuzzy_eq_eps(&other.m21, epsilon) &&
self.m22.fuzzy_eq_eps(&other.m22, epsilon)
self.m21.approx_eq_eps(&other.m21, epsilon) &&
self.m22.approx_eq_eps(&other.m22, epsilon)
}
}
impl<T:Rand + Copy> Rand for Mat2<T>
{
fn rand<R: Rng>(rng: &R) -> Mat2<T>
fn rand<R: Rng>(rng: &mut R) -> Mat2<T>
{ mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
}

View File

@ -1,7 +1,7 @@
use core::num::{Zero, One, Algebraic};
use core::rand::{Rand, Rng, RngUtil};
use dim1::vec1::{Vec1, vec1};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::basis::Basis;
use traits::cross::Cross;
use traits::dim::Dim;
@ -52,7 +52,7 @@ ScalarMul<T> for Vec2<T>
}
impl<T: Copy + Quot<T, T>>
impl<T: Copy + Div<T, T>>
ScalarDiv<T> for Vec2<T>
{
fn scalar_div(&self, s: &T) -> Vec2<T>
@ -109,7 +109,7 @@ impl<T:Copy + Mul<T, T> + Add<T, T> + Algebraic> Dot<T> for Vec2<T>
{ self.x * other.x + self.y * other.y }
}
impl<T:Copy + Mul<T, T> + Add<T, T> + Quot<T, T> + Algebraic>
impl<T:Copy + Mul<T, T> + Add<T, T> + Div<T, T> + Algebraic>
Norm<T> for Vec2<T>
{
fn sqnorm(&self) -> T
@ -173,21 +173,24 @@ impl<T: Copy + One + Zero + Neg<T>> Basis for Vec2<T>
{ ~[ vec2(-self.y, self.x) ] }
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec2<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Vec2<T>
{
fn fuzzy_eq(&self, other: &Vec2<T>) -> bool
{ self.x.fuzzy_eq(&other.x) && self.y.fuzzy_eq(&other.y) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool
fn approx_eq(&self, other: &Vec2<T>) -> bool
{ self.x.approx_eq(&other.x) && self.y.approx_eq(&other.y) }
fn approx_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool
{
self.x.fuzzy_eq_eps(&other.x, epsilon) &&
self.y.fuzzy_eq_eps(&other.y, epsilon)
self.x.approx_eq_eps(&other.x, epsilon) &&
self.y.approx_eq_eps(&other.y, epsilon)
}
}
impl<T:Rand + Copy> Rand for Vec2<T>
{
fn rand<R: Rng>(rng: &R) -> Vec2<T>
fn rand<R: Rng>(rng: &mut R) -> Vec2<T>
{ vec2(rng.gen(), rng.gen()) }
}

View File

@ -1,6 +1,7 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use core::util::swap;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
@ -106,7 +107,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec3<T>> for Mat3<T>
}
}
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Add<T, T> + Neg<T> + Zero>
impl<T:Copy + Mul<T, T> + Div<T, T> + Sub<T, T> + Add<T, T> + Neg<T> + Zero>
Inv for Mat3<T>
{
fn inverse(&self) -> Mat3<T>
@ -157,48 +158,51 @@ impl<T:Copy> Transpose for Mat3<T>
fn transpose(&mut self)
{
self.m12 <-> self.m21;
self.m13 <-> self.m31;
self.m23 <-> self.m32;
swap(&mut self.m12, &mut self.m21);
swap(&mut self.m13, &mut self.m31);
swap(&mut self.m23, &mut self.m32);
}
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat3<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Mat3<T>
{
fn fuzzy_eq(&self, other: &Mat3<T>) -> bool
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn approx_eq(&self, other: &Mat3<T>) -> bool
{
self.m11.fuzzy_eq(&other.m11) &&
self.m12.fuzzy_eq(&other.m12) &&
self.m13.fuzzy_eq(&other.m13) &&
self.m11.approx_eq(&other.m11) &&
self.m12.approx_eq(&other.m12) &&
self.m13.approx_eq(&other.m13) &&
self.m21.fuzzy_eq(&other.m21) &&
self.m22.fuzzy_eq(&other.m22) &&
self.m23.fuzzy_eq(&other.m23) &&
self.m21.approx_eq(&other.m21) &&
self.m22.approx_eq(&other.m22) &&
self.m23.approx_eq(&other.m23) &&
self.m31.fuzzy_eq(&other.m31) &&
self.m32.fuzzy_eq(&other.m32) &&
self.m33.fuzzy_eq(&other.m33)
self.m31.approx_eq(&other.m31) &&
self.m32.approx_eq(&other.m32) &&
self.m33.approx_eq(&other.m33)
}
fn fuzzy_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool
fn approx_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool
{
self.m11.fuzzy_eq_eps(&other.m11, epsilon) &&
self.m12.fuzzy_eq_eps(&other.m12, epsilon) &&
self.m13.fuzzy_eq_eps(&other.m13, epsilon) &&
self.m11.approx_eq_eps(&other.m11, epsilon) &&
self.m12.approx_eq_eps(&other.m12, epsilon) &&
self.m13.approx_eq_eps(&other.m13, epsilon) &&
self.m21.fuzzy_eq_eps(&other.m21, epsilon) &&
self.m22.fuzzy_eq_eps(&other.m22, epsilon) &&
self.m23.fuzzy_eq_eps(&other.m23, epsilon) &&
self.m21.approx_eq_eps(&other.m21, epsilon) &&
self.m22.approx_eq_eps(&other.m22, epsilon) &&
self.m23.approx_eq_eps(&other.m23, epsilon) &&
self.m31.fuzzy_eq_eps(&other.m31, epsilon) &&
self.m32.fuzzy_eq_eps(&other.m32, epsilon) &&
self.m33.fuzzy_eq_eps(&other.m33, epsilon)
self.m31.approx_eq_eps(&other.m31, epsilon) &&
self.m32.approx_eq_eps(&other.m32, epsilon) &&
self.m33.approx_eq_eps(&other.m33, epsilon)
}
}
impl<T:Rand + Copy> Rand for Mat3<T>
{
fn rand<R: Rng>(rng: &R) -> Mat3<T>
fn rand<R: Rng>(rng: &mut R) -> Mat3<T>
{
mat3(rng.gen(), rng.gen(), rng.gen(),
rng.gen(), rng.gen(), rng.gen(),

View File

@ -1,6 +1,6 @@
use core::num::{Zero, One, Algebraic, abs};
use core::rand::{Rand, Rng, RngUtil};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::basis::Basis;
use traits::cross::Cross;
use traits::dim::Dim;
@ -53,7 +53,7 @@ ScalarMul<T> for Vec3<T>
}
impl<T: Copy + Quot<T, T>>
impl<T: Copy + Div<T, T>>
ScalarDiv<T> for Vec3<T>
{
fn scalar_div(&self, s: &T) -> Vec3<T>
@ -121,7 +121,7 @@ impl<T:Copy + Mul<T, T> + Add<T, T> + Algebraic> Dot<T> for Vec3<T>
{ self.x * other.x + self.y * other.y + self.z * other.z }
}
impl<T:Copy + Mul<T, T> + Add<T, T> + Quot<T, T> + Algebraic>
impl<T:Copy + Mul<T, T> + Add<T, T> + Div<T, T> + Algebraic>
Norm<T> for Vec3<T>
{
fn sqnorm(&self) -> T
@ -174,7 +174,7 @@ impl<T:Copy + Zero> Zero for Vec3<T>
}
impl<T: Copy + One + Zero + Neg<T> + Ord + Mul<T, T> + Sub<T, T> + Add<T, T> +
Quot<T, T> + Algebraic>
Div<T, T> + Algebraic>
Basis for Vec3<T>
{
fn canonical_basis() -> ~[Vec3<T>]
@ -197,26 +197,29 @@ Basis for Vec3<T>
}
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec3<T>
impl<T:ApproxEq<T>> ApproxEq<T> for Vec3<T>
{
fn fuzzy_eq(&self, other: &Vec3<T>) -> bool
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn approx_eq(&self, other: &Vec3<T>) -> bool
{
self.x.fuzzy_eq(&other.x) &&
self.y.fuzzy_eq(&other.y) &&
self.z.fuzzy_eq(&other.z)
self.x.approx_eq(&other.x) &&
self.y.approx_eq(&other.y) &&
self.z.approx_eq(&other.z)
}
fn fuzzy_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool
fn approx_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool
{
self.x.fuzzy_eq_eps(&other.x, epsilon) &&
self.y.fuzzy_eq_eps(&other.y, epsilon) &&
self.z.fuzzy_eq_eps(&other.z, epsilon)
self.x.approx_eq_eps(&other.x, epsilon) &&
self.y.approx_eq_eps(&other.y, epsilon) &&
self.z.approx_eq_eps(&other.z, epsilon)
}
}
impl<T:Copy + Rand> Rand for Vec3<T>
{
fn rand<R: Rng>(rng: &R) -> Vec3<T>
fn rand<R: Rng>(rng: &mut R) -> Vec3<T>
{ vec3(rng.gen(), rng.gen(), rng.gen()) }
}

View File

@ -1,3 +1,11 @@
/*!
# The n-dimensional linear algebra library.
*/
#[link(name = "nalgebra"
, vers = "0.0"
, author = "Sébastien Crozet"
@ -7,61 +15,72 @@
extern mod std;
mod dim2
/// 1-dimensional linear algebra.
pub mod dim1
{
mod vec2;
mod mat2;
pub mod vec1;
pub mod mat1;
}
mod dim1
/// 2-dimensional linear algebra.
pub mod dim2
{
mod vec1;
mod mat1;
pub mod vec2;
pub mod mat2;
}
mod dim3
/// 3-dimensional linear algebra.
pub mod dim3
{
mod vec3;
mod mat3;
pub mod vec3;
pub mod mat3;
}
mod ndim
/// n-dimensional linear algebra (slower).
pub mod ndim
{
mod nvec;
mod nmat;
pub mod nvec;
pub mod nmat;
}
mod adaptors
/// Wrappers around raw matrices to restrict their behaviour.
pub mod adaptors
{
mod rotmat;
mod transform;
pub mod rotmat;
pub mod transform;
}
mod traits
/// Useful linear-algebra related traits.
pub mod traits
{
mod dot;
mod cross;
mod inv;
mod transpose;
mod dim;
mod basis;
mod norm;
mod rotation;
mod translation;
mod delta_transform;
mod vector_space;
mod ring;
mod division_ring;
pub mod dot;
pub mod cross;
pub mod inv;
pub mod transpose;
pub mod dim;
pub mod basis;
pub mod norm;
pub mod rotation;
pub mod translation;
pub mod delta_transform;
pub mod vector_space;
pub mod ring;
pub mod division_ring;
mod workarounds
/// This package contains everything done because the current compiler either
/// crashes or miss features.
/// Therefore, keep in mind anything in there will be inevitably removed some
/// days. So dont rely on them too much.
pub mod workarounds
{
mod rlmul;
mod scalar_op;
pub mod rlmul;
pub mod scalar_op;
}
}
mod tests
#[cfg(test)]
pub mod tests
{
mod mat;
mod vec;
pub mod mat;
pub mod vec;
}

View File

@ -1,7 +1,7 @@
use core::num::{One, Zero};
use core::rand::{Rand, Rng, RngUtil};
use core::vec::{from_elem, swap, all, all2};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
@ -136,7 +136,7 @@ LMul<NVec<D, T>> for NMat<D, T>
impl<D: Dim,
T: Clone + Copy + Eq + One + Zero +
Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T>>
Mul<T, T> + Div<T, T> + Sub<T, T> + Neg<T>>
Inv for NMat<D, T>
{
fn inverse(&self) -> NMat<D, T>
@ -194,8 +194,13 @@ Inv for NMat<D, T>
for uint::range(k, dim) |j|
{
self.set(k, j, &(self[(k, j)] / pivot));
res.set(k, j, &(res[(k, j)] / pivot));
// FIXME: not to putting selfal exression directly on the nuction call
// is uggly but does not seem to compile any more…
let selfval = &(self[(k, j)] / pivot);
let resval = &(res[(k, j)] / pivot);
self.set(k, j, selfval);
res.set(k, j, resval);
}
for uint::range(0u, dim) |l|
@ -206,8 +211,11 @@ Inv for NMat<D, T>
for uint::range(k, dim) |j|
{
self.set(k, j, &(self[(l, j)] - self[(k, j)] * normalizer));
res.set(k, j, &(res[(l, j)] - res[(k, j)] * normalizer));
let selfval = &(self[(l, j)] - self[(k, j)] * normalizer);
let resval = &(res[(l, j)] - res[(k, j)] * normalizer);
self.set(k, j, selfval);
res.set(k, j, resval);
}
}
}
@ -242,18 +250,21 @@ impl<D: Dim, T:Copy> Transpose for NMat<D, T>
}
}
impl<D, T: FuzzyEq<T>> FuzzyEq<T> for NMat<D, T>
impl<D, T: ApproxEq<T>> ApproxEq<T> for NMat<D, T>
{
fn fuzzy_eq(&self, other: &NMat<D, T>) -> bool
{ all2(self.mij, other.mij, |a, b| a.fuzzy_eq(b)) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &NMat<D, T>, epsilon: &T) -> bool
{ all2(self.mij, other.mij, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
fn approx_eq(&self, other: &NMat<D, T>) -> bool
{ all2(self.mij, other.mij, |a, b| a.approx_eq(b)) }
fn approx_eq_eps(&self, other: &NMat<D, T>, epsilon: &T) -> bool
{ all2(self.mij, other.mij, |a, b| a.approx_eq_eps(b, epsilon)) }
}
impl<D: Dim, T: Rand + Zero + Copy> Rand for NMat<D, T>
{
fn rand<R: Rng>(rng: &R) -> NMat<D, T>
fn rand<R: Rng>(rng: &mut R) -> NMat<D, T>
{
let dim = Dim::dim::<D>();
let mut res : NMat<D, T> = Zero::zero();

View File

@ -1,7 +1,7 @@
use core::num::{Zero, One, Algebraic};
use core::rand::{Rand, Rng, RngUtil};
use core::vec::{map_zip, from_elem, map, all, all2};
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
use traits::basis::Basis;
use traits::dim::Dim;
use traits::dot::Dot;
@ -80,7 +80,7 @@ ScalarMul<T> for NVec<D, T>
}
impl<D: Dim, T: Copy + Quot<T, T>>
impl<D: Dim, T: Copy + Div<T, T>>
ScalarDiv<T> for NVec<D, T>
{
fn scalar_div(&self, s: &T) -> NVec<D, T>
@ -131,7 +131,7 @@ impl<D: Dim, T: Clone + Copy + Add<T, T>> Translation<NVec<D, T>> for NVec<D, T>
{ *self = *self + *t; }
}
impl<D: Dim, T: Copy + Mul<T, T> + Add<T, T> + Quot<T, T> + Algebraic + Zero +
impl<D: Dim, T: Copy + Mul<T, T> + Add<T, T> + Div<T, T> + Algebraic + Zero +
Clone>
Norm<T> for NVec<D, T>
{
@ -163,7 +163,7 @@ Norm<T> for NVec<D, T>
impl<D: Dim,
T: Copy + One + Zero + Neg<T> + Ord + Mul<T, T> + Sub<T, T> + Add<T, T> +
Quot<T, T> + Algebraic + Clone + FuzzyEq<T>>
Div<T, T> + Algebraic + Clone + ApproxEq<T>>
Basis for NVec<D, T>
{
fn canonical_basis() -> ~[NVec<D, T>]
@ -206,7 +206,7 @@ Basis for NVec<D, T>
for res.each |v|
{ elt -= v.scalar_mul(&elt.dot(v)) };
if (!elt.sqnorm().fuzzy_eq(&Zero::zero()))
if (!elt.sqnorm().approx_eq(&Zero::zero()))
{ res.push(elt.normalized()); }
}
@ -239,18 +239,21 @@ impl<D: Dim, T: Copy + Zero> Zero for NVec<D, T>
}
}
impl<D, T: FuzzyEq<T>> FuzzyEq<T> for NVec<D, T>
impl<D, T: ApproxEq<T>> ApproxEq<T> for NVec<D, T>
{
fn fuzzy_eq(&self, other: &NVec<D, T>) -> bool
{ all2(self.at, other.at, |a, b| a.fuzzy_eq(b)) }
fn approx_epsilon() -> T
{ ApproxEq::approx_epsilon::<T, T>() }
fn fuzzy_eq_eps(&self, other: &NVec<D, T>, epsilon: &T) -> bool
{ all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
fn approx_eq(&self, other: &NVec<D, T>) -> bool
{ all2(self.at, other.at, |a, b| a.approx_eq(b)) }
fn approx_eq_eps(&self, other: &NVec<D, T>, epsilon: &T) -> bool
{ all2(self.at, other.at, |a, b| a.approx_eq_eps(b, epsilon)) }
}
impl<D: Dim, T: Rand + Zero + Copy> Rand for NVec<D, T>
{
fn rand<R: Rng>(rng: &R) -> NVec<D, T>
fn rand<R: Rng>(rng: &mut R) -> NVec<D, T>
{
let dim = Dim::dim::<D>();
let mut res : NVec<D, T> = Zero::zero();

View File

@ -3,7 +3,7 @@ use core::num::{One, abs};
#[test]
use core::rand::{random};
#[test]
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
#[test]
use traits::inv::Inv;
#[test]
@ -25,7 +25,7 @@ use adaptors::rotmat::Rotmat;
// {
// let randmat : NMat<d7, f64> = random();
//
// assert!((randmat.inverse() * randmat).fuzzy_eq(&One::one()));
// assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
// }
#[test]
@ -35,7 +35,7 @@ fn test_inv_mat1()
{
let randmat : Mat1<f64> = random();
assert!((randmat.inverse() * randmat).fuzzy_eq(&One::one()));
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
@ -46,7 +46,7 @@ fn test_inv_mat2()
{
let randmat : Mat2<f64> = random();
assert!((randmat.inverse() * randmat).fuzzy_eq(&One::one()));
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
@ -57,7 +57,7 @@ fn test_inv_mat3()
{
let randmat : Mat3<f64> = random();
assert!((randmat.inverse() * randmat).fuzzy_eq(&One::one()));
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
@ -69,6 +69,6 @@ fn test_rotation2()
let randmat = One::one::<Rotmat<Mat2<f64>>>();
let ang = &vec1(abs::<f64>(random()) % f64::consts::pi);
assert!(randmat.rotated(ang).rotation().fuzzy_eq(ang));
assert!(randmat.rotated(ang).rotation().approx_eq(ang));
}
}

View File

@ -5,7 +5,7 @@ use core::rand::{random};
#[test]
use core::vec::{all, all2};
#[test]
use std::cmp::FuzzyEq;
use core::cmp::ApproxEq;
#[test]
use dim3::vec3::Vec3;
#[test]
@ -35,8 +35,8 @@ fn test_cross_vec3()
let v2 : Vec3<f64> = random();
let v3 : Vec3<f64> = v1.cross(&v2);
assert!(v3.dot(&v2).fuzzy_eq(&Zero::zero()));
assert!(v3.dot(&v1).fuzzy_eq(&Zero::zero()));
assert!(v3.dot(&v2).approx_eq(&Zero::zero()));
assert!(v3.dot(&v1).approx_eq(&Zero::zero()));
}
}
@ -48,7 +48,7 @@ fn test_dot_nvec()
let v1 : NVec<d7, f64> = random();
let v2 : NVec<d7, f64> = random();
assert!(v1.dot(&v2).fuzzy_eq(&v2.dot(&v1)));
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
@ -60,7 +60,7 @@ fn test_commut_dot_vec3()
let v1 : Vec3<f64> = random();
let v2 : Vec3<f64> = random();
assert!(v1.dot(&v2).fuzzy_eq(&v2.dot(&v1)));
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
@ -72,7 +72,7 @@ fn test_commut_dot_vec2()
let v1 : Vec2<f64> = random();
let v2 : Vec2<f64> = random();
assert!(v1.dot(&v2).fuzzy_eq(&v2.dot(&v1)));
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
@ -84,7 +84,7 @@ fn test_commut_dot_vec1()
let v1 : Vec1<f64> = random();
let v2 : Vec1<f64> = random();
assert!(v1.dot(&v2).fuzzy_eq(&v2.dot(&v1)));
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
@ -94,9 +94,9 @@ fn test_basis_vec1()
let basis = Basis::canonical_basis::<Vec1<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
#[test]
@ -105,9 +105,9 @@ fn test_basis_vec2()
let basis = Basis::canonical_basis::<Vec2<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
#[test]
@ -116,9 +116,9 @@ fn test_basis_vec3()
let basis = Basis::canonical_basis::<Vec3<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
#[test]
@ -127,9 +127,9 @@ fn test_basis_nvec()
let basis = Basis::canonical_basis::<NVec<d7, f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
#[test]
@ -142,11 +142,11 @@ fn test_subspace_basis_vec1()
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).fuzzy_eq(&Zero::zero())));
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
@ -160,11 +160,11 @@ fn test_subspace_basis_vec2()
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).fuzzy_eq(&Zero::zero())));
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
@ -178,11 +178,11 @@ fn test_subspace_basis_vec3()
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).fuzzy_eq(&Zero::zero())));
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().fuzzy_eq(&One::one())));
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
@ -198,10 +198,10 @@ fn test_subspace_basis_vec3()
// let subbasis = v1.orthogonal_subspace_basis();
//
// // check vectors are orthogonal to v1
// assert!(all(subbasis, |e| v1.dot(e).fuzzy_eq(&Zero::zero())));
// assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// // check vectors form an ortogonal basis
// assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).fuzzy_eq(&Zero::zero())));
// assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// // check vectors form an orthonormal basis
// assert!(all(subbasis, |e| e.norm().fuzzy_eq(&One::one())));
// assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
// }
// }

View File

@ -1,5 +1,7 @@
pub trait Basis
{
fn canonical_basis() -> ~[Self]; // FIXME: is it the right pointer?
/// Computes the canonical basis of the space in which this object lives.
// FIXME: need type-associated values
fn canonical_basis() -> ~[Self];
fn orthogonal_subspace_basis(&self) -> ~[Self];
}

View File

@ -1,3 +1,6 @@
/**
* Trait of elements having a cross product.
*/
pub trait Cross<Result>
{
/// Computes the cross product between two elements (usually vectors).

View File

@ -1,6 +1,8 @@
/// A delta-transformation is the generalization of rotation. A delta transform
/// can apply any transformation to the object without translating it.
/// In partilular, 0 is neutral wrt. the delta-transform.
/**
* A delta-transformation is the generalization of rotation. A delta transform
* can apply any transformation to the object without translating it.
* In partilular, 0 is neutral wrt. the delta-transform.
*/
pub trait DeltaTransform<DT>
{
/// Extracts the delta transformation associated with this transformation.

View File

@ -1,3 +1,6 @@
/**
* Trait of objects having a dimension (in term of spacial dimension).
*/
pub trait Dim {
/// The dimension of the object.
fn dim() -> uint;
@ -5,6 +8,7 @@ pub trait Dim {
// Some dimension token. Useful to restrict the dimension of n-dimensional
// object at the type-level.
/// Dimensional token for 0-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq)]

View File

@ -1,4 +1,8 @@
use traits::ring::Ring;
pub trait DivisionRing : Ring + Quot<Self, Self>
/**
* Trait of elements of a division ring. A division ring is an algebraic
* structure like a ring, but with the division operator.
*/
pub trait DivisionRing : Ring + Div<Self, Self>
{ }

View File

@ -1,3 +1,6 @@
/**
* Trait of objects having a dot product (also called inner product).
*/
pub trait Dot<T>
{
/// Computes the dot (inner) product of two objects.

View File

@ -1,3 +1,6 @@
/**
* Trait of inversible objects. Typically used to implement matrix inverse.
*/
pub trait Inv
{
/// Returns the inverse of an element.

View File

@ -1,3 +1,6 @@
/**
* Trait of objects having a L² norm and which can be normalized.
*/
pub trait Norm<T>
{
/// Computes the norm a an object.
@ -11,9 +14,9 @@ pub trait Norm<T>
*/
fn sqnorm(&self) -> T;
/// Returns the normalized version of the argument.
/// Gets the normalized version of the argument.
fn normalized(&self) -> Self;
/// Inplace version of `normalized`.
/// In-place version of `normalized`.
fn normalize(&mut self) -> T;
}

View File

@ -1,5 +1,11 @@
use core::num::{One, Zero};
/**
* Trait of elements of a ring. A rings is an algebraic structure, the
* elements of which have all the common numeric operation but the division:
* addition, subtraction, multiplication and distinct elements (`One` and
* `Zero`) respectively neutral and absorbant wrt the multiplication.
*/
pub trait Ring :
Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Mul<Self, Self> + One + Zero
{ }

View File

@ -1,6 +1,15 @@
/// Trait of object which represent a rotation, and to wich new rotations can
/// be appended. A rotation is assumed to be an isomitry without translation
/// and without reflexion.
pub trait Rotation<V>
{
/// Gets the rotation associated with this object.
fn rotation(&self) -> V;
/// Appends a rotation from an alternative representation. Such
/// representation has the same format as the one returned by `rotation`.
fn rotated(&self, &V) -> Self;
/// In-place version of `rotated`.
fn rotate(&mut self, &V);
}

View File

@ -1,6 +1,14 @@
/// Trait of object which represent a translation, and to wich new translation
/// can be appended.
pub trait Translation<V>
{
/// Gets the translation associated with this object.
fn translation(&self) -> V;
/// Appends a translation from an alternative representation. Such
/// representation has the same format as the one returned by `translation`.
fn translated(&self, &V) -> Self;
/// In-place version of `translate`.
fn translate(&mut self, &V);
}

View File

@ -1,8 +1,12 @@
// FIXME: valid only for square matrices…
/// Trait of objects which can be transposed. Note that, for the moment, this
/// does not allow the implementation by non-square matrix (or anything which
/// is not stable by transposition).
pub trait Transpose
{
/// Computes the transpose of a matrix.
fn transposed(&self) -> Self;
/// Inplace version of `transposed`.
/// In-place version of `transposed`.
fn transpose(&mut self);
}

View File

@ -2,6 +2,11 @@ use core::num::Zero;
use traits::division_ring::DivisionRing;
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv};
pub trait VectorSpace<T: DivisionRing> : Sub<Self, Self> + Add<Self, Self> +
Neg<Self> + Zero + ScalarMul<T> + ScalarDiv<T>
/// Trait of elements of a vector space. A vector space is an algebraic
/// structure, the elements of which have addition, substraction, negation,
/// scalar multiplication (the scalar being a element of a `DivisionRing`), and
/// has a distinct element (`Zero`) neutral wrt the addition.
pub trait VectorSpace<T: DivisionRing>
: Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero +
ScalarMul<T> + ScalarDiv<T>
{ }

View File

@ -1,4 +0,0 @@
This packages contains everything done because current compiler either
bugs or miss features.
Therefore, keep in mind anything in there will be inevitably removed some days.
So dont rely on them too much.

View File

@ -1,8 +1,12 @@
/** This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type:
/**
* Trait of objects having a right multiplication with another element.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Mul<V, V> for M
* trait Mul<V2, V2> for M
* trait Mul<V, M> for M
* trait Mul<V2, M> for M
* ~~~
*/
pub trait RMul<V>
@ -11,6 +15,17 @@ pub trait RMul<V>
fn rmul(&self, v : &V) -> V;
}
/**
* Trait of objects having a left multiplication with another element.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Mul<V, M> for M
* trait Mul<V2, M> for M
* ~~~
*/
pub trait LMul<V>
{
/// Computes v * self

View File

@ -1,23 +1,79 @@
/**
* Trait of objects having a multiplication with a scalar.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Mul<V, T> for T
* trait Mul<V2, T> for T
* ~~~
*/
pub trait ScalarMul<T>
{
/// Gets the result of a multiplication by a scalar.
fn scalar_mul(&self, &T) -> Self;
/// In-place version of `scalar_mul`.
fn scalar_mul_inplace(&mut self, &T);
}
/**
* Trait of objects having a division with a scalar.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Div<V, T> for T
* trait Div<V2, T> for T
* ~~~
*/
pub trait ScalarDiv<T>
{
/// Gets the result of a division by a scalar.
fn scalar_div(&self, &T) -> Self;
/// In-place version of `scalar_div`.
fn scalar_div_inplace(&mut self, &T);
}
/**
* Trait of objects having an addition with a scalar.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Add<V, T> for T
* trait Add<V2, T> for T
* ~~~
*/
pub trait ScalarAdd<T>
{
/// Gets the result of an addition by a scalar.
fn scalar_add(&self, &T) -> Self;
/// In-place version of `scalar_add`.
fn scalar_add_inplace(&mut self, &T);
}
/**
* Trait of objects having a subtraction with a scalar.
* This is a workaround of the fact we cannot implement the same trait
* (with different type parameters) twice for the same type. The following
* exemple does not compile (end with an ICE):
*
* ~~~
* trait Sub<V, T> for T
* trait Sub<V2, T> for T
* ~~~
*/
pub trait ScalarSub<T>
{
/// Gets the result of a subtraction by a scalar.
fn scalar_sub(&self, &T) -> Self;
/// In-place version of `scalar_sub`.
fn scalar_sub_inplace(&mut self, &T);
}