containsPoint method

bool containsPoint(
  1. Vector2 point, {
  2. double epsilon = 0.000001,
})

Implementation

bool containsPoint(Vector2 point, {double epsilon = 0.000001}) {
  final delta = to - from;
  final crossProduct =
      (point.y - from.y) * delta.x - (point.x - from.x) * delta.y;

  // compare versus epsilon for floating point values
  if (crossProduct.abs() > epsilon) {
    return false;
  }

  final dotProduct =
      (point.x - from.x) * delta.x + (point.y - from.y) * delta.y;
  if (dotProduct < 0) {
    return false;
  }

  final squaredLength = from.distanceToSquared(to);
  if (dotProduct > squaredLength) {
    return false;
  }

  return true;
}