diff --git a/src/matrix.rs b/src/matrix.rs index 6cf355a..50fb8a2 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -103,12 +103,11 @@ impl Matrix2 { } #[inline] - pub fn from_angle(theta: Rad) -> Matrix2 { - let cos_theta = Rad::cos(theta); - let sin_theta = Rad::sin(theta); + pub fn from_angle>>(theta: A) -> Matrix2 { + let (s, c) = Rad::sin_cos(theta.into()); - Matrix2::new(cos_theta, sin_theta, - -sin_theta, cos_theta) + Matrix2::new(c, s, + -s, c) } } @@ -140,27 +139,27 @@ impl Matrix3 { } /// Create a rotation matrix from a rotation around the `x` axis (pitch). - pub fn from_angle_x(theta: Rad) -> Matrix3 { + pub fn from_angle_x>>(theta: A) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix3::new(S::one(), S::zero(), S::zero(), S::zero(), c, s, S::zero(), -s, c) } /// Create a rotation matrix from a rotation around the `y` axis (yaw). - pub fn from_angle_y(theta: Rad) -> Matrix3 { + pub fn from_angle_y>>(theta: A) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix3::new(c, S::zero(), -s, S::zero(), S::one(), S::zero(), s, S::zero(), c) } /// Create a rotation matrix from a rotation around the `z` axis (roll). - pub fn from_angle_z(theta: Rad) -> Matrix3 { + pub fn from_angle_z>>(theta: A) -> Matrix3 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix3::new( c, s, S::zero(), -s, c, S::zero(), S::zero(), S::zero(), S::one()) @@ -169,8 +168,8 @@ impl Matrix3 { /// Create a rotation matrix from an angle around an arbitrary axis. /// /// The specified axis **must be normalized**, or it represents an invalid rotation. - pub fn from_axis_angle(axis: Vector3, angle: Rad) -> Matrix3 { - let (s, c) = Rad::sin_cos(angle); + pub fn from_axis_angle>>(axis: Vector3, angle: A) -> Matrix3 { + let (s, c) = Rad::sin_cos(angle.into()); let _1subc = S::one() - c; Matrix3::new(_1subc * axis.x * axis.x + c, @@ -244,9 +243,9 @@ impl Matrix4 { } /// Create a homogeneous transformation matrix from a rotation around the `x` axis (pitch). - pub fn from_angle_x(theta: Rad) -> Matrix4 { + pub fn from_angle_x>>(theta: A) -> Matrix4 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix4::new(S::one(), S::zero(), S::zero(), S::zero(), S::zero(), c, s, S::zero(), S::zero(), -s, c, S::zero(), @@ -254,9 +253,9 @@ impl Matrix4 { } /// Create a homogeneous transformation matrix from a rotation around the `y` axis (yaw). - pub fn from_angle_y(theta: Rad) -> Matrix4 { + pub fn from_angle_y>>(theta: A) -> Matrix4 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix4::new(c, S::zero(), -s, S::zero(), S::zero(), S::one(), S::zero(), S::zero(), s, S::zero(), c, S::zero(), @@ -264,9 +263,9 @@ impl Matrix4 { } /// Create a homogeneous transformation matrix from a rotation around the `z` axis (roll). - pub fn from_angle_z(theta: Rad) -> Matrix4 { + pub fn from_angle_z>>(theta: A) -> Matrix4 { // http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations - let (s, c) = Rad::sin_cos(theta); + let (s, c) = Rad::sin_cos(theta.into()); Matrix4::new( c, s, S::zero(), S::zero(), -s, c, S::zero(), S::zero(), S::zero(), S::zero(), S::one(), S::zero(), @@ -276,8 +275,8 @@ impl Matrix4 { /// Create a homogeneous transformation matrix from an angle around an arbitrary axis. /// /// The specified axis **must be normalized**, or it represents an invalid rotation. - pub fn from_axis_angle(axis: Vector3, angle: Rad) -> Matrix4 { - let (s, c) = Rad::sin_cos(angle); + pub fn from_axis_angle>>(axis: Vector3, angle: A) -> Matrix4 { + let (s, c) = Rad::sin_cos(angle.into()); let _1subc = S::one() - c; Matrix4::new(_1subc * axis.x * axis.x + c, diff --git a/src/quaternion.rs b/src/quaternion.rs index 3414eb6..bef4851 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -387,8 +387,8 @@ impl Rotation> for Quaternion { impl Rotation3 for Quaternion { #[inline] - fn from_axis_angle(axis: Vector3, angle: Rad) -> Quaternion { - let (s, c) = Rad::sin_cos(angle * cast(0.5f64).unwrap()); + fn from_axis_angle>>(axis: Vector3, angle: A) -> Quaternion { + let (s, c) = Rad::sin_cos(angle.into() * cast(0.5f64).unwrap()); Quaternion::from_sv(c, axis * s) } } diff --git a/src/rotation.rs b/src/rotation.rs index 0f93ad0..829e204 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -62,7 +62,7 @@ pub trait Rotation2: Rotation> + Into> { /// Create a rotation by a given angle. Thus is a redundant case of both /// from_axis_angle() and from_euler() for 2D space. - fn from_angle(theta: Rad) -> Self; + fn from_angle>>(theta: A) -> Self; } /// A three-dimensional rotation. @@ -74,23 +74,23 @@ pub trait Rotation3: Rotation> /// Create a rotation using an angle around a given axis. /// /// The specified axis **must be normalized**, or it represents an invalid rotation. - fn from_axis_angle(axis: Vector3, angle: Rad) -> Self; + fn from_axis_angle>>(axis: Vector3, angle: A) -> Self; /// Create a rotation from an angle around the `x` axis (pitch). #[inline] - fn from_angle_x(theta: Rad) -> Self { + fn from_angle_x>>(theta: A) -> Self { Rotation3::from_axis_angle(Vector3::unit_x(), theta) } /// Create a rotation from an angle around the `y` axis (yaw). #[inline] - fn from_angle_y(theta: Rad) -> Self { + fn from_angle_y>>(theta: A) -> Self { Rotation3::from_axis_angle(Vector3::unit_y(), theta) } /// Create a rotation from an angle around the `z` axis (roll). #[inline] - fn from_angle_z(theta: Rad) -> Self { + fn from_angle_z>>(theta: A) -> Self { Rotation3::from_axis_angle(Vector3::unit_z(), theta) } } @@ -197,7 +197,7 @@ impl ApproxEq for Basis2 { } impl Rotation2 for Basis2 { - fn from_angle(theta: Rad) -> Basis2 { Basis2 { mat: Matrix2::from_angle(theta) } } + fn from_angle>>(theta: A) -> Basis2 { Basis2 { mat: Matrix2::from_angle(theta) } } } impl fmt::Debug for Basis2 { @@ -285,19 +285,19 @@ impl ApproxEq for Basis3 { } impl Rotation3 for Basis3 { - fn from_axis_angle(axis: Vector3, angle: Rad) -> Basis3 { + fn from_axis_angle>>(axis: Vector3, angle: A) -> Basis3 { Basis3 { mat: Matrix3::from_axis_angle(axis, angle) } } - fn from_angle_x(theta: Rad) -> Basis3 { + fn from_angle_x>>(theta: A) -> Basis3 { Basis3 { mat: Matrix3::from_angle_x(theta) } } - fn from_angle_y(theta: Rad) -> Basis3 { + fn from_angle_y>>(theta: A) -> Basis3 { Basis3 { mat: Matrix3::from_angle_y(theta) } } - fn from_angle_z(theta: Rad) -> Basis3 { + fn from_angle_z>>(theta: A) -> Basis3 { Basis3 { mat: Matrix3::from_angle_z(theta) } } }