From 1eed234e0888723737cc2eb2ec435bdf7506cf98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 13 Apr 2014 10:24:17 +0200 Subject: [PATCH] Avoid name conflicts with the standard lib. The `Vec` trait is renamed `AnyVec`. The `Less`, `Greater`, `Equal` variants are renamed `PartialLess`, `PartialGreater`, `PartialEqual`. Those new names are not very good, so they might change in the future. --- src/bench/mat.rs | 42 +++++++++++++++++++------------------- src/bench/vec.rs | 12 +++++------ src/na.rs | 4 ++-- src/structs/vec.rs | 4 ++-- src/structs/vec_macros.rs | 6 +++--- src/traits/mod.rs | 4 ++-- src/traits/operations.rs | 43 +++++++++++++++++++-------------------- src/traits/structure.rs | 14 ++++++------- 8 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/bench/mat.rs b/src/bench/mat.rs index 0cdfa2bf..7618637b 100644 --- a/src/bench/mat.rs +++ b/src/bench/mat.rs @@ -1,5 +1,5 @@ use rand::random; -use test::BenchHarness; +use test::Bencher; use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat}; macro_rules! bench_mul_mat( @@ -18,27 +18,27 @@ macro_rules! bench_mul_mat( ) #[bench] -fn bench_mul_mat2(bh: &mut BenchHarness) { +fn bench_mul_mat2(bh: &mut Bencher) { bench_mul_mat!(bh, Mat2) } #[bench] -fn bench_mul_mat3(bh: &mut BenchHarness) { +fn bench_mul_mat3(bh: &mut Bencher) { bench_mul_mat!(bh, Mat3) } #[bench] -fn bench_mul_mat4(bh: &mut BenchHarness) { +fn bench_mul_mat4(bh: &mut Bencher) { bench_mul_mat!(bh, Mat4) } #[bench] -fn bench_mul_mat5(bh: &mut BenchHarness) { +fn bench_mul_mat5(bh: &mut Bencher) { bench_mul_mat!(bh, Mat5) } #[bench] -fn bench_mul_mat6(bh: &mut BenchHarness) { +fn bench_mul_mat6(bh: &mut Bencher) { bench_mul_mat!(bh, Mat6) } @@ -58,27 +58,27 @@ macro_rules! bench_mul_dmat( ) #[bench] -fn bench_mul_dmat2(bh: &mut BenchHarness) { +fn bench_mul_dmat2(bh: &mut Bencher) { bench_mul_dmat!(bh, 2, 2) } #[bench] -fn bench_mul_dmat3(bh: &mut BenchHarness) { +fn bench_mul_dmat3(bh: &mut Bencher) { bench_mul_dmat!(bh, 3, 3) } #[bench] -fn bench_mul_dmat4(bh: &mut BenchHarness) { +fn bench_mul_dmat4(bh: &mut Bencher) { bench_mul_dmat!(bh, 4, 4) } #[bench] -fn bench_mul_dmat5(bh: &mut BenchHarness) { +fn bench_mul_dmat5(bh: &mut Bencher) { bench_mul_dmat!(bh, 5, 5) } #[bench] -fn bench_mul_dmat6(bh: &mut BenchHarness) { +fn bench_mul_dmat6(bh: &mut Bencher) { bench_mul_dmat!(bh, 6, 6) } @@ -98,27 +98,27 @@ macro_rules! bench_mul_mat_vec( ) #[bench] -fn bench_mul_mat_vec2(bh: &mut BenchHarness) { +fn bench_mul_mat_vec2(bh: &mut Bencher) { bench_mul_mat_vec!(bh, Mat2, Vec2) } #[bench] -fn bench_mul_mat_vec3(bh: &mut BenchHarness) { +fn bench_mul_mat_vec3(bh: &mut Bencher) { bench_mul_mat_vec!(bh, Mat3, Vec3) } #[bench] -fn bench_mul_mat_vec4(bh: &mut BenchHarness) { +fn bench_mul_mat_vec4(bh: &mut Bencher) { bench_mul_mat_vec!(bh, Mat4, Vec4) } #[bench] -fn bench_mul_mat_vec5(bh: &mut BenchHarness) { +fn bench_mul_mat_vec5(bh: &mut Bencher) { bench_mul_mat_vec!(bh, Mat5, Vec5) } #[bench] -fn bench_mul_mat_vec6(bh: &mut BenchHarness) { +fn bench_mul_mat_vec6(bh: &mut Bencher) { bench_mul_mat_vec!(bh, Mat6, Vec6) } @@ -138,26 +138,26 @@ macro_rules! bench_mul_dmat_dvec( ) #[bench] -fn bench_mul_dmat_dvec2(bh: &mut BenchHarness) { +fn bench_mul_dmat_dvec2(bh: &mut Bencher) { bench_mul_dmat_dvec!(bh, 2, 2) } #[bench] -fn bench_mul_dmat_dvec3(bh: &mut BenchHarness) { +fn bench_mul_dmat_dvec3(bh: &mut Bencher) { bench_mul_dmat_dvec!(bh, 3, 3) } #[bench] -fn bench_mul_dmat_dvec4(bh: &mut BenchHarness) { +fn bench_mul_dmat_dvec4(bh: &mut Bencher) { bench_mul_dmat_dvec!(bh, 4, 4) } #[bench] -fn bench_mul_dmat_dvec5(bh: &mut BenchHarness) { +fn bench_mul_dmat_dvec5(bh: &mut Bencher) { bench_mul_dmat_dvec!(bh, 5, 5) } #[bench] -fn bench_mul_dmat_dvec6(bh: &mut BenchHarness) { +fn bench_mul_dmat_dvec6(bh: &mut Bencher) { bench_mul_dmat_dvec!(bh, 6, 6) } diff --git a/src/bench/vec.rs b/src/bench/vec.rs index 900a5cf7..d570b69d 100644 --- a/src/bench/vec.rs +++ b/src/bench/vec.rs @@ -1,5 +1,5 @@ use rand::random; -use test::BenchHarness; +use test::Bencher; use na::{Vec2, Vec3, Vec4, Vec5, Vec6}; use na; @@ -20,26 +20,26 @@ macro_rules! bench_dot_vec( ) #[bench] -fn bench_dot_vec2(bh: &mut BenchHarness) { +fn bench_dot_vec2(bh: &mut Bencher) { bench_dot_vec!(bh, Vec2) } #[bench] -fn bench_dot_vec3(bh: &mut BenchHarness) { +fn bench_dot_vec3(bh: &mut Bencher) { bench_dot_vec!(bh, Vec3) } #[bench] -fn bench_dot_vec4(bh: &mut BenchHarness) { +fn bench_dot_vec4(bh: &mut Bencher) { bench_dot_vec!(bh, Vec4) } #[bench] -fn bench_dot_vec5(bh: &mut BenchHarness) { +fn bench_dot_vec5(bh: &mut Bencher) { bench_dot_vec!(bh, Vec5) } #[bench] -fn bench_dot_vec6(bh: &mut BenchHarness) { +fn bench_dot_vec6(bh: &mut Bencher) { bench_dot_vec!(bh, Vec6) } diff --git a/src/na.rs b/src/na.rs index 984ca22b..813647ab 100644 --- a/src/na.rs +++ b/src/na.rs @@ -2,7 +2,7 @@ use std::num::{Zero, One}; use std::cmp; -pub use traits::{Less, Equal, Greater, NotComparable}; +pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable}; pub use traits::{ Absolute, AbsoluteRotate, @@ -38,7 +38,7 @@ pub use traits::{ Translate, Translation, Transpose, UniformSphereSample, - Vec, + AnyVec, VecExt }; diff --git a/src/structs/vec.rs b/src/structs/vec.rs index ca72e130..dfe960fc 100644 --- a/src/structs/vec.rs +++ b/src/structs/vec.rs @@ -6,8 +6,8 @@ use std::cast; use std::num::{Zero, One, Float, Bounded}; use std::slice::{Items, MutItems}; use std::iter::{Iterator, FromIterator}; -use traits::operations::{ApproxEq, PartialOrd, PartialOrdering, Less, Equal, Greater, NotComparable}; - +use traits::operations::{ApproxEq, PartialOrd, PartialOrdering, PartialLess, PartialEqual, + PartialGreater, NotComparable}; use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm, Translation, Translate}; use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut}; diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 584f5675..fd492d63 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -64,7 +64,7 @@ macro_rules! ord_impl( } )* - Less + PartialLess } else { // >= $( @@ -78,10 +78,10 @@ macro_rules! ord_impl( )* if is_eq { - Equal + PartialEqual } else { - Greater + PartialGreater } } } diff --git a/src/traits/mod.rs b/src/traits/mod.rs index f192a654..8a62fab5 100644 --- a/src/traits/mod.rs +++ b/src/traits/mod.rs @@ -5,11 +5,11 @@ pub use self::geometry::{AbsoluteRotate, Cross, CrossMatrix, Dot, FromHomogeneou Transform, Transformation, Translate, Translation, UniformSphereSample}; pub use self::structure::{FloatVec, FloatVecExt, Basis, Cast, Col, Dim, Indexable, - Iterable, IterableMut, Mat, Row, Vec, VecExt}; + Iterable, IterableMut, Mat, Row, AnyVec, VecExt}; pub use self::operations::{Absolute, ApproxEq, Cov, Inv, LMul, Mean, Outer, PartialOrd, RMul, ScalarAdd, ScalarSub, Transpose}; -pub use self::operations::{PartialOrdering, Less, Equal, Greater, NotComparable}; +pub use self::operations::{PartialOrdering, PartialLess, PartialEqual, PartialGreater, NotComparable}; pub mod geometry; pub mod structure; diff --git a/src/traits/operations.rs b/src/traits/operations.rs index eab0af88..0f836fbc 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -1,17 +1,16 @@ //! Low level operations on vectors and matrices. -use std::cmp; /// Result of a partial ordering. #[deriving(TotalEq, Eq, Encodable, Decodable, Clone, Show)] pub enum PartialOrdering { /// Result of a strict comparison. - Less, + PartialLess, /// Equality relationship. - Equal, + PartialEqual, /// Result of a strict comparison. - Greater, + PartialGreater, /// Result of a comparison between two objects that are not comparable. NotComparable } @@ -19,27 +18,27 @@ pub enum PartialOrdering { impl PartialOrdering { /// Returns `true` if `self` is equal to `Equal`. pub fn is_eq(&self) -> bool { - *self == Equal + *self == PartialEqual } /// Returns `true` if `self` is equal to `Less`. pub fn is_lt(&self) -> bool { - *self == Less + *self == PartialLess } /// Returns `true` if `self` is equal to `Less` or `Equal`. pub fn is_le(&self) -> bool { - *self == Less || *self == Equal + *self == PartialLess || *self == PartialEqual } /// Returns `true` if `self` is equal to `Greater`. pub fn is_gt(&self) -> bool { - *self == Greater + *self == PartialGreater } /// Returns `true` if `self` is equal to `Greater` or `Equal`. pub fn is_ge(&self) -> bool { - *self == Greater || *self == Equal + *self == PartialGreater || *self == PartialEqual } /// Returns `true` if `self` is equal to `NotComparable`. @@ -50,9 +49,9 @@ impl PartialOrdering { /// Creates a `PartialOrdering` from an `Ordering`. pub fn from_ordering(ord: Ordering) -> PartialOrdering { match ord { - cmp::Less => Less, - cmp::Equal => Equal, - cmp::Greater => Greater + Less => PartialLess, + Equal => PartialEqual, + Greater => PartialGreater } } @@ -61,10 +60,10 @@ impl PartialOrdering { /// Returns `None` if `self` is `NotComparable`. pub fn to_ordering(self) -> Option { match self { - Less => Some(cmp::Less), - Equal => Some(cmp::Equal), - Greater => Some(cmp::Greater), - NotComparable => None + PartialLess => Some(Less), + PartialEqual => Some(Equal), + PartialGreater => Some(Greater), + NotComparable => None } } } @@ -108,9 +107,9 @@ pub trait PartialOrd { #[inline] fn partial_min<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> { match PartialOrd::partial_cmp(a, b) { - Less | Equal => Some(a), - Greater => Some(b), - NotComparable => None + PartialLess | PartialEqual => Some(a), + PartialGreater => Some(b), + NotComparable => None } } @@ -118,9 +117,9 @@ pub trait PartialOrd { #[inline] fn partial_max<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> { match PartialOrd::partial_cmp(a, b) { - Greater | Equal => Some(a), - Less => Some(b), - NotComparable => None + PartialGreater | PartialEqual => Some(a), + PartialLess => Some(b), + NotComparable => None } } diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 9dab3b68..0b3784b3 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -23,17 +23,17 @@ impl + Col + RMul + LMul, R, C> Mat for M { // different Add/Sub traits. This is _so_ unfortunateā€¦ /// Trait grouping most common operations on vectors. -pub trait Vec: Dim + Sub + Add + Neg + Zero + Eq + Mul - + Div + Dot { +pub trait AnyVec: Dim + Sub + Add + Neg + Zero + Eq + Mul + + Div + Dot { } /// Trait of vector with components implementing the `Float` trait. -pub trait FloatVec: Vec + Norm { +pub trait FloatVec: AnyVec + Norm { } /// Trait grouping uncommon, low-level and borderline (from the mathematical point of view) /// operations on vectors. -pub trait VecExt: Vec + Indexable + Iterable + +pub trait VecExt: AnyVec + Indexable + Iterable + UniformSphereSample + ScalarAdd + ScalarSub + Bounded { } @@ -42,12 +42,12 @@ pub trait VecExt: Vec + Indexable + Iterable + pub trait FloatVecExt: FloatVec + VecExt + Basis + Round { } impl + Add + Neg + Zero + Eq + Mul + Div + Dot> -Vec for V { } +AnyVec for V { } -impl + Norm> FloatVec for V { } +impl + Norm> FloatVec for V { } impl + Indexable + Iterable + + V: AnyVec + Indexable + Iterable + UniformSphereSample + ScalarAdd + ScalarSub + Bounded> VecExt for V { }