Replace as_matrix* by impl AsRef<Matrix
This commit is contained in:
parent
8ab8d7551d
commit
151c6c6e64
2 changed files with 15 additions and 7 deletions
|
@ -167,10 +167,11 @@ pub struct Basis2<S> {
|
|||
mat: Matrix2<S>
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> Basis2<S> {
|
||||
/// Coerce to a `Matrix2`
|
||||
impl<S: BaseFloat> AsRef<Matrix2<S>> for Basis2<S> {
|
||||
#[inline]
|
||||
pub fn as_matrix2<'a>(&'a self) -> &'a Matrix2<S> { &self.mat }
|
||||
fn as_ref(&self) -> &Matrix2<S> {
|
||||
&self.mat
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents types which can be converted to a rotation matrix.
|
||||
|
@ -251,10 +252,13 @@ impl<S: BaseFloat> Basis3<S> {
|
|||
pub fn from_quaternion(quaternion: &Quaternion<S>) -> Basis3<S> {
|
||||
Basis3 { mat: quaternion.clone().into() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Coerce to a `Matrix3`
|
||||
impl<S> AsRef<Matrix3<S>> for Basis3<S> {
|
||||
#[inline]
|
||||
pub fn as_matrix3<'a>(&'a self) -> &'a Matrix3<S> { &self.mat }
|
||||
fn as_ref(&self) -> &Matrix3<S> {
|
||||
&self.mat
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents types which can be converted to a rotation matrix.
|
||||
|
|
|
@ -33,11 +33,15 @@ mod rotation {
|
|||
#[test]
|
||||
fn test_invert_basis2() {
|
||||
let a: Basis2<_> = rotation::a2();
|
||||
assert!(a.concat(&a.invert()).as_matrix2().is_identity());
|
||||
let a = a.concat(&a.invert());
|
||||
let a: &Matrix2<_> = a.as_ref();
|
||||
assert!(a.is_identity());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invert_basis3() {
|
||||
let a: Basis3<_> = rotation::a3();
|
||||
assert!(a.concat(&a.invert()).as_matrix3().is_identity());
|
||||
let a = a.concat(&a.invert());
|
||||
let a: &Matrix3<_> = a.as_ref();
|
||||
assert!(a.is_identity());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue