mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 16:49:40 +02:00
Avoid recomputing geometry in an inner loop
This commit is contained in:
+3
-3
@@ -57,9 +57,9 @@ iD.presets = function(context) {
|
||||
};
|
||||
|
||||
all.defaults = function(entity, n) {
|
||||
var rec = recent.matchGeometry(entity, context.graph()).collection.slice(0, 4),
|
||||
def = _.uniq(rec.concat(defaults[entity.geometry(context.graph())].collection)).slice(0, n - 1),
|
||||
geometry = entity.geometry(context.graph());
|
||||
var geometry = entity.geometry(context.graph()),
|
||||
rec = recent.matchGeometry(geometry).collection.slice(0, 4),
|
||||
def = _.uniq(rec.concat(defaults[geometry].collection)).slice(0, n - 1);
|
||||
return iD.presets.Collection(_.unique(rec.concat(def).concat(geometry === 'area' ? other_area : other)));
|
||||
};
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ iD.presets.Category = function(id, category, all) {
|
||||
return all.item(id);
|
||||
}));
|
||||
|
||||
category.matchGeometry = function(entity, resolver) {
|
||||
return category.geometry.indexOf(entity.geometry(resolver)) >= 0;
|
||||
category.matchGeometry = function(geometry) {
|
||||
return category.geometry.indexOf(geometry) >= 0;
|
||||
};
|
||||
|
||||
category.matchTags = function() { return false; };
|
||||
|
||||
@@ -11,12 +11,12 @@ iD.presets.Collection = function(collection) {
|
||||
},
|
||||
|
||||
match: function(entity, resolver) {
|
||||
return presets.matchGeometry(entity, resolver).matchTags(entity);
|
||||
return presets.matchGeometry(entity.geometry(resolver)).matchTags(entity);
|
||||
},
|
||||
|
||||
matchGeometry: function(entity, resolver) {
|
||||
matchGeometry: function(geometry) {
|
||||
return iD.presets.Collection(collection.filter(function(d) {
|
||||
return d.matchGeometry(entity, resolver);
|
||||
return d.matchGeometry(geometry);
|
||||
}));
|
||||
},
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ iD.presets.Preset = function(id, preset, fields) {
|
||||
return fields[f];
|
||||
}
|
||||
|
||||
preset.matchGeometry = function(entity, resolver) {
|
||||
return preset.geometry.indexOf(entity.geometry(resolver)) >= 0;
|
||||
preset.matchGeometry = function(geometry) {
|
||||
return preset.geometry.indexOf(geometry) >= 0;
|
||||
};
|
||||
|
||||
preset.matchTags = function(entity) {
|
||||
|
||||
@@ -9,7 +9,7 @@ iD.ui.PresetGrid = function(context, entity) {
|
||||
|
||||
selection.html('');
|
||||
|
||||
presets = context.presets().matchGeometry(entity, context.graph());
|
||||
presets = context.presets().matchGeometry(entity.geometry(context.graph()));
|
||||
|
||||
var messagewrap = selection.append('div')
|
||||
.attr('class', 'header fillL cf');
|
||||
|
||||
@@ -29,8 +29,8 @@ describe("iD.presets.Category", function() {
|
||||
w = iD.Way(),
|
||||
n = iD.Node(),
|
||||
g = iD.Graph().replace(w);
|
||||
expect(c.matchGeometry(w, g)).to.eql(true);
|
||||
expect(c.matchGeometry(n, g)).to.eql(false);
|
||||
expect(c.matchGeometry('line')).to.eql(true);
|
||||
expect(c.matchGeometry('point')).to.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,8 +31,8 @@ describe("iD.presets.Collection", function() {
|
||||
});
|
||||
|
||||
describe("#matchGeometry", function() {
|
||||
it("returns a new collection only containing presets matching an entity's type", function() {
|
||||
expect(c.matchGeometry(w, g).collection).to.eql([p.other, p.residential]);
|
||||
it("returns a new collection only containing presets matching a geometry", function() {
|
||||
expect(c.matchGeometry('line').collection).to.eql([p.other, p.residential]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -40,12 +40,13 @@ describe('iD.presets.Preset', function() {
|
||||
describe('#matchGeometry', function() {
|
||||
var n = iD.Node();
|
||||
var g = iD.Graph().replace(n);
|
||||
it("returns false if it doesn't match the entity type", function() {
|
||||
expect(p['highway/residential'].matchGeometry(n, g)).to.equal(false);
|
||||
|
||||
it("returns false if it doesn't match", function() {
|
||||
expect(p['highway/residential'].matchGeometry('point')).to.equal(false);
|
||||
});
|
||||
|
||||
it("returns true if it does match the entity type", function() {
|
||||
expect(p.other.matchGeometry(n, g)).to.equal(true);
|
||||
it("returns true if it does match", function() {
|
||||
expect(p.other.matchGeometry('point')).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user