Skip to content

Polygon simplicity#15981

Merged
alice-i-cecile merged 8 commits intobevyengine:mainfrom
lynn-lumen:convex-polygon
Dec 10, 2024
Merged

Polygon simplicity#15981
alice-i-cecile merged 8 commits intobevyengine:mainfrom
lynn-lumen:convex-polygon

Conversation

@lynn-lumen
Copy link
Copy Markdown
Contributor

@lynn-lumen lynn-lumen commented Oct 18, 2024

Objective

  • This PR adds the ability to determine whether a Polygon<N> or BoxedPolygon is simple (aka. not self-intersecting) by calling my_polygon.is_simple().
  • This may be useful information for users to determine whether their polygons are 'valid' and will be useful when adding meshing for polygons.

Solution

  • Implemented the Shamos-Hoey algorithm in its own module polygon.

Testing

  • Tests are included, and can be verified visually.

Performance

  • The Shamos-Hoey algorithm runs in O(n * log n)
  • In reality, the results look more linear to me.
  • Determining simplicity for a simple polygon (the worst case) with less than 100 vertices takes less than 0.2ms.

image

@IQuick143 IQuick143 added C-Feature A new feature, making something new possible A-Math Fundamental domain-agnostic mathematical operations S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 18, 2024
@IQuick143 IQuick143 self-requested a review October 18, 2024 05:12
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Oct 19, 2024
@alice-i-cecile alice-i-cecile added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Oct 19, 2024
@BenjaminBrienen
Copy link
Copy Markdown
Contributor

O(n*log_9999999(n)) I guess

@mnmaita mnmaita added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 9, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 10, 2024
Merged via the queue into bevyengine:main with commit fcaa271 Dec 10, 2024
@pcwalton
Copy link
Copy Markdown
Contributor

I think this may have broken the test that checks to ensure that bevy_math compiles with libcore.

pcwalton added a commit to pcwalton/bevy that referenced this pull request Dec 10, 2024
CI was failing because `bevy_math` no longer compiled with `libcore`.
This was due to PR bevyengine#15981. This commit fixes the issue by moving the
applicable functionality behind `#[cfg(feature = "alloc")]`.
github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2024
CI was failing because `bevy_math` no longer compiled with `libcore`.
This was due to PR #15981. This commit fixes the issue by moving the
applicable functionality behind `#[cfg(feature = "alloc")]`.
BD103 pushed a commit to BD103/bevy that referenced this pull request Dec 10, 2024
# Objective

- This PR adds the ability to determine whether a `Polygon<N>` or
`BoxedPolygon` is simple (aka. not self-intersecting) by calling
`my_polygon.is_simple()`.
- This may be useful information for users to determine whether their
polygons are 'valid' and will be useful when adding meshing for
polygons.
  - As such this is a step towards fixing bevyengine#15255

## Solution

- Implemented the Shamos-Hoey algorithm in its own module `polygon`.

## Testing

- Tests are included, and can be verified visually.

---

## Performance

- The Shamos-Hoey algorithm runs in O(n * log n)
- In reality, the results look more linear to me.
- Determining simplicity for a simple polygon (the worst case) with less
than 100 vertices takes less than 0.2ms.


![image](https://github.com/user-attachments/assets/23c62234-abdc-4710-a3b4-feaad5929133)
BD103 pushed a commit to BD103/bevy that referenced this pull request Dec 10, 2024
…ine#16739)

CI was failing because `bevy_math` no longer compiled with `libcore`.
This was due to PR bevyengine#15981. This commit fixes the issue by moving the
applicable functionality behind `#[cfg(feature = "alloc")]`.
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# Objective

- This PR adds the ability to determine whether a `Polygon<N>` or
`BoxedPolygon` is simple (aka. not self-intersecting) by calling
`my_polygon.is_simple()`.
- This may be useful information for users to determine whether their
polygons are 'valid' and will be useful when adding meshing for
polygons.
  - As such this is a step towards fixing bevyengine#15255

## Solution

- Implemented the Shamos-Hoey algorithm in its own module `polygon`.

## Testing

- Tests are included, and can be verified visually.

---

## Performance

- The Shamos-Hoey algorithm runs in O(n * log n)
- In reality, the results look more linear to me.
- Determining simplicity for a simple polygon (the worst case) with less
than 100 vertices takes less than 0.2ms.


![image](https://github.com/user-attachments/assets/23c62234-abdc-4710-a3b4-feaad5929133)
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
…ine#16739)

CI was failing because `bevy_math` no longer compiled with `libcore`.
This was due to PR bevyengine#15981. This commit fixes the issue by moving the
applicable functionality behind `#[cfg(feature = "alloc")]`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Math Fundamental domain-agnostic mathematical operations C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants