mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 13:38:26 +02:00
Removed pointInFeature
This commit is contained in:
@@ -135,33 +135,3 @@ iD.geo.pathLength = function(path) {
|
||||
}
|
||||
return length;
|
||||
};
|
||||
|
||||
iD.geo.pointInFeature = function(point, feature) {
|
||||
if (feature.bounds) {
|
||||
var bounds = feature.bounds;
|
||||
|
||||
if (point[0] < bounds[0][0] || point[0] > bounds[1][0] || point[1] < bounds[0][1] || point[1] > bounds[1][1])
|
||||
return false;
|
||||
}
|
||||
|
||||
if (feature.geometry.type === 'Polygon') {
|
||||
return _.every(feature.geometry.coordinates, function (ring, i) {
|
||||
if (i === 0)
|
||||
return iD.geo.pointInPolygon(point, ring);
|
||||
|
||||
return !iD.geo.pointInPolygon(point, ring);
|
||||
});
|
||||
}
|
||||
else if (feature.geometry.type === 'MultiPolygon') {
|
||||
return _.some(feature.geometry.coordinates, function (polygon) {
|
||||
return _.every(polygon, function (ring, i) {
|
||||
if (i === 0)
|
||||
return iD.geo.pointInPolygon(point, ring);
|
||||
|
||||
return !iD.geo.pointInPolygon(point, ring);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -223,52 +223,4 @@ describe('iD.geo', function() {
|
||||
expect(iD.geo.pathLength(path)).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.pointInFeature', function() {
|
||||
it('point should be in a polygon feature', function() {
|
||||
var feature = { geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] } };
|
||||
var point = [0.5, 0.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.true;
|
||||
});
|
||||
it('point should not be in a polygon feature with a hole', function() {
|
||||
var feature = { geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0.1, 0.1], [0.1, 0.9], [0.9, 0.9], [0.9, 0.1], [0.1, 0.1]]] } };
|
||||
var point = [0.5, 0.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.false;
|
||||
});
|
||||
it('point should be in a polygon feature with a hole', function() {
|
||||
var feature = { geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [[0.1, 0.1], [0.1, 0.9], [0.9, 0.9], [0.9, 0.1], [0.1, 0.1]]] } };
|
||||
var point = [0.05, 0.05];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.true;
|
||||
});
|
||||
it('point should be in a polygon feature with bounds', function() {
|
||||
var feature = { geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] }, bounds: [[0, 0], [1, 1]] };
|
||||
var point = [0.5, 0.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.true;
|
||||
});
|
||||
it('point should not be in a polygon feature with bounds', function() {
|
||||
var feature = { geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] }, bounds: [[0, 0], [1, 1]] };
|
||||
var point = [0.5, 1.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.false;
|
||||
});
|
||||
it('point should not be in a point feature', function() {
|
||||
var feature = { geometry: { type: 'Point', coordinates: [0, 0] } };
|
||||
var point = [0.5, 0.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.false;
|
||||
});
|
||||
it('point should be in a multipolygon feature', function() {
|
||||
var feature = { geometry: { type: 'MultiPolygon', coordinates: [[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], [[[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]]] } };
|
||||
var point = [0.5, 0.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.true;
|
||||
});
|
||||
it('point should be in a multipolygon feature in second polygon', function() {
|
||||
var feature = { geometry: { type: 'MultiPolygon', coordinates: [[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], [[[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]]] } };
|
||||
var point = [2.5, 2.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.true;
|
||||
});
|
||||
it('point should not be in a multipolygon feature', function() {
|
||||
var feature = { geometry: { type: 'MultiPolygon', coordinates: [[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], [[[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]]] } };
|
||||
var point = [0.5, 1.5];
|
||||
expect(iD.geo.pointInFeature(point, feature)).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user