From 36eb25de3a8a84a230688792ae37e9131e2a9895 Mon Sep 17 00:00:00 2001 From: Fabio Pedretti Date: Mon, 5 Oct 2026 14:18:16 +0200 Subject: [PATCH] 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. --- binaries/data/mods/public/maps/random/rmgen/Area.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/binaries/data/mods/public/maps/random/rmgen/Area.js b/binaries/data/mods/public/maps/random/rmgen/Area.js index 2d8b97dd74..eb87f19b89 100644 --- a/binaries/data/mods/public/maps/random/rmgen/Area.js +++ b/binaries/data/mods/public/maps/random/rmgen/Area.js @@ -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; }