New structure for extent: [minCoord, maxCoord]
This commit is contained in:
115
src/ol/extent.js
115
src/ol/extent.js
@@ -8,7 +8,7 @@ goog.require('ol.TransformFunction');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<number>}
|
||||
* @typedef {Array.<ol.Coordinate>}
|
||||
*/
|
||||
ol.Extent;
|
||||
|
||||
@@ -56,8 +56,8 @@ ol.extent.boundingExtentXYs_ = function(xs, ys, opt_extent) {
|
||||
* @return {boolean} Contains.
|
||||
*/
|
||||
ol.extent.containsCoordinate = function(extent, coordinate) {
|
||||
return extent[0] <= coordinate[0] && coordinate[0] <= extent[1] &&
|
||||
extent[2] <= coordinate[1] && coordinate[1] <= extent[3];
|
||||
return extent[0][0] <= coordinate[0] && coordinate[0] <= extent[1][0] &&
|
||||
extent[0][1] <= coordinate[1] && coordinate[1] <= extent[1][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ ol.extent.containsCoordinate = function(extent, coordinate) {
|
||||
* @return {boolean} Contains.
|
||||
*/
|
||||
ol.extent.containsExtent = function(extent1, extent2) {
|
||||
return extent1[0] <= extent2[0] && extent2[1] <= extent1[1] &&
|
||||
extent1[2] <= extent2[2] && extent2[3] <= extent1[3];
|
||||
return extent1[0][0] <= extent2[0][0] && extent2[1][0] <= extent1[1][0] &&
|
||||
extent1[0][1] <= extent2[0][1] && extent2[1][1] <= extent1[1][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ ol.extent.containsExtent = function(extent1, extent2) {
|
||||
* @return {ol.Extent} Empty extent.
|
||||
*/
|
||||
ol.extent.createEmpty = function() {
|
||||
return [Infinity, -Infinity, Infinity, -Infinity];
|
||||
return [[Infinity, Infinity], [-Infinity, -Infinity]];
|
||||
};
|
||||
|
||||
|
||||
@@ -92,13 +92,13 @@ ol.extent.createEmpty = function() {
|
||||
*/
|
||||
ol.extent.createOrUpdate = function(minX, maxX, minY, maxY, opt_extent) {
|
||||
if (goog.isDef(opt_extent)) {
|
||||
opt_extent[0] = minX;
|
||||
opt_extent[1] = maxX;
|
||||
opt_extent[2] = minY;
|
||||
opt_extent[3] = maxY;
|
||||
opt_extent[0][0] = minX;
|
||||
opt_extent[1][0] = maxX;
|
||||
opt_extent[0][1] = minY;
|
||||
opt_extent[1][1] = maxY;
|
||||
return opt_extent;
|
||||
} else {
|
||||
return [minX, maxX, minY, maxY];
|
||||
return [[minX, minY], [maxX, maxY]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -109,8 +109,8 @@ ol.extent.createOrUpdate = function(minX, maxX, minY, maxY, opt_extent) {
|
||||
* @return {ol.Extent} Extent.
|
||||
*/
|
||||
ol.extent.empty = function(extent) {
|
||||
extent[0] = extent[2] = Infinity;
|
||||
extent[1] = extent[3] = -Infinity;
|
||||
extent[0][0] = extent[0][1] = Infinity;
|
||||
extent[1][0] = extent[1][1] = -Infinity;
|
||||
return extent;
|
||||
};
|
||||
|
||||
@@ -121,8 +121,8 @@ ol.extent.empty = function(extent) {
|
||||
* @return {boolean} Equals.
|
||||
*/
|
||||
ol.extent.equals = function(extent1, extent2) {
|
||||
return extent1[0] == extent2[0] && extent1[1] == extent2[1] &&
|
||||
extent1[2] == extent2[2] && extent1[3] == extent2[3];
|
||||
return extent1[0][0] == extent2[0][0] && extent1[1][0] == extent2[1][0] &&
|
||||
extent1[0][1] == extent2[0][1] && extent1[1][1] == extent2[1][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -131,17 +131,17 @@ ol.extent.equals = function(extent1, extent2) {
|
||||
* @param {ol.Extent} extent2 Extent 2.
|
||||
*/
|
||||
ol.extent.extend = function(extent1, extent2) {
|
||||
if (extent2[0] < extent1[0]) {
|
||||
extent1[0] = extent2[0];
|
||||
if (extent2[0][0] < extent1[0][0]) {
|
||||
extent1[0][0] = extent2[0][0];
|
||||
}
|
||||
if (extent2[1] > extent1[1]) {
|
||||
extent1[1] = extent2[1];
|
||||
if (extent2[1][0] > extent1[1][0]) {
|
||||
extent1[1][0] = extent2[1][0];
|
||||
}
|
||||
if (extent2[2] < extent1[2]) {
|
||||
extent1[2] = extent2[2];
|
||||
if (extent2[0][1] < extent1[0][1]) {
|
||||
extent1[0][1] = extent2[0][1];
|
||||
}
|
||||
if (extent2[3] > extent1[3]) {
|
||||
extent1[3] = extent2[3];
|
||||
if (extent2[1][1] > extent1[1][1]) {
|
||||
extent1[1][1] = extent2[1][1];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,17 +151,17 @@ ol.extent.extend = function(extent1, extent2) {
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
*/
|
||||
ol.extent.extendCoordinate = function(extent, coordinate) {
|
||||
if (coordinate[0] < extent[0]) {
|
||||
extent[0] = coordinate[0];
|
||||
if (coordinate[0] < extent[0][0]) {
|
||||
extent[0][0] = coordinate[0];
|
||||
}
|
||||
if (coordinate[0] > extent[1]) {
|
||||
extent[1] = coordinate[0];
|
||||
if (coordinate[0] > extent[1][0]) {
|
||||
extent[1][0] = coordinate[0];
|
||||
}
|
||||
if (coordinate[1] < extent[2]) {
|
||||
extent[2] = coordinate[1];
|
||||
if (coordinate[1] < extent[0][1]) {
|
||||
extent[0][1] = coordinate[1];
|
||||
}
|
||||
if (coordinate[1] > extent[3]) {
|
||||
extent[3] = coordinate[1];
|
||||
if (coordinate[1] > extent[1][1]) {
|
||||
extent[1][1] = coordinate[1];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -171,7 +171,7 @@ ol.extent.extendCoordinate = function(extent, coordinate) {
|
||||
* @return {ol.Coordinate} Bottom left coordinate.
|
||||
*/
|
||||
ol.extent.getBottomLeft = function(extent) {
|
||||
return [extent[0], extent[2]];
|
||||
return [extent[0][0], extent[0][1]];
|
||||
};
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ ol.extent.getBottomLeft = function(extent) {
|
||||
* @return {ol.Coordinate} Bottom right coordinate.
|
||||
*/
|
||||
ol.extent.getBottomRight = function(extent) {
|
||||
return [extent[1], extent[2]];
|
||||
return [extent[1][0], extent[0][1]];
|
||||
};
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ ol.extent.getBottomRight = function(extent) {
|
||||
* @return {ol.Coordinate} Center.
|
||||
*/
|
||||
ol.extent.getCenter = function(extent) {
|
||||
return [(extent[0] + extent[1]) / 2, (extent[2] + extent[3]) / 2];
|
||||
return [(extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2];
|
||||
};
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ ol.extent.getForView2DAndSize =
|
||||
* @return {number} Height.
|
||||
*/
|
||||
ol.extent.getHeight = function(extent) {
|
||||
return extent[3] - extent[2];
|
||||
return extent[1][1] - extent[0][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ ol.extent.getHeight = function(extent) {
|
||||
* @return {ol.Size} Size.
|
||||
*/
|
||||
ol.extent.getSize = function(extent) {
|
||||
return [extent[1] - extent[0], extent[3] - extent[2]];
|
||||
return [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
|
||||
};
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ ol.extent.getSize = function(extent) {
|
||||
* @return {ol.Coordinate} Top left coordinate.
|
||||
*/
|
||||
ol.extent.getTopLeft = function(extent) {
|
||||
return [extent[0], extent[3]];
|
||||
return [extent[0][0], extent[1][1]];
|
||||
};
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ ol.extent.getTopLeft = function(extent) {
|
||||
* @return {ol.Coordinate} Top right coordinate.
|
||||
*/
|
||||
ol.extent.getTopRight = function(extent) {
|
||||
return [extent[1], extent[3]];
|
||||
return [extent[1][0], extent[1][1]];
|
||||
};
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ ol.extent.getTopRight = function(extent) {
|
||||
* @return {number} Width.
|
||||
*/
|
||||
ol.extent.getWidth = function(extent) {
|
||||
return extent[1] - extent[0];
|
||||
return extent[1][0] - extent[0][0];
|
||||
};
|
||||
|
||||
|
||||
@@ -273,10 +273,10 @@ ol.extent.getWidth = function(extent) {
|
||||
* @return {boolean} Intersects.
|
||||
*/
|
||||
ol.extent.intersects = function(extent1, extent2) {
|
||||
return extent1[0] <= extent2[1] &&
|
||||
extent1[1] >= extent2[0] &&
|
||||
extent1[2] <= extent2[3] &&
|
||||
extent1[3] >= extent2[2];
|
||||
return extent1[0][0] <= extent2[1][0] &&
|
||||
extent1[1][0] >= extent2[0][0] &&
|
||||
extent1[0][1] <= extent2[1][1] &&
|
||||
extent1[1][1] >= extent2[0][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ ol.extent.intersects = function(extent1, extent2) {
|
||||
* @return {boolean} Is empty.
|
||||
*/
|
||||
ol.extent.isEmpty = function(extent) {
|
||||
return extent[1] < extent[0] || extent[3] < extent[2];
|
||||
return extent[1][0] < extent[0][0] || extent[1][1] < extent[0][1];
|
||||
};
|
||||
|
||||
|
||||
@@ -296,8 +296,8 @@ ol.extent.isEmpty = function(extent) {
|
||||
*/
|
||||
ol.extent.normalize = function(extent, coordinate) {
|
||||
return [
|
||||
(coordinate[0] - extent[0]) / (extent[1] - extent[0]),
|
||||
(coordinate[1] - extent[2]) / (extent[3] - extent[2])
|
||||
(coordinate[0] - extent[0][0]) / (extent[1][0] - extent[0][0]),
|
||||
(coordinate[1] - extent[0][1]) / (extent[1][1] - extent[0][1])
|
||||
];
|
||||
};
|
||||
|
||||
@@ -307,12 +307,12 @@ ol.extent.normalize = function(extent, coordinate) {
|
||||
* @param {number} value Value.
|
||||
*/
|
||||
ol.extent.scaleFromCenter = function(extent, value) {
|
||||
var deltaX = ((extent[1] - extent[0]) / 2) * (value - 1);
|
||||
var deltaY = ((extent[3] - extent[2]) / 2) * (value - 1);
|
||||
extent[0] -= deltaX;
|
||||
extent[1] += deltaX;
|
||||
extent[2] -= deltaY;
|
||||
extent[3] += deltaY;
|
||||
var deltaX = ((extent[1][0] - extent[0][0]) / 2) * (value - 1);
|
||||
var deltaY = ((extent[1][1] - extent[0][1]) / 2) * (value - 1);
|
||||
extent[0][0] -= deltaX;
|
||||
extent[1][0] += deltaX;
|
||||
extent[0][1] -= deltaY;
|
||||
extent[1][1] += deltaY;
|
||||
};
|
||||
|
||||
|
||||
@@ -321,7 +321,8 @@ ol.extent.scaleFromCenter = function(extent, value) {
|
||||
* @return {string} String.
|
||||
*/
|
||||
ol.extent.toString = function(extent) {
|
||||
return '(' + [extent[0], extent[1], extent[2], extent[3]].join(', ') + ')';
|
||||
return '(' + [extent[0][0], extent[1][0], extent[0][1],
|
||||
extent[1][1]].join(', ') + ')';
|
||||
};
|
||||
|
||||
|
||||
@@ -333,10 +334,10 @@ ol.extent.toString = function(extent) {
|
||||
*/
|
||||
ol.extent.transform = function(extent, transformFn, opt_extent) {
|
||||
var coordinates = [
|
||||
extent[0], extent[2],
|
||||
extent[0], extent[3],
|
||||
extent[1], extent[2],
|
||||
extent[1], extent[3]
|
||||
extent[0][0], extent[0][1],
|
||||
extent[0][0], extent[1][1],
|
||||
extent[1][0], extent[0][1],
|
||||
extent[1][0], extent[1][1]
|
||||
];
|
||||
transformFn(coordinates, coordinates, 2);
|
||||
var xs = [coordinates[0], coordinates[2], coordinates[4], coordinates[6]];
|
||||
|
||||
@@ -7,7 +7,7 @@ describe('ol.extent', function() {
|
||||
|
||||
describe('positive', function() {
|
||||
it('returns true', function() {
|
||||
var extent = [1, 3, 2, 4];
|
||||
var extent = [[1, 2], [3, 4]];
|
||||
expect(ol.extent.containsCoordinate(extent, [1, 2])).to.be.ok();
|
||||
expect(ol.extent.containsCoordinate(extent, [1, 3])).to.be.ok();
|
||||
expect(ol.extent.containsCoordinate(extent, [1, 4])).to.be.ok();
|
||||
@@ -22,7 +22,7 @@ describe('ol.extent', function() {
|
||||
|
||||
describe('negative', function() {
|
||||
it('returns false', function() {
|
||||
var extent = [1, 3, 2, 4];
|
||||
var extent = [[1, 2], [3, 4]];
|
||||
expect(ol.extent.containsCoordinate(extent, [0, 1])).to.not.be();
|
||||
expect(ol.extent.containsCoordinate(extent, [0, 2])).to.not.be();
|
||||
expect(ol.extent.containsCoordinate(extent, [0, 3])).to.not.be();
|
||||
@@ -45,7 +45,7 @@ describe('ol.extent', function() {
|
||||
|
||||
describe('getCenter', function() {
|
||||
it('returns the expected center', function() {
|
||||
var extent = [1, 3, 2, 4];
|
||||
var extent = [[1, 2], [3, 4]];
|
||||
var center = ol.extent.getCenter(extent);
|
||||
expect(center[0]).to.eql(2);
|
||||
expect(center[1]).to.eql(3);
|
||||
@@ -57,53 +57,53 @@ describe('ol.extent', function() {
|
||||
it('works for a unit square', function() {
|
||||
var extent = ol.extent.getForView2DAndSize(
|
||||
[0, 0], 1, 0, [1, 1]);
|
||||
expect(extent[0]).to.be(-0.5);
|
||||
expect(extent[1]).to.be(0.5);
|
||||
expect(extent[2]).to.be(-0.5);
|
||||
expect(extent[3]).to.be(0.5);
|
||||
expect(extent[0][0]).to.be(-0.5);
|
||||
expect(extent[1][0]).to.be(0.5);
|
||||
expect(extent[0][1]).to.be(-0.5);
|
||||
expect(extent[1][1]).to.be(0.5);
|
||||
});
|
||||
|
||||
it('works for center', function() {
|
||||
var extent = ol.extent.getForView2DAndSize(
|
||||
[5, 10], 1, 0, [1, 1]);
|
||||
expect(extent[0]).to.be(4.5);
|
||||
expect(extent[1]).to.be(5.5);
|
||||
expect(extent[2]).to.be(9.5);
|
||||
expect(extent[3]).to.be(10.5);
|
||||
expect(extent[0][0]).to.be(4.5);
|
||||
expect(extent[1][0]).to.be(5.5);
|
||||
expect(extent[0][1]).to.be(9.5);
|
||||
expect(extent[1][1]).to.be(10.5);
|
||||
});
|
||||
|
||||
it('works for rotation', function() {
|
||||
var extent = ol.extent.getForView2DAndSize(
|
||||
[0, 0], 1, Math.PI / 4, [1, 1]);
|
||||
expect(extent[0]).to.roughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[1]).to.roughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[2]).to.roughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[3]).to.roughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[0][0]).to.roughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[1][0]).to.roughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[0][1]).to.roughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent[1][1]).to.roughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
});
|
||||
|
||||
it('works for resolution', function() {
|
||||
var extent = ol.extent.getForView2DAndSize(
|
||||
[0, 0], 2, 0, [1, 1]);
|
||||
expect(extent[0]).to.be(-1);
|
||||
expect(extent[1]).to.be(1);
|
||||
expect(extent[2]).to.be(-1);
|
||||
expect(extent[3]).to.be(1);
|
||||
expect(extent[0][0]).to.be(-1);
|
||||
expect(extent[1][0]).to.be(1);
|
||||
expect(extent[0][1]).to.be(-1);
|
||||
expect(extent[1][1]).to.be(1);
|
||||
});
|
||||
|
||||
it('works for size', function() {
|
||||
var extent = ol.extent.getForView2DAndSize(
|
||||
[0, 0], 1, 0, [10, 5]);
|
||||
expect(extent[0]).to.be(-5);
|
||||
expect(extent[1]).to.be(5);
|
||||
expect(extent[2]).to.be(-2.5);
|
||||
expect(extent[3]).to.be(2.5);
|
||||
expect(extent[0][0]).to.be(-5);
|
||||
expect(extent[1][0]).to.be(5);
|
||||
expect(extent[0][1]).to.be(-2.5);
|
||||
expect(extent[1][1]).to.be(2.5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getSize', function() {
|
||||
it('returns the expected size', function() {
|
||||
var extent = [0, 2, 1, 4];
|
||||
var extent = [[0, 1], [2, 4]];
|
||||
var size = ol.extent.getSize(extent);
|
||||
expect(size).to.eql([2, 3]);
|
||||
});
|
||||
@@ -111,46 +111,42 @@ describe('ol.extent', function() {
|
||||
|
||||
describe('intersect', function() {
|
||||
|
||||
var extent1;
|
||||
|
||||
beforeEach(function() {
|
||||
extent1 = [50, 100, 50, 100];
|
||||
});
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(ol.extent.intersects(extent1, extent1)).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [20, 80, 20, 80])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [20, 80, 50, 100])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [20, 80, 80, 120])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [50, 100, 20, 80])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [50, 100, 80, 120])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [80, 120, 20, 80])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [80, 120, 50, 100])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [80, 120, 80, 120])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [20, 120, 20, 120])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [70, 80, 70, 80])).to.be(true);
|
||||
expect(ol.extent.intersects(extent1, [10, 30, 10, 30])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [30, 70, 10, 30])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [50, 100, 10, 30])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [80, 120, 10, 30])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [120, 140, 10, 30])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [10, 30, 30, 70])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [120, 140, 30, 70])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [10, 30, 50, 100])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [120, 140, 50, 100])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [10, 30, 80, 120])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [120, 140, 80, 120])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [10, 30, 120, 140])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [30, 70, 120, 140])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [50, 100, 120, 140])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [80, 120, 120, 140])).to.be(false);
|
||||
expect(ol.extent.intersects(extent1, [120, 140, 120, 140])).to.be(false);
|
||||
var intersects = ol.extent.intersects;
|
||||
var extent = [[50, 50], [100, 100]];
|
||||
expect(intersects(extent, extent)).to.be(true);
|
||||
expect(intersects(extent, [[20, 20], [80, 80]])).to.be(true);
|
||||
expect(intersects(extent, [[20, 50], [80, 100]])).to.be(true);
|
||||
expect(intersects(extent, [[20, 80], [80, 120]])).to.be(true);
|
||||
expect(intersects(extent, [[50, 20], [100, 80]])).to.be(true);
|
||||
expect(intersects(extent, [[50, 80], [100, 120]])).to.be(true);
|
||||
expect(intersects(extent, [[80, 20], [120, 80]])).to.be(true);
|
||||
expect(intersects(extent, [[80, 50], [120, 100]])).to.be(true);
|
||||
expect(intersects(extent, [[80, 80], [120, 120]])).to.be(true);
|
||||
expect(intersects(extent, [[20, 20], [120, 120]])).to.be(true);
|
||||
expect(intersects(extent, [[70, 70], [80, 80]])).to.be(true);
|
||||
expect(intersects(extent, [[10, 10], [30, 30]])).to.be(false);
|
||||
expect(intersects(extent, [[30, 10], [70, 30]])).to.be(false);
|
||||
expect(intersects(extent, [[50, 10], [100, 30]])).to.be(false);
|
||||
expect(intersects(extent, [[80, 10], [120, 30]])).to.be(false);
|
||||
expect(intersects(extent, [[120, 10], [140, 30]])).to.be(false);
|
||||
expect(intersects(extent, [[10, 30], [30, 70]])).to.be(false);
|
||||
expect(intersects(extent, [[120, 30], [140, 70]])).to.be(false);
|
||||
expect(intersects(extent, [[10, 50], [30, 100]])).to.be(false);
|
||||
expect(intersects(extent, [[120, 50], [140, 100]])).to.be(false);
|
||||
expect(intersects(extent, [[10, 80], [30, 120]])).to.be(false);
|
||||
expect(intersects(extent, [[120, 80], [140, 120]])).to.be(false);
|
||||
expect(intersects(extent, [[10, 120], [30, 140]])).to.be(false);
|
||||
expect(intersects(extent, [[30, 120], [70, 140]])).to.be(false);
|
||||
expect(intersects(extent, [[50, 120], [100, 140]])).to.be(false);
|
||||
expect(intersects(extent, [[80, 120], [120, 140]])).to.be(false);
|
||||
expect(intersects(extent, [[120, 120], [140, 140]])).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalize', function() {
|
||||
it('returns the expected coordinate', function() {
|
||||
var extent = [0, 2, 1, 3];
|
||||
var extent = [[0, 1], [2, 3]];
|
||||
var coordinate;
|
||||
|
||||
coordinate = ol.extent.normalize(extent, [1, 2]);
|
||||
@@ -177,18 +173,18 @@ describe('ol.extent', function() {
|
||||
|
||||
describe('scaleFromCenter', function() {
|
||||
it('scales the extent from its center', function() {
|
||||
var extent = [1, 3, 1, 3];
|
||||
var extent = [[1, 1], [3, 3]];
|
||||
ol.extent.scaleFromCenter(extent, 2);
|
||||
expect(extent[0]).to.eql(0);
|
||||
expect(extent[1]).to.eql(4);
|
||||
expect(extent[2]).to.eql(0);
|
||||
expect(extent[3]).to.eql(4);
|
||||
expect(extent[0][0]).to.eql(0);
|
||||
expect(extent[1][0]).to.eql(4);
|
||||
expect(extent[0][1]).to.eql(0);
|
||||
expect(extent[1][1]).to.eql(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
it('returns the expected string', function() {
|
||||
var extent = [0, 2, 1, 3];
|
||||
var extent = [[0, 1], [2, 3]];
|
||||
expect(ol.extent.toString(extent)).to.eql('(0, 2, 1, 3)');
|
||||
});
|
||||
});
|
||||
@@ -197,15 +193,16 @@ describe('ol.extent', function() {
|
||||
|
||||
it('does transform', function() {
|
||||
var transformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var sourceExtent = [-15, 45, -30, 60];
|
||||
var sourceExtent = [[-15, -30], [45, 60]];
|
||||
var destinationExtent = ol.extent.transform(sourceExtent, transformFn);
|
||||
expect(destinationExtent).not.to.be(undefined);
|
||||
expect(destinationExtent).not.to.be(null);
|
||||
// FIXME check values with third-party tool
|
||||
expect(destinationExtent[0]).to.roughlyEqual(-1669792.3618991037, 1e-9);
|
||||
expect(destinationExtent[1]).to.roughlyEqual(5009377.085697311, 1e-9);
|
||||
expect(destinationExtent[2]).to.roughlyEqual(-3503549.843504376, 1e-8);
|
||||
expect(destinationExtent[3]).to.roughlyEqual(8399737.889818361, 1e-9);
|
||||
expect(destinationExtent[0][0])
|
||||
.to.roughlyEqual(-1669792.3618991037, 1e-9);
|
||||
expect(destinationExtent[1][0]).to.roughlyEqual(5009377.085697311, 1e-9);
|
||||
expect(destinationExtent[0][1]).to.roughlyEqual(-3503549.843504376, 1e-8);
|
||||
expect(destinationExtent[1][1]).to.roughlyEqual(8399737.889818361, 1e-9);
|
||||
});
|
||||
|
||||
it('takes arbitrary function', function() {
|
||||
@@ -222,14 +219,14 @@ describe('ol.extent', function() {
|
||||
}
|
||||
return output;
|
||||
};
|
||||
var sourceExtent = [-15, 45, -30, 60];
|
||||
var sourceExtent = [[-15, -30], [45, 60]];
|
||||
var destinationExtent = ol.extent.transform(sourceExtent, transformFn);
|
||||
expect(destinationExtent).not.to.be(undefined);
|
||||
expect(destinationExtent).not.to.be(null);
|
||||
expect(destinationExtent[0]).to.be(-45);
|
||||
expect(destinationExtent[1]).to.be(15);
|
||||
expect(destinationExtent[2]).to.be(-60);
|
||||
expect(destinationExtent[3]).to.be(30);
|
||||
expect(destinationExtent[0][0]).to.be(-45);
|
||||
expect(destinationExtent[1][0]).to.be(15);
|
||||
expect(destinationExtent[0][1]).to.be(-60);
|
||||
expect(destinationExtent[1][1]).to.be(30);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user