mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 08:17:30 +02:00
Less strict polygon intersection test in findOuter (closes #2755)
This commit is contained in:
@@ -506,8 +506,6 @@ en:
|
||||
deciduous: Deciduous
|
||||
# leaf_cycle=evergreen
|
||||
evergreen: Evergreen
|
||||
# leaf_cycle=mixed
|
||||
mixed: Mixed
|
||||
# leaf_cycle=semi_deciduous
|
||||
semi_deciduous: Semi-Deciduous
|
||||
# leaf_cycle=semi_evergreen
|
||||
@@ -532,8 +530,6 @@ en:
|
||||
broadleaved: Broadleaved
|
||||
# leaf_type=leafless
|
||||
leafless: Leafless
|
||||
# leaf_type=mixed
|
||||
mixed: Mixed
|
||||
# leaf_type=needleleaved
|
||||
needleleaved: Needleleaved
|
||||
leisure:
|
||||
|
||||
@@ -682,8 +682,7 @@
|
||||
"evergreen": "Evergreen",
|
||||
"deciduous": "Deciduous",
|
||||
"semi_evergreen": "Semi-Evergreen",
|
||||
"semi_deciduous": "Semi-Deciduous",
|
||||
"mixed": "Mixed"
|
||||
"semi_deciduous": "Semi-Deciduous"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -708,7 +707,6 @@
|
||||
"options": {
|
||||
"broadleaved": "Broadleaved",
|
||||
"needleleaved": "Needleleaved",
|
||||
"mixed": "Mixed",
|
||||
"leafless": "Leafless"
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-3
@@ -1019,8 +1019,7 @@
|
||||
"evergreen": "Evergreen",
|
||||
"deciduous": "Deciduous",
|
||||
"semi_evergreen": "Semi-Evergreen",
|
||||
"semi_deciduous": "Semi-Deciduous",
|
||||
"mixed": "Mixed"
|
||||
"semi_deciduous": "Semi-Deciduous"
|
||||
}
|
||||
},
|
||||
"leaf_type": {
|
||||
@@ -1037,7 +1036,6 @@
|
||||
"options": {
|
||||
"broadleaved": "Broadleaved",
|
||||
"needleleaved": "Needleleaved",
|
||||
"mixed": "Mixed",
|
||||
"leafless": "Leafless"
|
||||
}
|
||||
},
|
||||
|
||||
+8
-4
@@ -192,7 +192,7 @@ iD.geo.polygonContainsPolygon = function(outer, inner) {
|
||||
});
|
||||
};
|
||||
|
||||
iD.geo.polygonIntersectsPolygon = function(outer, inner) {
|
||||
iD.geo.polygonIntersectsPolygon = function(outer, inner, checkSegments) {
|
||||
function testSegments(outer, inner) {
|
||||
for (var i = 0; i < outer.length - 1; i++) {
|
||||
for (var j = 0; j < inner.length - 1; j++) {
|
||||
@@ -204,9 +204,13 @@ iD.geo.polygonIntersectsPolygon = function(outer, inner) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _.some(inner, function(point) {
|
||||
return iD.geo.pointInPolygon(point, outer);
|
||||
}) || testSegments(outer, inner);
|
||||
function testPoints(outer, inner) {
|
||||
return _.some(inner, function(point) {
|
||||
return iD.geo.pointInPolygon(point, outer);
|
||||
});
|
||||
}
|
||||
|
||||
return testPoints(outer, inner) || (!!checkSegments && testSegments(outer, inner));
|
||||
};
|
||||
|
||||
iD.geo.pathLength = function(path) {
|
||||
|
||||
@@ -159,7 +159,7 @@ iD.Background = function(context) {
|
||||
return _.union(coords, feature.geometry.type === 'Point' ? [c] : c);
|
||||
}, []);
|
||||
|
||||
if (!iD.geo.polygonIntersectsPolygon(viewport, coords)) {
|
||||
if (!iD.geo.polygonIntersectsPolygon(viewport, coords, true)) {
|
||||
var extent = iD.geo.Extent(d3.geo.bounds(gpxLayer.geojson()));
|
||||
map.centerZoom(extent.center(), map.trimmedExtentZoom(extent));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ iD.BackgroundSource = function(data) {
|
||||
source.intersects = function(extent) {
|
||||
extent = extent.polygon();
|
||||
return !data.polygon || data.polygon.some(function(polygon) {
|
||||
return iD.geo.polygonIntersectsPolygon(polygon, extent);
|
||||
return iD.geo.polygonIntersectsPolygon(polygon, extent, true);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+11
-5
@@ -288,25 +288,31 @@ describe('iD.geo', function() {
|
||||
});
|
||||
|
||||
describe('.polygonIntersectsPolygon', function() {
|
||||
it('says a polygon in a polygon intersects it', function() {
|
||||
it('returns true when outer polygon fully contains inner', 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 some points are contained', function() {
|
||||
it('returns true when outer polygon partially contains inner (some vertices 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() {
|
||||
it('returns false when outer polygon partially contains inner (no vertices contained - lax test)', 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;
|
||||
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.false;
|
||||
});
|
||||
|
||||
it('says totally disjoint polygons do not intersect', function() {
|
||||
it('returns true when outer polygon partially contains inner (no vertices contained - strict test)', 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, true)).to.be.true;
|
||||
});
|
||||
|
||||
it('returns false when outer and inner are fully disjoint', 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.false;
|
||||
|
||||
Reference in New Issue
Block a user