Matrix4

Struct Matrix4 

Source
pub struct Matrix4 { /* private fields */ }
Expand description
  • Matrix4 Module
  • 2D Representation of a 4x4 Matrix
  • It’s a row-major matrix.

Implementations§

Source§

impl Matrix4

Source

pub fn elements(&self) -> Vec<f64>

Examples found in repository?
examples/matrix-example.rs (line 6)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
Source

pub fn new() -> Matrix4

  • Create a new Matrix4 with identity elements.
Examples found in repository?
examples/matrix-example.rs (line 5)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
Source

pub fn set( m0: f64, m1: f64, m2: f64, m3: f64, m4: f64, m5: f64, m6: f64, m7: f64, m8: f64, m9: f64, m10: f64, m11: f64, m12: f64, m13: f64, m14: f64, m15: f64, ) -> Matrix4

Examples found in repository?
examples/matrix-example.rs (lines 13-18)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
More examples
Hide additional examples
examples/vector-example.rs (lines 99-104)
3fn main() {
4  // Create two Vector3 instances
5  let mut v1 = Vector3::new(1.0, 2.0, 3.0);
6  let v2 = Vector3::new(4.0, 5.0, 6.0);
7
8  // Vector addition
9  v1.add(&v2);
10  println!("1. Elements of v1 after addition: ({}, {}, {})", v1.x, v1.y, v1.z);
11
12  // Adding a Scalar value to a Vector3
13  let mut v3 = Vector3::new(1.0, 3.0, 2.0);
14  v3.add_scalar(2.0);
15  println!("2. Adding a Scalar to v3, new elements: ({}, {}, {})", v3.x, v3.y, v3.z);
16
17  // Subtracting a Vector3
18  let mut v4 = Vector3::new(10.0, 9.0, 8.0);
19  v4.subtract(&v2);
20  println!("3. Elements of v4 after subtraction: ({}, {}, {})", v4.x, v4.y, v4.z);
21
22  // Subtracting a Scalar value from a Vector3
23  let mut v5 = Vector3::new(5.0, 6.0, 7.0);
24  v5.subtract_scalar(3.0);
25  println!("4. Subtracting a Scalar from v5, new elements: ({}, {}, {})", v5.x, v5.y, v5.z);
26
27  // Cloning a Vector3
28  let v6 = v1.clone();
29  println!("5. Cloned Vector3 v6: ({}, {}, {})", v6.x, v6.y, v6.z);
30
31  // Zeroing a Vector3
32  let mut v7 = Vector3::new(8.0, 9.0, 10.0);
33  v7.zero();
34  println!("6. Zeroed Vector3 v7: ({}, {}, {})", v7.x, v7.y, v7.z);
35
36  // Copying a Vector3
37  let mut v8 = Vector3::new(2.0, 3.0, 4.0);
38  v8.copy(&v6);
39  println!("7. Copied Vector3 v8 from v6: ({}, {}, {})", v8.x, v8.y, v8.z);
40
41  // Multiplying a Vector3 by a scalar
42  let mut v9 = Vector3::new(1.0, 2.0, 3.0);
43  v9.multiply_scalar(2.0);
44  println!("8. v9 after multiplying by scalar: ({}, {}, {})", v9.x, v9.y, v9.z);
45
46  // Multiply two vectors
47  let v10 = Vector3::new(2.0, 3.0, 4.0);
48  let v11 = Vector3::new(5.0, 6.0, 7.0);
49  let mut v12 = v10.clone();
50  v12.multiply(&v11);
51  println!("9. v12 after multiplying v10 and v11: ({}, {}, {})", v12.x, v12.y, v12.z);
52
53  // Divide a Vector3 by a scalar
54  let mut v13 = Vector3::new(10.0, 20.0, 30.0);
55  v13.divide_scalar(2.0);
56  println!("10. v13 after dividing by scalar: ({}, {}, {})", v13.x, v13.y, v13.z);
57
58  // Divide two vectors
59  let mut v14 = Vector3::new(20.0, 30.0, 40.0);
60  let v15 = Vector3::new(2.0, 3.0, 4.0);
61  v14.divide(&v15);
62  println!("11. v14 after dividing by v15: ({}, {}, {})", v14.x, v14.y, v14.z);
63
64  // Negate a Vector3
65  let mut v16 = Vector3::new(1.0, -2.0, 3.0);
66  v16.negate();
67  println!("12. v16 after negation: ({}, {}, {})", v16.x, v16.y, v16.z);
68
69  // Dot product of two vectors
70  let v17 = Vector3::new(1.0, 2.0, 3.0);
71  let v18 = Vector3::new(4.0, 5.0, 6.0);
72  let dot_product = v17.dot(&v18);
73  println!("13. Dot product of v17 and v18: {}", dot_product);
74
75  // Magnitude of a Vector3
76  let v19 = Vector3::new(3.0, 4.0, 0.0);
77  let magnitude = v19.magnitude();
78  println!("14. Magnitude/Length of v19: {}", magnitude);
79
80  // Normalize a Vector3
81  let mut v20 = Vector3::new(3.0, 4.0, 0.0);
82  v20.normalize();
83  println!("15. Normalized v20: ({}, {}, {})", v20.x, v20.y, v20.z);
84
85  // Cross product of two vectors
86  let v21 = Vector3::new(1.0, 0.0, 0.0);
87  let v22 = Vector3::new(0.0, 1.0, 0.0);
88  let v23 = v21.cross(&v22);
89  println!("16. Cross product of v21 and v22: ({}, {}, {})", v23.x, v23.y, v23.z);
90
91  // Distance between two vectors
92  let v24 = Vector3::new(1.0, 2.0, 3.0);
93  let v25 = Vector3::new(4.0, 5.0, 6.0);
94  let distance = v24.distance(&v25);
95  println!("17. Distance between v24 and v25: {}", distance);
96
97  // Apply a transformation matrix with translation at 2 in x axis, to a vector
98  let mut v26 = Vector3::new(1.0, 2.0, 3.0);
99  let matrix = openmaths::Matrix4::set(
100    1.0, 0.0, 0.0, 2.0,
101    0.0, 1.0, 0.0, 5.0,
102    0.0, 0.0, 1.0, 0.0,
103    0.0, 0.0, 0.0, 1.0
104  );
105  v26.apply_matrix4(matrix);
106  println!("18. v26 after applying transformation matrix: ({}, {}, {})", v26.x, v26.y, v26.z);
107}
Source

