mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 00:07:03 +02:00
Optimize presets.match
Previous implementation was linear in the number of presets. This should be near constant time.
This commit is contained in:
@@ -246,6 +246,7 @@
|
||||
|
||||
<script src="spec/modes/add_point.js"></script>
|
||||
|
||||
<script src="spec/presets.js"></script>
|
||||
<script src="spec/presets/preset.js"></script>
|
||||
<script src="spec/presets/collection.js"></script>
|
||||
<script src="spec/presets/category.js"></script>
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
|
||||
<script src="spec/modes/add_point.js"></script>
|
||||
|
||||
<script src="spec/presets.js"></script>
|
||||
<script src="spec/presets/preset.js"></script>
|
||||
<script src="spec/presets/collection.js"></script>
|
||||
<script src="spec/presets/category.js"></script>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
describe("iD.presets", function() {
|
||||
var p = {
|
||||
other: {
|
||||
tags: {},
|
||||
geometry: ['point', 'vertex', 'line', 'area']
|
||||
},
|
||||
residential: {
|
||||
tags: {
|
||||
highway: 'residential'
|
||||
},
|
||||
geometry: ['line']
|
||||
},
|
||||
park: {
|
||||
tags: {
|
||||
leisure: 'park'
|
||||
},
|
||||
geometry: ['point', 'area']
|
||||
}
|
||||
};
|
||||
|
||||
var c = iD.presets().load({presets: p}),
|
||||
w = iD.Way({tags: { highway: 'residential'}}),
|
||||
g = iD.Graph().replace(w);
|
||||
|
||||
describe("#match", function() {
|
||||
it("returns a collection containing presets matching a geometry and tags", function() {
|
||||
var way = iD.Way({tags: { highway: 'residential'}}),
|
||||
graph = iD.Graph([way]);
|
||||
expect(c.match(way, graph).id).to.eql('residential');
|
||||
});
|
||||
|
||||
it("returns an other preset when no tags match", function() {
|
||||
var way = iD.Way({tags: {foo: 'bar'}}),
|
||||
graph = iD.Graph([way]);
|
||||
expect(c.match(way, graph).id).to.eql('other');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -36,12 +36,6 @@ describe("iD.presets.Collection", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#matchTags", function() {
|
||||
it("returns a new collection only containing presets matching an entity's tags", function() {
|
||||
expect(c.matchTags(w, g)).to.eql(p.residential);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#search", function() {
|
||||
it("filters presets by name", function() {
|
||||
expect(c.search("resid").collection.indexOf(p.residential) >= 0).to.eql(true);
|
||||
|
||||
Reference in New Issue
Block a user