Make FloatPnt and FloatVec derive from Index.

The point it that `Index` provides the i-th element decomposed into the trivial basis of their
associated vector spaces.
This commit is contained in:
Sébastien Crozet 2014-10-26 10:31:14 +01:00
parent 2b23446d54
commit 3354ffc37b

View File

@ -106,8 +106,10 @@ pub trait Diag<V> {
/// Thus, this is the same as the `Index` trait but without the syntactic sugar and with a method /// Thus, this is the same as the `Index` trait but without the syntactic sugar and with a method
/// to write to a specific index. /// to write to a specific index.
pub trait Indexable<Index, Res> { pub trait Indexable<Index, Res> {
#[deprecated = "use the Index `[]` overloaded operator instead"]
/// Reads the `i`-th element of `self`. /// Reads the `i`-th element of `self`.
fn at(&self, i: Index) -> Res; fn at(&self, i: Index) -> Res;
#[deprecated = "use the IndexMut `[]` overloaded operator instead"]
/// Writes to the `i`-th element of `self`. /// Writes to the `i`-th element of `self`.
fn set(&mut self, i: Index, Res); fn set(&mut self, i: Index, Res);
/// Swaps the `i`-th element of `self` with its `j`-th element. /// Swaps the `i`-th element of `self` with its `j`-th element.
@ -156,16 +158,18 @@ pub trait VecAsPnt<P> {
} }
/// Trait grouping most common operations on vectors. /// Trait grouping most common operations on vectors.
pub trait AnyVec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + PartialEq + Mul<N, Self> pub trait AnyVec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + PartialEq +
+ Div<N, Self> + Dot<N> + Axpy<N> + Basis { Mul<N, Self> + Div<N, Self> + Dot<N> + Axpy<N> + Basis + Index<uint, N> {
} }
/// Trait of vector with components implementing the `Float` trait. /// Trait of vector with components implementing the `Float` trait.
pub trait FloatVec<N: Float>: AnyVec<N> + Norm<N> { pub trait FloatVec<N: Float>: AnyVec<N> + Norm<N> {
} }
impl<N, V: Dim + Sub<V, V> + Add<V, V> + Neg<V> + Zero + PartialEq + Mul<N, V> + Div<N, V> + Dot<N> + Axpy<N> + Basis> impl<N, V> AnyVec<N> for V
AnyVec<N> for V { } where V: Dim + Sub<V, V> + Add<V, V> + Neg<V> + Zero + PartialEq + Mul<N, V> + Div<N, V> +
Dot<N> + Axpy<N> + Basis + Index<uint, N> {
}
impl<N: Float, V: AnyVec<N> + Norm<N>> FloatVec<N> for V { } impl<N: Float, V: AnyVec<N> + Norm<N>> FloatVec<N> for V { }
@ -191,7 +195,7 @@ pub trait PntAsVec<V> {
// having bounds (they are not supported yet). So, for now, we will just use a type parameter. // having bounds (they are not supported yet). So, for now, we will just use a type parameter.
pub trait AnyPnt<N, V>: pub trait AnyPnt<N, V>:
PntAsVec<V> + Dim + Sub<Self, V> + Orig + Neg<Self> + PartialEq + Mul<N, Self> + PntAsVec<V> + Dim + Sub<Self, V> + Orig + Neg<Self> + PartialEq + Mul<N, Self> +
Div<N, Self> + Add<V, Self> { // FIXME: + Sub<V, Self> Div<N, Self> + Add<V, Self> + Axpy<N> + Index<uint, N> { // FIXME: + Sub<V, Self>
} }
/// Trait of points with components implementing the `Float` trait. /// Trait of points with components implementing the `Float` trait.
@ -209,6 +213,13 @@ pub trait FloatPnt<N: Float, V: Norm<N>>: AnyPnt<N, V> {
} }
} }
impl<N, V, P: PntAsVec<V> + Dim + Sub<P, V> + Add<V, P> + Orig + Neg<P> + PartialEq + Mul<N, P> + Div<N, P>> impl<N, V, P> AnyPnt<N, V> for P
AnyPnt<N, V> for P { } where P: PntAsVec<V> + Dim + Sub<P, V> + Add<V, P> + Orig + Neg<P> + PartialEq + Mul<N, P> +
impl<N: Float, V: Norm<N>, P: AnyPnt<N, V>> FloatPnt<N, V> for P { } Div<N, P> + Axpy<N> + Index<uint, N> {
}
impl<N, V, P> FloatPnt<N, V> for P
where N: Float,
V: Norm<N>,
P: AnyPnt<N, V> {
}