mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 16:19:48 +02:00
Pass entity array to Tree#rebase
This commit is contained in:
@@ -42,17 +42,11 @@ iD.History = function(context) {
|
||||
},
|
||||
|
||||
merge: function(entities, extent) {
|
||||
|
||||
var base = stack[0].graph.base(),
|
||||
newentities = Object.keys(entities).filter(function(i) {
|
||||
return !base.entities[i];
|
||||
});
|
||||
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
stack[i].graph.rebase(entities);
|
||||
}
|
||||
|
||||
tree.rebase(newentities);
|
||||
tree.rebase(d3.values(entities));
|
||||
|
||||
dispatch.change(undefined, extent);
|
||||
},
|
||||
|
||||
+7
-9
@@ -43,11 +43,14 @@ iD.Tree = function(graph) {
|
||||
var tree = {
|
||||
|
||||
rebase: function(entities) {
|
||||
for (var i = 0, inserted = []; i < entities.length; i++) {
|
||||
if (!graph.entities.hasOwnProperty(entities[i])) {
|
||||
inserted.push(graph.entity(entities[i]));
|
||||
var inserted = [];
|
||||
|
||||
entities.forEach(function(entity) {
|
||||
if (!graph.entities.hasOwnProperty(entity.id) && !rectangles.hasOwnProperty(entity.id)) {
|
||||
inserted.push(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bulkInsert(inserted);
|
||||
rebased = true;
|
||||
return tree;
|
||||
@@ -101,12 +104,7 @@ iD.Tree = function(graph) {
|
||||
return rtree.search(extentRectangle(extent)).map(function (rect) {
|
||||
return graph.entities[rect.id];
|
||||
});
|
||||
},
|
||||
|
||||
graph: function() {
|
||||
return graph;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return tree;
|
||||
|
||||
+32
-3
@@ -6,11 +6,26 @@ describe("iD.Tree", function() {
|
||||
node = iD.Node({id: 'n', loc: [1, 1]});
|
||||
|
||||
graph.rebase({n: node});
|
||||
tree.rebase(['n']);
|
||||
tree.rebase([node]);
|
||||
|
||||
expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), graph)).to.eql([node]);
|
||||
});
|
||||
|
||||
it("is idempotent", function() {
|
||||
var graph = iD.Graph(),
|
||||
tree = iD.Tree(graph),
|
||||
node = iD.Node({id: 'n', loc: [1, 1]}),
|
||||
extent = iD.geo.Extent([0, 0], [2, 2]);
|
||||
|
||||
graph.rebase({n: node});
|
||||
tree.rebase([node]);
|
||||
expect(tree.intersects(extent, graph)).to.eql([node]);
|
||||
|
||||
graph.rebase({n: node});
|
||||
tree.rebase([node]);
|
||||
expect(tree.intersects(extent, graph)).to.eql([node]);
|
||||
});
|
||||
|
||||
it("does not insert if entity has a modified version", function() {
|
||||
var graph = iD.Graph(),
|
||||
tree = iD.Tree(graph),
|
||||
@@ -21,7 +36,7 @@ describe("iD.Tree", function() {
|
||||
expect(tree.intersects(iD.geo.Extent([9, 9], [11, 11]), g)).to.eql([node_]);
|
||||
|
||||
graph.rebase({n: node});
|
||||
tree.rebase(['n']);
|
||||
tree.rebase([node]);
|
||||
|
||||
expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), g)).to.eql([]);
|
||||
expect(tree.intersects(iD.geo.Extent([0, 0], [11, 11]), g)).to.eql([node_]);
|
||||
@@ -51,7 +66,7 @@ describe("iD.Tree", function() {
|
||||
expect(tree.intersects(extent, graph)).to.eql([]);
|
||||
|
||||
base.rebase({n: node});
|
||||
tree.rebase(['n']);
|
||||
tree.rebase([node]);
|
||||
expect(tree.intersects(extent, graph)).to.eql([node, way]);
|
||||
});
|
||||
|
||||
@@ -67,5 +82,19 @@ describe("iD.Tree", function() {
|
||||
graph = graph.remove(node);
|
||||
expect(tree.intersects(extent, graph)).to.eql([]);
|
||||
});
|
||||
|
||||
it("doesn't include removed entities after rebase", function() {
|
||||
var base = iD.Graph(),
|
||||
tree = iD.Tree(base),
|
||||
node = iD.Node({id: 'n', loc: [1, 1]}),
|
||||
extent = iD.geo.Extent([0, 0], [2, 2]);
|
||||
|
||||
var graph = base.replace(node).remove(node);
|
||||
expect(tree.intersects(extent, graph)).to.eql([]);
|
||||
|
||||
base.rebase({n: node});
|
||||
tree.rebase([node]);
|
||||
expect(tree.intersects(extent, graph)).to.eql([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user