nearestRectangle method
Implementation
Rectangle<num>? nearestRectangle(
List<Rectangle<num>> rectangles, Point<num> p) {
if (rectangles.isEmpty) return null;
Rectangle<num>? nearest;
double? nearestDistance;
for (var rect in rectangles) {
var rectCenter = getRectangleCenter(rect);
var distance = rectCenter.distanceTo(p);
if (nearestDistance == null || distance < nearestDistance) {
nearest = rect;
nearestDistance = distance;
}
}
return nearest;
}