⚡ Optimize AABB-Polygon intersection with early bounds rejection#11
Conversation
Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
AABB.Intersects(Polygon2D)by evaluating the polygon's min/max bounds on the fly against the AABB's bounds.AABB.Intersects(Polygon2D)returnedfalseif the AABB was completely inside the polygon (added apolygon.Contains(Center)check as a fallback).GameUtils.Benchmarksproject to establish baseline measurements usingBenchmarkDotNet.GameUtils.Tests.Geometry.AABBTeststo verify all intersection edge cases.🎯 Why:
The previous implementation iterated through all vertices and edges of a polygon regardless of how far apart the shapes were. By first calculating and checking against the polygon's bounding box, we drastically reduce the work required for shapes that don't intersect, solving the performance bottleneck on collision hot paths. The bug where a contained AABB did not register an intersection was also resolved to ensure mathematical correctness.
📊 Measured Improvement:
Using BenchmarkDotNet with 4 scenarios (Inside, Intersecting, Outside, ContainsAABB):
PR created automatically by Jules for task 5602852543587852411 started by @johnstrand