#[repr(C, packed(1))]pub struct Matrix3 {
pub m: [f32; 9],
}
Fields§
§m: [f32; 9]
Implementations§
Source§impl Matrix3
impl Matrix3
Sourcepub fn new() -> Matrix3
pub fn new() -> Matrix3
Creates a matrix set to its identity
§Examples
use vex::Matrix3;
let actual = Matrix3::new();
assert_eq!(actual, Matrix3 {
m: [
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
],
});
Sourcepub fn make(
m11: f32,
m21: f32,
m31: f32,
m12: f32,
m22: f32,
m32: f32,
m13: f32,
m23: f32,
m33: f32,
) -> Matrix3
pub fn make( m11: f32, m21: f32, m31: f32, m12: f32, m22: f32, m32: f32, m13: f32, m23: f32, m33: f32, ) -> Matrix3
Creates a matrix from the provided values
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let expected = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
assert_eq!(actual.m, expected);
Sourcepub fn m11(&self) -> f32
pub fn m11(&self) -> f32
Gets the value for the m11 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m11(), 1.0);
Sourcepub fn m21(&self) -> f32
pub fn m21(&self) -> f32
Gets the value for the m21 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m21(), 2.0);
Sourcepub fn m31(&self) -> f32
pub fn m31(&self) -> f32
Gets the value for the m31 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m31(), 3.0);
Sourcepub fn m12(&self) -> f32
pub fn m12(&self) -> f32
Gets the value for the m12 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m12(), 4.0);
Sourcepub fn m22(&self) -> f32
pub fn m22(&self) -> f32
Gets the value for the m22 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m22(), 5.0);
Sourcepub fn m32(&self) -> f32
pub fn m32(&self) -> f32
Gets the value for the m32 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m32(), 6.0);
Sourcepub fn m13(&self) -> f32
pub fn m13(&self) -> f32
Gets the value for the m13 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m13(), 7.0);
Sourcepub fn m23(&self) -> f32
pub fn m23(&self) -> f32
Gets the value for the m23 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m23(), 8.0);
Sourcepub fn m33(&self) -> f32
pub fn m33(&self) -> f32
Gets the value for the m33 element
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual.m33(), 9.0);
Sourcepub fn set_m11(&mut self, v: f32)
pub fn set_m11(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m11(1.0);
let expected = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m21(&mut self, v: f32)
pub fn set_m21(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m21(1.0);
let expected = [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m31(&mut self, v: f32)
pub fn set_m31(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m31(1.0);
let expected = [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m12(&mut self, v: f32)
pub fn set_m12(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m12(1.0);
let expected = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m22(&mut self, v: f32)
pub fn set_m22(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m22(1.0);
let expected = [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m32(&mut self, v: f32)
pub fn set_m32(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m32(1.0);
let expected = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m13(&mut self, v: f32)
pub fn set_m13(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m13(1.0);
let expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m23(&mut self, v: f32)
pub fn set_m23(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m23(1.0);
let expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0];
assert_eq!(actual.m, expected);
Sourcepub fn set_m33(&mut self, v: f32)
pub fn set_m33(&mut self, v: f32)
Sets the value for the m11 element
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
actual.set_m33(1.0);
let expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0];
assert_eq!(actual.m, expected);
Sourcepub fn set(
&mut self,
m11: f32,
m21: f32,
m31: f32,
m12: f32,
m22: f32,
m32: f32,
m13: f32,
m23: f32,
m33: f32,
)
pub fn set( &mut self, m11: f32, m21: f32, m31: f32, m12: f32, m22: f32, m32: f32, m13: f32, m23: f32, m33: f32, )
Sets the internal contents of the matrix
§Examples
use vex::Matrix3;
let mut actual = Matrix3::new();
actual.set(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let expected = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
assert_eq!(actual, expected);
Sourcepub fn transpose(&mut self)
pub fn transpose(&mut self)
Transposes the matrix’s elements
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual.transpose();
let expected = Matrix3::make(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);
assert_eq!(actual, expected);
Sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Find the matrix’s determinant
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0).determinant();
assert_eq!(actual, 0.0);
Trait Implementations§
Source§impl Add<f32> for Matrix3
impl Add<f32> for Matrix3
Source§fn add(self, _rhs: f32) -> Matrix3
fn add(self, _rhs: f32) -> Matrix3
Find the resulting matrix by adding a scalar to a matrix’s elements
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) + 1.0;
let expected = Matrix3::make(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
assert_eq!(actual, expected);
Source§impl Add for Matrix3
impl Add for Matrix3
Source§fn add(self, _rhs: Matrix3) -> Matrix3
fn add(self, _rhs: Matrix3) -> Matrix3
Add two matrices
§Examples
use vex::Matrix3;
let a = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let b = Matrix3::make(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
let actual = a + b;
let expected = Matrix3::make(10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0);
assert_eq!(actual, expected);
Source§impl AddAssign<f32> for Matrix3
impl AddAssign<f32> for Matrix3
Source§fn add_assign(&mut self, _rhs: f32)
fn add_assign(&mut self, _rhs: f32)
Increment a matrix by a scalar
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual += 10.0;
let expected = Matrix3::make(11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0);
assert_eq!(actual, expected);
Source§impl AddAssign for Matrix3
impl AddAssign for Matrix3
Source§fn add_assign(&mut self, _rhs: Matrix3)
fn add_assign(&mut self, _rhs: Matrix3)
Increment a matrix by another matrix
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual += Matrix3::make(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
let expected = Matrix3::make(10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0);
assert_eq!(actual, expected);
Source§impl Div<f32> for Matrix3
impl Div<f32> for Matrix3
Source§fn div(self, _rhs: f32) -> Matrix3
fn div(self, _rhs: f32) -> Matrix3
Find the resulting matrix by dividing a scalar to a matrix’s elements
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) / 2.0;
let expected = Matrix3::make(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5);
assert_eq!(actual, expected);
Source§impl DivAssign<f32> for Matrix3
impl DivAssign<f32> for Matrix3
Source§fn div_assign(&mut self, _rhs: f32)
fn div_assign(&mut self, _rhs: f32)
Divide a matrix by a scalar
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual /= 2.0;
let expected = Matrix3::make(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5);
assert_eq!(actual, expected);
Source§impl Matrix<Vector2> for Matrix3
impl Matrix<Vector2> for Matrix3
Source§fn transform_point(&self, point: &Vector2) -> Vector2
fn transform_point(&self, point: &Vector2) -> Vector2
Find the resulting vector given a vector and matrix
§Examples
use vex::Matrix;
use vex::Matrix3;
use vex::Vector2;
let m = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let v = Vector2::make(1.0, 2.0);
let actual = m.transform_point(&v);
let expected = Vector2::make(16.0, 20.0);
assert_eq!(actual, expected);
Source§impl Matrix<Vector3> for Matrix3
impl Matrix<Vector3> for Matrix3
Source§fn transform_point(&self, point: &Vector3) -> Vector3
fn transform_point(&self, point: &Vector3) -> Vector3
Find the resulting vector given a vector and matrix
§Examples
use vex::Matrix;
use vex::Matrix3;
use vex::Vector3;
let m = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let v = Vector3::make(1.0, 2.0, 3.0);
let actual = m.transform_point(&v);
let expected = Vector3::make(30.0, 36.0, 42.0);
assert_eq!(actual, expected);
Source§impl Mul<f32> for Matrix3
impl Mul<f32> for Matrix3
Source§fn mul(self, _rhs: f32) -> Matrix3
fn mul(self, _rhs: f32) -> Matrix3
Find the resulting matrix by multiplying a scalar to a matrix’s elements
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) * 2.0;
let expected = Matrix3::make(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0);
assert_eq!(actual, expected);
Source§impl Mul for Matrix3
impl Mul for Matrix3
Source§fn mul(self, _rhs: Matrix3) -> Matrix3
fn mul(self, _rhs: Matrix3) -> Matrix3
Multiply two matrices
§Examples
use vex::Matrix3;
let a = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let b = Matrix3::make(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
let actual = a * b;
let expected = Matrix3::make(90.0, 114.0, 138.0, 54.0, 69.0, 84.0, 18.0, 24.0, 30.0);
assert_eq!(actual, expected);
Source§impl MulAssign<f32> for Matrix3
impl MulAssign<f32> for Matrix3
Source§fn mul_assign(&mut self, _rhs: f32)
fn mul_assign(&mut self, _rhs: f32)
Multiply a matrix by a scalar
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual *= 2.0;
let expected = Matrix3::make(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0);
assert_eq!(actual, expected);
Source§impl MulAssign for Matrix3
impl MulAssign for Matrix3
Source§fn mul_assign(&mut self, _rhs: Matrix3)
fn mul_assign(&mut self, _rhs: Matrix3)
Multiply a matrix by another matrix
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual *= Matrix3::make(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
let expected = Matrix3::make(90.0, 114.0, 138.0, 54.0, 69.0, 84.0, 18.0, 24.0, 30.0);
assert_eq!(actual, expected);
Source§impl Neg for Matrix3
impl Neg for Matrix3
Source§impl PartialEq for Matrix3
impl PartialEq for Matrix3
Source§impl Sub<f32> for Matrix3
impl Sub<f32> for Matrix3
Source§fn sub(self, _rhs: f32) -> Matrix3
fn sub(self, _rhs: f32) -> Matrix3
Find the resulting matrix by subtracting a scalar from a matrix’s elements
§Examples
use vex::Matrix3;
let actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0) - 10.0;
let expected = Matrix3::make(-9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0);
assert_eq!(actual, expected);
Source§impl Sub for Matrix3
impl Sub for Matrix3
Source§fn sub(self, _rhs: Matrix3) -> Matrix3
fn sub(self, _rhs: Matrix3) -> Matrix3
Subtract two matrices
§Examples
use vex::Matrix3;
let a = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
let b = Matrix3::make(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0);
let actual = a - b;
let expected = Matrix3::make(-8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0);
assert_eq!(actual, expected);
Source§impl SubAssign<f32> for Matrix3
impl SubAssign<f32> for Matrix3
Source§fn sub_assign(&mut self, _rhs: f32)
fn sub_assign(&mut self, _rhs: f32)
Decrement a matrix by a scalar
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
actual -= 1.0;
let expected = Matrix3::make(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
assert_eq!(actual, expected);
Source§impl SubAssign for Matrix3
impl SubAssign for Matrix3
Source§fn sub_assign(&mut self, _rhs: Matrix3)
fn sub_assign(&mut self, _rhs: Matrix3)
Decrement a matrix by another matrix
§Examples
use vex::Matrix3;
let mut actual = Matrix3::make(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
actual -= Matrix3::make(1.0, 3.0, 4.0, 5.0, 5.0, 7.0, 8.0, 9.0, 9.0);
assert_eq!(actual, Matrix3::new());