nearestPoint method

Point<num>? nearestPoint(
  1. List<Point<num>>? points,
  2. Point<num> p
)

Implementation

Point<num>? nearestPoint(List<Point<num>>? points, Point<num> p) {
  if (points == null || points.isEmpty) return null;

  Point<num>? nearest;
  double? nearestDistance;

  for (var point in points) {
    var distance = point.distanceTo(p);
    if (nearestDistance == null || distance < nearestDistance) {
      nearest = point;
      nearestDistance = distance;
    }
  }

  return nearest;
}