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:
parent
16aa5c8937
commit
1eed234e08
|
@ -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<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_mat3(bh: &mut BenchHarness) {
|
||||
fn bench_mul_mat3(bh: &mut Bencher) {
|
||||
bench_mul_mat!(bh, Mat3<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_mat4(bh: &mut BenchHarness) {
|
||||
fn bench_mul_mat4(bh: &mut Bencher) {
|
||||
bench_mul_mat!(bh, Mat4<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_mat5(bh: &mut BenchHarness) {
|
||||
fn bench_mul_mat5(bh: &mut Bencher) {
|
||||
bench_mul_mat!(bh, Mat5<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_mat6(bh: &mut BenchHarness) {
|
||||
fn bench_mul_mat6(bh: &mut Bencher) {
|
||||
bench_mul_mat!(bh, Mat6<f64>)
|
||||
}
|
||||
|
||||
|
@ -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<f64>, Vec2<f64>)
|
||||
}
|
||||
|
||||
#[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]
|
||||
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]
|
||||
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]
|
||||
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>)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_dot_vec3(bh: &mut BenchHarness) {
|
||||
fn bench_dot_vec3(bh: &mut Bencher) {
|
||||
bench_dot_vec!(bh, Vec3<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_dot_vec4(bh: &mut BenchHarness) {
|
||||
fn bench_dot_vec4(bh: &mut Bencher) {
|
||||
bench_dot_vec!(bh, Vec4<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_dot_vec5(bh: &mut BenchHarness) {
|
||||
fn bench_dot_vec5(bh: &mut Bencher) {
|
||||
bench_dot_vec!(bh, Vec5<f64>)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_dot_vec6(bh: &mut BenchHarness) {
|
||||
fn bench_dot_vec6(bh: &mut Bencher) {
|
||||
bench_dot_vec!(bh, Vec6<f64>)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,9 +60,9 @@ impl PartialOrdering {
|
|||
/// Returns `None` if `self` is `NotComparable`.
|
||||
pub fn to_ordering(self) -> Option<Ordering> {
|
||||
match self {
|
||||
Less => Some(cmp::Less),
|
||||
Equal => Some(cmp::Equal),
|
||||
Greater => Some(cmp::Greater),
|
||||
PartialLess => Some(Less),
|
||||
PartialEqual => Some(Equal),
|
||||
PartialGreater => Some(Greater),
|
||||
NotComparable => None
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +107,8 @@ 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),
|
||||
PartialLess | PartialEqual => Some(a),
|
||||
PartialGreater => Some(b),
|
||||
NotComparable => None
|
||||
}
|
||||
}
|
||||
|
@ -118,8 +117,8 @@ 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),
|
||||
PartialGreater | PartialEqual => Some(a),
|
||||
PartialLess => Some(b),
|
||||
NotComparable => None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
|
||||
|
||||
/// 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> {
|
||||
}
|
||||
|
||||
/// 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)
|
||||
/// 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
|
||||
{ }
|
||||
|
||||
|
@ -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 { }
|
||||
|
||||
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,
|
||||
V: Vec<N> + Indexable<uint, N> + Iterable<N> +
|
||||
V: AnyVec<N> + Indexable<uint, N> + Iterable<N> +
|
||||
UniformSphereSample + ScalarAdd<N> + ScalarSub<N> + Bounded>
|
||||
VecExt<N> for V { }
|
||||
|
||||
|
|
Loading…
Reference in New Issue