pointToLine static method

bool pointToLine(
  1. Vec2 p,
  2. Line line, [
  3. double tolerance = 0.1
])

Implementation

static bool pointToLine(Vec2 p, Line line, [double tolerance = 0.1]) {
  if (p.x < line.left - tolerance ||
      p.x > line.right + tolerance ||
      p.y < line.top - tolerance ||
      p.y > line.bottom + tolerance) {
    return false;
  }

  final d1 = p.distanceTo(line.p1);
  final d2 = p.distanceTo(line.p2);
  final lineLen = line.p1.distanceTo(line.p2);

  return (d1 + d2 - lineLen).abs() <= tolerance;
}