Rename: PartialOrd -> POrd, PartialOrdering -> POrdering.
This avoids name clashes with the standard library.
This commit is contained in:
parent
a960afa4f9
commit
074c9356bf
46
src/lib.rs
46
src/lib.rs
|
@ -147,8 +147,8 @@ pub use traits::{
|
||||||
Norm,
|
Norm,
|
||||||
Orig,
|
Orig,
|
||||||
Outer,
|
Outer,
|
||||||
PartialOrd,
|
POrd,
|
||||||
PartialOrdering,
|
POrdering,
|
||||||
PntAsVec,
|
PntAsVec,
|
||||||
RMul,
|
RMul,
|
||||||
Rotate, Rotation, RotationMatrix, RotationWithTranslation,
|
Rotate, Rotation, RotationMatrix, RotationWithTranslation,
|
||||||
|
@ -228,7 +228,7 @@ pub mod overload {
|
||||||
|
|
||||||
/// Change the input value to ensure it is on the range `[min, max]`.
|
/// Change the input value to ensure it is on the range `[min, max]`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn clamp<T: cmp::PartialOrd>(val: T, min: T, max: T) -> T {
|
pub fn clamp<T: PartialOrd>(val: T, min: T, max: T) -> T {
|
||||||
if val > min {
|
if val > min {
|
||||||
if val < max {
|
if val < max {
|
||||||
val
|
val
|
||||||
|
@ -256,63 +256,63 @@ pub fn min<T: Ord>(a: T, b: T) -> T {
|
||||||
|
|
||||||
/// Returns the infimum of `a` and `b`.
|
/// Returns the infimum of `a` and `b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn inf<T: PartialOrd>(a: &T, b: &T) -> T {
|
pub fn inf<T: POrd>(a: &T, b: &T) -> T {
|
||||||
PartialOrd::inf(a, b)
|
POrd::inf(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the supremum of `a` and `b`.
|
/// Returns the supremum of `a` and `b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sup<T: PartialOrd>(a: &T, b: &T) -> T {
|
pub fn sup<T: POrd>(a: &T, b: &T) -> T {
|
||||||
PartialOrd::sup(a, b)
|
POrd::sup(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare `a` and `b` using a partial ordering relation.
|
/// Compare `a` and `b` using a partial ordering relation.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_cmp<T: PartialOrd>(a: &T, b: &T) -> PartialOrdering {
|
pub fn partial_cmp<T: POrd>(a: &T, b: &T) -> POrdering {
|
||||||
PartialOrd::partial_cmp(a, b)
|
POrd::partial_cmp(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_lt<T: PartialOrd>(a: &T, b: &T) -> bool {
|
pub fn partial_lt<T: POrd>(a: &T, b: &T) -> bool {
|
||||||
PartialOrd::partial_lt(a, b)
|
POrd::partial_lt(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_le<T: PartialOrd>(a: &T, b: &T) -> bool {
|
pub fn partial_le<T: POrd>(a: &T, b: &T) -> bool {
|
||||||
PartialOrd::partial_le(a, b)
|
POrd::partial_le(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_gt<T: PartialOrd>(a: &T, b: &T) -> bool {
|
pub fn partial_gt<T: POrd>(a: &T, b: &T) -> bool {
|
||||||
PartialOrd::partial_gt(a, b)
|
POrd::partial_gt(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_ge<T: PartialOrd>(a: &T, b: &T) -> bool {
|
pub fn partial_ge<T: POrd>(a: &T, b: &T) -> bool {
|
||||||
PartialOrd::partial_ge(a, b)
|
POrd::partial_ge(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the minimum of `a` and `b` if they are comparable.
|
/// Return the minimum of `a` and `b` if they are comparable.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_min<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
pub fn partial_min<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||||
PartialOrd::partial_min(a, b)
|
POrd::partial_min(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the maximum of `a` and `b` if they are comparable.
|
/// Return the maximum of `a` and `b` if they are comparable.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_max<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
pub fn partial_max<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||||
PartialOrd::partial_max(a, b)
|
POrd::partial_max(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to
|
/// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to
|
||||||
/// `min` or `max`.
|
/// `min` or `max`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn partial_clamp<'a, T: PartialOrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> {
|
pub fn partial_clamp<'a, T: POrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> {
|
||||||
PartialOrd::partial_clamp(value, min, max)
|
POrd::partial_clamp(value, min, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::mem;
|
||||||
use std::num::{Zero, One, Bounded};
|
use std::num::{Zero, One, 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, PartialLess, PartialEqual,
|
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
|
||||||
PartialGreater, NotComparable, Axpy};
|
PartialGreater, NotComparable, Axpy};
|
||||||
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec};
|
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec};
|
||||||
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::num;
|
||||||
use std::rand::{Rand, Rng};
|
use std::rand::{Rand, Rng};
|
||||||
use std::slice::{Items, MutItems};
|
use std::slice::{Items, MutItems};
|
||||||
use structs::{Vec3, Pnt3, Rot3, Mat3, Vec3MulRhs, Pnt3MulRhs};
|
use structs::{Vec3, Pnt3, Rot3, Mat3, Vec3MulRhs, Pnt3MulRhs};
|
||||||
use traits::operations::{ApproxEq, Inv, PartialOrd, PartialOrdering, NotComparable, PartialLess,
|
use traits::operations::{ApproxEq, Inv, POrd, POrdering, NotComparable, PartialLess,
|
||||||
PartialGreater, PartialEqual, Axpy};
|
PartialGreater, PartialEqual, Axpy};
|
||||||
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim};
|
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim};
|
||||||
use traits::geometry::{Norm, Cross, Rotation, Rotate, Transform};
|
use traits::geometry::{Norm, Cross, Rotation, Rotate, Transform};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::mem;
|
||||||
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, PartialLess, PartialEqual,
|
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
|
||||||
PartialGreater, NotComparable, Axpy};
|
PartialGreater, NotComparable, Axpy};
|
||||||
use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
|
use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
|
||||||
Translation, Translate};
|
Translation, Translate};
|
||||||
|
|
|
@ -58,7 +58,7 @@ macro_rules! at_fast_impl(
|
||||||
// However, f32/f64 does not implement Ord…
|
// However, f32/f64 does not implement Ord…
|
||||||
macro_rules! ord_impl(
|
macro_rules! ord_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<N: FloatMath + Clone> PartialOrd for $t<N> {
|
impl<N: FloatMath + Clone> POrd for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
||||||
$t::new(a.$comp0.min(b.$comp0.clone())
|
$t::new(a.$comp0.min(b.$comp0.clone())
|
||||||
|
@ -73,7 +73,7 @@ macro_rules! ord_impl(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1.
|
#[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1.
|
||||||
fn partial_cmp(a: &$t<N>, b: &$t<N>) -> PartialOrdering {
|
fn partial_cmp(a: &$t<N>, b: &$t<N>) -> POrdering {
|
||||||
let is_lt = a.$comp0 < b.$comp0;
|
let is_lt = a.$comp0 < b.$comp0;
|
||||||
let mut is_eq = a.$comp0 == b.$comp0;
|
let mut is_eq = a.$comp0 == b.$comp0;
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ pub use self::structure::{FloatVec, FloatVecExt, FloatPnt, FloatPntExt, Basis, C
|
||||||
Indexable, Iterable, IterableMut, Mat, Row, AnyVec, AnyVecExt, AnyPnt,
|
Indexable, Iterable, IterableMut, Mat, Row, AnyVec, AnyVecExt, AnyPnt,
|
||||||
AnyPntExt, PntAsVec, VecAsPnt, ColSlice, RowSlice, Diag, Eye};
|
AnyPntExt, PntAsVec, VecAsPnt, ColSlice, RowSlice, Diag, Eye};
|
||||||
|
|
||||||
pub use self::operations::{Absolute, ApproxEq, Axpy, Cov, Det, Inv, LMul, Mean, Outer, PartialOrd,
|
pub use self::operations::{Absolute, ApproxEq, Axpy, Cov, Det, Inv, LMul, Mean, Outer, POrd,
|
||||||
RMul, ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose};
|
RMul, ScalarAdd, ScalarSub, ScalarMul, ScalarDiv, Transpose};
|
||||||
pub use self::operations::{PartialOrdering, PartialLess, PartialEqual, PartialGreater, NotComparable};
|
pub use self::operations::{POrdering, PartialLess, PartialEqual, PartialGreater, NotComparable};
|
||||||
|
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
pub mod structure;
|
pub mod structure;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
/// Result of a partial ordering.
|
/// Result of a partial ordering.
|
||||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show)]
|
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show)]
|
||||||
pub enum PartialOrdering {
|
pub enum POrdering {
|
||||||
/// Result of a strict comparison.
|
/// Result of a strict comparison.
|
||||||
PartialLess,
|
PartialLess,
|
||||||
/// Equality relationship.
|
/// Equality relationship.
|
||||||
|
@ -15,7 +15,7 @@ pub enum PartialOrdering {
|
||||||
NotComparable
|
NotComparable
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialOrdering {
|
impl POrdering {
|
||||||
/// 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 == PartialEqual
|
*self == PartialEqual
|
||||||
|
@ -46,8 +46,8 @@ impl PartialOrdering {
|
||||||
*self == NotComparable
|
*self == NotComparable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `PartialOrdering` from an `Ordering`.
|
/// Creates a `POrdering` from an `Ordering`.
|
||||||
pub fn from_ordering(ord: Ordering) -> PartialOrdering {
|
pub fn from_ordering(ord: Ordering) -> POrdering {
|
||||||
match ord {
|
match ord {
|
||||||
Less => PartialLess,
|
Less => PartialLess,
|
||||||
Equal => PartialEqual,
|
Equal => PartialEqual,
|
||||||
|
@ -55,7 +55,7 @@ impl PartialOrdering {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts this `PartialOrdering` to an `Ordering`.
|
/// Converts this `POrdering` to an `Ordering`.
|
||||||
///
|
///
|
||||||
/// 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> {
|
||||||
|
@ -69,7 +69,7 @@ impl PartialOrdering {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pointwise ordering operations.
|
/// Pointwise ordering operations.
|
||||||
pub trait PartialOrd {
|
pub trait POrd {
|
||||||
/// Returns the infimum of `a` and `b`.
|
/// Returns the infimum of `a` and `b`.
|
||||||
fn inf(a: &Self, b: &Self) -> Self;
|
fn inf(a: &Self, b: &Self) -> Self;
|
||||||
|
|
||||||
|
@ -77,36 +77,36 @@ pub trait PartialOrd {
|
||||||
fn sup(a: &Self, b: &Self) -> Self;
|
fn sup(a: &Self, b: &Self) -> Self;
|
||||||
|
|
||||||
/// Compare `a` and `b` using a partial ordering relation.
|
/// Compare `a` and `b` using a partial ordering relation.
|
||||||
fn partial_cmp(a: &Self, b: &Self) -> PartialOrdering;
|
fn partial_cmp(a: &Self, b: &Self) -> POrdering;
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_le(a: &Self, b: &Self) -> bool {
|
fn partial_le(a: &Self, b: &Self) -> bool {
|
||||||
PartialOrd::partial_cmp(a, b).is_le()
|
POrd::partial_cmp(a, b).is_le()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_lt(a: &Self, b: &Self) -> bool {
|
fn partial_lt(a: &Self, b: &Self) -> bool {
|
||||||
PartialOrd::partial_cmp(a, b).is_lt()
|
POrd::partial_cmp(a, b).is_lt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_ge(a: &Self, b: &Self) -> bool {
|
fn partial_ge(a: &Self, b: &Self) -> bool {
|
||||||
PartialOrd::partial_cmp(a, b).is_ge()
|
POrd::partial_cmp(a, b).is_ge()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_gt(a: &Self, b: &Self) -> bool {
|
fn partial_gt(a: &Self, b: &Self) -> bool {
|
||||||
PartialOrd::partial_cmp(a, b).is_gt()
|
POrd::partial_cmp(a, b).is_gt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the minimum of `a` and `b` if they are comparable.
|
/// Return the minimum of `a` and `b` if they are comparable.
|
||||||
#[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 POrd::partial_cmp(a, b) {
|
||||||
PartialLess | PartialEqual => Some(a),
|
PartialLess | PartialEqual => Some(a),
|
||||||
PartialGreater => Some(b),
|
PartialGreater => Some(b),
|
||||||
NotComparable => None
|
NotComparable => None
|
||||||
|
@ -116,7 +116,7 @@ pub trait PartialOrd {
|
||||||
/// Return the maximum of `a` and `b` if they are comparable.
|
/// Return the maximum of `a` and `b` if they are comparable.
|
||||||
#[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 POrd::partial_cmp(a, b) {
|
||||||
PartialGreater | PartialEqual => Some(a),
|
PartialGreater | PartialEqual => Some(a),
|
||||||
PartialLess => Some(b),
|
PartialLess => Some(b),
|
||||||
NotComparable => None
|
NotComparable => None
|
||||||
|
@ -127,8 +127,8 @@ pub trait PartialOrd {
|
||||||
/// `min` or `max`.
|
/// `min` or `max`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_clamp<'a>(value: &'a Self, min: &'a Self, max: &'a Self) -> Option<&'a Self> {
|
fn partial_clamp<'a>(value: &'a Self, min: &'a Self, max: &'a Self) -> Option<&'a Self> {
|
||||||
let v_min = PartialOrd::partial_cmp(value, min);
|
let v_min = POrd::partial_cmp(value, min);
|
||||||
let v_max = PartialOrd::partial_cmp(value, max);
|
let v_max = POrd::partial_cmp(value, max);
|
||||||
|
|
||||||
if v_min.is_not_comparable() || v_max.is_not_comparable() {
|
if v_min.is_not_comparable() || v_max.is_not_comparable() {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in New Issue