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.
This commit is contained in:
Sébastien Crozet 2014-04-13 10:24:17 +02:00
parent 16aa5c8937
commit 1eed234e08
8 changed files with 64 additions and 65 deletions

View File

@ -1,5 +1,5 @@
use rand::random; use rand::random;
use test::BenchHarness; use test::Bencher;
use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat}; use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat};
macro_rules! bench_mul_mat( macro_rules! bench_mul_mat(
@ -18,27 +18,27 @@ macro_rules! bench_mul_mat(
) )
#[bench] #[bench]
fn bench_mul_mat2(bh: &mut BenchHarness) { fn bench_mul_mat2(bh: &mut Bencher) {
bench_mul_mat!(bh, Mat2<f64>) bench_mul_mat!(bh, Mat2<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat3(bh: &mut BenchHarness) { fn bench_mul_mat3(bh: &mut Bencher) {
bench_mul_mat!(bh, Mat3<f64>) bench_mul_mat!(bh, Mat3<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat4(bh: &mut BenchHarness) { fn bench_mul_mat4(bh: &mut Bencher) {
bench_mul_mat!(bh, Mat4<f64>) bench_mul_mat!(bh, Mat4<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat5(bh: &mut BenchHarness) { fn bench_mul_mat5(bh: &mut Bencher) {
bench_mul_mat!(bh, Mat5<f64>) bench_mul_mat!(bh, Mat5<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat6(bh: &mut BenchHarness) { fn bench_mul_mat6(bh: &mut Bencher) {
bench_mul_mat!(bh, Mat6<f64>) bench_mul_mat!(bh, Mat6<f64>)
} }
@ -58,27 +58,27 @@ macro_rules! bench_mul_dmat(
) )
#[bench] #[bench]
fn bench_mul_dmat2(bh: &mut BenchHarness) { fn bench_mul_dmat2(bh: &mut Bencher) {
bench_mul_dmat!(bh, 2, 2) bench_mul_dmat!(bh, 2, 2)
} }
#[bench] #[bench]
fn bench_mul_dmat3(bh: &mut BenchHarness) { fn bench_mul_dmat3(bh: &mut Bencher) {
bench_mul_dmat!(bh, 3, 3) bench_mul_dmat!(bh, 3, 3)
} }
#[bench] #[bench]
fn bench_mul_dmat4(bh: &mut BenchHarness) { fn bench_mul_dmat4(bh: &mut Bencher) {
bench_mul_dmat!(bh, 4, 4) bench_mul_dmat!(bh, 4, 4)
} }
#[bench] #[bench]
fn bench_mul_dmat5(bh: &mut BenchHarness) { fn bench_mul_dmat5(bh: &mut Bencher) {
bench_mul_dmat!(bh, 5, 5) bench_mul_dmat!(bh, 5, 5)
} }
#[bench] #[bench]
fn bench_mul_dmat6(bh: &mut BenchHarness) { fn bench_mul_dmat6(bh: &mut Bencher) {
bench_mul_dmat!(bh, 6, 6) bench_mul_dmat!(bh, 6, 6)
} }
@ -98,27 +98,27 @@ macro_rules! bench_mul_mat_vec(
) )
#[bench] #[bench]
fn bench_mul_mat_vec2(bh: &mut BenchHarness) { fn bench_mul_mat_vec2(bh: &mut Bencher) {
bench_mul_mat_vec!(bh, Mat2<f64>, Vec2<f64>) bench_mul_mat_vec!(bh, Mat2<f64>, Vec2<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat_vec3(bh: &mut BenchHarness) { fn bench_mul_mat_vec3(bh: &mut Bencher) {
bench_mul_mat_vec!(bh, Mat3<f64>, Vec3<f64>) bench_mul_mat_vec!(bh, Mat3<f64>, Vec3<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat_vec4(bh: &mut BenchHarness) { fn bench_mul_mat_vec4(bh: &mut Bencher) {
bench_mul_mat_vec!(bh, Mat4<f64>, Vec4<f64>) bench_mul_mat_vec!(bh, Mat4<f64>, Vec4<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat_vec5(bh: &mut BenchHarness) { fn bench_mul_mat_vec5(bh: &mut Bencher) {
bench_mul_mat_vec!(bh, Mat5<f64>, Vec5<f64>) bench_mul_mat_vec!(bh, Mat5<f64>, Vec5<f64>)
} }
#[bench] #[bench]
fn bench_mul_mat_vec6(bh: &mut BenchHarness) { fn bench_mul_mat_vec6(bh: &mut Bencher) {
bench_mul_mat_vec!(bh, Mat6<f64>, Vec6<f64>) bench_mul_mat_vec!(bh, Mat6<f64>, Vec6<f64>)
} }
@ -138,26 +138,26 @@ macro_rules! bench_mul_dmat_dvec(
) )
#[bench] #[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_mul_dmat_dvec!(bh, 2, 2)
} }
#[bench] #[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_mul_dmat_dvec!(bh, 3, 3)
} }
#[bench] #[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_mul_dmat_dvec!(bh, 4, 4)
} }
#[bench] #[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_mul_dmat_dvec!(bh, 5, 5)
} }
#[bench] #[bench]
fn bench_mul_dmat_dvec6(bh: &mut BenchHarness) { fn bench_mul_dmat_dvec6(bh: &mut Bencher) {
bench_mul_dmat_dvec!(bh, 6, 6) bench_mul_dmat_dvec!(bh, 6, 6)
} }

View File

@ -1,5 +1,5 @@
use rand::random; use rand::random;
use test::BenchHarness; use test::Bencher;
use na::{Vec2, Vec3, Vec4, Vec5, Vec6}; use na::{Vec2, Vec3, Vec4, Vec5, Vec6};
use na; use na;
@ -20,26 +20,26 @@ macro_rules! bench_dot_vec(
) )
#[bench] #[bench]
fn bench_dot_vec2(bh: &mut BenchHarness) { fn bench_dot_vec2(bh: &mut Bencher) {
bench_dot_vec!(bh, Vec2<f64>) bench_dot_vec!(bh, Vec2<f64>)
} }
#[bench] #[bench]
fn bench_dot_vec3(bh: &mut BenchHarness) { fn bench_dot_vec3(bh: &mut Bencher) {
bench_dot_vec!(bh, Vec3<f64>) bench_dot_vec!(bh, Vec3<f64>)
} }
#[bench] #[bench]
fn bench_dot_vec4(bh: &mut BenchHarness) { fn bench_dot_vec4(bh: &mut Bencher) {
bench_dot_vec!(bh, Vec4<f64>) bench_dot_vec!(bh, Vec4<f64>)
} }
#[bench] #[bench]
fn bench_dot_vec5(bh: &mut BenchHarness) { fn bench_dot_vec5(bh: &mut Bencher) {
bench_dot_vec!(bh, Vec5<f64>) bench_dot_vec!(bh, Vec5<f64>)
} }
#[bench] #[bench]
fn bench_dot_vec6(bh: &mut BenchHarness) { fn bench_dot_vec6(bh: &mut Bencher) {
bench_dot_vec!(bh, Vec6<f64>) bench_dot_vec!(bh, Vec6<f64>)
} }

View File

@ -2,7 +2,7 @@
use std::num::{Zero, One}; use std::num::{Zero, One};
use std::cmp; use std::cmp;
pub use traits::{Less, Equal, Greater, NotComparable}; pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable};
pub use traits::{ pub use traits::{
Absolute, Absolute,
AbsoluteRotate, AbsoluteRotate,
@ -38,7 +38,7 @@ pub use traits::{
Translate, Translation, Translate, Translation,
Transpose, Transpose,
UniformSphereSample, UniformSphereSample,
Vec, AnyVec,
VecExt VecExt
}; };

View File

@ -6,8 +6,8 @@ use std::cast;
use std::num::{Zero, One, Float, Bounded}; use std::num::{Zero, One, Float, Bounded};
use std::slice::{Items, MutItems}; use std::slice::{Items, MutItems};
use std::iter::{Iterator, FromIterator}; 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, use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
Translation, Translate}; Translation, Translate};
use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut}; use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut};

View File

@ -64,7 +64,7 @@ macro_rules! ord_impl(
} }
)* )*
Less PartialLess
} }
else { // >= else { // >=
$( $(
@ -78,10 +78,10 @@ macro_rules! ord_impl(
)* )*
if is_eq { if is_eq {
Equal PartialEqual
} }
else { else {
Greater PartialGreater
} }
} }
} }

