intersect method
Set<Vector2>
intersect(
- CircleComponent circle,
- PolygonComponent polygon, {
- Rect? overlappingRect,
override
Implementation
@override
Set<Vector2> intersect(
CircleComponent circle,
PolygonComponent polygon, {
Rect? overlappingRect,
}) {
final intersectionPoints = <Vector2>{};
final possibleVertices = polygon.possibleIntersectionVertices(
overlappingRect,
);
for (final line in possibleVertices) {
intersectionPoints.addAll(circle.lineSegmentIntersections(line));
}
if (intersectionPoints.isEmpty && (circle.isSolid || polygon.isSolid)) {
final outerShape = circle.containsPoint(polygon.globalVertices().first)
? circle
: (polygon.containsPoint(circle.absoluteCenter) ? polygon : null);
if (outerShape != null && outerShape.isSolid) {
final innerShape = outerShape == circle ? polygon : circle;
return {innerShape.absoluteCenter};
}
}
return intersectionPoints;
}