[Pkg-javascript-commits] [leaflet-markercluster] 06/18: Make DistanceGrid cells closed sets

Jonas Smedegaard dr at jones.dk
Sat Jan 6 19:29:06 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 cc61460fcaf2bbccc79039d22fe8b5a5bff121d6
Author: Lucas Werkmeister <lucas.werkmeister at wikimedia.de>
Date:   Fri Nov 3 15:04:32 2017 +0100

    Make DistanceGrid cells closed sets
    
    If the closest object in a DistanceGrid lies exactly on the border of a
    cell, still return it in getNearObject(). In mathematical terms, this
    makes the cell a closed set (that is, a set which contains all of its
    boundary points).
    
    A test with two getNearObject() calls is added. The first expectation
    works with the old and the new behavior, the second expectation only
    succeeds with the new behavior.
---
 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 118dbec..ae3119f 100644
--- a/spec/suites/DistanceGridSpec.js
+++ b/spec/suites/DistanceGridSpec.js
@@ -18,4 +18,14 @@
 			done();
 		});
 	});
+
+	it('getNearObject', function () {
+		var grid = new L.DistanceGrid(100),
+			obj = {};
+
+		grid.addObject(obj, { x: 0, y: 0 });
+
+		expect(grid.getNearObject({ x: 50, y: 50 })).to.equal(obj);
+		expect(grid.getNearObject({ x: 100, y: 0 })).to.equal(obj);
+	});
 });
diff --git a/src/DistanceGrid.js b/src/DistanceGrid.js
index 5670c49..0f86c9c 100644
--- a/src/DistanceGrid.js
+++ b/src/DistanceGrid.js
@@ -92,7 +92,8 @@ L.DistanceGrid.prototype = {
 						for (k = 0, len = cell.length; k < len; k++) {
 							obj = cell[k];
 							dist = this._sqDist(objectPoint[L.Util.stamp(obj)], point);
-							if (dist < closestDistSq) {
+							if (dist < closestDistSq ||
+								dist <= closestDistSq && closest === null) {
 								closestDistSq = dist;
 								closest = obj;
 							}

-- 
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