Updated to latest Rust: math changes
This commit is contained in:
parent
12e01894b7
commit
3ee67019dd
7 changed files with 14 additions and 18 deletions
|
@ -15,9 +15,6 @@
|
|||
|
||||
//! Angle units for type-safe, self-documenting code.
|
||||
|
||||
pub use std::num::{sinh, cosh, tanh};
|
||||
pub use std::num::{asinh, acosh, atanh};
|
||||
|
||||
use std::fmt;
|
||||
use std::num::{One, one, Zero, zero, cast};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//! Column major, square matrix types and traits.
|
||||
|
||||
use std::fmt;
|
||||
use std::num::{Zero, zero, One, one, cast, sqrt};
|
||||
use std::num::{Zero, zero, One, one, cast};
|
||||
|
||||
use angle::{Rad, sin, cos, sin_cos};
|
||||
use approx::ApproxEq;
|
||||
|
@ -684,7 +684,7 @@ ToQuat<S> for Mat3<S> {
|
|||
let half: S = cast(0.5).unwrap();
|
||||
match () {
|
||||
() if trace >= zero::<S>() => {
|
||||
let s = sqrt(one::<S>() + trace);
|
||||
let s = (one::<S>() + trace).sqrt();
|
||||
let w = half * s;
|
||||
let s = half / s;
|
||||
let x = (*self.cr(1, 2) - *self.cr(2, 1)) * s;
|
||||
|
@ -693,7 +693,7 @@ ToQuat<S> for Mat3<S> {
|
|||
Quat::new(w, x, y, z)
|
||||
}
|
||||
() if (*self.cr(0, 0) > *self.cr(1, 1)) && (*self.cr(0, 0) > *self.cr(2, 2)) => {
|
||||
let s = sqrt(half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2)));
|
||||
let s = (half + (*self.cr(0, 0) - *self.cr(1, 1) - *self.cr(2, 2))).sqrt();
|
||||
let w = half * s;
|
||||
let s = half / s;
|
||||
let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s;
|
||||
|
@ -702,7 +702,7 @@ ToQuat<S> for Mat3<S> {
|
|||
Quat::new(w, x, y, z)
|
||||
}
|
||||
() if *self.cr(1, 1) > *self.cr(2, 2) => {
|
||||
let s = sqrt(half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2)));
|
||||
let s = (half + (*self.cr(1, 1) - *self.cr(0, 0) - *self.cr(2, 2))).sqrt();
|
||||
let w = half * s;
|
||||
let s = half / s;
|
||||
let x = (*self.cr(0, 1) - *self.cr(1, 0)) * s;
|
||||
|
@ -711,7 +711,7 @@ ToQuat<S> for Mat3<S> {
|
|||
Quat::new(w, x, y, z)
|
||||
}
|
||||
() => {
|
||||
let s = sqrt(half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1)));
|
||||
let s = (half + (*self.cr(2, 2) - *self.cr(0, 0) - *self.cr(1, 1))).sqrt();
|
||||
let w = half * s;
|
||||
let s = half / s;
|
||||
let x = (*self.cr(2, 0) - *self.cr(0, 2)) * s;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
use std::fmt;
|
||||
use std::num::{zero, one, cast, sqrt};
|
||||
use std::num::{zero, one, cast};
|
||||
|
||||
use angle::{Angle, Rad, acos, sin, sin_cos};
|
||||
use approx::ApproxEq;
|
||||
|
@ -155,7 +155,7 @@ Quat<S> {
|
|||
/// it is advisable to use the `magnitude2` method instead.
|
||||
#[inline]
|
||||
pub fn magnitude(&self) -> S {
|
||||
sqrt(self.magnitude2())
|
||||
self.magnitude2().sqrt()
|
||||
}
|
||||
|
||||
/// The normalized quaternion
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<S: PartOrdFloat<S>> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
|
|||
if tca < cast(0.0) { return None; }
|
||||
let d2 = l.dot(&l) - tca*tca;
|
||||
if d2 > s.radius*s.radius { return None; }
|
||||
let thc = num::sqrt(s.radius*s.radius - d2);
|
||||
let thc = (s.radius*s.radius - d2).sqrt();
|
||||
Some(r.origin.add_v(&r.direction.mul_s(tca - thc)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
use std::fmt;
|
||||
use std::num::{Zero, zero, One, one, sqrt};
|
||||
use std::num::{Zero, zero, One, one};
|
||||
|
||||
use angle::{Rad, atan2, acos};
|
||||
use approx::ApproxEq;
|
||||
|
@ -230,7 +230,7 @@ pub trait EuclideanVector
|
|||
/// The norm of the vector.
|
||||
#[inline]
|
||||
fn length(&self) -> S {
|
||||
sqrt(self.dot(self))
|
||||
self.dot(self).sqrt()
|
||||
}
|
||||
|
||||
/// The angle between the vector and `other`.
|
||||
|
|
|
@ -4,17 +4,16 @@ use cgmath::vector::*;
|
|||
use cgmath::ray::*;
|
||||
use cgmath::approx::ApproxEq;
|
||||
use cgmath::intersect::Intersect;
|
||||
use std::num;
|
||||
|
||||
#[test]
|
||||
fn test_intersection() {
|
||||
let sphere = Sphere {center: Point3::new(0f64,0f64,0f64), radius: 1f64};
|
||||
let r0 = Ray::new(Point3::new(0f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
|
||||
let r1 = Ray::new(Point3::new(num::cos(1f64), 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
|
||||
let r1 = Ray::new(Point3::new(1f64.cos(), 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
|
||||
let r2 = Ray::new(Point3::new(1f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
|
||||
let r3 = Ray::new(Point3::new(2f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
|
||||
assert_eq!((sphere,r0).intersection(), Some(Point3::new(0f64, 0f64, 1f64)));
|
||||
assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(num::cos(1f64), 0f64, num::sin(1f64)) ));
|
||||
assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(1f64.cos(), 0f64, 1f64.sin()) ));
|
||||
assert_eq!((sphere,r2).intersection(), Some(Point3::new(1f64, 0f64, 0f64)));
|
||||
assert_eq!((sphere,r3).intersection(), None);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#[feature(globs)];
|
||||
#![feature(globs)]
|
||||
|
||||
#[feature(globs)];
|
||||
#![feature(globs)]
|
||||
|
||||
extern crate cgmath;
|
||||
|
||||
|
|
Loading…
Reference in a new issue