mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 07:46:58 +02:00
Avoid consecutive identical nodes when adding a midpoint
Previously, adding a midpoint to an invalidly doubled-back segment (aba) resulted in a self-intersection with an invalid consecutive node (accba). Now a self-intersection is still produced, but with only one c node (acba). Refs #1296
This commit is contained in:
@@ -13,6 +13,10 @@ iD.actions.AddMidpoint = function(midpoint, node) {
|
||||
(way.nodes[i] === midpoint.edge[1] &&
|
||||
way.nodes[i + 1] === midpoint.edge[0])) {
|
||||
graph = graph.replace(graph.entity(way.id).addNode(node.id, i + 1));
|
||||
|
||||
// Add only one midpoint on doubled-back segments,
|
||||
// turning them into self-intersections.
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -34,4 +34,21 @@ describe("iD.actions.AddMidpoint", function () {
|
||||
expect(graph.entity(w1.id).nodes).to.eql([]);
|
||||
expect(graph.entity(w2.id).nodes).to.eql([b.id, node.id, a.id]);
|
||||
});
|
||||
|
||||
it("turns an invalid double-back into a self-intersection", function () {
|
||||
// a====b (aba)
|
||||
// Expected result (converts to a valid loop):
|
||||
// a---b (acba)
|
||||
// \ /
|
||||
// c
|
||||
|
||||
var a = iD.Node(),
|
||||
b = iD.Node(),
|
||||
c = iD.Node(),
|
||||
w = iD.Way({nodes: [a.id, b.id, a.id]}),
|
||||
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
|
||||
graph = iD.actions.AddMidpoint(midpoint, c)(iD.Graph([a, b, w]));
|
||||
|
||||
expect(graph.entity(w.id).nodes).to.eql([a.id, c.id, b.id, a.id]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user