lineToRect static method

bool lineToRect(
  1. Line line,
  2. AABB rect
)

Implementation

static bool lineToRect(Line line, AABB rect) {
  if (pointToRect(line.p1, rect) || pointToRect(line.p2, rect)) return true;

  final top = Line(p1: Vec2(rect.left, rect.top), p2: Vec2(rect.right, rect.top));
  final bottom = Line(p1: Vec2(rect.left, rect.bottom), p2: Vec2(rect.right, rect.bottom));
  final left = Line(p1: Vec2(rect.left, rect.top), p2: Vec2(rect.left, rect.bottom));
  final right = Line(p1: Vec2(rect.right, rect.top), p2: Vec2(rect.right, rect.bottom));

  return lineToLine(line, top) ||
      lineToLine(line, bottom) ||
      lineToLine(line, left) ||
      lineToLine(line, right);
}