Merge pull request #4753 from fredj/export_contains
Export ol.geom.Geometry#containsCoordinate function
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -129,10 +129,13 @@ 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.
|
||||
* @api
|
||||
*/
|
||||
ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) {
|
||||
ol.geom.Geometry.prototype.intersectsCoordinate = function(coordinate) {
|
||||
return this.containsXY(coordinate[0], coordinate[1]);
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user