Files
iD/test/spec/actions/add_midpoint.js
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

55 lines
2.0 KiB
JavaScript

describe("iD.actions.AddMidpoint", function () {
it("adds the node at the midpoint location", function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actions.AddMidpoint(midpoint, node)(iD.Graph([a, b]));
expect(graph.entity(node.id).loc).to.eql([1, 2]);
});
it("adds the node to a way that contains the given edge in forward order", function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
w1 = iD.Way(),
w2 = iD.Way({nodes: [a.id, b.id]}),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actions.AddMidpoint(midpoint, node)(iD.Graph([a, b, w1, w2]));
expect(graph.entity(w1.id).nodes).to.eql([]);
expect(graph.entity(w2.id).nodes).to.eql([a.id, node.id, b.id]);
});
it("adds the node to a way that contains the given edge in reverse order", function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
w1 = iD.Way(),
w2 = iD.Way({nodes: [b.id, a.id]}),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actions.AddMidpoint(midpoint, node)(iD.Graph([a, b, w1, w2]));
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]);
});
});