Closed icefoxen closed 5 years ago
This is tricky as this kind of design decision is quite opinionated and is neither really "right" nor "wrong".
Well, my answer is "please no", and I'll try my best to justify it here. :) It's more for posterity than trying very hard to prove my point.
To start with, this falls into the category of "using the type system to enforce mathematical properties". Other examples that come to my mind (and are strictly equivalent to me) are :
nalgebra
;These do a good job at making the API and client code more explicit and precise (hard to misunderstand what a Orthographic3 is) and "mathematically correct" at compile-time ("you fool, trying to add two Points together! Next thing you know we'll be able to divide by zero.").
However there are big deal breakers to me :
vek
's Mat4
, you don't get all of these mathematical properties made explicit by the type system, but at least the API is unified. A Mat4
is a "transform" if you want to see it like one. It is "affine" if you make it so. You can write functions that just take a Mat4
instead of searching for the best mathematically accurate trait bounds or whatever.vek
's design goals is not to hide the truth of the hardware, hence the #[repr(simd)]
versions for each type. Vec4
is intended to be viewed as a "hardware type". vek
is intended as a "hardware lib" in that sense.That's pretty much it :)
Good reasons! Thanks for the explanation, it's a perfectly reasonable set of choices. I was just wondering what your thoughts were. :)
nalgebra
andcgmath
both separatePoint
types fromVector
types... aPoint
is a location, and aVector
is an offset from a location. Thus you can add together aPoint
and aVector
and get a newPoint
, or you can add twoVector
's and get a newVector
, but you can't add together twoPoint
's.While this starts off weird, the distinction has grown on me a lot. Since the actual representation of a
Point
and aVector
are identical, as are many of the actual math operations on them, I totally understand if you don't want to do this, but I was wondering if you'd considered it.