intersect method

  1. @override
Set<Vector2> intersect(
  1. CircleComponent circle,
  2. PolygonComponent polygon, {
  3. 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;
}