Add Ord instances.

This commit is contained in:
Sébastien Crozet 2013-06-15 18:06:13 +00:00
parent 3ccade3d2f
commit 6e627f3378
6 changed files with 15 additions and 15 deletions

View File

@ -10,7 +10,7 @@ use traits::sub_dot::SubDot;
use traits::flatten::Flatten; use traits::flatten::Flatten;
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct Vec1<N> pub struct Vec1<N>
{ x : N } { x : N }
@ -194,7 +194,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec1<N>
{ self.x.approx_eq_eps(&other.x, epsilon) } { self.x.approx_eq_eps(&other.x, epsilon) }
} }
impl<N:Rand + Copy> Rand for Vec1<N> impl<N: Rand + Copy> Rand for Vec1<N>
{ {
#[inline(always)] #[inline(always)]
fn rand<R: Rng>(rng: &mut R) -> Vec1<N> fn rand<R: Rng>(rng: &mut R) -> Vec1<N>

View File

@ -12,7 +12,7 @@ use traits::flatten::Flatten;
use traits::translation::Translation; use traits::translation::Translation;
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct Vec2<N> pub struct Vec2<N>
{ {
x : N, x : N,

View File

@ -11,7 +11,7 @@ use traits::flatten::Flatten;
use traits::translation::Translation; use traits::translation::Translation;
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct Vec3<N> pub struct Vec3<N>
{ {
x : N, x : N,

View File

@ -11,7 +11,7 @@ use traits::norm::Norm;
use traits::translation::Translation; use traits::translation::Translation;
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
#[deriving(Eq, ToStr, Clone)] #[deriving(Eq, Ord, ToStr, Clone)]
pub struct DVec<N> pub struct DVec<N>
{ {
at: ~[N] at: ~[N]

View File

@ -21,7 +21,7 @@ use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}
// using d0, d1, d2, d3, ..., d7 (or your own dn) are prefered. // using d0, d1, d2, d3, ..., d7 (or your own dn) are prefered.
// FIXME: it might be possible to implement type-level integers and use them // FIXME: it might be possible to implement type-level integers and use them
// here? // here?
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct NVec<D, N> pub struct NVec<D, N>
{ at: DVec<N> } { at: DVec<N> }

View File

@ -11,42 +11,42 @@ pub trait Dim {
/// Dimensional token for 0-dimensions. Dimensional tokens are the preferred /// Dimensional token for 0-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d0; pub struct d0;
/// Dimensional token for 1-dimension. Dimensional tokens are the preferred /// Dimensional token for 1-dimension. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d1; pub struct d1;
/// Dimensional token for 2-dimensions. Dimensional tokens are the preferred /// Dimensional token for 2-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d2; pub struct d2;
/// Dimensional token for 3-dimensions. Dimensional tokens are the preferred /// Dimensional token for 3-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d3; pub struct d3;
/// Dimensional token for 4-dimensions. Dimensional tokens are the preferred /// Dimensional token for 4-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d4; pub struct d4;
/// Dimensional token for 5-dimensions. Dimensional tokens are the preferred /// Dimensional token for 5-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d5; pub struct d5;
/// Dimensional token for 6-dimensions. Dimensional tokens are the preferred /// Dimensional token for 6-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d6; pub struct d6;
/// Dimensional token for 7-dimensions. Dimensional tokens are the preferred /// Dimensional token for 7-dimensions. Dimensional tokens are the preferred
/// way to specify at the type level the dimension of n-dimensional objects. /// way to specify at the type level the dimension of n-dimensional objects.
#[deriving(Eq, ToStr)] #[deriving(Eq, Ord, ToStr)]
pub struct d7; pub struct d7;
impl Dim for d0 impl Dim for d0