1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::*;

/// Computes the determinant of a matrix.
///
/// This gives the scale factor of a unit square (or cube, or hyper-cube) in the
/// matrix's modified coordinate space:
/// * Positive means that the output orientation is generally similar.
/// * Negative means that the output orientation is flipped.
/// * Zero means that the output loses _at least_ 1 dimension (meaning that
///   hyper-cubes become cubes, squares, lines, or points).
#[inline]
pub fn determinant<M: CanDeterminant>(m: M) -> f32 {
  m.determinant()
}

/// A trait for types that can have a determinant computed.
pub trait CanDeterminant {
  /// See [`determinant`](module@determinant) for info.
  fn determinant(self) -> f32;
}

impl CanDeterminant for Mat2 {
  #[inline]
  fn determinant(self) -> f32 {
    Mat2::determinant(self)
  }
}

impl CanDeterminant for Mat3 {
  #[inline]
  fn determinant(self) -> f32 {
    Mat3::determinant(self)
  }
}

impl CanDeterminant for Mat4 {
  #[inline]
  fn determinant(self) -> f32 {
    Mat4::determinant(self)
  }
}