Add support for non-square tiles

This commit is contained in:
Andreas Hocevar
2015-04-14 22:54:57 +02:00
parent 5dfa9e0a67
commit 2b75341068
19 changed files with 396 additions and 119 deletions
+57
View File
@@ -2,6 +2,9 @@ goog.provide('ol.Size');
goog.provide('ol.size');
goog.require('goog.asserts');
/**
* An array of numbers representing a size: `[width, height]`.
* @typedef {Array.<number>}
@@ -10,6 +13,23 @@ goog.provide('ol.size');
ol.Size;
/**
* Returns a buffered size.
* @param {ol.Size} size Size.
* @param {number} buffer Buffer.
* @param {ol.Size=} opt_size Optional reusable size array.
* @return {ol.Size}
*/
ol.size.buffer = function(size, buffer, opt_size) {
if (!goog.isDef(opt_size)) {
opt_size = [0, 0];
}
opt_size[0] = size[0] + 2 * buffer;
opt_size[1] = size[1] + 2 * buffer;
return opt_size;
};
/**
* Compares sizes for equality.
* @param {ol.Size} a Size.
@@ -19,3 +39,40 @@ ol.Size;
ol.size.equals = function(a, b) {
return a[0] == b[0] && a[1] == b[1];
};
/**
* Returns a size scaled by a ratio. The result will be an array of integers.
* @param {ol.Size} size Size.
* @param {number} ratio Ratio.
* @param {ol.Size=} opt_size Optional reusable size array.
* @return {ol.Size}
*/
ol.size.scale = function(size, ratio, opt_size) {
if (!goog.isDef(opt_size)) {
opt_size = [0, 0];
}
opt_size[0] = (size[0] * ratio + 0.5) | 0;
opt_size[1] = (size[1] * ratio + 0.5) | 0;
return opt_size;
};
/**
* @param {number|ol.Size} size Width and height.
* @param {ol.Size=} opt_size Optional reusable size array.
* @return {ol.Size} Size.
*/
ol.size.toSize = function(size, opt_size) {
if (goog.isArray(size)) {
return size;
} else {
if (!goog.isDef(opt_size)) {
opt_size = [0, 0];
}
goog.asserts.assert(goog.isNumber(size));
opt_size[0] = size;
opt_size[1] = size;
return opt_size;
}
};