mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-02 00:32:09 +02:00
Make getNearObject always return the closest point to make the clusters do stupid things less often
This commit is contained in:
+8
-5
@@ -74,7 +74,9 @@ L.DistanceGrid.prototype = {
|
|||||||
getNearObject: function (point) {
|
getNearObject: function (point) {
|
||||||
var x = this._getCoord(point.x),
|
var x = this._getCoord(point.x),
|
||||||
y = this._getCoord(point.y),
|
y = this._getCoord(point.y),
|
||||||
i, j, k, row, cell, len, obj;
|
i, j, k, row, cell, len, obj, dist,
|
||||||
|
closestDistSq = this._sqCellSize,
|
||||||
|
closest = null;
|
||||||
|
|
||||||
for (i = y - 1; i <= y + 1; i++) {
|
for (i = y - 1; i <= y + 1; i++) {
|
||||||
row = this._grid[i];
|
row = this._grid[i];
|
||||||
@@ -86,16 +88,17 @@ L.DistanceGrid.prototype = {
|
|||||||
|
|
||||||
for (k = 0, len = cell.length; k < len; k++) {
|
for (k = 0, len = cell.length; k < len; k++) {
|
||||||
obj = cell[k];
|
obj = cell[k];
|
||||||
if (this._sqDist(obj._dGridPoint, point) < this._sqCellSize) {
|
dist = this._sqDist(obj._dGridPoint, point);
|
||||||
return obj;
|
if (dist < closestDistSq) {
|
||||||
|
closestDistSq = dist;
|
||||||
|
closest = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return closest;
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_getCoord: function (x) {
|
_getCoord: function (x) {
|
||||||
|
|||||||
Reference in New Issue
Block a user