Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Tim Schaub
2013-01-24 22:21:25 -07:00
49 changed files with 1694 additions and 571 deletions

View File

@@ -55,6 +55,21 @@ describe('ol.Extent', function() {
expect(destinationExtent.maxX).toRoughlyEqual(5009377.085697311, 1e-9);
expect(destinationExtent.maxY).toRoughlyEqual(8399737.889818361, 1e-9);
});
it('takes arbitrary function', function() {
var transformFn = function(coordinate) {
return new ol.Coordinate(-coordinate.x, -coordinate.y);
};
var sourceExtent = new ol.Extent(-15, -30, 45, 60);
var destinationExtent = sourceExtent.transform(transformFn);
expect(destinationExtent).not.toBeUndefined();
expect(destinationExtent).not.toBeNull();
expect(destinationExtent.minX).toBe(-45);
expect(destinationExtent.minY).toBe(-60);
expect(destinationExtent.maxX).toBe(15);
expect(destinationExtent.maxY).toBe(30);
});
});
});

View File

@@ -0,0 +1,68 @@
describe('ol.TileQueue', function() {
// is the tile queue's array a heap?
function isHeap(tq) {
var heap = tq.heap_;
var i;
var key;
var leftKey;
var rightKey;
for (i = 0; i < (heap.length >> 1) - 1; i++) {
key = heap[i][0];
leftKey = heap[tq.getLeftChildIndex_(i)][0];
rightKey = heap[tq.getRightChildIndex_(i)][0];
if (leftKey < key || rightKey < key) {
return false;
}
}
return true;
}
function addRandomPriorityTiles(tq, num) {
var i, tile, priority;
for (i = 0; i < num; i++) {
tile = new ol.Tile();
priority = Math.floor(Math.random() * 100);
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
tq.queuedTileKeys_[tile.getKey()] = true;
}
}
describe('heapify', function() {
it('does convert an arbitrary array into a heap', function() {
var tq = new ol.TileQueue(function() {});
addRandomPriorityTiles(tq, 100);
tq.heapify_();
expect(isHeap(tq)).toBeTruthy();
});
});
describe('reprioritize', function() {
it('does reprioritize the array', function() {
var tq = new ol.TileQueue(function() {});
addRandomPriorityTiles(tq, 100);
tq.heapify_();
// now reprioritize, changing the priority of 50 tiles and removing the
// rest
var i = 0;
tq.tilePriorityFunction_ = function() {
if ((i++) % 2 === 0) {
return ol.TileQueue.DROP;
}
return Math.floor(Math.random() * 100);
};
tq.reprioritize();
expect(tq.heap_.length).toEqual(50);
expect(isHeap(tq)).toBeTruthy();
});
});
});