Merge pull request #421 from pengowen123/quaternion-cast
Add cast method to Quaternion
This commit is contained in:
commit
34b3f7b7ed
2 changed files with 18 additions and 1 deletions
|
@ -18,7 +18,7 @@ use std::mem;
|
|||
use std::ops::*;
|
||||
|
||||
use rand::{Rand, Rng};
|
||||
use num_traits::cast;
|
||||
use num_traits::{NumCast, cast};
|
||||
|
||||
use structure::*;
|
||||
|
||||
|
@ -229,6 +229,13 @@ impl<S: BaseFloat> MetricSpace for Quaternion<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: NumCast + Copy> Quaternion<S> {
|
||||
/// Component-wise casting to another type.
|
||||
pub fn cast<T: BaseFloat>(&self) -> Quaternion<T> {
|
||||
Quaternion::from_sv(NumCast::from(self.s).unwrap(), self.v.cast())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "simd"))]
|
||||
impl<S: BaseFloat> InnerSpace for Quaternion<S> {
|
||||
#[inline]
|
||||
|
|
|
@ -331,3 +331,13 @@ mod rotate_between_vectors {
|
|||
assert_ulps_eq!(Quaternion::between_vectors(a, b), expected);
|
||||
}
|
||||
}
|
||||
|
||||
mod cast {
|
||||
use cgmath::*;
|
||||
|
||||
#[test]
|
||||
fn test_cast() {
|
||||
assert_ulps_eq!(Quaternion::new(0.9f64, 1.5, 2.4, 7.6).cast(),
|
||||
Quaternion::new(0.9f32, 1.5, 2.4, 7.6));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue