Moved DivisionRing to ring.rs.

This commit is contained in:
Sébastien Crozet 2013-08-17 17:50:01 +02:00
parent 344d761be5
commit cead4f8410
13 changed files with 50 additions and 56 deletions

View File

@ -1,7 +1,7 @@
use std::num::{One, Zero}; use std::num::{One, Zero};
use std::rand::{Rand, Rng, RngUtil}; use std::rand::{Rand, Rng, RngUtil};
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::rlmul::{RMul, LMul}; use traits::rlmul::{RMul, LMul};
use traits::cross::Cross; use traits::cross::Cross;
use traits::dim::Dim; use traits::dim::Dim;

View File

@ -3,7 +3,7 @@ use std::rand::{Rand, Rng, RngUtil};
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use traits::dim::Dim; use traits::dim::Dim;
use traits::inv::Inv; use traits::inv::Inv;
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::rotation::{Rotation, Rotate, Rotatable}; use traits::rotation::{Rotation, Rotate, Rotatable};
use traits::translation::{Translation, Translate, Translatable}; use traits::translation::{Translation, Translate, Translatable};
use Ts = traits::transformation::Transform; use Ts = traits::transformation::Transform;

View File

@ -2,7 +2,7 @@ use std::num::{One, Zero};
use std::vec::from_elem; use std::vec::from_elem;
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use traits::inv::Inv; use traits::inv::Inv;
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::transpose::Transpose; use traits::transpose::Transpose;
use traits::rlmul::{RMul, LMul}; use traits::rlmul::{RMul, LMul};
use dvec::{DVec, zero_vec_with_dim}; use dvec::{DVec, zero_vec_with_dim};

View File

@ -4,8 +4,7 @@ use std::vec::from_elem;
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use std::iterator::FromIterator; use std::iterator::FromIterator;
use traits::iterable::{Iterable, IterableMut}; use traits::iterable::{Iterable, IterableMut};
use traits::ring::Ring; use traits::ring::{Ring, DivisionRing};
use traits::division_ring::DivisionRing;
use traits::dot::Dot; use traits::dot::Dot;
use traits::sub_dot::SubDot; use traits::sub_dot::SubDot;
use traits::norm::Norm; use traits::norm::Norm;

View File

@ -6,9 +6,8 @@ use std::cmp::ApproxEq;
use std::vec::{VecIterator, VecMutIterator}; use std::vec::{VecIterator, VecMutIterator};
use vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6}; use vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
use traits::dim::Dim; use traits::dim::Dim;
use traits::ring::Ring; use traits::ring::{Ring, DivisionRing};
use traits::inv::Inv; use traits::inv::Inv;
use traits::division_ring::DivisionRing;
use traits::transpose::Transpose; use traits::transpose::Transpose;
use traits::rlmul::{RMul, LMul}; use traits::rlmul::{RMul, LMul};
use traits::transformation::Transform; use traits::transformation::Transform;

View File

@ -1,6 +1,6 @@
use std::num::{Zero, One}; use std::num::{Zero, One};
use mat::{Mat1, Mat2, Mat3}; use mat::{Mat1, Mat2, Mat3};
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::inv::Inv; use traits::inv::Inv;
// some specializations: // some specializations:
@ -52,8 +52,9 @@ Inv for Mat2<N> {
false false
} }
else { else {
*self = Mat2::new(self.m22 / det , -self.m12 / det, *self = Mat2::new(
-self.m21 / det, self.m11 / det); self.m22 / det , -self.m12 / det,
-self.m21 / det, self.m11 / det);
true true
} }

View File

@ -30,8 +30,8 @@ mod vec0_spec;
/// Wrappers around raw matrices to restrict their behaviour. /// Wrappers around raw matrices to restrict their behaviour.
pub mod adaptors pub mod adaptors
{ {
pub mod rotmat; pub mod rotmat;
pub mod transform; pub mod transform;
} }
pub mod types; pub mod types;
@ -47,35 +47,34 @@ pub mod types;
// FIXME: it would be better to hide all those from the outside! // FIXME: it would be better to hide all those from the outside!
pub mod traits pub mod traits
{ {
pub mod sample; pub mod sample;
pub mod indexable; pub mod indexable;
pub mod column; pub mod column;
pub mod iterable; pub mod iterable;
pub mod dot; pub mod dot;
pub mod outer; pub mod outer;
pub mod cross; pub mod cross;
pub mod inv; pub mod inv;
pub mod transpose; pub mod transpose;
pub mod dim; pub mod dim;
pub mod basis; pub mod basis;
pub mod norm; pub mod norm;
pub mod rotation; pub mod rotation;
pub mod translation; pub mod translation;
pub mod transformation; pub mod transformation;
pub mod vector_space; pub mod vector_space;
pub mod ring; pub mod ring;
pub mod division_ring; pub mod sub_dot;
pub mod sub_dot; pub mod rlmul;
pub mod rlmul; pub mod scalar_op;
pub mod scalar_op; pub mod homogeneous;
pub mod homogeneous; pub mod vec_cast;
pub mod vec_cast; pub mod mat_cast;
pub mod mat_cast;
} }
#[cfg(test)] #[cfg(test)]
pub mod tests pub mod tests
{ {
pub mod mat; pub mod mat;
pub mod vec; pub mod vec;
} }

