diff options
Diffstat (limited to 'engine')
| -rw-r--r-- | engine/src/data_types/matrix.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/engine/src/data_types/matrix.rs b/engine/src/data_types/matrix.rs index ef263a1..9ab5bd4 100644 --- a/engine/src/data_types/matrix.rs +++ b/engine/src/data_types/matrix.rs @@ -61,6 +61,23 @@ impl<Value, const ROWS: usize, const COLUMNS: usize> Matrix<Value, ROWS, COLUMNS { &self.items.as_flattened() } + + pub fn to_column_major(&self) -> [[Value; ROWS]; COLUMNS] + where + Value: Default + Clone, + { + let mut transposed = std::array::from_fn::<_, COLUMNS, _>(|_| { + std::array::from_fn::<_, ROWS, _>(|_| Value::default()) + }); + + for (row_index, row) in self.items.iter().enumerate() { + for (column_index, item) in row.iter().enumerate() { + transposed[column_index][row_index] = item.clone(); + } + } + + transposed + } } impl<Value, const ROWS: usize, const COLUMNS: usize> Default |