pub fn clone(&self) -> Matrix4

  • Clone the Matrix4 instance and return a new one.
Examples found in repository?
examples/matrix-example.rs (line 62)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
Source

pub fn identity(&mut self)

  • Sets the matrix element to create an identity matrix.
Examples found in repository?
examples/matrix-example.rs (line 9)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
Source

pub fn determinant(&self) -> f64

  • Determinant for a 4x4 matrix.
  • https://en.wikipedia.org/wiki/Determinant
Examples found in repository?
examples/matrix-example.rs (line 41)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}
Source

pub fn adjucate(&self) -> Matrix4

Source

pub fn inverse(&self) -> Matrix4

  • Inverse of a matrix
  • Returns a new Matrix4 instance.
  • If the determinant is zero, it returns a zero matrix.
  • It can be checked with is_zero() method.
Source

pub fn multiply(&self, other: &Matrix4) -> Matrix4

  • Multiply this matrix with another Matrix4
  • Returns a new Matrix4 instance
Source

pub fn add(&self, incoming: &Matrix4) -> Matrix4

  • Add another Matrix4 to this one.
  • Returns a new Matrix4 instance with the result.
Source

pub fn subtract(&self, incoming: &Matrix4) -> Matrix4

  • Subtract another Matrix4 from this one.
  • Returns a new Matrix4 instance with the result.
Source

pub fn flatten(&self) -> Vec<f64>

  • Flatten the matrix into a vector of f64.
Source

pub fn get_element_at(&self, index: usize) -> Option<f64>

  • Get the element at a specific index in the flattened matrix.
