@@ -38,38 +38,6 @@ ol.array.binarySearch = function(haystack, needle, opt_comparator) {
|
||||
return found ? low : ~low;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} arr Array.
|
||||
* @param {number} target Target.
|
||||
* @return {number} Index.
|
||||
*/
|
||||
ol.array.binaryFindNearest = function(arr, target) {
|
||||
var index = ol.array.binarySearch(arr, target,
|
||||
/**
|
||||
* @param {number} a A.
|
||||
* @param {number} b B.
|
||||
* @return {number} b minus a.
|
||||
*/
|
||||
function(a, b) {
|
||||
return b - a;
|
||||
});
|
||||
if (index >= 0) {
|
||||
return index;
|
||||
} else if (index == -1) {
|
||||
return 0;
|
||||
} else if (index == -arr.length - 1) {
|
||||
return arr.length - 1;
|
||||
} else {
|
||||
var left = -index - 2;
|
||||
var right = -index - 1;
|
||||
if (arr[left] - target < target - arr[right]) {
|
||||
return left;
|
||||
} else {
|
||||
return right;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Compare function for array sort that is safe for numbers.
|
||||
|
||||
@@ -319,28 +319,3 @@ ol.coordinate.toStringHDMS = function(coordinate, opt_fractionDigits) {
|
||||
ol.coordinate.toStringXY = function(coordinate, opt_fractionDigits) {
|
||||
return ol.coordinate.format(coordinate, '{x}, {y}', opt_fractionDigits);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an ol.Coordinate from an Array and take into account axis order.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* var northCoord = ol.coordinate.fromProjectedArray([1, 2], 'n');
|
||||
* // northCoord is now [2, 1]
|
||||
*
|
||||
* var eastCoord = ol.coordinate.fromProjectedArray([1, 2], 'e');
|
||||
* // eastCoord is now [1, 2]
|
||||
*
|
||||
* @param {Array} array The array with coordinates.
|
||||
* @param {string} axis the axis info.
|
||||
* @return {ol.Coordinate} The coordinate created.
|
||||
*/
|
||||
ol.coordinate.fromProjectedArray = function(array, axis) {
|
||||
var firstAxis = axis.charAt(0);
|
||||
if (firstAxis === 'n' || firstAxis === 's') {
|
||||
return [array[1], array[0]];
|
||||
} else {
|
||||
return array;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,17 +18,6 @@ ol.size.buffer = function(size, buffer, opt_size) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Compares sizes for equality.
|
||||
* @param {ol.Size} a Size.
|
||||
* @param {ol.Size} b Size.
|
||||
* @return {boolean} Equals.
|
||||
*/
|
||||
ol.size.equals = function(a, b) {
|
||||
return a[0] == b[0] && a[1] == b[1];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines if a size has a positive area.
|
||||
* @param {ol.Size} size The size to test.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
goog.provide('ol.TileRange');
|
||||
|
||||
goog.require('ol.asserts');
|
||||
|
||||
|
||||
/**
|
||||
* A representation of a contiguous block of tiles. A tile range is specified
|
||||
@@ -39,34 +37,6 @@ ol.TileRange = function(minX, maxX, minY, maxY) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {...ol.TileCoord} var_args Tile coordinates.
|
||||
* @return {!ol.TileRange} Bounding tile box.
|
||||
*/
|
||||
ol.TileRange.boundingTileRange = function(var_args) {
|
||||
var tileCoord0 = /** @type {ol.TileCoord} */ (arguments[0]);
|
||||
var tileCoord0Z = tileCoord0[0];
|
||||
var tileCoord0X = tileCoord0[1];
|
||||
var tileCoord0Y = tileCoord0[2];
|
||||
var tileRange = new ol.TileRange(tileCoord0X, tileCoord0X,
|
||||
tileCoord0Y, tileCoord0Y);
|
||||
var i, ii, tileCoord, tileCoordX, tileCoordY, tileCoordZ;
|
||||
for (i = 1, ii = arguments.length; i < ii; ++i) {
|
||||
tileCoord = /** @type {ol.TileCoord} */ (arguments[i]);
|
||||
tileCoordZ = tileCoord[0];
|
||||
tileCoordX = tileCoord[1];
|
||||
tileCoordY = tileCoord[2];
|
||||
ol.asserts.assert(tileCoordZ == tileCoord0Z,
|
||||
23); // The passed `ol.TileCoord`s must all have the same `z` value
|
||||
tileRange.minX = Math.min(tileRange.minX, tileCoordX);
|
||||
tileRange.maxX = Math.max(tileRange.maxX, tileCoordX);
|
||||
tileRange.minY = Math.min(tileRange.minY, tileCoordY);
|
||||
tileRange.maxY = Math.max(tileRange.maxY, tileCoordY);
|
||||
}
|
||||
return tileRange;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
* @param {number} maxX Maximum X.
|
||||
|
||||
@@ -307,28 +307,6 @@ describe('ol.array', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('binaryFindNearest', function() {
|
||||
it('returns expected value', function() {
|
||||
var arr = [1000, 500, 100];
|
||||
|
||||
expect(ol.array.binaryFindNearest(arr, 10000)).to.eql(0);
|
||||
expect(ol.array.binaryFindNearest(arr, 1000)).to.eql(0);
|
||||
expect(ol.array.binaryFindNearest(arr, 900)).to.eql(0);
|
||||
|
||||
expect(ol.array.binaryFindNearest(arr, 750)).to.eql(1);
|
||||
|
||||
expect(ol.array.binaryFindNearest(arr, 550)).to.eql(1);
|
||||
expect(ol.array.binaryFindNearest(arr, 500)).to.eql(1);
|
||||
expect(ol.array.binaryFindNearest(arr, 450)).to.eql(1);
|
||||
|
||||
expect(ol.array.binaryFindNearest(arr, 300)).to.eql(2);
|
||||
|
||||
expect(ol.array.binaryFindNearest(arr, 200)).to.eql(2);
|
||||
expect(ol.array.binaryFindNearest(arr, 100)).to.eql(2);
|
||||
expect(ol.array.binaryFindNearest(arr, 50)).to.eql(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('equals', function() {
|
||||
it('returns true for [] == []', function() {
|
||||
expect(ol.array.equals([], [])).to.be(true);
|
||||
|
||||
@@ -232,22 +232,4 @@ describe('ol.coordinate', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fromProjectedArray', function() {
|
||||
it('returns an inverted coord for "n" or "s"', function() {
|
||||
var northCoord = ol.coordinate.fromProjectedArray([1, 2], 'n');
|
||||
var southCoord = ol.coordinate.fromProjectedArray([1, 2], 's');
|
||||
expect(northCoord).to.eql([2, 1]);
|
||||
expect(southCoord).to.eql([2, 1]);
|
||||
});
|
||||
it('returns an unchanged coord for any other "axis"', function() {
|
||||
var eastCoord = ol.coordinate.fromProjectedArray([1, 2], 'e');
|
||||
var westCoord = ol.coordinate.fromProjectedArray([1, 2], 'w');
|
||||
var bogusCoord = ol.coordinate.fromProjectedArray([1, 2], 'q');
|
||||
var unchangedCoord = ol.coordinate.fromProjectedArray([1, 2], '');
|
||||
expect(eastCoord).to.eql([1, 2]);
|
||||
expect(westCoord).to.eql([1, 2]);
|
||||
expect(bogusCoord).to.eql([1, 2]);
|
||||
expect(unchangedCoord).to.eql([1, 2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,25 +50,6 @@ describe('ol.TileRange', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('boundingTileRange', function() {
|
||||
it('returns the expected TileRange', function() {
|
||||
var tileRange = new ol.TileRange.boundingTileRange(
|
||||
[3, 1, 3], [3, 2, 0]);
|
||||
expect(tileRange.minX).to.eql(1);
|
||||
expect(tileRange.maxX).to.eql(2);
|
||||
expect(tileRange.minY).to.eql(0);
|
||||
expect(tileRange.maxY).to.eql(3);
|
||||
});
|
||||
|
||||
describe('with mixed z', function() {
|
||||
it('returns the expected TileRange', function() {
|
||||
expect(function() {
|
||||
return new ol.TileRange.boundingTileRange([3, 1, 3], [4, 2, 0]);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('equals', function() {
|
||||
it('determines equivalence of two ranges', function() {
|
||||
var one = new ol.TileRange(0, 2, 1, 4);
|
||||
|
||||
Reference in New Issue
Block a user