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,
|
||||
Orig,
|
||||
Outer,
|
||||
PartialOrd,
|
||||
PartialOrdering,
|
||||
POrd,
|
||||
POrdering,
|
||||
PntAsVec,
|
||||
RMul,
|
||||
Rotate, Rotation, RotationMatrix, RotationWithTranslation,
|
||||
|
@ -228,7 +228,7 @@ pub mod overload {
|
|||
|
||||
/// Change the input value to ensure it is on the range `[min, max]`.
|
||||
#[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 < max {
|
||||
val
|
||||
|
@ -256,63 +256,63 @@ pub fn min<T: Ord>(a: T, b: T) -> T {
|
|||
|
||||
/// Returns the infimum of `a` and `b`.
|
||||
#[inline(always)]
|
||||
pub fn inf<T: PartialOrd>(a: &T, b: &T) -> T {
|
||||
PartialOrd::inf(a, b)
|
||||
pub fn inf<T: POrd>(a: &T, b: &T) -> T {
|
||||
POrd::inf(a, b)
|
||||
}
|
||||
|
||||
/// Returns the supremum of `a` and `b`.
|
||||
#[inline(always)]
|
||||
pub fn sup<T: PartialOrd>(a: &T, b: &T) -> T {
|
||||
PartialOrd::sup(a, b)
|
||||
pub fn sup<T: POrd>(a: &T, b: &T) -> T {
|
||||
POrd::sup(a, b)
|
||||
}
|
||||
|
||||
/// Compare `a` and `b` using a partial ordering relation.
|
||||
#[inline(always)]
|
||||
pub fn partial_cmp<T: PartialOrd>(a: &T, b: &T) -> PartialOrdering {
|
||||
PartialOrd::partial_cmp(a, b)
|
||||
pub fn partial_cmp<T: POrd>(a: &T, b: &T) -> POrdering {
|
||||
POrd::partial_cmp(a, b)
|
||||
}
|
||||
|
||||
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
||||
#[inline(always)]
|
||||
pub fn partial_lt<T: PartialOrd>(a: &T, b: &T) -> bool {
|
||||
PartialOrd::partial_lt(a, b)
|
||||
pub fn partial_lt<T: POrd>(a: &T, b: &T) -> bool {
|
||||
POrd::partial_lt(a, b)
|
||||
}
|
||||
|
||||
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
||||
#[inline(always)]
|
||||
pub fn partial_le<T: PartialOrd>(a: &T, b: &T) -> bool {
|
||||
PartialOrd::partial_le(a, b)
|
||||
pub fn partial_le<T: POrd>(a: &T, b: &T) -> bool {
|
||||
POrd::partial_le(a, b)
|
||||
}
|
||||
|
||||
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
||||
#[inline(always)]
|
||||
pub fn partial_gt<T: PartialOrd>(a: &T, b: &T) -> bool {
|
||||
PartialOrd::partial_gt(a, b)
|
||||
pub fn partial_gt<T: POrd>(a: &T, b: &T) -> bool {
|
||||
POrd::partial_gt(a, b)
|
||||
}
|
||||
|
||||
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
||||
#[inline(always)]
|
||||
pub fn partial_ge<T: PartialOrd>(a: &T, b: &T) -> bool {
|
||||
PartialOrd::partial_ge(a, b)
|
||||
pub fn partial_ge<T: POrd>(a: &T, b: &T) -> bool {
|
||||
POrd::partial_ge(a, b)
|
||||
}
|
||||
|
||||
/// Return the minimum of `a` and `b` if they are comparable.
|
||||
#[inline(always)]
|
||||
pub fn partial_min<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||
PartialOrd::partial_min(a, b)
|
||||
pub fn partial_min<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||
POrd::partial_min(a, b)
|
||||
}
|
||||
|
||||
/// Return the maximum of `a` and `b` if they are comparable.
|
||||
#[inline(always)]
|
||||
pub fn partial_max<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||
PartialOrd::partial_max(a, b)
|
||||
pub fn partial_max<'a, T: POrd>(a: &'a T, b: &'a T) -> Option<&'a T> {
|
||||
POrd::partial_max(a, b)
|
||||
}
|
||||
|
||||
/// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to
|
||||
/// `min` or `max`.
|
||||
#[inline(always)]
|
||||
pub fn partial_clamp<'a, T: PartialOrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> {
|
||||
PartialOrd::partial_clamp(value, min, max)
|
||||
pub fn partial_clamp<'a, T: POrd>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> {
|
||||
POrd::partial_clamp(value, min, max)
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::mem;
|
|||
use std::num::{Zero, One, Bounded};
|
||||
use std::slice::{Items, MutItems};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use traits::operations::{ApproxEq, PartialOrd, PartialOrdering, PartialLess, PartialEqual,
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
|
||||
PartialGreater, NotComparable, Axpy};
|
||||
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec};
|
||||
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::num;
|
|||
use std::rand::{Rand, Rng};
|
||||
use std::slice::{Items, MutItems};
|
||||
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};
|
||||
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim};
|
||||
use traits::geometry::{Norm, Cross, Rotation, Rotate, Transform};
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::mem;
|
|||
use std::num::{Zero, One, Float, Bounded};
|
||||
use std::slice::{Items, MutItems};
|
||||
use std::iter::{Iterator, FromIterator};
|
||||
use traits::operations::{ApproxEq, PartialOrd, PartialOrdering, PartialLess, PartialEqual,
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, PartialLess, PartialEqual,
|
||||
PartialGreater, NotComparable, Axpy};
|
||||
use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
|
||||
Translation, Translate};
|
||||
|
|
|
@ -58,7 +58,7 @@ macro_rules! at_fast_impl(
|
|||
// However, f32/f64 does not implement Ord…
|
||||
macro_rules! ord_impl(
|
||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||
impl<N: FloatMath + Clone> PartialOrd for $t<N> {
|
||||
impl<N: FloatMath + Clone> POrd for $t<N> {
|
||||
#[inline]
|
||||
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
||||
$t::new(a.$comp0.min(b.$comp0.clone())
|
||||
|
@ -73,7 +73,7 @@ macro_rules! ord_impl(
|
|||
|
||||
#[inline]
|
||||
#[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 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,
|
||||
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};
|
||||
pub use self::operations::{PartialOrdering, PartialLess, PartialEqual, PartialGreater, NotComparable};
|
||||
pub use self::operations::{POrdering, PartialLess, PartialEqual, PartialGreater, NotComparable};
|
||||
|
||||
pub mod geometry;
|
||||
pub mod structure;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
/// Result of a partial ordering.
|
||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Show)]
|
||||
pub enum PartialOrdering {
|
||||
pub enum POrdering {
|
||||
/// Result of a strict comparison.
|
||||
PartialLess,
|
||||
/// Equality relationship.
|
||||
|
@ -15,7 +15,7 @@ pub enum PartialOrdering {
|
|||
NotComparable
|
||||
}
|
||||
|
||||
impl PartialOrdering {
|
||||
impl POrdering {
|
||||
/// Returns `true` if `self` is equal to `Equal`.
|
||||
pub fn is_eq(&self) -> bool {
|
||||
*self == PartialEqual
|
||||
|
@ -46,8 +46,8 @@ impl PartialOrdering {
|
|||
*self == NotComparable
|
||||
}
|
||||
|
||||
/// Creates a `PartialOrdering` from an `Ordering`.
|
||||
pub fn from_ordering(ord: Ordering) -> PartialOrdering {
|
||||
/// Creates a `POrdering` from an `Ordering`.
|
||||
pub fn from_ordering(ord: Ordering) -> POrdering {
|
||||
match ord {
|
||||
Less => PartialLess,
|
||||
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`.
|
||||
pub fn to_ordering(self) -> Option<Ordering> {
|
||||
|
@ -69,7 +69,7 @@ impl PartialOrdering {
|
|||
}
|
||||
|
||||
/// Pointwise ordering operations.
|
||||
pub trait PartialOrd {
|
||||
pub trait POrd {
|
||||
/// Returns the infimum of `a` and `b`.
|
||||
fn inf(a: &Self, b: &Self) -> Self;
|
||||
|
||||
|
@ -77,36 +77,36 @@ pub trait PartialOrd {
|
|||
fn sup(a: &Self, b: &Self) -> Self;
|
||||
|
||||
/// 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`.
|
||||
#[inline]
|
||||
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`.
|
||||
#[inline]
|
||||
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`.
|
||||
#[inline]
|
||||
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`.
|
||||
#[inline]
|
||||
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.
|
||||
#[inline]
|
||||
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),
|
||||
PartialGreater => Some(b),
|
||||
NotComparable => None
|
||||
|
@ -116,7 +116,7 @@ pub trait PartialOrd {
|
|||
/// Return the maximum of `a` and `b` if they are comparable.
|
||||
#[inline]
|
||||
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),
|
||||
PartialLess => Some(b),
|
||||
NotComparable => None
|
||||
|
@ -127,8 +127,8 @@ pub trait PartialOrd {
|
|||
/// `min` or `max`.
|
||||
#[inline]
|
||||
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_max = PartialOrd::partial_cmp(value, max);
|
||||
let v_min = POrd::partial_cmp(value, min);
|
||||
let v_max = POrd::partial_cmp(value, max);
|
||||
|
||||
if v_min.is_not_comparable() || v_max.is_not_comparable() {
|
||||
None
|
||||
|
|
Loading…
Reference in New Issue