mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 05:49:16 +02:00
Merge pull request #5745 from jguthrie100/stop_merge_overlapping_self
Add check to stop joining ways if resulting way intersects itself
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _groupBy from 'lodash-es/groupBy';
|
||||
import _intersection from 'lodash-es/intersection';
|
||||
|
||||
import { actionDeleteWay } from './delete_way';
|
||||
import { osmIsInterestingTag, osmJoinWays } from '../osm';
|
||||
import { geoPathIntersections } from '../geo';
|
||||
|
||||
|
||||
// Join ways at the end node they share.
|
||||
@@ -70,6 +72,27 @@ export function actionJoin(ids) {
|
||||
if (joined.length > 1)
|
||||
return 'not_adjacent';
|
||||
|
||||
// Loop through all combinations of path-pairs to check potential intersections
|
||||
// between all pairs
|
||||
for (var i = 0; i < ids.length-1; i++) {
|
||||
for (var j = i+1; j < ids.length; j++) {
|
||||
var path1 = graph.childNodes(graph.entity(ids[i])).map(function(e) {
|
||||
return e.loc;
|
||||
});
|
||||
var path2 = graph.childNodes(graph.entity(ids[j])).map(function(e) {
|
||||
return e.loc;
|
||||
});
|
||||
var intersections = geoPathIntersections(path1, path2);
|
||||
|
||||
// Check if intersections are just nodes lying on top of each other/the line,
|
||||
// as opposed to crossing it
|
||||
if (_intersection(
|
||||
joined[0].nodes.map(function(n) { return n.loc.toString(); }),
|
||||
intersections.map(function(n) { return n.toString(); })
|
||||
).length !== intersections.length) return 'paths_intersect';
|
||||
}
|
||||
}
|
||||
|
||||
var nodeIds = joined[0].nodes.map(function(n) { return n.id; }).slice(1, -1);
|
||||
var relation;
|
||||
var tags = {};
|
||||
|
||||
Reference in New Issue
Block a user