Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does Point exist? #502

Open
InnocentusLime opened this issue May 16, 2020 · 8 comments
Open

Why does Point exist? #502

InnocentusLime opened this issue May 16, 2020 · 8 comments

Comments

@InnocentusLime
Copy link

InnocentusLime commented May 16, 2020

I've been re-reading the docs for cgmath and I honestly don't understand why there are both Vector and Point in the library.

In pure maths these two concepts are barely distinguished, while in cgmath they are strictly split by introducing two structs. Not only that, these structs have different functionality implemented for them which consequently makes the crate more complicated. What was the motivation behind that partition?

P.S.
I personally feel like all the functionality for Vector and Point should be implemented for one struct --- Vector (and Point should be depreacted). That will drastically simplify the crate and can fix issue #501. I can send a PR

@elrnv
Copy link
Contributor

elrnv commented May 16, 2020

I think traditionally having Point be distinct from Vector is an effort to encode the distinction between affine spaces and euclidean spaces into the type system. This is usually done to prevent certain types of bugs (for example adding two points together is invalid, but subtracting them is perfectly fine).

I think the graphics community is somewhat split on this topic because each choice has its tradeoffs.

FWIW I think that nalgebra already fills the niche of dense linear algebra with strict types, so probably cgmath can play the role of a simpler API as you propose.

@InnocentusLime
Copy link
Author

I see. Well, I guess I'll create a PR for that.

@nstoddard
Copy link
Contributor

When I switched to cgmath I expected the distinction between Point and Vector to prevent some bugs in my code, but in practice I don't think I've encountered many, if any, situations where it actually prevented a bug. On the other hand, I've found many cases where I've had to convert between points and vectors, so I'm somewhat in favor of merging the two (only somewhat because the distinction does make sense mathematically).

@kvark
Copy link
Collaborator

kvark commented Jun 3, 2020

Just wanted to explicitly chime in here to say that your feedback is much welcome, and I agree that the niche for rich typing is already taken, and we can have cgmath with simpler types.

@LukasKalbertodt
Copy link
Contributor

Just to throw my opinion out there, too: I very much appreciate the distinction between Point and Vector in cgmath. In fact, it's one of the biggest positive things about the library IMO. The following is not meant in a threatening way, but if cgmath removes Point, I will probably switch to another library which has two types. And for me, the distinction of the two types actually prevented some real world bugs.

Instead of thinking about removing Point, maybe just try to make it easier to convert between them. One example where the distinction "annoyed" me when I had to calculate the centroid of some points (I am aware cgmath has a function for that, but it only works for a slice of points, not iterators). But yeah, even the current API is fine in my book.

@kvark
Copy link
Collaborator

kvark commented Jun 23, 2020

@LukasKalbertodt it really comes down to what niche cgmath tries to settle in. It used to be one of the first libraries with a clear-ish goal. But after a long period of being unmaintained, and with a lot of interesting alternatives appearing, cgmath needs to play a catch-up if it wants to stay afloat. It needs to re-find itself again in the ecosystem.

If you truly care, help with reviews and code cleanup, API shaping for 0.18. Would be interesting to see some basic analysis on what other libraries expose in terms of vector-point distinction.

@aloucks
Copy link
Collaborator

aloucks commented Jun 27, 2020

I agree overall that cgmath should fill the "simple to use" niche, but I don't think that precludes keeping the Point struct. I've also found it useful. Maybe the solution is to make explicit point/vector conversion more ergonomic?

@InnocentusLime
Copy link
Author

InnocentusLime commented Jun 28, 2020

I agree overall that cgmath should fill the "simple to use" niche, but I don't think that precludes keeping the Point struct. I've also found it useful. Maybe the solution is to make explicit point/vector conversion more ergonomic?

The conversion is kind of here. Thanks to points implementing EuclideanSpace. The main problem in my opinion would be confusing times a person may have when trying to use the Decomposed struct.

Not only that, I see no benefit in having Point, because OpenGL (and probably DirectX) don't have that. They have only VecN. So, removing Point will not only simplify the api (because it may invoke removal or merging of some traits), but will also make cgmath more familiar to the existing Graphics APIs. And, to my knowledge, cgmath exists to be used together with things like OpenGL, doesn't it? If it is so, the user should have little trouble translating data to the OpenGL implementation and there should be less difference between code in GLSL/HLSL and in Rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants