mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:09:16 +00:00
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:
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user