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

Add TriangulateEarcut algorithm. #1007

Merged
merged 6 commits into from
May 29, 2023
Merged

Add TriangulateEarcut algorithm. #1007

merged 6 commits into from
May 29, 2023

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Apr 3, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

#1002

@frewsxcv frewsxcv force-pushed the frewsxcv/triangulate branch from d7a4a64 to 8722d72 Compare May 19, 2023 02:38
@frewsxcv frewsxcv marked this pull request as ready for review May 19, 2023 02:39
@frewsxcv frewsxcv force-pushed the frewsxcv/triangulate branch from 8722d72 to 99d5b23 Compare May 19, 2023 02:41
Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great.

I left a bunch of small suggestions that I hoped would make it a little more intuitive to use, but I don't feel strongly about any of it, so please only apply what resonates with you.

impl<T: CoordFloat> Iter<T> {
fn triangle_index_to_coord(&self, triangle_index: usize) -> crate::Coord<T> {
coord! {
x: self.0.vertices[triangle_index * 2],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you use vertices elsewhere you use vertexes, can you consolidate around vertices which is used elsewhere in `geo?


/// The raw result of triangulating a polygon from `earcutr`.
#[derive(Debug, PartialEq, Clone)]
pub struct Raw<T: CoordFloat> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is public, I feel like a more descriptive name is in order. Maybe Triangulation ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth bearing in mind that if we went with Triangulation it would also have to be suitable for any future triangulations (e.g. Delaunay) we might add.

Copy link
Member

@michaelkirk michaelkirk May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is namespaced to the module, so triangulate_earcut::Triangulation v.s. the hypothetical delaunay::Triangulation. I think it'd be fine.

That said, I'm also fine with the clarity/verboseness tradeoff of triangulate_earcut::EarcutTriangulation

I just think Raw is a bit inexplicable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case to be made for triangulate_earcut::Triangulation, but I wonder if we should have a larger discussion about naming and namespacing to be consistent with our other traits. For example we also don't do geo::euclidean_distance::Distance nor geo::geodeisc_length::Length.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geo::euclidean_distance::Distance nor geo::geodeisc_length::Length

I don't understand the comparison to EuclideanDistance and GeodesicLength which both return scalars. We don't currently have bespoke types for those operations.

We could introduce something like:

 mod euclidean_distance {
+    struct Distance<T: CoordNum>(T);
     trait EuclideanDistance<T> {
-         fn euclidean_distance(&self) -> T;
+         fn euclidean_distance(&self) -> Distance<T>;
     }
 }

Is that what you mean? I don't see the value in it, but maybe I'm missing something.

In the case of this triangulation module, we already have this bespoke type: Raw, I'm saying we should give it a more descriptive name than "Raw".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard my previous comment! I interpreted your message:

This is namespaced to the module, so triangulate_earcut::Triangulation ...

to mean that you were suggesting renaming the TriangulateEarcut trait to Triangulation and forgot this was a discussion about the struct that is being returned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right! Sorry for not being clearer from the get-go. I probably should have just led with:

Suggested change
pub struct Raw<T: CoordFloat> {
pub struct Triangulation<T: CoordFloat> {


fn flat_line_string_coords_2<T: CoordFloat>(
line_string: &crate::LineString<T>,
vertexes: &mut Vec<T>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "vertex" naming confused me a bit. It's not actually a Vec of vertices, it's a vec of the flattened scalars of the vertices. flattened_vertex_scalars is kind of a mouthful though.

I can't think of anything better, so no change requested unless you can think of something clearer.

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great.

I left a bunch of small suggestions that I hoped would make it a little more intuitive to use, but I don't feel strongly about any of it, so please only apply what resonates with you.

frewsxcv and others added 4 commits May 20, 2023 00:43
@frewsxcv
Copy link
Member Author

bors r=michaelkirk

@bors
Copy link
Contributor

bors bot commented May 29, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 562e34a into main May 29, 2023
@bors bors bot deleted the frewsxcv/triangulate branch May 29, 2023 23:14
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

Successfully merging this pull request may close these issues.

3 participants