pub struct Matrix2 {
pub m00: f64,
pub m01: f64,
pub m10: f64,
pub m11: f64,
}Expand description
A 2x2 matrix stored in row-major order.
§Examples
use use_matrix::Matrix2;
let matrix = Matrix2::new(
1.0, 2.0,
3.0, 4.0,
);
assert_eq!(matrix.trace(), 5.0);
assert_eq!(matrix.determinant(), -2.0);Fields§
§m00: f64§m01: f64§m10: f64§m11: f64Implementations§
Source§impl Matrix2
impl Matrix2
Sourcepub const IDENTITY: Self
pub const IDENTITY: Self
The identity matrix.
§Examples
use use_matrix::Matrix2;
let matrix = Matrix2::new(
4.0, 7.0,
2.0, 6.0,
);
assert_eq!(Matrix2::IDENTITY * matrix, matrix);
assert_eq!(matrix * Matrix2::IDENTITY, matrix);Sourcepub const fn new(m00: f64, m01: f64, m10: f64, m11: f64) -> Self
pub const fn new(m00: f64, m01: f64, m10: f64, m11: f64) -> Self
Creates a matrix from row-major entries.
Sourcepub const fn determinant(self) -> f64
pub const fn determinant(self) -> f64
Returns the determinant.
Sourcepub fn inverse(self) -> Option<Self>
pub fn inverse(self) -> Option<Self>
Returns the inverse when the determinant is finite and non-zero.
Returns None for singular matrices or matrices with non-finite
determinants.
§Examples
use use_matrix::Matrix2;
let matrix = Matrix2::new(
4.0, 7.0,
2.0, 6.0,
);
let inverse = matrix.inverse().expect("matrix should invert");
assert!((inverse.m00 - 0.6).abs() < 1.0e-12);
assert!((inverse.m11 - 0.4).abs() < 1.0e-12);Trait Implementations§
impl Copy for Matrix2
impl StructuralPartialEq for Matrix2
Auto Trait Implementations§
impl Freeze for Matrix2
impl RefUnwindSafe for Matrix2
impl Send for Matrix2
impl Sync for Matrix2
impl Unpin for Matrix2
impl UnsafeUnpin for Matrix2
impl UnwindSafe for Matrix2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more