Retry queued entities after rebase

This commit is contained in:
Ansis Brammanis
2013-02-13 14:16:18 -05:00
parent 529b570c89
commit 9a4d4ab9c5
3 changed files with 29 additions and 7 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ iD.History = function(context) {
merge: function(entities) {
var base = tree.base(),
var base = tree.graph(),
newentities = Object.keys(entities).filter(function(i) {
return !base.entities.hasOwnProperty(i) && !base.entities[i];
});
+5 -3
View File
@@ -5,7 +5,7 @@ iD.Tree = function(graph) {
head = graph,
queuedCreated = [],
queuedModified = [],
x, y, dx, dy;
x, y, dx, dy, rebased;
function extentRectangle(extent) {
x = m * extent[0][0],
@@ -34,6 +34,7 @@ iD.Tree = function(graph) {
for (var i = 0; i < entities.length; i++) {
insert(graph.entity(entities[i]), true);
}
rebased = true;
return tree;
},
@@ -41,7 +42,7 @@ iD.Tree = function(graph) {
head = g;
if (graph !== head) {
if (graph !== head || rebased) {
var diff = iD.Difference(graph, head),
modified = {};
@@ -70,13 +71,14 @@ iD.Tree = function(graph) {
diff.deleted().forEach(remove);
graph = head;
rebased = false;
}
return rtree.search(extentRectangle(extent))
.map(function(id) { return graph.entity(id); });
},
base: function() {
graph: function() {
return graph;
}
+23 -3
View File
@@ -5,13 +5,33 @@ describe("iD.Tree", function() {
tree = iD.Tree(iD.Graph());
});
describe("intersects", function() {
describe("#rebase", function() {
it("adds entities to the tree", function() {
var node = iD.Node({ id: 'n', loc: [1, 1]});
tree.graph().rebase({ 'n': node });
tree.rebase(['n']);
expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), tree.graph())).to.eql([node]);
});
});
describe("#intersects", function() {
it("excludes entities with missing children, adds them when all are present", function() {
var way = iD.Way({id: 'w1', nodes: ['n']});
var g = tree.base().replace(way);
var g = tree.graph().replace(way);
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([]);
var node = iD.Node({id: 'n', loc: [0.5, 0.5]});
g = tree.base().replace(node);
g = tree.graph().replace(node);
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([way, node]);
});
it("includes entities that used to have missing children, after rebase added them", function() {
var base = tree.graph();
var way = iD.Way({id: 'w1', nodes: ['n']});
var g = base.replace(way);
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([]);
var node = iD.Node({id: 'n', loc: [0.5, 0.5]});
base.rebase({ 'n': node });
tree.rebase(['n']);
expect(tree.intersects(iD.geo.Extent([0, 0], [1, 1]), g)).to.eql([way, node]);
});
});