diff --git a/src/matrix.rs b/src/matrix.rs index 138d1bd..ab07af3 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -90,8 +90,8 @@ impl Matrix2 { 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()) } } diff --git a/src/rotation.rs b/src/rotation.rs index 914f5ae..7b8b5ee 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -149,7 +149,7 @@ pub trait Rotation3: Rotation, Point3> /// /// // 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); diff --git a/src/test/matrix.rs b/src/test/matrix.rs index f2294e1..f503811 100644 --- a/src/test/matrix.rs +++ b/src/test/matrix.rs @@ -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 = Matrix2::from_angle(rad(Float::pi())); + assert!(rot3.mul_v(&Vector2::new(1.0, 1.0)).approx_eq(&Vector2::new(-1.0, -1.0))); +}