getNearestPoint static method

Offset? getNearestPoint(
  1. List<Offset> points,
  2. Offset latestPoints
)

Get the nearest point.

Implementation

static Offset? getNearestPoint(List<Offset> points, Offset latestPoints) {
  Offset? nearestPoints;
  double threshold = 30;
  double nearestDistance = 10000;
  for (final Offset point in points) {
    double x = point.dx - latestPoints.dx;
    double y = point.dy - latestPoints.dy;
    double distance = sqrt((x * x) + (y * y)).abs();
    if (distance < nearestDistance && distance <= threshold) {
      nearestPoints = point;
      nearestDistance = distance;
    }
  }
  if (nearestPoints != null) return nearestPoints;
  return null;
}