I just remembered an experiment I did a month ago which I wanted to share with you.
While playing with all the nice things in Scala for a while I thought it was time to create some basic Vector/Matrix math with it. Beside the obvious benefits like operators, I wanted to see if there are other things one can do with this expressive language.
So in the end I got way more features than expected:
- vector/matrix size encoded as generic type parameters
- type checked matrix multiplication(the width of the first matrix has to be the same as the height of the second)
- unified types: a matrix with a width or height of 1 is a vector(I know that this might not be correct)
- macro based vector swizzling
- dynamic factories(i.e. create a 2x2 or 4x4 rotation matrix as needed)
- size based optimized implementations(Vector3) which are hidden by the user. Also can be extended by user.
For code samples and some more in depth explanation take a look at:
I just wanted to put this out here to maybe get some comments or constructive criticism :). In the spirit of perhaps inspiring someone else or getting inspired by some interesting idea from someone else.