possibleIntersectionVertices method

List<LineSegment> possibleIntersectionVertices(
  1. Rect? rect
)

Return all edges of all polygons as LineSegments that intersect rect, if rect is null return all edges as LineSegments.

Implementation

List<LineSegment> possibleIntersectionVertices(Rect? rect) {
  final rectIntersections = <LineSegment>[];
  if ((rect?.width == 0 || false) ||
      (rect?.height == 0 || false) ||
      width == 0 ||
      height == 0) {
    return rectIntersections;
  }
  final polygons = globalPolygons();
  for (var i = 0; i < polygons.length; i++) {
    final vertices = polygons[i];
    final lineSegments = _lineSegments[i];
    for (var j = 0; j < vertices.length; j++) {
      final edge = lineSegments[j]
        ..from.setFrom(vertices[j])
        ..to.setFrom(vertices[(j + 1) % vertices.length]);
      if (rect?.intersectsSegment(edge.from, edge.to) ?? true) {
        rectIntersections.add(edge);
      }
    }
  }
  return rectIntersections;
}