Pass entity array to Tree#rebase

This commit is contained in:
John Firebaugh
2013-10-28 14:17:18 -07:00
parent e6d3cb242c
commit e0e08115e5
3 changed files with 40 additions and 19 deletions
+1 -7
View File
@@ -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
View File
@@ -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
View File
@@ -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([]);
});
});
});