isTwoLineSegmentsIntersect method Null safety

bool isTwoLineSegmentsIntersect(
  1. Line line1,
  2. Line line2
)

Check if 2 lines segments intersects

Implementation

static bool isTwoLineSegmentsIntersect(Line line1, Line line2) {
  final x1 = line1.x1;
  final x2 = line1.x2;
  final x3 = line2.x1;
  final x4 = line2.x2;

  final y1 = line1.y1;
  final y2 = line1.y2;
  final y3 = line2.y1;
  final y4 = line2.y2;

  final t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) /
      ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4));

  return t >= 0 && t <= 1;
}