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:
John Firebaugh
2013-09-01 12:56:08 -07:00
parent 3b16886574
commit e11ab9699d
2 changed files with 21 additions and 0 deletions
+4
View File
@@ -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;
}
}
});
+17
View File
@@ -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]);
});
});