Remove problematic (and unused) clone methods, move contains out of ol.Rectangle

This commit is contained in:
Tom Payne
2012-09-24 23:12:32 +02:00
parent c43e04ea77
commit 424dbd7582
13 changed files with 38 additions and 122 deletions

View File

@@ -1,5 +1,3 @@
goog.require('ol.Coordinate');
goog.exportSymbol('ol.Coordinate', ol.Coordinate);
goog.exportProperty(ol.Coordinate.prototype,
'clone', ol.Coordinate.prototype.clone);

View File

@@ -1,5 +1,3 @@
goog.require('ol.Extent');
goog.exportSymbol('ol.Extent', ol.Extent);
goog.exportProperty(ol.Extent.prototype,
'clone', ol.Extent.prototype.clone);

View File

@@ -46,11 +46,3 @@ ol.Color.createFromString = function(str, opt_a) {
var a = opt_a || 255;
return new ol.Color(rgb[0], rgb[1], rgb[2], a);
};
/**
* @return {ol.Color} Clone.
*/
ol.Color.prototype.clone = function() {
return new ol.Color(this.r, this.g, this.b, this.a);
};

View File

@@ -21,11 +21,3 @@ goog.inherits(ol.Coordinate, goog.math.Vec2);
* @type {ol.Coordinate}
*/
ol.Coordinate.ZERO = new ol.Coordinate(0, 0);
/**
* @return {ol.Coordinate} Clone.
*/
ol.Coordinate.prototype.clone = function() {
return new ol.Coordinate(this.x, this.y);
};

View File

