parent
c85198bf1d
commit
2dc0a4a43f
5 changed files with 40 additions and 45 deletions
|
@ -351,8 +351,9 @@ pub trait SquareMatrix where
|
||||||
/// Create a matrix from a non-uniform scale
|
/// Create a matrix from a non-uniform scale
|
||||||
fn from_diagonal(diagonal: Self::Column) -> Self;
|
fn from_diagonal(diagonal: Self::Column) -> Self;
|
||||||
|
|
||||||
/// Create a matrix where the each element of the diagonal is equal to one.
|
/// The [identity matrix](https://en.wikipedia.org/wiki/Identity_matrix). Multiplying this
|
||||||
fn one() -> Self;
|
/// matrix with another has no effect.
|
||||||
|
fn identity() -> Self;
|
||||||
|
|
||||||
/// Add this matrix with another matrix, returning the new metrix.
|
/// Add this matrix with another matrix, returning the new metrix.
|
||||||
fn add_m(&self, m: &Self) -> Self;
|
fn add_m(&self, m: &Self) -> Self;
|
||||||
|
@ -398,7 +399,7 @@ pub trait SquareMatrix where
|
||||||
/// Test if this matrix is the identity matrix. That is, it is diagonal
|
/// Test if this matrix is the identity matrix. That is, it is diagonal
|
||||||
/// and every element in the diagonal is one.
|
/// and every element in the diagonal is one.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_one(&self) -> bool { self.approx_eq(&Self::one()) }
|
fn is_identity(&self) -> bool { self.approx_eq(&Self::identity()) }
|
||||||
|
|
||||||
/// Test if this is a diagonal matrix. That is, every element outside of
|
/// Test if this is a diagonal matrix. That is, every element outside of
|
||||||
/// the diagonal is 0.
|
/// the diagonal is 0.
|
||||||
|
@ -491,9 +492,8 @@ impl<S: BaseFloat> SquareMatrix for Matrix2<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Matrix2<S> {
|
fn identity() -> Matrix2<S> {
|
||||||
Matrix2::new(S::one(), S::zero(),
|
Matrix2::from_value(S::one())
|
||||||
S::zero(), S::one())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -645,10 +645,8 @@ impl<S: BaseFloat> SquareMatrix for Matrix3<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Matrix3<S> {
|
fn identity() -> Matrix3<S> {
|
||||||
Matrix3::new(S::one(), S::zero(), S::zero(),
|
Matrix3::from_value(S::one())
|
||||||
S::zero(), S::one(), S::zero(),
|
|
||||||
S::zero(), S::zero(), S::one())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -821,11 +819,8 @@ impl<S: BaseFloat> SquareMatrix for Matrix4<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Matrix4<S> {
|
fn identity() -> Matrix4<S> {
|
||||||
Matrix4::new(S::one(), S::zero(), S::zero(), S::zero(),
|
Matrix4::from_value(S::one())
|
||||||
S::zero(), S::one(), S::zero(), S::zero(),
|
|
||||||
S::zero(), S::zero(), S::one(), S::zero(),
|
|
||||||
S::zero(), S::zero(), S::zero(), S::one())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl<S: BaseFloat> From<Basis2<S>> for Matrix2<S> {
|
||||||
|
|
||||||
impl<S: BaseFloat> Rotation<Point2<S>> for Basis2<S> {
|
impl<S: BaseFloat> Rotation<Point2<S>> for Basis2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Basis2<S> { Basis2 { mat: Matrix2::one() } }
|
fn one() -> Basis2<S> { Basis2 { mat: Matrix2::identity() } }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Basis2<S> {
|
fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Basis2<S> {
|
||||||
|
@ -260,7 +260,7 @@ impl<S: BaseFloat> From<Basis3<S>> for Quaternion<S> {
|
||||||
|
|
||||||
impl<S: BaseFloat> Rotation<Point3<S>> for Basis3<S> {
|
impl<S: BaseFloat> Rotation<Point3<S>> for Basis3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> Basis3<S> { Basis3 { mat: Matrix3::one() } }
|
fn one() -> Basis3<S> { Basis3 { mat: Matrix3::identity() } }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Basis3<S> {
|
fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Basis3<S> {
|
||||||
|
|
|
@ -177,7 +177,7 @@ pub struct AffineMatrix3<S> {
|
||||||
impl<S: BaseFloat> Transform<Point3<S>> for AffineMatrix3<S> {
|
impl<S: BaseFloat> Transform<Point3<S>> for AffineMatrix3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> AffineMatrix3<S> {
|
fn one() -> AffineMatrix3<S> {
|
||||||
AffineMatrix3 { mat: Matrix4::one() }
|
AffineMatrix3 { mat: Matrix4::identity() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -265,7 +265,7 @@ fn test_transpose() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invert() {
|
fn test_invert() {
|
||||||
// Matrix2
|
// Matrix2
|
||||||
assert!(Matrix2::<f64>::one().invert().unwrap().is_one());
|
assert!(Matrix2::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert_eq!(matrix2::A.invert().unwrap(),
|
assert_eq!(matrix2::A.invert().unwrap(),
|
||||||
Matrix2::new(-2.0f64, 1.5f64,
|
Matrix2::new(-2.0f64, 1.5f64,
|
||||||
|
@ -277,7 +277,7 @@ fn test_invert() {
|
||||||
assert_eq!(mut_a, matrix2::A.invert().unwrap());
|
assert_eq!(mut_a, matrix2::A.invert().unwrap());
|
||||||
|
|
||||||
// Matrix3
|
// Matrix3
|
||||||
assert!(Matrix3::<f64>::one().invert().unwrap().is_one());
|
assert!(Matrix3::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert_eq!(matrix3::A.invert(), None);
|
assert_eq!(matrix3::A.invert(), None);
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ fn test_invert() {
|
||||||
assert_eq!(mut_c, matrix3::C.invert().unwrap());
|
assert_eq!(mut_c, matrix3::C.invert().unwrap());
|
||||||
|
|
||||||
// Matrix4
|
// Matrix4
|
||||||
assert!(Matrix4::<f64>::one().invert().unwrap().is_one());
|
assert!(Matrix4::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert!(matrix4::C.invert().unwrap().approx_eq(&
|
assert!(matrix4::C.invert().unwrap().approx_eq(&
|
||||||
Matrix4::new( 5.0f64, -4.0f64, 1.0f64, 0.0f64,
|
Matrix4::new( 5.0f64, -4.0f64, 1.0f64, 0.0f64,
|
||||||
|
@ -305,25 +305,25 @@ fn test_invert() {
|
||||||
-0., 0.631364f64, 0.775487f64, 0.0f64,
|
-0., 0.631364f64, 0.775487f64, 0.0f64,
|
||||||
-0.991261f64, 0.1023f64, -0.083287f64, 0.0f64,
|
-0.991261f64, 0.1023f64, -0.083287f64, 0.0f64,
|
||||||
0., -1.262728f64, -1.550973f64, 1.0f64);
|
0., -1.262728f64, -1.550973f64, 1.0f64);
|
||||||
assert!(mat_c.invert().unwrap().mul_m(&mat_c).is_one());
|
assert!(mat_c.invert().unwrap().mul_m(&mat_c).is_identity());
|
||||||
|
|
||||||
let mat_d = Matrix4::new( 0.065455f64, -0.720002f64, 0.690879f64, 0.0f64,
|
let mat_d = Matrix4::new( 0.065455f64, -0.720002f64, 0.690879f64, 0.0f64,
|
||||||
-0., 0.692364f64, 0.721549f64, 0.0f64,
|
-0., 0.692364f64, 0.721549f64, 0.0f64,
|
||||||
-0.997856f64, -0.047229f64, 0.045318f64, 0.0f64,
|
-0.997856f64, -0.047229f64, 0.045318f64, 0.0f64,
|
||||||
0., -1.384727f64, -1.443098f64, 1.0f64);
|
0., -1.384727f64, -1.443098f64, 1.0f64);
|
||||||
assert!(mat_d.invert().unwrap().mul_m(&mat_d).is_one());
|
assert!(mat_d.invert().unwrap().mul_m(&mat_d).is_identity());
|
||||||
|
|
||||||
let mat_e = Matrix4::new( 0.409936f64, 0.683812f64, -0.603617f64, 0.0f64,
|
let mat_e = Matrix4::new( 0.409936f64, 0.683812f64, -0.603617f64, 0.0f64,
|
||||||
0., 0.661778f64, 0.7497f64, 0.0f64,
|
0., 0.661778f64, 0.7497f64, 0.0f64,
|
||||||
0.912114f64, -0.307329f64, 0.271286f64, 0.0f64,
|
0.912114f64, -0.307329f64, 0.271286f64, 0.0f64,
|
||||||
-0., -1.323555f64, -1.499401f64, 1.0f64);
|
-0., -1.323555f64, -1.499401f64, 1.0f64);
|
||||||
assert!(mat_e.invert().unwrap().mul_m(&mat_e).is_one());
|
assert!(mat_e.invert().unwrap().mul_m(&mat_e).is_identity());
|
||||||
|
|
||||||
let mat_f = Matrix4::new(-0.160691f64, -0.772608f64, 0.614211f64, 0.0f64,
|
let mat_f = Matrix4::new(-0.160691f64, -0.772608f64, 0.614211f64, 0.0f64,
|
||||||
-0., 0.622298f64, 0.78278f64, 0.0f64,
|
-0., 0.622298f64, 0.78278f64, 0.0f64,
|
||||||
-0.987005f64, 0.125786f64, -0.099998f64, 0.0f64,
|
-0.987005f64, 0.125786f64, -0.099998f64, 0.0f64,
|
||||||
0., -1.244597f64, -1.565561f64, 1.0f64);
|
0., -1.244597f64, -1.565561f64, 1.0f64);
|
||||||
assert!(mat_f.invert().unwrap().mul_m(&mat_f).is_one());
|
assert!(mat_f.invert().unwrap().mul_m(&mat_f).is_identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -338,17 +338,17 @@ fn test_from_translation() {
|
||||||
fn test_predicates() {
|
fn test_predicates() {
|
||||||
// Matrix2
|
// Matrix2
|
||||||
|
|
||||||
assert!(Matrix2::<f64>::one().is_one());
|
assert!(Matrix2::<f64>::identity().is_identity());
|
||||||
assert!(Matrix2::<f64>::one().is_symmetric());
|
assert!(Matrix2::<f64>::identity().is_symmetric());
|
||||||
assert!(Matrix2::<f64>::one().is_diagonal());
|
assert!(Matrix2::<f64>::identity().is_diagonal());
|
||||||
assert!(Matrix2::<f64>::one().is_invertible());
|
assert!(Matrix2::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!matrix2::A.is_one());
|
assert!(!matrix2::A.is_identity());
|
||||||
assert!(!matrix2::A.is_symmetric());
|
assert!(!matrix2::A.is_symmetric());
|
||||||
assert!(!matrix2::A.is_diagonal());
|
assert!(!matrix2::A.is_diagonal());
|
||||||
assert!(matrix2::A.is_invertible());
|
assert!(matrix2::A.is_invertible());
|
||||||
|
|
||||||
assert!(!matrix2::C.is_one());
|
assert!(!matrix2::C.is_identity());
|
||||||
assert!(matrix2::C.is_symmetric());
|
assert!(matrix2::C.is_symmetric());
|
||||||
assert!(!matrix2::C.is_diagonal());
|
assert!(!matrix2::C.is_diagonal());
|
||||||
assert!(matrix2::C.is_invertible());
|
assert!(matrix2::C.is_invertible());
|
||||||
|
@ -357,17 +357,17 @@ fn test_predicates() {
|
||||||
|
|
||||||
// Matrix3
|
// Matrix3
|
||||||
|
|
||||||
assert!(Matrix3::<f64>::one().is_one());
|
assert!(Matrix3::<f64>::identity().is_identity());
|
||||||
assert!(Matrix3::<f64>::one().is_symmetric());
|
assert!(Matrix3::<f64>::identity().is_symmetric());
|
||||||
assert!(Matrix3::<f64>::one().is_diagonal());
|
assert!(Matrix3::<f64>::identity().is_diagonal());
|
||||||
assert!(Matrix3::<f64>::one().is_invertible());
|
assert!(Matrix3::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!matrix3::A.is_one());
|
assert!(!matrix3::A.is_identity());
|
||||||
assert!(!matrix3::A.is_symmetric());
|
assert!(!matrix3::A.is_symmetric());
|
||||||
assert!(!matrix3::A.is_diagonal());
|
assert!(!matrix3::A.is_diagonal());
|
||||||
assert!(!matrix3::A.is_invertible());
|
assert!(!matrix3::A.is_invertible());
|
||||||
|
|
||||||
assert!(!matrix3::D.is_one());
|
assert!(!matrix3::D.is_identity());
|
||||||
assert!(matrix3::D.is_symmetric());
|
assert!(matrix3::D.is_symmetric());
|
||||||
assert!(!matrix3::D.is_diagonal());
|
assert!(!matrix3::D.is_diagonal());
|
||||||
assert!(matrix3::D.is_invertible());
|
assert!(matrix3::D.is_invertible());
|
||||||
|
@ -376,17 +376,17 @@ fn test_predicates() {
|
||||||
|
|
||||||
// Matrix4
|
// Matrix4
|
||||||
|
|
||||||
assert!(Matrix4::<f64>::one().is_one());
|
assert!(Matrix4::<f64>::identity().is_identity());
|
||||||
assert!(Matrix4::<f64>::one().is_symmetric());
|
assert!(Matrix4::<f64>::identity().is_symmetric());
|
||||||
assert!(Matrix4::<f64>::one().is_diagonal());
|
assert!(Matrix4::<f64>::identity().is_diagonal());
|
||||||
assert!(Matrix4::<f64>::one().is_invertible());
|
assert!(Matrix4::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!matrix4::A.is_one());
|
assert!(!matrix4::A.is_identity());
|
||||||
assert!(!matrix4::A.is_symmetric());
|
assert!(!matrix4::A.is_symmetric());
|
||||||
assert!(!matrix4::A.is_diagonal());
|
assert!(!matrix4::A.is_diagonal());
|
||||||
assert!(!matrix4::A.is_invertible());
|
assert!(!matrix4::A.is_invertible());
|
||||||
|
|
||||||
assert!(!matrix4::D.is_one());
|
assert!(!matrix4::D.is_identity());
|
||||||
assert!(matrix4::D.is_symmetric());
|
assert!(matrix4::D.is_symmetric());
|
||||||
assert!(!matrix4::D.is_diagonal());
|
assert!(!matrix4::D.is_diagonal());
|
||||||
assert!(matrix4::D.is_invertible());
|
assert!(matrix4::D.is_invertible());
|
||||||
|
|
|
@ -35,7 +35,7 @@ fn test_invert_basis2() {
|
||||||
let a: Basis2<_> = rotation::a2();
|
let a: Basis2<_> = rotation::a2();
|
||||||
let a = a.concat(&a.invert());
|
let a = a.concat(&a.invert());
|
||||||
let a: &Matrix2<_> = a.as_ref();
|
let a: &Matrix2<_> = a.as_ref();
|
||||||
assert!(a.is_one());
|
assert!(a.is_identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -43,5 +43,5 @@ fn test_invert_basis3() {
|
||||||
let a: Basis3<_> = rotation::a3();
|
let a: Basis3<_> = rotation::a3();
|
||||||
let a = a.concat(&a.invert());
|
let a = a.concat(&a.invert());
|
||||||
let a: &Matrix3<_> = a.as_ref();
|
let a: &Matrix3<_> = a.as_ref();
|
||||||
assert!(a.is_one());
|
assert!(a.is_identity());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue