Add containsExtent to ol.Extent
This commit is contained in:
+16
-2
@@ -46,17 +46,31 @@ ol.Extent.boundingExtent = function(var_args) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given coordinate is contained or on the edge of the extent.
|
* Checks if the passed coordinate is contained or on the edge
|
||||||
|
* of the extent.
|
||||||
*
|
*
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @return {boolean} Contains.
|
* @return {boolean} Contains.
|
||||||
*/
|
*/
|
||||||
ol.Extent.prototype.contains = function(coordinate) {
|
ol.Extent.prototype.containsCoordinate = function(coordinate) {
|
||||||
return this.minX <= coordinate.x && coordinate.x <= this.maxX &&
|
return this.minX <= coordinate.x && coordinate.x <= this.maxX &&
|
||||||
this.minY <= coordinate.y && coordinate.y <= this.maxY;
|
this.minY <= coordinate.y && coordinate.y <= this.maxY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed extent is contained or on the edge of the
|
||||||
|
* extent.
|
||||||
|
*
|
||||||
|
* @param {ol.Extent} extent Extent.
|
||||||
|
* @return {boolean} Contains.
|
||||||
|
*/
|
||||||
|
ol.Extent.prototype.containsExtent = function(extent) {
|
||||||
|
return this.minX <= extent.minX && extent.maxX <= this.maxX &&
|
||||||
|
this.minY <= extent.minY && extent.maxY <= this.maxY;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Coordinate} Bottom left coordinate.
|
* @return {ol.Coordinate} Bottom left coordinate.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+51
-26
@@ -2,42 +2,67 @@ goog.provide('ol.test.Extent');
|
|||||||
|
|
||||||
describe('ol.Extent', function() {
|
describe('ol.Extent', function() {
|
||||||
|
|
||||||
describe('contains', function() {
|
describe('containsCoordinate', function() {
|
||||||
|
|
||||||
describe('positive', function() {
|
describe('positive', function() {
|
||||||
it('returns true', function() {
|
it('returns true', function() {
|
||||||
var extent = new ol.Extent(1, 2, 3, 4);
|
var extent = new ol.Extent(1, 2, 3, 4);
|
||||||
expect(extent.contains(new ol.Coordinate(1, 2))).toBeTruthy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(1, 3))).toBeTruthy();
|
new ol.Coordinate(1, 2))).toBeTruthy();
|
||||||
expect(extent.contains(new ol.Coordinate(1, 4))).toBeTruthy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(2, 2))).toBeTruthy();
|
new ol.Coordinate(1, 3))).toBeTruthy();
|
||||||
expect(extent.contains(new ol.Coordinate(2, 3))).toBeTruthy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(2, 4))).toBeTruthy();
|
new ol.Coordinate(1, 4))).toBeTruthy();
|
||||||
expect(extent.contains(new ol.Coordinate(3, 2))).toBeTruthy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(3, 3))).toBeTruthy();
|
new ol.Coordinate(2, 2))).toBeTruthy();
|
||||||
expect(extent.contains(new ol.Coordinate(3, 4))).toBeTruthy();
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(2, 3))).toBeTruthy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(2, 4))).toBeTruthy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(3, 2))).toBeTruthy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(3, 3))).toBeTruthy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(3, 4))).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('negative', function() {
|
describe('negative', function() {
|
||||||
it('returns false', function() {
|
it('returns false', function() {
|
||||||
var extent = new ol.Extent(1, 2, 3, 4);
|
var extent = new ol.Extent(1, 2, 3, 4);
|
||||||
expect(extent.contains(new ol.Coordinate(0, 1))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(0, 2))).toBeFalsy();
|
new ol.Coordinate(0, 1))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(0, 3))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(0, 4))).toBeFalsy();
|
new ol.Coordinate(0, 2))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(0, 5))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(1, 1))).toBeFalsy();
|
new ol.Coordinate(0, 3))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(1, 5))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(2, 1))).toBeFalsy();
|
new ol.Coordinate(0, 4))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(2, 5))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(3, 1))).toBeFalsy();
|
new ol.Coordinate(0, 5))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(3, 5))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(4, 1))).toBeFalsy();
|
new ol.Coordinate(1, 1))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(4, 2))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(4, 3))).toBeFalsy();
|
new ol.Coordinate(1, 5))).toBeFalsy();
|
||||||
expect(extent.contains(new ol.Coordinate(4, 4))).toBeFalsy();
|
expect(extent.containsCoordinate(
|
||||||
expect(extent.contains(new ol.Coordinate(4, 5))).toBeFalsy();
|
new ol.Coordinate(2, 1))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(2, 5))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(3, 1))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(3, 5))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(4, 1))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(4, 2))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(4, 3))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(4, 4))).toBeFalsy();
|
||||||
|
expect(extent.containsCoordinate(
|
||||||
|
new ol.Coordinate(4, 5))).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user