diff --git a/src/cgmath/aabb.rs b/src/cgmath/aabb.rs index 34a4e9b..0bd26b6 100644 --- a/src/cgmath/aabb.rs +++ b/src/cgmath/aabb.rs @@ -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 { max: Point2, } -impl Aabb2 { +impl Aabb2 { /// Construct a new axis-aligned bounding box from two points. #[inline] pub fn new(p1: Point2, p2: Point2) -> Aabb2 { 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 { max: Point3, } -impl Aabb3 { +impl Aabb3 { /// Construct a new axis-aligned bounding box from two points. #[inline] pub fn new(p1: Point3, p2: Point3) -> Aabb3 { 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())), } } } diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 8790a78..6c4f0b9 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -173,7 +173,7 @@ Quat { } } -impl> +impl + Ord> Quat { /// Spherical Linear Intoperlation /// @@ -205,7 +205,14 @@ Quat { self.nlerp(other, amount) } else { // stay within the domain of acos() - let robust_dot = dot.clamp(&-one::(), &one::()); + // TODO REMOVE WHEN https://github.com/mozilla/rust/issues/12068 IS RESOLVED + let robust_dot = if dot > one::() { + one::() + } else if dot < -one::() { + -one::() + } else { + dot + }; let theta: Rad = acos(robust_dot.clone()); diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index 83bceb9..6bd0080 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -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>(a: V, b: V) -> S { a.dot(&b) }