feat!: Return a list instead of a set from the collision detection methods - #4003
Merged
Conversation
luanpotter
approved these changes
Aug 16, 2026
luanpotter
left a comment
Member
There was a problem hiding this comment.
I am not happy, but I accept
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 collision detection system previously passed the intersection points around as a
Set<Vector2>, which meant that every collision check in the hot loop had to hashVector2s and allocate hash sets. This PR changes all of these APIs to useList<Vector2>instead.The returned points are still guaranteed to be unique: the polygon and circle-polygon
intersection accumulation now deduplicates with a linear
containscheck (the pointlists are tiny, so this is cheaper than hashing), and tangent circles now explicitly
return a single point instead of relying on the set to collapse the two identical
solutions.
Changed APIs (all from
Set<Vector2>toList<Vector2>):CollisionCallbacks.onCollision/onCollisionStartand the corresponding methods onGenericCollisionCallbacks,ShapeHitboxandCollisionPassthrough, as well as theCollisionCallbacktypedef.CollisionDetection.intersections,handleCollisionStartandhandleCollision(and the
StandardCollisionDetectionoverrides).Hitbox.intersectionsandShapeHitbox.intersections.Intersections.intersect/unorderedIntersectand the top-levelintersectionsfunction in the geometry package.
Rectangle.intersections.Benchmarked the accumulation strategies against each other with the real intersection
workloads (200k iterations per case): the list version is roughly 2x faster for
circle-circle intersections, faster for overlapping axis-aligned rectangles (which
produce collinear duplicate candidates), and equal within noise for tilted polygons.
flame_behaviorsand all examples, docs and tutorials have been updated accordingly.Migration: change the
Set<Vector2> intersectionPointsparameter type toList<Vector2>inonCollision/onCollisionStartoverrides (and in customCollisionDetection/Hitboximplementations).Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Migration instructions
Replace
Set<Vector2>withList<Vector2>in youronCollisionandonCollisionStartoverrides and collision callbacks:
The same applies to custom
CollisionDetection,HitboxandIntersectionsimplementations, which now return
List<Vector2>from their intersection methods.The points in the list are still unique.
Related Issues
Closes #4001