From 9074bd9783155fbbbfbe8df0da6ac727f9bcdd27 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 23 Aug 2016 14:36:09 +0200 Subject: [PATCH 1/2] Rename ol.geom.Geometry#containsCoordinate to intersectsCoordinate --- src/ol/geom/circle.js | 2 +- src/ol/geom/geometry.js | 4 +++- src/ol/source/vector.js | 2 +- test/spec/ol/geom/circle.test.js | 28 ++++++++++++++-------------- test/spec/ol/geom/polygon.test.js | 26 +++++++++++++------------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/ol/geom/circle.js b/src/ol/geom/circle.js index 2706d926cf..3df88b5e9d 100644 --- a/src/ol/geom/circle.js +++ b/src/ol/geom/circle.js @@ -149,7 +149,7 @@ ol.geom.Circle.prototype.intersectsExtent = function(extent) { return true; } - return ol.extent.forEachCorner(extent, this.containsCoordinate, this); + return ol.extent.forEachCorner(extent, this.intersectsCoordinate, this); } return false; diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index f503f79226..346e9afa5e 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -129,10 +129,12 @@ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) { /** + * Returns true if this geometry includes the specified coordinate. If the + * coordinate is on the boundary of the geometry, returns false. * @param {ol.Coordinate} coordinate Coordinate. * @return {boolean} Contains coordinate. */ -ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) { +ol.geom.Geometry.prototype.intersectsCoordinate = function(coordinate) { return this.containsXY(coordinate[0], coordinate[1]); }; diff --git a/src/ol/source/vector.js b/src/ol/source/vector.js index a12c7bb089..8f5e0949db 100644 --- a/src/ol/source/vector.js +++ b/src/ol/source/vector.js @@ -452,7 +452,7 @@ ol.source.Vector.prototype.forEachFeatureAtCoordinateDirect = function(coordinat return this.forEachFeatureInExtent(extent, function(feature) { var geometry = feature.getGeometry(); goog.DEBUG && console.assert(geometry, 'feature geometry is defined and not null'); - if (geometry.containsCoordinate(coordinate)) { + if (geometry.intersectsCoordinate(coordinate)) { return callback.call(opt_this, feature); } else { return undefined; diff --git a/test/spec/ol/geom/circle.test.js b/test/spec/ol/geom/circle.test.js index 0118f7af64..67c950974c 100644 --- a/test/spec/ol/geom/circle.test.js +++ b/test/spec/ol/geom/circle.test.js @@ -24,31 +24,31 @@ describe('ol.geom.Circle', function() { }); - describe('#containsCoordinate', function() { + describe('#intersectsCoordinate', function() { it('contains the center', function() { - expect(circle.containsCoordinate([0, 0])).to.be(true); + expect(circle.intersectsCoordinate([0, 0])).to.be(true); }); it('contains points inside the perimeter', function() { - expect(circle.containsCoordinate([0.5, 0.5])).to.be(true); - expect(circle.containsCoordinate([-0.5, 0.5])).to.be(true); - expect(circle.containsCoordinate([-0.5, -0.5])).to.be(true); - expect(circle.containsCoordinate([0.5, -0.5])).to.be(true); + expect(circle.intersectsCoordinate([0.5, 0.5])).to.be(true); + expect(circle.intersectsCoordinate([-0.5, 0.5])).to.be(true); + expect(circle.intersectsCoordinate([-0.5, -0.5])).to.be(true); + expect(circle.intersectsCoordinate([0.5, -0.5])).to.be(true); }); it('contains points on the perimeter', function() { - expect(circle.containsCoordinate([1, 0])).to.be(true); - expect(circle.containsCoordinate([0, 1])).to.be(true); - expect(circle.containsCoordinate([-1, 0])).to.be(true); - expect(circle.containsCoordinate([0, -1])).to.be(true); + expect(circle.intersectsCoordinate([1, 0])).to.be(true); + expect(circle.intersectsCoordinate([0, 1])).to.be(true); + expect(circle.intersectsCoordinate([-1, 0])).to.be(true); + expect(circle.intersectsCoordinate([0, -1])).to.be(true); }); it('does not contain points outside the perimeter', function() { - expect(circle.containsCoordinate([2, 0])).to.be(false); - expect(circle.containsCoordinate([1, 1])).to.be(false); - expect(circle.containsCoordinate([-2, 0])).to.be(false); - expect(circle.containsCoordinate([0, -2])).to.be(false); + expect(circle.intersectsCoordinate([2, 0])).to.be(false); + expect(circle.intersectsCoordinate([1, 1])).to.be(false); + expect(circle.intersectsCoordinate([-2, 0])).to.be(false); + expect(circle.intersectsCoordinate([0, -2])).to.be(false); }); }); diff --git a/test/spec/ol/geom/polygon.test.js b/test/spec/ol/geom/polygon.test.js index 06bb1785ef..4aacf6ad2f 100644 --- a/test/spec/ol/geom/polygon.test.js +++ b/test/spec/ol/geom/polygon.test.js @@ -113,15 +113,15 @@ describe('ol.geom.Polygon', function() { }); it('does not contain outside coordinates', function() { - expect(polygon.containsCoordinate(outsideOuter)).to.be(false); + expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false); }); it('does contain inside coordinates', function() { - expect(polygon.containsCoordinate(inside)).to.be(true); + expect(polygon.intersectsCoordinate(inside)).to.be(true); }); it('does not contain inside inner coordinates', function() { - expect(polygon.containsCoordinate(insideInner)).to.be(false); + expect(polygon.intersectsCoordinate(insideInner)).to.be(false); }); describe('#getCoordinates()', function() { @@ -208,15 +208,15 @@ describe('ol.geom.Polygon', function() { }); it('does not contain outside coordinates', function() { - expect(polygon.containsCoordinate(outsideOuter)).to.be(false); + expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false); }); it('does contain inside coordinates', function() { - expect(polygon.containsCoordinate(inside)).to.be(true); + expect(polygon.intersectsCoordinate(inside)).to.be(true); }); it('does not contain inside inner coordinates', function() { - expect(polygon.containsCoordinate(insideInner)).to.be(false); + expect(polygon.intersectsCoordinate(insideInner)).to.be(false); }); describe('#intersectsExtent', function() { @@ -307,15 +307,15 @@ describe('ol.geom.Polygon', function() { }); it('does not contain outside coordinates', function() { - expect(polygon.containsCoordinate(outsideOuter)).to.be(false); + expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false); }); it('does contain inside coordinates', function() { - expect(polygon.containsCoordinate(inside)).to.be(true); + expect(polygon.intersectsCoordinate(inside)).to.be(true); }); it('does not contain inside inner coordinates', function() { - expect(polygon.containsCoordinate(insideInner)).to.be(false); + expect(polygon.intersectsCoordinate(insideInner)).to.be(false); }); describe('#intersectsExtent', function() { @@ -413,16 +413,16 @@ describe('ol.geom.Polygon', function() { }); it('does not contain outside coordinates', function() { - expect(polygon.containsCoordinate(outsideOuter)).to.be(false); + expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false); }); it('does contain inside coordinates', function() { - expect(polygon.containsCoordinate(inside)).to.be(true); + expect(polygon.intersectsCoordinate(inside)).to.be(true); }); it('does not contain inside inner coordinates', function() { - expect(polygon.containsCoordinate(insideInner1)).to.be(false); - expect(polygon.containsCoordinate(insideInner2)).to.be(false); + expect(polygon.intersectsCoordinate(insideInner1)).to.be(false); + expect(polygon.intersectsCoordinate(insideInner2)).to.be(false); }); describe('#intersectsExtent', function() { From 8d1a26dd5b3be8670b0448e2ccc3e4e6dd536fe1 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 23 Aug 2016 14:36:49 +0200 Subject: [PATCH 2/2] Export ol.geom.Geometry#intersectsCoordinate --- src/ol/geom/geometry.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index 346e9afa5e..256f78144d 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -133,6 +133,7 @@ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) { * coordinate is on the boundary of the geometry, returns false. * @param {ol.Coordinate} coordinate Coordinate. * @return {boolean} Contains coordinate. + * @api */ ol.geom.Geometry.prototype.intersectsCoordinate = function(coordinate) { return this.containsXY(coordinate[0], coordinate[1]);