glam-rs icon indicating copy to clipboard operation
glam-rs copied to clipboard

Functions to work with rows

Open Danvil opened this issue 7 months ago • 1 comments

Matrix types (Mat3, DMat3, ..) seem to be missing functions to work with rows. This would be useful to have for various mathematical operations and also for interop with other libraries.

I would propose to add these functions:

  • Mat3::set_row(&mut self, i: usize, value: Vec3)
  • Mat3::from_rows(row_1: Vec3, row_2: Vec3, row_3: Vec3) -> Self
  • Mat3::from_rows_array(m: &[f32; 9) -> Self
  • Mat3::from_rows_slice(slice: &[f32]) -> Self
  • Mat3::to_rows_array(&self) -> [f32; 9]

Similarly for all of these matrix types:

  • Mat2
  • DMat2
  • Mat3
  • DMat3
  • Mat4
  • DMat4

Happy to create a PR if this is something which you would appreciate.

Danvil avatar May 19 '25 21:05 Danvil

The main reason I didn't add them is working with rows will incur additional overhead due to the need to transpose, because the user needs to transpose data themselves that cost is explicit. However as long as row functions include a doc comment reminding the user that glam stores matrix vectors as columns and accessing rows has a higher overhead then I'm OK with adding them for convenience.

bitshifter avatar May 20 '25 20:05 bitshifter