View File

@ -1,10 +0,0 @@
use traits::ring::Ring;
/**
* 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>
{ }
impl<N: Ring + Div<N, N>> DivisionRing for N;

View File

@ -11,3 +11,12 @@ Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Mul<Self, Self> + One + Zero { }
impl<N: Sub<N, N> + Add<N, N> + Neg<N> + Mul<N, N> + One + Zero> impl<N: Sub<N, N> + Add<N, N> + Neg<N> + Mul<N, N> + One + Zero>
Ring for N; Ring for N;
/**
* 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>
{ }
impl<N: Ring + Div<N, N>> DivisionRing for N;

View File

@ -1,5 +1,5 @@
use std::num::Zero; use std::num::Zero;
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::scalar_op::{ScalarMul, ScalarDiv}; use traits::scalar_op::{ScalarMul, ScalarDiv};
/// Trait of elements of a vector space. A vector space is an algebraic /// Trait of elements of a vector space. A vector space is an algebraic
@ -7,8 +7,7 @@ use traits::scalar_op::{ScalarMul, ScalarDiv};
/// scalar multiplication (the scalar being a element of a `DivisionRing`), and /// scalar multiplication (the scalar being a element of a `DivisionRing`), and
/// has a distinct element (`Zero`) neutral wrt the addition. /// has a distinct element (`Zero`) neutral wrt the addition.
pub trait VectorSpace<N> pub trait VectorSpace<N>
: Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + : Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + ScalarMul<N> + ScalarDiv<N> { }
ScalarMul<N> + ScalarDiv<N> { }
impl<V: Sub<V, V> + Add<V, V> + Neg<V> + Zero + ScalarMul<N> + ScalarDiv<N>, impl<V: Sub<V, V> + Add<V, V> + Neg<V> + Zero + ScalarMul<N> + ScalarDiv<N>,
N: DivisionRing> VectorSpace<N> for V; N: DivisionRing> VectorSpace<N> for V;

View File

@ -7,8 +7,7 @@ use std::cmp::ApproxEq;
use traits::basis::Basis; use traits::basis::Basis;
use traits::dim::Dim; use traits::dim::Dim;
use traits::translation::{Translation, Translatable}; use traits::translation::{Translation, Translatable};
use traits::ring::Ring; use traits::ring::{Ring, DivisionRing};
use traits::division_ring::DivisionRing;
use traits::homogeneous::{FromHomogeneous, ToHomogeneous}; use traits::homogeneous::{FromHomogeneous, ToHomogeneous};
use traits::indexable::Indexable; use traits::indexable::Indexable;

View File

@ -11,8 +11,7 @@ use traits::sub_dot::SubDot;
use traits::norm::Norm; use traits::norm::Norm;
use traits::translation::{Translation, Translatable}; use traits::translation::{Translation, Translatable};
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
use traits::ring::Ring; use traits::ring::{Ring, DivisionRing};
use traits::division_ring::DivisionRing;
use traits::indexable::Indexable; use traits::indexable::Indexable;
use vec; use vec;

View File

@ -1,7 +1,7 @@
use std::num::{Zero, One}; use std::num::{Zero, One};
use traits::basis::Basis; use traits::basis::Basis;
use traits::cross::Cross; use traits::cross::Cross;
use traits::division_ring::DivisionRing; use traits::ring::DivisionRing;
use traits::norm::Norm; use traits::norm::Norm;
use traits::sample::UniformSphereSample; use traits::sample::UniformSphereSample;
use vec::{Vec1, Vec2, Vec3}; use vec::{Vec1, Vec2, Vec3};