mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 01:33:03 +00:00
Split on self-intersections
This commit is contained in:
@@ -15,9 +15,17 @@ iD.actions.Split = function(nodeId, newWayIds) {
|
||||
parents = graph.parentWays(node);
|
||||
|
||||
return parents.filter(function(parent) {
|
||||
return parent.isClosed() ||
|
||||
(parent.first() !== nodeId &&
|
||||
parent.last() !== nodeId);
|
||||
if (parent.isClosed()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = 1; i < parent.nodes.length - 1; i++) {
|
||||
if (parent.nodes[i] === nodeId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,7 +49,7 @@ iD.actions.Split = function(nodeId, newWayIds) {
|
||||
nodesB = nodes.slice(idxB).concat(nodes.slice(0, idxA + 1));
|
||||
}
|
||||
} else {
|
||||
var idx = _.indexOf(wayA.nodes, nodeId);
|
||||
var idx = _.indexOf(wayA.nodes, nodeId, 1);
|
||||
nodesA = wayA.nodes.slice(0, idx + 1);
|
||||
nodesB = wayA.nodes.slice(idx);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,18 @@ describe("iD.actions.Split", function () {
|
||||
expect(iD.actions.Split('*').disabled(graph)).not.to.be.ok;
|
||||
});
|
||||
|
||||
it("returns falsy for a self-intersection", function () {
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
'b': iD.Node({id: 'b'}),
|
||||
'c': iD.Node({id: 'c'}),
|
||||
'd': iD.Node({id: 'c'}),
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']})
|
||||
});
|
||||
|
||||
expect(iD.actions.Split('a').disabled(graph)).not.to.be.ok;
|
||||
});
|
||||
|
||||
it("returns 'not_eligible' for the first node of a single way", function () {
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
@@ -148,6 +160,35 @@ describe("iD.actions.Split", function () {
|
||||
expect(graph.entity('¦').nodes).to.eql(['*', 'd']);
|
||||
});
|
||||
|
||||
it("splits self-intersecting ways", function () {
|
||||
// Situation:
|
||||
// b
|
||||
// / |
|
||||
// / |
|
||||
// c - a -- d
|
||||
//
|
||||
// Split at a.
|
||||
//
|
||||
// Expected result:
|
||||
// b
|
||||
// / |
|
||||
// / |
|
||||
// c - a == d
|
||||
//
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
'b': iD.Node({id: 'b'}),
|
||||
'c': iD.Node({id: 'c'}),
|
||||
'd': iD.Node({id: 'c'}),
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c', 'a', 'd']})
|
||||
});
|
||||
|
||||
graph = iD.actions.Split('a', ['='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'a']);
|
||||
expect(graph.entity('=').nodes).to.eql(['a', 'd']);
|
||||
});
|
||||
|
||||
it("splits a closed way at the given point and its antipode", function () {
|
||||
// Situation:
|
||||
// a ---- b
|
||||
|
||||
Reference in New Issue
Block a user