Stoeoef / spade

Delaunay Triangulations for the Rust Ecosystem
Apache License 2.0
273 stars 48 forks source link

Optional implementation of `HasPosition2D` for `glam::Vec2` and `glam::DVec2` #63

Open timothee-haudebourg opened 3 years ago

timothee-haudebourg commented 3 years ago

I use the glam crate in a project where I need to compute a delaunay triangulation. It would be nice to have a HasPosition2D implementation for the glam 2D vector types. Could this be added as an optional feature?

Stoeoef commented 2 years ago

Sorry for the late reply.

I'm really torn about how to support external geometry libraries. I really, really dislike gluing code like triangulation.insert(Point2::new(glam_point.x, glam_point.y)). However, the point abstraction in Spade 1 (via the PointN trait) also had a few disadvantages:

My current least-unfavourable solution would probably to simply depend on a proper algebra library - likely nalgebra as that seems to become more and more a standard. The second least-unfavourable solution would be to start a "algebra_traits" library (similar to num_traits) that defines common traits for Points and Vectors. This would look similar to the alga crate, but hopefully less complex. This crate could then implement nalgebra, glam and you-name-it support.

Unfortunately, none of this makes interaction with glam easier. I'm not sure how that could be achieved. In any case, integration with other linear algebra libraries is on the roadmap for spade 3.

caspark commented 6 months ago

Mint is an interop standard which glam supports and nalgebra supports too. The Mint types themselves (e.g. Vector2) don't have any useful operations themselves - they solely exist to work around Rust's orphan rules.

Still, if HasPosition were implemented for them (under a cargo feature of course), then I think that would address this minor ergonomics papercut of having to convert into Point2.

(And FWIW, in case you are still considering depending on a proper algebra library directly: I prefer glam over nalgebra as the latter's generic programming makes compiler error messages a bit painful to understand sometimes. But with Bevy using Glam and Rapier & Parry obviously using nalgebra then I think there's reasonable arguments to be made either way - in the gamedev space at least.)