perf: Only test polygon edges inside the hitbox overlap and drop allocations from segment intersection - #4
Merged
Conversation
…cations from segment intersection ShapeHitbox.intersections now passes the overlap of the two AABBs to the intersection systems, which already knew how to filter edges by a rect but never received one. LineSegment.intersections rejects segment pairs whose bounding boxes do not overlap before doing any math and no longer allocates Line objects or result lists for misses.
This was referenced Sep 13, 2026
Owner
|
Love this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The same narrow phase changes as flame-engine#4045, rebased on
feat/path-shapesso the path contour hitboxes benefit from them right away. None of it depends on the path work, so this can also just be picked up by merging main once the upstream PR lands.Only test the edges inside the overlapping area.
ShapeHitbox.intersectionsnow passes the overlap of the two AABBs, inflated by the existing 0.01 tolerance, to the intersection systems. They already knew how to filter edges by a rect throughpossibleIntersectionVerticesbut never received one.Allocation-free segment intersection with a bounding box early out.
LineSegment.intersectionsrejects pairs whose bounding boxes do not overlap before doing any math and no longer allocatesLineobjects or result lists for misses.Measured with the benchmark from #3 on this branch, milliseconds per 20 ticks in JIT, 50 hitboxes of each kind:
The path hitbox is the flame logo sampled at granularity 1.0, 37 vertices at 60 pixels, and the polygon is the same logo hand-written with its 10 anchor points. #5 is stacked on this PR and continues from these numbers.
Note that
classifies a concave polygon with multiple crossings correctlyinpolygon_ray_intersection_test.dartfails onfeat/path-shapesbefore this change as well: it expects the old one-crossing heuristic while the branch switched to odd parity.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?