@@ -41,10 +41,12 @@ ol.Extent.boundingExtent = function(var_args) {
/**
* @return {ol.Extent} Extent.
* @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Contains.
*/
ol.Extent.prototype.clone = function() {
return new ol.Extent(this.minX, this.minY, this.maxX, this.maxY);
ol.Extent.prototype.contains = function(coordinate) {
return this.minX <= coordinate.x && coordinate.x <= this.maxX &&
this.minY <= coordinate.y && coordinate.y <= this.maxY;
};

View File

@@ -3,15 +3,38 @@ goog.require('ol.Extent');
goog.require('ol.Projection');
function testClone() {
function testContainsPositive() {
var extent = new ol.Extent(1, 2, 3, 4);
var clonedExtent = extent.clone();
assertTrue(clonedExtent instanceof ol.Extent);
assertFalse(clonedExtent === extent);
assertEquals(extent.minX, clonedExtent.minX);
assertEquals(extent.minY, clonedExtent.minY);
assertEquals(extent.maxX, clonedExtent.maxX);
assertEquals(extent.maxY, clonedExtent.maxY);
assertTrue(extent.contains(new ol.Coordinate(1, 2)));
assertTrue(extent.contains(new ol.Coordinate(1, 3)));
assertTrue(extent.contains(new ol.Coordinate(1, 4)));
assertTrue(extent.contains(new ol.Coordinate(2, 2)));
assertTrue(extent.contains(new ol.Coordinate(2, 3)));
assertTrue(extent.contains(new ol.Coordinate(2, 4)));
assertTrue(extent.contains(new ol.Coordinate(3, 2)));
assertTrue(extent.contains(new ol.Coordinate(3, 3)));
assertTrue(extent.contains(new ol.Coordinate(3, 4)));
}
function testContainsNegative() {
var extent = new ol.Extent(1, 2, 3, 4);
assertFalse(extent.contains(new ol.Coordinate(0, 1)));
assertFalse(extent.contains(new ol.Coordinate(0, 2)));
assertFalse(extent.contains(new ol.Coordinate(0, 3)));
assertFalse(extent.contains(new ol.Coordinate(0, 4)));
assertFalse(extent.contains(new ol.Coordinate(0, 5)));
assertFalse(extent.contains(new ol.Coordinate(1, 1)));
assertFalse(extent.contains(new ol.Coordinate(1, 5)));
assertFalse(extent.contains(new ol.Coordinate(2, 1)));
assertFalse(extent.contains(new ol.Coordinate(2, 5)));
assertFalse(extent.contains(new ol.Coordinate(3, 1)));
assertFalse(extent.contains(new ol.Coordinate(3, 5)));
assertFalse(extent.contains(new ol.Coordinate(4, 1)));
assertFalse(extent.contains(new ol.Coordinate(4, 2)));
assertFalse(extent.contains(new ol.Coordinate(4, 3)));
assertFalse(extent.contains(new ol.Coordinate(4, 4)));
assertFalse(extent.contains(new ol.Coordinate(4, 5)));
}

View File

@@ -14,11 +14,3 @@ ol.Pixel = function(x, y) {
goog.base(this, x, y);
};
goog.inherits(ol.Pixel, goog.math.Coordinate);
/**
* @return {ol.Pixel} Clone.
*/
ol.Pixel.prototype.clone = function() {
return new ol.Pixel(this.x, this.y);
};

View File

@@ -350,7 +350,7 @@ ol.Projection.identityTransform = function(point) {
* @return {ol.Coordinate} Point.
*/
ol.Projection.cloneTransform = function(point) {
return point.clone();
return new ol.Coordinate(point.x, point.y);
};

View File

@@ -41,24 +41,6 @@ ol.Rectangle = function(minX, minY, maxX, maxY) {
};
/**
* @return {ol.Rectangle} Clone.
*/
ol.Rectangle.prototype.clone = function() {
return new ol.Rectangle(this.minX, this.minY, this.maxX, this.maxY);
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Contains.
*/
ol.Rectangle.prototype.contains = function(coordinate) {
return this.minX <= coordinate.x && coordinate.x <= this.maxX &&
this.minY <= coordinate.y && coordinate.y <= this.maxY;
};
/**
* @return {ol.Coordinate} Center.
*/

View File

@@ -11,41 +11,6 @@ function testCenter() {
}
function testContainsPositive() {
var rectangle = new ol.Rectangle(1, 2, 3, 4);
assertTrue(rectangle.contains(new ol.Coordinate(1, 2)));
assertTrue(rectangle.contains(new ol.Coordinate(1, 3)));
assertTrue(rectangle.contains(new ol.Coordinate(1, 4)));
assertTrue(rectangle.contains(new ol.Coordinate(2, 2)));
assertTrue(rectangle.contains(new ol.Coordinate(2, 3)));
assertTrue(rectangle.contains(new ol.Coordinate(2, 4)));
assertTrue(rectangle.contains(new ol.Coordinate(3, 2)));
assertTrue(rectangle.contains(new ol.Coordinate(3, 3)));
assertTrue(rectangle.contains(new ol.Coordinate(3, 4)));
}
function testContainsNegative() {
var rectangle = new ol.Rectangle(1, 2, 3, 4);
assertFalse(rectangle.contains(new ol.Coordinate(0, 1)));
assertFalse(rectangle.contains(new ol.Coordinate(0, 2)));
assertFalse(rectangle.contains(new ol.Coordinate(0, 3)));
assertFalse(rectangle.contains(new ol.Coordinate(0, 4)));
assertFalse(rectangle.contains(new ol.Coordinate(0, 5)));
assertFalse(rectangle.contains(new ol.Coordinate(1, 1)));
assertFalse(rectangle.contains(new ol.Coordinate(1, 5)));
assertFalse(rectangle.contains(new ol.Coordinate(2, 1)));
assertFalse(rectangle.contains(new ol.Coordinate(2, 5)));
assertFalse(rectangle.contains(new ol.Coordinate(3, 1)));
assertFalse(rectangle.contains(new ol.Coordinate(3, 5)));
assertFalse(rectangle.contains(new ol.Coordinate(4, 1)));
assertFalse(rectangle.contains(new ol.Coordinate(4, 2)));
assertFalse(rectangle.contains(new ol.Coordinate(4, 3)));
assertFalse(rectangle.contains(new ol.Coordinate(4, 4)));
assertFalse(rectangle.contains(new ol.Coordinate(4, 5)));
}
function testIntersects() {
var rectangle1 = new ol.Rectangle(50, 50, 100, 100);

View File

@@ -76,14 +76,6 @@ ol.TileCoord.createFromString = function(str) {
};
/**
* @return {ol.TileCoord} Clone.
*/
ol.TileCoord.prototype.clone = function() {
return new ol.TileCoord(this.z, this.x, this.y);
};
/**
* @return {number} Hash.
*/

View File

@@ -41,14 +41,6 @@ ol.TileRange.boundingTileRange = function(var_args) {
};
/**
* @return {ol.TileRange} Clone.
*/
ol.TileRange.prototype.clone = function() {
return new ol.TileRange(this.minX, this.minY, this.maxX, this.maxY);
};
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @return {boolean} Contains tile coordinate.

View File

@@ -2,18 +2,6 @@ goog.require('goog.testing.jsunit');
goog.require('ol.TileRange');
function testClone() {
var tileRange = new ol.TileRange(1, 2, 3, 4);
var clonedTileRange = tileRange.clone();
assertTrue(clonedTileRange instanceof ol.TileRange);
assertFalse(clonedTileRange === tileRange);
assertEquals(tileRange.minX, clonedTileRange.minX);
assertEquals(tileRange.minY, clonedTileRange.minY);
assertEquals(tileRange.maxX, clonedTileRange.maxX);
assertEquals(tileRange.maxY, clonedTileRange.maxY);
}
function testContains() {
var tileRange = new ol.TileRange(1, 1, 3, 3);
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 0)));
@@ -70,7 +58,7 @@ function testForEachTileCoord() {
var tileCoords = [];
tileRange.forEachTileCoord(5, function(tileCoord) {
tileCoords.push(tileCoord.clone());
tileCoords.push(new ol.TileCoord(tileCoord.z, tileCoord.x, tileCoord.y));
});
assertEquals(4, tileCoords.length);