Source

pub fn is_zero(&self) -> bool

  • Check if the matrix is a zero matrix.
Source

pub fn is_identity(&self) -> bool

  • Check if the matrix is an identity matrix.
Source

pub fn transpose(&self) -> Matrix4

  • Create a Transpose of the matrix.
  • Returns a new Matrix4 instance.
Examples found in repository?
examples/matrix-example.rs (line 62)
3fn main() {
4    // Create a new Matrix4 instance
5    let mut m1 = Matrix4::new();
6    println!("1. Initial Matrix4 m1: {:?}", m1.elements());
7
8    // Set m1 to identity matrix
9    m1.identity();
10    println!("2. Identity Matrix4 m1: {:?}", m1.elements());
11
12    // Create another Matrix4 instance with specific elements
13    let m2 = Matrix4::set(
14        1.0, 2.0, 3.0, 4.0,
15        5.0, 6.0, 7.0, 8.0,
16        9.0, 10.0, 11.0, 12.0,
17        13.0, 14.0, 15.0, 16.0,
18    );
19
20    println!("3. Matrix4 m2: {:?}", m2.elements());
21
22    // // Multiply two matrices
23    // let m3 = m1.clone().multiply(&m2);
24    // println!("4. Result of multiplying m1 and m2: {:?}", m3.elements);
25
26    // // Add two matrices
27    // let m4 = m1.clone().add(&m2);
28    // println!("5. Result of adding m1 and m2: {:?}", m4.elements);
29
30    // // Subtract two matrices
31    // let m5 = m2.clone().subtract(&m1);
32    // println!("6. Result of subtracting m1 from m2: {:?}", m5.elements);
33
34    // Determinant of a matrix m6
35    let m6 = Matrix4::set(
36        1.0, 2.0, 3.0, 4.0,
37        5.0, 6.0, 7.0, 8.0,
38        9.0, 10.0, 11.0, 12.0,
39        13.0, 14.0, 15.0, 16.0,
40    );
41    let det = m6.determinant();
42    println!("7. Determinant of m6: {}", det);
43
44    // // Adjugate of a matrix
45    // let adj = m6.adjucate();
46    // println!("8. Adjugate of m6: {:?}", adj.elements);
47
48    // // Inverse of a matrix
49    // let m7 = m6.clone().inverse();
50    // println!("9. Inverse of m6: {:?}", m7.elements);
51
52    // // Check if the inverse is correct by multiplying m6 with its inverse
53    // let m6_cloned = m6.clone();
54    // let m6_inverse_multiplied = m6_cloned.multiply(&m7);
55    // println!("10. Result of multiplying m6 with its inverse: {:?}", m6_inverse_multiplied.elements);
56    
57    // // Check if the inverse multiplication gives identity matrix
58    // let identity_check = m6_inverse_multiplied.is_identity();
59    // println!("11. Is the result an identity matrix? - {}", identity_check);
60
61    // Transpose of a matrix
62    let m8 = m2.clone().transpose();
63    println!("12. Transpose of m2: {:?}", m8.elements());
64}

Trait Implementations§

Source§

impl Clone for Matrix4

Source§

fn clone(&self) -> Matrix4

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Deserialize<'de> for Matrix4

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Matrix4> for JsValue

Source§

fn from(value: Matrix4) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for Matrix4

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for Matrix4

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for Matrix4

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<Matrix4>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for Matrix4

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for Matrix4

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for Matrix4

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<Matrix4>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for Matrix4

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<Matrix4>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl Serialize for Matrix4

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFromJsValue for Matrix4

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for Matrix4

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Matrix4]>

Source§

impl VectorIntoJsValue for Matrix4

Source§

impl VectorIntoWasmAbi for Matrix4

Source§

impl WasmDescribe for Matrix4

Source§

impl WasmDescribeVector for Matrix4

Source§

impl SupportsConstructor for Matrix4

Source§

impl SupportsInstanceProperty for Matrix4

Source§

impl SupportsStaticProperty for Matrix4

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,