[Pkg-javascript-commits] [leaflet-markercluster] 07/18: Support DistanceGrid with cell size 0
Jonas Smedegaard
dr at jones.dk
Sat Jan 6 19:29:07 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/1.2.0_dfsg-1
in repository leaflet-markercluster.
commit 17e8cb710a884fc185a771611776b718c3c359fe
Author: Lucas Werkmeister <lucas.werkmeister at wikimedia.de>
Date: Fri Nov 3 15:12:59 2017 +0100
Support DistanceGrid with cell size 0
For extremely small cell sizes, fall back to returning the original
coordinate in _getCoord(), instead of Infinity. Together with the
previous change, this groups objects with identical coordinates into the
same cell and therefore fixes #836 for maxClusterRadius values like 0 or
Number.MIN_VALUE. (However, Number.EPSILON is actually large enough that
dividing normal values for x by it does not yet yield Infinity, so in
that case the bug persists.)
We use isFinite() instead of Number.isFinite() because the latter is not
as widely supported (in particular, it doesn’t work in `jake test`).
Since the argument is the result of Math.floor, it should always be a
number, so the difference should not matter.
---
spec/suites/DistanceGridSpec.js | 10 ++++++++++
src/DistanceGrid.js | 3 ++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/spec/suites/DistanceGridSpec.js b/spec/suites/DistanceGridSpec.js
index ae3119f..cc364f0 100644
--- a/spec/suites/DistanceGridSpec.js
+++ b/spec/suites/DistanceGridSpec.js
@@ -28,4 +28,14 @@
expect(grid.getNearObject({ x: 50, y: 50 })).to.equal(obj);
expect(grid.getNearObject({ x: 100, y: 0 })).to.equal(obj);
});
+
+ it('getNearObject with cellSize 0', function () {
+ var grid = new L.DistanceGrid(0),
+ obj = {};
+
+ grid.addObject(obj, { x: 0, y: 0 });
+
+ expect(grid.getNearObject({ x: 50, y: 50 })).to.equal(null);
+ expect(grid.getNearObject({ x: 0, y: 0 })).to.equal(obj);
+ });
});
diff --git a/src/DistanceGrid.js b/src/DistanceGrid.js
index 0f86c9c..eee7411 100644
--- a/src/DistanceGrid.js
+++ b/src/DistanceGrid.js
@@ -106,7 +106,8 @@ L.DistanceGrid.prototype = {
},
_getCoord: function (x) {
- return Math.floor(x / this._cellSize);
+ var coord = Math.floor(x / this._cellSize);
+ return isFinite(coord) ? coord : x;
},
_sqDist: function (p, p2) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git
More information about the Pkg-javascript-commits
mailing list