From daffbde80b9c0bc43169f4ded4daf0b7820c4cef Mon Sep 17 00:00:00 2001 From: timkeane Date: Thu, 25 Oct 2018 17:53:42 -0400 Subject: [PATCH 1/5] ol/geom/Point#containsXY --- src/ol/geom/Point.js | 10 ++++++++++ test/spec/ol/geom/point.test.js | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js index 92b27d6a0e..d4a798ffc5 100644 --- a/src/ol/geom/Point.js +++ b/src/ol/geom/Point.js @@ -35,6 +35,16 @@ class Point extends SimpleGeometry { return point; } + /** + * @inheritDoc + * @override + * @api + */ + containsXY(x, y) { + const coord = this.getCoordinates(); + return coord[0] === x && coord[1] === y; + } + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/point.test.js b/test/spec/ol/geom/point.test.js index 0f9e4e9aa6..3865b5ccd5 100644 --- a/test/spec/ol/geom/point.test.js +++ b/test/spec/ol/geom/point.test.js @@ -215,4 +215,22 @@ describe('ol.geom.Point', function() { }); + describe('#containsXY()', function() { + + it('does contain XY', function() { + const point = new Point([1, 2]); + + expect(point.containsXY(1, 2)).to.be(true); + }); + + it('does not contain XY', function() { + const point = new Point([1, 2]); + + expect(point.containsXY(1, 3)).to.be(false); + expect(point.containsXY(2, 2)).to.be(false); + expect(point.containsXY(2, 3)).to.be(false); + }); + + }); + }); From 58b474225c276b5479036f2efe740356fec683d9 Mon Sep 17 00:00:00 2001 From: timkeane Date: Thu, 25 Oct 2018 18:28:51 -0400 Subject: [PATCH 2/5] ol/geom/MultiPoint#containsXY --- src/ol/geom/MultiPoint.js | 11 +++++++++++ test/spec/ol/geom/multipoint.test.js | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index e433e51bf3..65a88f4283 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -57,6 +57,17 @@ class MultiPoint extends SimpleGeometry { return multiPoint; } + /** + * @inheritDoc + * @override + * @api + */ + containsXY(x, y) { + return this.getCoordinates().some(function(coord) { + return coord[0] === x && coord[1] === y; + }); + } + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/multipoint.test.js b/test/spec/ol/geom/multipoint.test.js index bdbb32533c..206eb8dd5f 100644 --- a/test/spec/ol/geom/multipoint.test.js +++ b/test/spec/ol/geom/multipoint.test.js @@ -287,4 +287,27 @@ describe('ol.geom.MultiPoint', function() { }); + describe('#containsXY()', function() { + + it('does contain XY', function() { + const multi = new MultiPoint([[1, 2], [10, 20]]); + + expect(multi.containsXY(1, 2)).to.be(true); + expect(multi.containsXY(10, 20)).to.be(true); + }); + + it('does not contain XY', function() { + const multi = new MultiPoint([[1, 2], [10, 20]]); + + expect(multi.containsXY(1, 3)).to.be(false); + expect(multi.containsXY(2, 2)).to.be(false); + expect(multi.containsXY(2, 3)).to.be(false); + + expect(multi.containsXY(10, 30)).to.be(false); + expect(multi.containsXY(20, 20)).to.be(false); + expect(multi.containsXY(20, 30)).to.be(false); + }); + + }); + }); From c1963ba36995cbcde1fdcd5c11f4f626d49d2c97 Mon Sep 17 00:00:00 2001 From: timkeane Date: Thu, 25 Oct 2018 18:53:33 -0400 Subject: [PATCH 3/5] ol/geom/LineString#containsXY --- src/ol/geom/LineString.js | 10 +++++++++ test/spec/ol/geom/linestring.test.js | 33 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 0fe7da857b..b21c0bb44c 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -88,6 +88,16 @@ class LineString extends SimpleGeometry { return new LineString(this.flatCoordinates.slice(), this.layout); } + /** + * @inheritDoc + * @override + * @api + */ + containsXY(x, y) { + const coord = this.getClosestPoint([x, y]); + return coord[0] === x && coord[1] === y; + } + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/linestring.test.js b/test/spec/ol/geom/linestring.test.js index 70968b30a0..a4c7892bca 100644 --- a/test/spec/ol/geom/linestring.test.js +++ b/test/spec/ol/geom/linestring.test.js @@ -443,4 +443,37 @@ describe('ol.geom.LineString', function() { }); + describe('#containsXY()', function() { + + let lineString; + beforeEach(function() { + lineString = new LineString([ + [0, 0, 0, 0], + [1, -1, 2, 1], + [2, -2, 4, 2], + [4, -4, 8, 4], + [8, -8, 16, 8], + [12, -12, 24, 12], + [14, -14, 28, 14], + [15, -15, 30, 15], + [16, -16, 32, 16], + [18, -18, 36, 18], + [22, -22, 44, 22] + ]); + }); + + it('does contain XY', function() { + expect(lineString.containsXY(1, -1)).to.be(true); + expect(lineString.containsXY(16, -16)).to.be(true); + expect(lineString.containsXY(3, -3)).to.be(true); + }); + + it('does not contain XY', function() { + expect(lineString.containsXY(1, 3)).to.be(false); + expect(lineString.containsXY(2, 2)).to.be(false); + expect(lineString.containsXY(2, 3)).to.be(false); + }); + + }); + }); From 5967bc75ba235d7f797c00b2f2b231735a13a656 Mon Sep 17 00:00:00 2001 From: timkeane Date: Thu, 25 Oct 2018 19:15:05 -0400 Subject: [PATCH 4/5] ol/geom/MultiLineString#containsXY --- src/ol/geom/MultiLineString.js | 11 ++++++++++ test/spec/ol/geom/multilinestring.test.js | 26 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 449338bf1b..bd4b31e4ba 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -100,6 +100,17 @@ class MultiLineString extends SimpleGeometry { return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice()); } + /** + * @inheritDoc + * @override + * @api + */ + containsXY(x, y) { + return this.getLineStrings().some(function(lineString) { + return lineString.containsXY(x, y); + }); + } + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/multilinestring.test.js b/test/spec/ol/geom/multilinestring.test.js index e497d21db6..9b4b9302a9 100644 --- a/test/spec/ol/geom/multilinestring.test.js +++ b/test/spec/ol/geom/multilinestring.test.js @@ -355,4 +355,30 @@ describe('ol.geom.MultiLineString', function() { }); }); + describe('#containsXY()', function() { + + let multiLineString; + beforeEach(function() { + multiLineString = new MultiLineString( + [[[1, 2, 3], [4, 5, 6]], [[-1, -1, 9], [2, 2, 12]]]); + }); + + it('does contain XY', function() { + expect(multiLineString.containsXY(1, 2)).to.be(true); + expect(multiLineString.containsXY(4, 5)).to.be(true); + expect(multiLineString.containsXY(3, 4)).to.be(true); + + expect(multiLineString.containsXY(-1, -1)).to.be(true); + expect(multiLineString.containsXY(2, 2)).to.be(true); + expect(multiLineString.containsXY(0, 0)).to.be(true); + }); + + it('does not contain XY', function() { + expect(multiLineString.containsXY(1, 3)).to.be(false); + expect(multiLineString.containsXY(2, 11)).to.be(false); + expect(multiLineString.containsXY(-2, 3)).to.be(false); + }); + + }); + }); From 7274798aa1244a12b11611b8eef2b173f2489b6a Mon Sep 17 00:00:00 2001 From: timkeane Date: Fri, 9 Nov 2018 07:58:04 -0500 Subject: [PATCH 5/5] Implement ol/geom/Geometry#containsXY Fixes issue #8863 ol/source/Vector#getFeaturesAtCoordinate and implementations of ol/geom/Geometry#containsXY --- src/ol/geom/Geometry.js | 3 ++- src/ol/geom/LineString.js | 10 ---------- src/ol/geom/MultiLineString.js | 11 ----------- src/ol/geom/MultiPoint.js | 11 ----------- src/ol/geom/Point.js | 10 ---------- 5 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/ol/geom/Geometry.js b/src/ol/geom/Geometry.js index 540559670d..5886ca90fe 100644 --- a/src/ol/geom/Geometry.js +++ b/src/ol/geom/Geometry.js @@ -92,7 +92,8 @@ class Geometry extends BaseObject { * @return {boolean} Contains (x, y). */ containsXY(x, y) { - return false; + const coord = this.getClosestPoint([x, y]); + return coord[0] === x && coord[1] === y; } /** diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index b21c0bb44c..0fe7da857b 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -88,16 +88,6 @@ class LineString extends SimpleGeometry { return new LineString(this.flatCoordinates.slice(), this.layout); } - /** - * @inheritDoc - * @override - * @api - */ - containsXY(x, y) { - const coord = this.getClosestPoint([x, y]); - return coord[0] === x && coord[1] === y; - } - /** * @inheritDoc */ diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index bd4b31e4ba..449338bf1b 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -100,17 +100,6 @@ class MultiLineString extends SimpleGeometry { return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice()); } - /** - * @inheritDoc - * @override - * @api - */ - containsXY(x, y) { - return this.getLineStrings().some(function(lineString) { - return lineString.containsXY(x, y); - }); - } - /** * @inheritDoc */ diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index 65a88f4283..e433e51bf3 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -57,17 +57,6 @@ class MultiPoint extends SimpleGeometry { return multiPoint; } - /** - * @inheritDoc - * @override - * @api - */ - containsXY(x, y) { - return this.getCoordinates().some(function(coord) { - return coord[0] === x && coord[1] === y; - }); - } - /** * @inheritDoc */ diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js index d4a798ffc5..92b27d6a0e 100644 --- a/src/ol/geom/Point.js +++ b/src/ol/geom/Point.js @@ -35,16 +35,6 @@ class Point extends SimpleGeometry { return point; } - /** - * @inheritDoc - * @override - * @api - */ - containsXY(x, y) { - const coord = this.getCoordinates(); - return coord[0] === x && coord[1] === y; - } - /** * @inheritDoc */