Make ol.Rectangle.intersects a member function rather than a static function

This commit is contained in:
Tom Payne
2012-07-28 01:11:09 +02:00
parent bf20ec718e
commit b59fe13242
2 changed files with 14 additions and 15 deletions

View File

@@ -41,19 +41,6 @@ ol.Rectangle = function(minX, minY, maxX, maxY) {
};
/**
* @param {ol.Rectangle} rectangle1 Rectangle.
* @param {ol.Rectangle} rectangle2 Rectangle.
* @return {boolean} Intersects.
*/
ol.Rectangle.intersects = function(rectangle1, rectangle2) {
return rectangle1.minX <= rectangle2.maxX &&
rectangle1.maxX >= rectangle2.minX &&
rectangle1.minY <= rectangle2.maxY &&
rectangle1.maxY >= rectangle2.minY;
};
/**
* @return {ol.Rectangle} Clone.
*/
@@ -105,6 +92,18 @@ ol.Rectangle.prototype.getWidth = function() {
};
/**
* @param {ol.Rectangle} rectangle Rectangle.
* @return {boolean} Intersects.
*/
ol.Rectangle.prototype.intersects = function(rectangle) {
return this.minX <= rectangle.maxX &&
this.maxX >= rectangle.minX &&
this.minY <= rectangle.maxY &&
this.maxY >= rectangle.minY;
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @return {ol.Coordinate} Coordinate.

View File

@@ -64,11 +64,11 @@ function testIntersects() {
function assertIntersects(rectangle2) {
assertTrue(rectangle1 + ' expected to intersect ' + rectangle2,
ol.Rectangle.intersects(rectangle1, rectangle2));
rectangle1.intersects(rectangle2));
}
function assertNotIntersects(rectangle2) {
assertFalse(rectangle1 + ' expected to not intersect ' + rectangle2,
ol.Rectangle.intersects(rectangle1, rectangle2));
rectangle1.intersects(rectangle2));
}
assertIntersects(rectangle1);