Merge pull request #146 from jameson-ernst/master
Fixes for trait ambiguity and num reform
This commit is contained in:
commit
6f058eab4b
7 changed files with 25 additions and 22 deletions
|
@ -16,6 +16,7 @@
|
|||
//! Angle units for type-safe, self-documenting code.
|
||||
|
||||
use std::fmt;
|
||||
use std::f64;
|
||||
use std::num::{cast, Float};
|
||||
|
||||
use approx::ApproxEq;
|
||||
|
@ -212,7 +213,7 @@ Equiv<Deg<S>> for Deg<S> {
|
|||
impl<S: BaseFloat>
|
||||
Angle<S> for Rad<S> {
|
||||
#[inline] fn from<A: Angle<S>>(theta: A) -> Rad<S> { theta.to_rad() }
|
||||
#[inline] fn full_turn() -> Rad<S> { rad(Float::two_pi()) }
|
||||
#[inline] fn full_turn() -> Rad<S> { rad(cast(f64::consts::PI_2).unwrap()) }
|
||||
}
|
||||
|
||||
impl<S: BaseFloat>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::f64;
|
||||
use std::num::{cast, Float};
|
||||
|
||||
use angle::{Angle, Rad, acos, sin, sin_cos, rad};
|
||||
|
@ -284,11 +285,11 @@ impl<S: BaseFloat> Quaternion<S> {
|
|||
if test > sig * unit {
|
||||
(
|
||||
rad(zero::<S>()),
|
||||
rad(Float::frac_pi_2()),
|
||||
rad(cast(f64::consts::FRAC_PI_2).unwrap()),
|
||||
rad(two * qx.atan2(qw)),
|
||||
)
|
||||
} else if test < -sig * unit {
|
||||
let y: S = Float::frac_pi_2();
|
||||
let y: S = cast(f64::consts::FRAC_PI_2).unwrap();
|
||||
(
|
||||
rad(zero::<S>()),
|
||||
rad(-y),
|
||||
|
|
|
@ -63,7 +63,7 @@ pub trait Rotation<S: BaseNum, V: Vector<S>, P: Point<S, V>>: PartialEq + Approx
|
|||
/// Modify this rotation in-place by combining it with another.
|
||||
#[inline]
|
||||
fn concat_self(&mut self, other: &Self) {
|
||||
*self = self.concat(other);
|
||||
*self = Rotation::concat(self, other);
|
||||
}
|
||||
|
||||
/// Invert this rotation in-place.
|
||||
|
@ -138,12 +138,12 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
|
|||
/// use cgmath::{Matrix, ToMatrix2};
|
||||
/// use cgmath::{Rotation, Rotation2, Basis2};
|
||||
/// use cgmath::ApproxEq;
|
||||
/// use std::num::Float;
|
||||
/// use std::f64;
|
||||
///
|
||||
/// // For simplicity, we will rotate the unit x vector to the unit y vector --
|
||||
/// // so the angle is 90 degrees, or π/2.
|
||||
/// let unit_x: Vector2<f64> = Vector2::unit_x();
|
||||
/// let rot: Basis2<f64> = Rotation2::from_angle(rad(0.5f64 * Float::pi()));
|
||||
/// let rot: Basis2<f64> = Rotation2::from_angle(rad(0.5f64 * f64::consts::PI));
|
||||
///
|
||||
/// // Rotate the vector using the two-dimensional rotation matrix:
|
||||
/// let unit_y = rot.rotate_vector(&unit_x);
|
||||
|
@ -157,7 +157,7 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
|
|||
/// assert_eq!(unit_y2, unit_y);
|
||||
///
|
||||
/// // Note that we can also concatenate rotations:
|
||||
/// let rot_half: Basis2<f64> = Rotation2::from_angle(rad(0.25f64 * Float::pi()));
|
||||
/// let rot_half: Basis2<f64> = Rotation2::from_angle(rad(0.25f64 * f64::consts::PI));
|
||||
/// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x);
|
||||
/// assert!(unit_y3.approx_eq(&unit_y2));
|
||||
/// ```
|
||||
|
|
|
@ -63,7 +63,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S,V>> {
|
|||
/// Combine this transform with another, in-place.
|
||||
#[inline]
|
||||
fn concat_self(&mut self, other: &Self) {
|
||||
*self = self.concat(other);
|
||||
*self = Transform::concat(self, other);
|
||||
}
|
||||
|
||||
/// Invert this transform in-place, failing if the transformation is not
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
extern crate cgmath;
|
||||
|
||||
use cgmath::*;
|
||||
use std::num::Float;
|
||||
use std::f64;
|
||||
|
||||
pub mod matrix2 {
|
||||
use cgmath::*;
|
||||
|
@ -399,7 +399,7 @@ fn test_predicates() {
|
|||
#[test]
|
||||
fn test_from_angle() {
|
||||
// Rotate the vector (1, 0) by π/2 radians to the vector (0, 1)
|
||||
let rot1 = Matrix2::from_angle(rad(0.5f64 * Float::pi()));
|
||||
let rot1 = Matrix2::from_angle(rad(0.5f64 * f64::consts::PI));
|
||||
assert!(rot1.mul_v(&Vector2::unit_x()).approx_eq(&Vector2::unit_y()));
|
||||
|
||||
// Rotate the vector (-1, 0) by -π/2 radians to the vector (0, 1)
|
||||
|
@ -407,6 +407,6 @@ fn test_from_angle() {
|
|||
assert!(rot2.mul_v(&-Vector2::unit_x()).approx_eq(&Vector2::unit_y()));
|
||||
|
||||
// Rotate the vector (1, 1) by π radians to the vector (-1, -1)
|
||||
let rot3: Matrix2<f64> = Matrix2::from_angle(rad(Float::pi()));
|
||||
let rot3: Matrix2<f64> = Matrix2::from_angle(rad(f64::consts::PI));
|
||||
assert!(rot3.mul_v(&Vector2::new(1.0, 1.0)).approx_eq(&Vector2::new(-1.0, -1.0)));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ use cgmath::Quaternion;
|
|||
use cgmath::{Rad, rad, ApproxEq};
|
||||
use cgmath::Rotation3;
|
||||
|
||||
use std::num::Float;
|
||||
use std::f32;
|
||||
|
||||
#[test]
|
||||
fn to_matrix4()
|
||||
|
@ -49,7 +49,7 @@ fn to_and_from_quaternion()
|
|||
}
|
||||
}
|
||||
|
||||
let hpi = Float::frac_pi_2();
|
||||
let hpi = f32::consts::FRAC_PI_2;
|
||||
|
||||
let zero: Quaternion<f32> = Rotation3::from_euler(rad(0f32), rad(0f32), rad(0f32));
|
||||
eq((rad(0f32), rad(0f32), rad(0f32)), zero.to_euler());
|
||||
|
|
|
@ -21,6 +21,7 @@ extern crate cgmath;
|
|||
extern crate cgmath;
|
||||
|
||||
use cgmath::*;
|
||||
use std::f64;
|
||||
use std::num::{Float, FloatMath};
|
||||
|
||||
#[test]
|
||||
|
@ -143,17 +144,17 @@ mod test_length {
|
|||
|
||||
#[test]
|
||||
fn test_angle() {
|
||||
assert!(Vector2::new(1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector2::new(10.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 5.0f64)).approx_eq( &rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector2::new(-1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &-rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector2::new(1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) ));
|
||||
assert!(Vector2::new(10.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 5.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) ));
|
||||
assert!(Vector2::new(-1.0f64, 0.0f64).angle(&Vector2::new(0.0f64, 1.0f64)).approx_eq( &-rad(f64::consts::FRAC_PI_2) ));
|
||||
|
||||
assert!(Vector3::new(1.0f64, 0.0f64, 1.0f64).angle(&Vector3::new(1.0f64, 1.0f64, 0.0f64)).approx_eq( &rad(Float::frac_pi_3()) ));
|
||||
assert!(Vector3::new(10.0f64, 0.0f64, 10.0f64).angle(&Vector3::new(5.0f64, 5.0f64, 0.0f64)).approx_eq( &rad(Float::frac_pi_3()) ));
|
||||
assert!(Vector3::new(-1.0f64, 0.0f64, -1.0f64).angle(&Vector3::new(1.0f64, -1.0f64, 0.0f64)).approx_eq( &rad(2.0f64 * Float::frac_pi_3()) ));
|
||||
assert!(Vector3::new(1.0f64, 0.0f64, 1.0f64).angle(&Vector3::new(1.0f64, 1.0f64, 0.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_3) ));
|
||||
assert!(Vector3::new(10.0f64, 0.0f64, 10.0f64).angle(&Vector3::new(5.0f64, 5.0f64, 0.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_3) ));
|
||||
assert!(Vector3::new(-1.0f64, 0.0f64, -1.0f64).angle(&Vector3::new(1.0f64, -1.0f64, 0.0f64)).approx_eq( &rad(2.0f64 * f64::consts::FRAC_PI_3) ));
|
||||
|
||||
assert!(Vector4::new(1.0f64, 0.0f64, 1.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector4::new(10.0f64, 0.0f64, 10.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 5.0f64, 0.0f64, 5.0f64)).approx_eq( &rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector4::new(-1.0f64, 0.0f64, -1.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(Float::frac_pi_2()) ));
|
||||
assert!(Vector4::new(1.0f64, 0.0f64, 1.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) ));
|
||||
assert!(Vector4::new(10.0f64, 0.0f64, 10.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 5.0f64, 0.0f64, 5.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) ));
|
||||
assert!(Vector4::new(-1.0f64, 0.0f64, -1.0f64, 0.0f64).angle(&Vector4::new(0.0f64, 1.0f64, 0.0f64, 1.0f64)).approx_eq( &rad(f64::consts::FRAC_PI_2) ));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue