rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.13k stars 155 forks source link

Question: Utility of DiagonalMatrix struct #453

Open richard-uk1 opened 6 years ago

richard-uk1 commented 6 years ago

Multiplying by a diagonal matrix is faster than a general matrix, because it is equivalent to scaling rows if mat diag, or columns if diag mat. Should there be a DiagonalMatrix stored as a vector that implements matrix mult like this to be faster?

An application, for example, is scaling in a rotation/scale/translation transformation.

richard-uk1 commented 6 years ago

An alternative is some method on a matrix that takes a vector and applies it in this way.

brendanzab commented 6 years ago

Yeah, originally I was thinking this would be a nice optimization! I don't currently do it though. It's also a handy invariant to know in some cases, but again, I haven't taken advantage of it. Lots of unfinished business on cgmath - if you want to chat further I'm on Gitter!