Temporary workaround for the fact that std::num::Orderable is now removed.
This commit is contained in:
parent
f068af7717
commit
5872ef347e
3 changed files with 21 additions and 12 deletions
|
@ -21,6 +21,7 @@ use array::build;
|
|||
use std::fmt;
|
||||
use std::num::{zero, one};
|
||||
use std::iter::Iterator;
|
||||
use std::cmp::{max, min};
|
||||
|
||||
pub trait Aabb
|
||||
<
|
||||
|
@ -48,8 +49,8 @@ pub trait Aabb
|
|||
|
||||
// Returns a new AABB that is grown to include the given point.
|
||||
fn grow(&self, p: &P) -> Self {
|
||||
let min : P = build(|i| self.min().i(i).min(p.i(i)));
|
||||
let max : P = build(|i| self.max().i(i).max(p.i(i)));
|
||||
let min : P = build(|i| min(self.min().i(i).clone(), p.i(i).clone()));
|
||||
let max : P = build(|i| max(self.max().i(i).clone(), p.i(i).clone()));
|
||||
Aabb::new(min, max)
|
||||
}
|
||||
|
||||
|
@ -75,13 +76,13 @@ pub struct Aabb2<S> {
|
|||
max: Point2<S>,
|
||||
}
|
||||
|
||||
impl<S: Num + Orderable> Aabb2<S> {
|
||||
impl<S: Num + Ord + Clone> Aabb2<S> {
|
||||
/// Construct a new axis-aligned bounding box from two points.
|
||||
#[inline]
|
||||
pub fn new(p1: Point2<S>, p2: Point2<S>) -> Aabb2<S> {
|
||||
Aabb2 {
|
||||
min: Point2::new(p1.x.min(&p2.x), p1.y.min(&p2.y)),
|
||||
max: Point2::new(p1.x.max(&p2.x), p1.y.max(&p2.y)),
|
||||
min: Point2::new(min(p1.x.clone(), p2.x.clone()), min(p1.y.clone(), p2.y.clone())),
|
||||
max: Point2::new(max(p1.x.clone(), p2.x.clone()), max(p1.y.clone(), p2.y.clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,13 +105,13 @@ pub struct Aabb3<S> {
|
|||
max: Point3<S>,
|
||||
}
|
||||
|
||||
impl<S: Num + Orderable> Aabb3<S> {
|
||||
impl<S: Num + Ord + Clone> Aabb3<S> {
|
||||
/// Construct a new axis-aligned bounding box from two points.
|
||||
#[inline]
|
||||
pub fn new(p1: Point3<S>, p2: Point3<S>) -> Aabb3<S> {
|
||||
Aabb3 {
|
||||
min: Point3::new(p1.x.min(&p2.x), p1.y.min(&p2.y), p1.z.min(&p2.z)),
|
||||
max: Point3::new(p1.x.max(&p2.x), p1.y.max(&p2.y), p1.z.max(&p2.z)),
|
||||
min: Point3::new(min(p1.x.clone(), p2.x.clone()), min(p1.y.clone(), p2.y.clone()), min(p1.z.clone(), p2.z.clone())),
|
||||
max: Point3::new(max(p1.x.clone(), p2.x.clone()), max(p1.y.clone(), p2.y.clone()), max(p1.z.clone(), p2.z.clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ Quat<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: Float + ApproxEq<S>>
|
||||
impl<S: Float + ApproxEq<S> + Ord>
|
||||
Quat<S> {
|
||||
/// Spherical Linear Intoperlation
|
||||
///
|
||||
|
@ -205,7 +205,14 @@ Quat<S> {
|
|||
self.nlerp(other, amount)
|
||||
} else {
|
||||
// stay within the domain of acos()
|
||||
let robust_dot = dot.clamp(&-one::<S>(), &one::<S>());
|
||||
// TODO REMOVE WHEN https://github.com/mozilla/rust/issues/12068 IS RESOLVED
|
||||
let robust_dot = if dot > one::<S>() {
|
||||
one::<S>()
|
||||
} else if dot < -one::<S>() {
|
||||
-one::<S>()
|
||||
} else {
|
||||
dot
|
||||
};
|
||||
|
||||
let theta: Rad<S> = acos(robust_dot.clone());
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
use std::fmt;
|
||||
use std::num::{Zero, zero, One, one, sqrt};
|
||||
use std::cmp::{max, min};
|
||||
|
||||
use angle::{Rad, atan2, acos};
|
||||
use approx::ApproxEq;
|
||||
|
@ -68,10 +69,10 @@ pub trait Vector
|
|||
#[inline] fn dot(&self, other: &Self) -> S { self.mul_v(other).comp_add() }
|
||||
|
||||
/// The minimum component of the vector.
|
||||
#[inline] fn comp_min(&self) -> S { self.fold(|a, b| a.min(b)) }
|
||||
#[inline] fn comp_min(&self) -> S { self.fold(|a, b| min(a.clone(), b.clone())) }
|
||||
|
||||
/// The maximum component of the vector.
|
||||
#[inline] fn comp_max(&self) -> S { self.fold(|a, b| a.max(b)) }
|
||||
#[inline] fn comp_max(&self) -> S { self.fold(|a, b| max(a.clone(), b.clone())) }
|
||||
}
|
||||
|
||||
#[inline] pub fn dot<S: Primitive, Slice, V: Vector<S, Slice>>(a: V, b: V) -> S { a.dot(&b) }
|
||||
|
|
Loading…
Reference in a new issue