flame-engine / flame-engine/flame
PolygonRayIntersection failing on non-Euclidean/concave/hollow polygons
- Dominant language
- Dart
- Stars
- 10.8k
- Forks
- 1k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 21
Description
### What happened?
When using a `PolygonHitbox` for non-Euclidean/concave/hollow polygons, the `PolygonRayIntersection` mixin fails when a ray traverses multiple hollow parts of a concave polygon.
### What do you expect?
As long as a `PolygonHitbox` defines a closed polygon correctly, the actual topology should not confuse `PolygonRayIntersection`.
### How can we reproduce this?
While I no longer have steps to reproduce the issue, there is [a testbed](https://github.com/adario/flame_path_shapes) to verify the refactoring result in `PolygonRayIntersection`, which uses my Flame fork mentioned below.
### What steps should take to fix this?
These are the [relevant changes](https://github.com/adario/flame/commit/29755b2defe512c150406b66db70326f2888c82e) in my Flame fork; eventually I plan to submit a PR.
### Do have an example of where the bug occurs?
Without [my changes](https://github.com/adario/flame/commit/29755b2defe512c150406b66db70326f2888c82e), the bug used to occur with **all** the new `Path` shapes of the `RaysInShapeExample` in [the testbed](https://github.com/adario/flame_path_shapes); the pre-existing shapes (circle, rectangle, quadrilateral) used to work, but changing the quad into a sort of 'U' shape also failed.
### Relevant log output
```shell
```
### Execute in a terminal and put output into the code block below
Output of: flutter doctor -v
[✓] Flutter (Channel stable, 3.47.2, on macOS 26.6.2 25G83 darwin-arm64, locale en-IT) [881ms]
• Flutter version 3.47.2 on channel stable at /Users/d.accornero/Applications/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d3b14c8769 (12 days ago), 2026-08-26 16:07:51 -0700
• Engine revision a804b26164
• Dart version 3.13.2
• DevTools version 2.60.0
• Feature flags: enable-web, no-enable-linux-desktop, enable-macos-desktop, no-enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use,
enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1,658ms]
• Android SDK at /Users/d.accornero/Library/Android/sdk
• Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
• Platform android-36.1, build-tools 36.1.0
• ANDROID_HOME = /Users/d.accornero/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 25.0.3+-15898627-b508.16)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/to/macos-android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 26.6) [1,716ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17F113
• CocoaPods version 1.17.0
[✓] Chrome - develop for the web [6ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (4 available) [6.6s]
• Undici (mobile) • 00008030-001065060C42802E • ios • iOS 26.6.1 23G83
• iPhone 17e (mobile) • FD5942B7-8265-4568-B74E-698F1FB20941 • ios • com.apple.CoreSimulator.SimRuntime.iOS-26-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 26.6.2 25G83 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 152.0.7977.83
! Error: Browsing on the local area network for iPad di Sviluppo (2). Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Eleven. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for iPad di Julie. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources [285ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
### Affected platforms
iOS, Android, Web
### Other information
_No response_
### Are you interested in working on a PR for this?
- [x] I want to work on this
Contributor guide
Research direction
Start with the PolygonRayIntersection mixin and PolygonHitbox behavior, then compare them with the relevant changes in the linked Flame fork commit. Use the RaysInShapeExample shapes in the flame_path_shapes testbed to check rays crossing multiple hollow parts of concave polygons. Done means closed non-Euclidean, concave, and hollow polygons no longer confuse ray intersections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100