mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 05:49:16 +02:00
Add parameter to specify which way should keep the history when splitting ways (re: #7795)
Fix code tests
This commit is contained in:
@@ -22,6 +22,8 @@ import { utilArrayIntersection, utilWrap } from '../util';
|
||||
//
|
||||
export function actionSplit(nodeId, newWayIds) {
|
||||
var _wayIDs;
|
||||
// the strategy for picking which way will have a new version and which way is newly created
|
||||
var _keepHistoryOn = 'longest'; // 'longest', 'first'
|
||||
|
||||
// The IDs of the ways actually created by running this action
|
||||
var createdWayIDs = [];
|
||||
@@ -115,7 +117,8 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
nodesB = wayA.nodes.slice(idx);
|
||||
}
|
||||
|
||||
if (totalLengthBetweenNodes(graph, nodesB) > totalLengthBetweenNodes(graph, nodesA)) {
|
||||
if (_keepHistoryOn === 'longest' &&
|
||||
totalLengthBetweenNodes(graph, nodesB) > totalLengthBetweenNodes(graph, nodesA)) {
|
||||
// keep the history on the longer way, regardless of the node count
|
||||
wayA = wayA.update({ nodes: nodesB });
|
||||
wayB = wayB.update({ nodes: nodesA });
|
||||
@@ -279,5 +282,12 @@ export function actionSplit(nodeId, newWayIds) {
|
||||
};
|
||||
|
||||
|
||||
action.keepHistoryOn = function(val) {
|
||||
if (!arguments.length) return _keepHistoryOn;
|
||||
_keepHistoryOn = val;
|
||||
return action;
|
||||
};
|
||||
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -164,10 +164,10 @@ export function osmIntersection(graph, startVertexId, maxDistance) {
|
||||
// actions can be replayed on the main graph exactly in the same order.
|
||||
// (It is unintuitive, but the order of ways returned from graph.parentWays()
|
||||
// is arbitrary, depending on how the main graph and vgraph were built)
|
||||
var splitAll = actionSplit(v.id);
|
||||
var splitAll = actionSplit(v.id).keepHistoryOn('first');
|
||||
if (!splitAll.disabled(vgraph)) {
|
||||
splitAll.ways(vgraph).forEach(function(way) {
|
||||
var splitOne = actionSplit(v.id).limitWays([way.id]);
|
||||
var splitOne = actionSplit(v.id).limitWays([way.id]).keepHistoryOn('first');
|
||||
actions.push(splitOne);
|
||||
vgraph = splitOne(vgraph);
|
||||
});
|
||||
|
||||
+16
-16
@@ -307,8 +307,8 @@ describe('iD.actionSplit', function () {
|
||||
]);
|
||||
|
||||
var g1 = iD.actionSplit('a', ['='])(graph);
|
||||
expect(g1.entity('-').nodes).to.eql(['a', 'b', 'c']);
|
||||
expect(g1.entity('=').nodes).to.eql(['c', 'd', 'a']);
|
||||
expect(g1.entity('-').nodes).to.eql(['c', 'd', 'a']);
|
||||
expect(g1.entity('=').nodes).to.eql(['a', 'b', 'c']);
|
||||
|
||||
var g2 = iD.actionSplit('b', ['='])(graph);
|
||||
expect(g2.entity('-').nodes).to.eql(['b', 'c', 'd']);
|
||||
@@ -319,8 +319,8 @@ describe('iD.actionSplit', function () {
|
||||
expect(g3.entity('=').nodes).to.eql(['a', 'b', 'c']);
|
||||
|
||||
var g4 = iD.actionSplit('d', ['='])(graph);
|
||||
expect(g4.entity('-').nodes).to.eql(['d', 'a', 'b']);
|
||||
expect(g4.entity('=').nodes).to.eql(['b', 'c', 'd']);
|
||||
expect(g4.entity('-').nodes).to.eql(['b', 'c', 'd']);
|
||||
expect(g4.entity('=').nodes).to.eql(['d', 'a', 'b']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -957,17 +957,17 @@ describe('iD.actionSplit', function () {
|
||||
it('splits spoon2 route at d', function () {
|
||||
//
|
||||
// Expected result:
|
||||
// b <-- c
|
||||
// ‖ |
|
||||
// a ==> d ~~~> e ~~~> f
|
||||
// b <== c
|
||||
// | ‖
|
||||
// a --> d ~~~> e ~~~> f
|
||||
//
|
||||
// Relation: ['~', '-', '=', '~']
|
||||
//
|
||||
var graph = spoon2;
|
||||
graph = iD.actionSplit('d', ['='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['d', 'c', 'b']);
|
||||
expect(graph.entity('=').nodes).to.eql(['b', 'a', 'd']);
|
||||
expect(graph.entity('-').nodes).to.eql(['b', 'a', 'd']);
|
||||
expect(graph.entity('=').nodes).to.eql(['d', 'c', 'b']);
|
||||
expect(graph.entity('~').nodes).to.eql(['d', 'e', 'f']);
|
||||
expect(members(graph)).to.eql(['~', '-', '=', '~']);
|
||||
});
|
||||
@@ -993,17 +993,17 @@ describe('iD.actionSplit', function () {
|
||||
it('splits spoon4 route at d', function () {
|
||||
//
|
||||
// Expected result:
|
||||
// b <-- c
|
||||
// ‖ |
|
||||
// a ==> d <~~~ e <~~~ f
|
||||
// b <== c
|
||||
// | ‖
|
||||
// a --> d <~~~ e <~~~ f
|
||||
//
|
||||
// Relation: ['~', '-', '=', '~']
|
||||
//
|
||||
var graph = spoon4;
|
||||
graph = iD.actionSplit('d', ['='])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['d', 'c', 'b']);
|
||||
expect(graph.entity('=').nodes).to.eql(['b', 'a', 'd']);
|
||||
expect(graph.entity('-').nodes).to.eql(['b', 'a', 'd']);
|
||||
expect(graph.entity('=').nodes).to.eql(['d', 'c', 'b']);
|
||||
expect(graph.entity('~').nodes).to.eql(['f', 'e', 'd']);
|
||||
expect(members(graph)).to.eql(['~', '-', '=', '~']);
|
||||
});
|
||||
@@ -1130,8 +1130,8 @@ describe('iD.actionSplit', function () {
|
||||
|
||||
graph = iD.actionSplit('b', ['~'])(graph);
|
||||
|
||||
expect(graph.entity('-').nodes).to.eql(['a', 'b']);
|
||||
expect(graph.entity('~').nodes).to.eql(['b', 'c']);
|
||||
expect(graph.entity('-').nodes).to.eql(['b', 'c']);
|
||||
expect(graph.entity('~').nodes).to.eql(['a', 'b']);
|
||||
expect(graph.entity('=').nodes).to.eql(['a', 'b', 'c', 'a']);
|
||||
expect(graph.parentRelations(graph.entity('='))).to.have.length(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user