From 3354ffc37b5f9abba9b6f043b7e47704931f7474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 26 Oct 2014 10:31:14 +0100 Subject: [PATCH] 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. --- src/traits/structure.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 050bfcae..24f3fa91 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -106,8 +106,10 @@ pub trait Diag { /// Thus, this is the same as the `Index` trait but without the syntactic sugar and with a method /// to write to a specific index. pub trait Indexable { + #[deprecated = "use the Index `[]` overloaded operator instead"] /// Reads the `i`-th element of `self`. fn at(&self, i: Index) -> Res; + #[deprecated = "use the IndexMut `[]` overloaded operator instead"] /// Writes to the `i`-th element of `self`. fn set(&mut self, i: Index, Res); /// Swaps the `i`-th element of `self` with its `j`-th element. @@ -156,16 +158,18 @@ pub trait VecAsPnt

{ } /// Trait grouping most common operations on vectors. -pub trait AnyVec: Dim + Sub + Add + Neg + Zero + PartialEq + Mul - + Div + Dot + Axpy + Basis { +pub trait AnyVec: Dim + Sub + Add + Neg + Zero + PartialEq + + Mul + Div + Dot + Axpy + Basis + Index { } /// Trait of vector with components implementing the `Float` trait. pub trait FloatVec: AnyVec + Norm { } -impl + Add + Neg + Zero + PartialEq + Mul + Div + Dot + Axpy + Basis> -AnyVec for V { } +impl AnyVec for V + where V: Dim + Sub + Add + Neg + Zero + PartialEq + Mul + Div + + Dot + Axpy + Basis + Index { +} impl + Norm> FloatVec for V { } @@ -191,7 +195,7 @@ pub trait PntAsVec { // having bounds (they are not supported yet). So, for now, we will just use a type parameter. pub trait AnyPnt: PntAsVec + Dim + Sub + Orig + Neg + PartialEq + Mul + - Div + Add { // FIXME: + Sub + Div + Add + Axpy + Index { // FIXME: + Sub } /// Trait of points with components implementing the `Float` trait. @@ -209,6 +213,13 @@ pub trait FloatPnt>: AnyPnt { } } -impl + Dim + Sub + Add + Orig + Neg

+ PartialEq + Mul + Div> -AnyPnt for P { } -impl, P: AnyPnt> FloatPnt for P { } +impl AnyPnt for P + where P: PntAsVec + Dim + Sub + Add + Orig + Neg

+ PartialEq + Mul + + Div + Axpy + Index { +} + +impl FloatPnt for P + where N: Float, + V: Norm, + P: AnyPnt { +}