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

Update to mapbox/earcut v3.0.1 #19

Merged
merged 1 commit into from
Feb 18, 2025
Merged

Update to mapbox/earcut v3.0.1 #19

merged 1 commit into from
Feb 18, 2025

Conversation

ciscorn
Copy link
Member

@ciscorn ciscorn commented Feb 18, 2025

@ciscorn ciscorn self-assigned this Feb 18, 2025
@ciscorn ciscorn added the enhancement New feature or request label Feb 18, 2025
@MIERUNE MIERUNE deleted a comment from coderabbitai bot Feb 18, 2025
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.36%. Comparing base (3898cc0) to head (63b92f9).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/lib.rs 93.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
- Coverage   99.56%   99.36%   -0.20%     
==========================================
  Files           2        2              
  Lines         927      952      +25     
==========================================
+ Hits          923      946      +23     
- Misses          4        6       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ciscorn ciscorn merged commit 3a96d4d into main Feb 18, 2025
2 of 4 checks passed
@ciscorn ciscorn deleted the earcut-v301 branch February 18, 2025 14:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/lib.rs (2)

290-311: Consider handling infinite or NaN slopes explicitly.

When sorting by slope, division by zero or floating overflow might occur. You can guard against infinite or NaN slopes for more robust hole ordering:

 let a_slope = (node!(self.nodes, a.next_i).xy[1] - a.xy[1])
-    / (node!(self.nodes, a.next_i).xy[0] - a.xy[0]);
 let b_slope = (node!(self.nodes, b.next_i).xy[1] - b.xy[1])
-    / (node!(self.nodes, b.next_i).xy[0] - b.xy[0]);

+// Example approach to avoid infinite slope
+let dx_a = node!(self.nodes, a.next_i).xy[0] - a.xy[0];
+let a_slope = if dx_a == T::zero() {
+    T::infinity()
+} else {
+    (node!(self.nodes, a.next_i).xy[1] - a.xy[1]) / dx_a
+};
+// similarly for b_slope

1165-1169: Ensure naming reflects partial boundary exclusion.

point_in_triangle_except_first only excludes if the point matches the first vertex exactly. If you intend to exclude all boundary points, rename the function or expand the logic to exclude the second and third vertices as well.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3898cc0 and 63b92f9.

⛔ Files ignored due to path filters (6)
  • Cargo.toml is excluded by !**/*.toml
  • tests/fixtures/touching-holes2.json is excluded by !**/*.json
  • tests/fixtures/touching-holes3.json is excluded by !**/*.json
  • tests/fixtures/touching-holes4.json is excluded by !**/*.json
  • tests/fixtures/touching-holes5.json is excluded by !**/*.json
  • tests/fixtures/touching-holes6.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • src/lib.rs (8 hunks)
  • tests/fixture.rs (4 hunks)
🔇 Additional comments (17)
src/lib.rs (7)

429-429: Confirm if excluding the first vertex alone is intended.

Replacing point_in_triangle with point_in_triangle_except_first excludes points matching the first vertex. Verify if you also need to exclude the second or third vertex to avoid boundary conditions.


488-488: Same remark as line 429.


500-500: Same remark as line 429.


518-518: Same remark as line 429.


536-536: Same remark as line 429.


885-889: Consider a tolerance-based check for vertex equality.

If floating precision errors occur, two points might be logically equal but fail the equals check. Consider using a small epsilon-based approach for robust hole bridging.


893-895: Same remark as lines 885-889.

tests/fixture.rs (10)

78-78: Output triangle expectation changed.

Ensure 5176 is the correct updated count of triangles for "water-huge".


83-83: Deviation threshold changed.

Confirm 0.004 is the desired threshold for "water-huge2".


152-155: Good addition of new test scenario.

Thanks for adding "touching-holes2"; it broadens coverage.


156-159: Good addition of new test scenario.

"touching-holes3" test also improves coverage.


161-164: Added test scenario for holes.

"touching-holes4" scenario is valuable for verifying hole adjacency logic.


166-169: Another beneficial holes test.

"touching-holes5" ensures the algorithm handles more complex shapes.


171-174: Expanding coverage with holes.

"touching-holes6" might be a stress test — thanks for including it.


228-228: Reducing expected triangles from 19 to 18.

Confirm that "issue111" is now generating one fewer triangle as intended.


233-233: Updated expected triangles from 57 to 58.

Ensure the "boxy" fixture is correct for the new triangulation result.


263-263: Reduced expected triangles from 20 to 19.

Check that "touching4" fixture properly reflects the updated triangulation logic.

Copy link

coderabbitai bot commented Feb 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update refines the triangulation algorithm and adjusts test expectations. In the library code, the sorting logic in the eliminate_holes function now compares x-coordinates, then y-coordinates, and finally slopes to ensure counterclockwise ordering at vertices, and a new function point_in_triangle_except_first is introduced for refined point-in-triangle checks. In the tests, several expected triangle counts and deviation values have been updated, and new test cases have been added to improve coverage.

Changes

File(s) Change Summary
src/lib.rs Updated sorting logic in eliminate_holes to compare x, y, then segment slopes; added point_in_triangle_except_first to enhance point-in-triangle checks; replaced calls to point_in_triangle in ear checks.
tests/fixture.rs Adjusted expected triangle counts and deviation values in several tests ("water-huge", "water-huge2", "issue111", "boxy", "touching4"); added new test cases for "touching-holes2" to "touching-holes6" with specific expectations.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant EarChecker as is_ear
    participant PitEx as point_in_triangle_except_first
    participant Pit as point_in_triangle

    Caller->>EarChecker: Invoke is_ear()
    EarChecker->>PitEx: Call point_in_triangle_except_first()
    PitEx->>Pit: Call point_in_triangle()
    Pit-->>PitEx: Return boolean result
    PitEx-->>EarChecker: Return boolean result
    EarChecker-->>Caller: Return ear check result
Loading

Poem

Hopping through lines of code, I sing a joyful tune,
Sorting vertices in a dance under the silicon moon.
New checks and tests align in rhythmic, clever art,
As triangles and holes play their well-tuned part.
From my rabbit heart, I celebrate each change with glee!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3898cc0 and 63b92f9.

⛔ Files ignored due to path filters (6)
  • Cargo.toml is excluded by !**/*.toml
  • tests/fixtures/touching-holes2.json is excluded by !**/*.json
  • tests/fixtures/touching-holes3.json is excluded by !**/*.json
  • tests/fixtures/touching-holes4.json is excluded by !**/*.json
  • tests/fixtures/touching-holes5.json is excluded by !**/*.json
  • tests/fixtures/touching-holes6.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • src/lib.rs (8 hunks)
  • tests/fixture.rs (4 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

Successfully merging this pull request may close these issues.

earcut v3.0.1
1 participant