View File

@ -5,11 +5,11 @@ pub use self::geometry::{AbsoluteRotate, Cross, CrossMatrix, Dot, FromHomogeneou
Transform, Transformation, Translate, Translation, UniformSphereSample}; Transform, Transformation, Translate, Translation, UniformSphereSample};
pub use self::structure::{FloatVec, FloatVecExt, Basis, Cast, Col, Dim, Indexable, 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, pub use self::operations::{Absolute, ApproxEq, Cov, Inv, LMul, Mean, Outer, PartialOrd, RMul,
ScalarAdd, ScalarSub, Transpose}; 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 geometry;
pub mod structure; pub mod structure;

View File

@ -1,17 +1,16 @@
//! Low level operations on vectors and matrices. //! Low level operations on vectors and matrices.
use std::cmp;
/// Result of a partial ordering. /// Result of a partial ordering.
#[deriving(TotalEq, Eq, Encodable, Decodable, Clone, Show)] #[deriving(TotalEq, Eq, Encodable, Decodable, Clone, Show)]
pub enum PartialOrdering { pub enum PartialOrdering {
/// Result of a strict comparison. /// Result of a strict comparison.
Less, PartialLess,
/// Equality relationship. /// Equality relationship.
Equal, PartialEqual,
/// Result of a strict comparison. /// Result of a strict comparison.
Greater, PartialGreater,
/// Result of a comparison between two objects that are not comparable. /// Result of a comparison between two objects that are not comparable.
NotComparable NotComparable
} }
@ -19,27 +18,27 @@ pub enum PartialOrdering {
impl PartialOrdering { impl PartialOrdering {
/// Returns `true` if `self` is equal to `Equal`. /// Returns `true` if `self` is equal to `Equal`.
pub fn is_eq(&self) -> bool { pub fn is_eq(&self) -> bool {
*self == Equal *self == PartialEqual
} }
/// Returns `true` if `self` is equal to `Less`. /// Returns `true` if `self` is equal to `Less`.
pub fn is_lt(&self) -> bool { pub fn is_lt(&self) -> bool {
*self == Less *self == PartialLess
} }
/// Returns `true` if `self` is equal to `Less` or `Equal`. /// Returns `true` if `self` is equal to `Less` or `Equal`.
pub fn is_le(&self) -> bool { pub fn is_le(&self) -> bool {
*self == Less || *self == Equal *self == PartialLess || *self == PartialEqual
} }
/// Returns `true` if `self` is equal to `Greater`. /// Returns `true` if `self` is equal to `Greater`.
pub fn is_gt(&self) -> bool { pub fn is_gt(&self) -> bool {
*self == Greater *self == PartialGreater
} }
/// Returns `true` if `self` is equal to `Greater` or `Equal`. /// Returns `true` if `self` is equal to `Greater` or `Equal`.
pub fn is_ge(&self) -> bool { pub fn is_ge(&self) -> bool {
*self == Greater || *self == Equal *self == PartialGreater || *self == PartialEqual
} }
/// Returns `true` if `self` is equal to `NotComparable`. /// Returns `true` if `self` is equal to `NotComparable`.
@ -50,9 +49,9 @@ impl PartialOrdering {
/// Creates a `PartialOrdering` from an `Ordering`. /// Creates a `PartialOrdering` from an `Ordering`.
pub fn from_ordering(ord: Ordering) -> PartialOrdering { pub fn from_ordering(ord: Ordering) -> PartialOrdering {
match ord { match ord {
cmp::Less => Less, Less => PartialLess,
cmp::Equal => Equal, Equal => PartialEqual,
cmp::Greater => Greater Greater => PartialGreater
} }
} }
@ -61,10 +60,10 @@ impl PartialOrdering {
/// Returns `None` if `self` is `NotComparable`. /// Returns `None` if `self` is `NotComparable`.
pub fn to_ordering(self) -> Option<Ordering> { pub fn to_ordering(self) -> Option<Ordering> {
match self { match self {
Less => Some(cmp::Less), PartialLess => Some(Less),
Equal => Some(cmp::Equal), PartialEqual => Some(Equal),
Greater => Some(cmp::Greater), PartialGreater => Some(Greater),
NotComparable => None NotComparable => None
} }
} }
} }
@ -108,9 +107,9 @@ pub trait PartialOrd {
#[inline] #[inline]
fn partial_min<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> { fn partial_min<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> {
match PartialOrd::partial_cmp(a, b) { match PartialOrd::partial_cmp(a, b) {
Less | Equal => Some(a), PartialLess | PartialEqual => Some(a),
Greater => Some(b), PartialGreater => Some(b),
NotComparable => None NotComparable => None
} }
} }
@ -118,9 +117,9 @@ pub trait PartialOrd {
#[inline] #[inline]
fn partial_max<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> { fn partial_max<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> {
match PartialOrd::partial_cmp(a, b) { match PartialOrd::partial_cmp(a, b) {
Greater | Equal => Some(a), PartialGreater | PartialEqual => Some(a),
Less => Some(b), PartialLess => Some(b),
NotComparable => None NotComparable => None
} }
} }

View File

@ -23,17 +23,17 @@ impl<M: Row<R> + Col<C> + RMul<R> + LMul<C>, R, C> Mat<R, C> for M {
// different Add/Sub traits. This is _so_ unfortunate… // different Add/Sub traits. This is _so_ unfortunate…
/// Trait grouping most common operations on vectors. /// Trait grouping most common operations on vectors.
pub trait Vec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + Eq + Mul<N, Self> pub trait AnyVec<N>: Dim + Sub<Self, Self> + Add<Self, Self> + Neg<Self> + Zero + Eq + Mul<N, Self>
+ Div<N, Self> + Dot<N> { + Div<N, Self> + Dot<N> {
} }
/// Trait of vector with components implementing the `Float` trait. /// Trait of vector with components implementing the `Float` trait.
pub trait FloatVec<N: Float>: Vec<N> + Norm<N> { pub trait FloatVec<N: Float>: AnyVec<N> + Norm<N> {
} }
/// Trait grouping uncommon, low-level and borderline (from the mathematical point of view) /// Trait grouping uncommon, low-level and borderline (from the mathematical point of view)
/// operations on vectors. /// operations on vectors.
pub trait VecExt<N>: Vec<N> + Indexable<uint, N> + Iterable<N> + pub trait VecExt<N>: AnyVec<N> + Indexable<uint, N> + Iterable<N> +
UniformSphereSample + ScalarAdd<N> + ScalarSub<N> + Bounded UniformSphereSample + ScalarAdd<N> + ScalarSub<N> + Bounded
{ } { }
@ -42,12 +42,12 @@ pub trait VecExt<N>: Vec<N> + Indexable<uint, N> + Iterable<N> +
pub trait FloatVecExt<N: Float>: FloatVec<N> + VecExt<N> + Basis + Round { } pub trait FloatVecExt<N: Float>: FloatVec<N> + VecExt<N> + Basis + Round { }
impl<N, V: Dim + Sub<V, V> + Add<V, V> + Neg<V> + Zero + Eq + Mul<N, V> + Div<N, V> + Dot<N>> impl<N, V: Dim + Sub<V, V> + Add<V, V> + Neg<V> + Zero + Eq + Mul<N, V> + Div<N, V> + Dot<N>>
Vec<N> for V { } AnyVec<N> for V { }
impl<N: Float, V: Vec<N> + Norm<N>> FloatVec<N> for V { } impl<N: Float, V: AnyVec<N> + Norm<N>> FloatVec<N> for V { }
impl<N, impl<N,
V: Vec<N> + Indexable<uint, N> + Iterable<N> + V: AnyVec<N> + Indexable<uint, N> + Iterable<N> +
UniformSphereSample + ScalarAdd<N> + ScalarSub<N> + Bounded> UniformSphereSample + ScalarAdd<N> + ScalarSub<N> + Bounded>
VecExt<N> for V { } VecExt<N> for V { }