Return early on an exact match in getClosestPointTo()

If a point at squared distance 0 is found, no closer point can exist, so
return it immediately instead of scanning the rest of the points. The
returned point is the same as before, since the first point with the
smallest distance was already the one kept.
This commit is contained in:
Fabio Pedretti authored and Phosit committed 2026-10-12 16:24:13 +02:00
1 parent dda1e6c1a3
commit 36eb25de3a
1 file changed
+3
@@ -38,6 +38,9 @@ Area.prototype.getClosestPointTo = function(position)
const currentDistance = point.distanceToSquared(position);
if (currentDistance < shortestDistance)
{
if (currentDistance === 0)
return point;
shortestDistance = currentDistance;
closestPoint = point;
}