mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 08:17:30 +02:00
+12
-1
@@ -180,9 +180,20 @@ iD.geo.polygonContainsPolygon = function(outer, inner) {
|
||||
};
|
||||
|
||||
iD.geo.polygonIntersectsPolygon = function(outer, inner) {
|
||||
function testSegments(outer, inner) {
|
||||
for (var i = 0; i < outer.length - 1; i++) {
|
||||
for (var j = 0; j < inner.length - 1; j++) {
|
||||
var a = [ outer[i], outer[i+1] ],
|
||||
b = [ inner[j], inner[j+1] ];
|
||||
if (iD.geo.lineIntersection(a, b)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return _.some(inner, function(point) {
|
||||
return iD.geo.pointInPolygon(point, outer);
|
||||
});
|
||||
}) || testSegments(outer, inner);
|
||||
};
|
||||
|
||||
iD.geo.pathLength = function(path) {
|
||||
|
||||
+7
-1
@@ -294,12 +294,18 @@ describe('iD.geo', function() {
|
||||
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
|
||||
});
|
||||
|
||||
it('says a polygon that partially intersects does', function() {
|
||||
it('says a polygon that partially intersects does when some points are contained', function() {
|
||||
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
|
||||
var inner = [[-1, -1], [1, 2], [2, 2], [2, 1], [1, 1]];
|
||||
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
|
||||
});
|
||||
|
||||
it('says a polygon that partially intersects does when no points are contained', function() {
|
||||
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
|
||||
var inner = [[1, -1], [1, 4], [2, 4], [2, -1], [1, -1]];
|
||||
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
|
||||
});
|
||||
|
||||
it('says totally disjoint polygons do not intersect', function() {
|
||||
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
|
||||
var inner = [[-1, -1], [-1, -2], [-2, -2], [-2, -1], [-1, -1]];
|
||||
|
||||
Reference in New Issue
Block a user