Sharing code with rectangle

We cannot use the rectangle constructor here because a rectangle makes an assertion about min being less than max and a range may have equal min/max.
This commit is contained in:
Tim Schaub
2013-02-19 07:30:54 -07:00
parent 797dba2cdb
commit 5148ad038c

View File

@@ -1,7 +1,7 @@
goog.provide('ol.TileRange');
goog.require('goog.asserts');
goog.require('ol.Size');
goog.require('ol.Rectangle');
goog.require('ol.TileCoord');
@@ -11,6 +11,7 @@ goog.require('ol.TileCoord');
* by its min/max tile coordinates and is inclusive of coordinates.
*
* @constructor
* @extends {ol.Rectangle}
* @param {number} minX Minimum X.
* @param {number} minY Minimum Y.
* @param {number} maxX Maximum X.
@@ -39,6 +40,7 @@ ol.TileRange = function(minX, minY, maxX, maxY) {
this.maxY = maxY;
};
goog.inherits(ol.TileRange, ol.Rectangle);
/**
@@ -83,28 +85,7 @@ ol.TileRange.prototype.containsTileRange = function(tileRange) {
/**
* @param {ol.TileRange} range Other range.
* @return {boolean} The two ranges are equivalent.
*/
ol.TileRange.prototype.equals = function(range) {
return this.minX == range.minX && this.minY == range.minY &&
this.maxX == range.maxX && this.maxY == range.maxY;
};
/**
* Extend this range so it includes the other.
* @param {ol.TileRange} other Other range.
*/
ol.TileRange.prototype.extend = function(other) {
this.minX = Math.min(this.minX, other.minX);
this.minY = Math.min(this.minY, other.minY);
this.maxX = Math.max(this.maxX, other.maxX);
this.maxY = Math.max(this.maxY, other.maxY);
};
/**
* @inheritDoc
* @return {number} Height.
*/
ol.TileRange.prototype.getHeight = function() {
@@ -113,30 +94,9 @@ ol.TileRange.prototype.getHeight = function() {
/**
* @return {ol.Size} Size.
*/
ol.TileRange.prototype.getSize = function() {
return new ol.Size(this.getWidth(), this.getHeight());
};
/**
* @inheritDoc
* @return {number} Width.
*/
ol.TileRange.prototype.getWidth = function() {
return this.maxX - this.minX + 1;
};
/**
* Test for range intersection.
* @param {ol.TileRange} other Other range.
* @return {boolean} The two ranges intersect.
*/
ol.TileRange.prototype.intersects = function(other) {
return this.minX <= other.maxX &&
this.maxX >= other.minX &&
this.minY <= other.maxY &&
this.maxY >= other.minY;
};