Fixes Matrix2::from_angle invocation and adds a test for the feature.
Signed-off-by: Aaron Jacobs <atheriel@gmail.com>
This commit is contained in:
parent
e9a1723ef4
commit
bfc8efff80
3 changed files with 19 additions and 3 deletions
|
@ -90,8 +90,8 @@ impl<S: BaseFloat> Matrix2<S> {
|
|||
let cos_theta = cos(theta.clone());
|
||||
let sin_theta = sin(theta.clone());
|
||||
|
||||
Matrix2::new(cos_theta.clone(), -sin_theta.clone(),
|
||||
sin_theta.clone(), cos_theta.clone())
|
||||
Matrix2::new(cos_theta.clone(), sin_theta.clone(),
|
||||
-sin_theta.clone(), cos_theta.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
|
|||
///
|
||||
/// // Since sin(π/2) may not be exactly zero due to rounding errors, we can
|
||||
/// // use cgmath's approx_eq() feature to show that it is close enough.
|
||||
/// assert!(unit_y.approx_eq(&-Vector2::unit_y()));
|
||||
/// assert!(unit_y.approx_eq(&Vector2::unit_y()));
|
||||
///
|
||||
/// // This is exactly equivalent to using the raw matrix itself:
|
||||
/// let unit_y2 = rot.to_matrix2().mul_v(&unit_x);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
use cgmath::matrix::*;
|
||||
use cgmath::vector::*;
|
||||
use cgmath::angle::rad;
|
||||
use cgmath::approx::ApproxEq;
|
||||
|
||||
pub mod matrix2 {
|
||||
|
@ -395,3 +396,18 @@ fn test_predicates() {
|
|||
|
||||
assert!(Matrix4::from_value(6.0f64).is_diagonal());
|
||||
}
|
||||
|
||||
#[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()));
|
||||
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)
|
||||
let rot2 = -rot1;
|
||||
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()));
|
||||
assert!(rot3.mul_v(&Vector2::new(1.0, 1.0)).approx_eq(&Vector2::new(-1.0, -1.0)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue