yoanlcq / vek

Generic 2D-3D math swiss army knife for game engines, with SIMD support and focus on convenience.
https://docs.rs/vek
Apache License 2.0
281 stars 31 forks source link

Add `Point` types? #19

Closed icefoxen closed 5 years ago

icefoxen commented 5 years ago

nalgebra and cgmath both separate Point types from Vector types... a Point is a location, and a Vector is an offset from a location. Thus you can add together a Point and a Vector and get a new Point, or you can add two Vector's and get a new Vector, but you can't add together two Point's.

While this starts off weird, the distinction has grown on me a lot. Since the actual representation of a Point and a Vector 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.

yoanlcq commented 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 :

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 :

That's pretty much it :)

icefoxen commented 5 years ago

Good reasons! Thanks for the explanation, it's a perfectly reasonable set of choices. I was just wondering what your thoughts were. :)