Files
iD/js/id/actions/add_midpoint.js
T
John Firebaugh e11ab9699d 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
2013-09-01 12:57:10 -07:00

27 lines
980 B
JavaScript

iD.actions.AddMidpoint = function(midpoint, node) {
return function(graph) {
graph = graph.replace(node.move(midpoint.loc));
var parents = _.intersection(
graph.parentWays(graph.entity(midpoint.edge[0])),
graph.parentWays(graph.entity(midpoint.edge[1])));
parents.forEach(function(way) {
for (var i = 0; i < way.nodes.length - 1; i++) {
if ((way.nodes[i] === midpoint.edge[0] &&
way.nodes[i + 1] === midpoint.edge[1]) ||
(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;
}
}
});
return graph;
};
};