findClosesPointOnPolygon static method

int findClosesPointOnPolygon(
  1. Vector2 circleCenter,
  2. List<Vector2> vertices
)

Implementation

static int findClosesPointOnPolygon(
  Vector2 circleCenter,
  List<Vector2> vertices,
) {
  int result = -1;
  double minDistance = double.maxFinite;

  for (int i = 0; i < vertices.length; i++) {
    Vector2 v = vertices[i];
    double distance = v.distanceTo(circleCenter);

    if (distance < minDistance) {
      minDistance = distance;
      result = i;
    }
  }

  return result;
}