Add scale to ol.Rectangle

This commit is contained in:
Éric Lemoine
2013-01-29 15:41:27 +01:00
parent 35a6cac37f
commit aa9f820723
2 changed files with 24 additions and 0 deletions

View File

@@ -124,3 +124,16 @@ ol.Rectangle.prototype.normalize = function(coordinate) {
ol.Rectangle.prototype.toString = function() { ol.Rectangle.prototype.toString = function() {
return '(' + [this.minX, this.minY, this.maxX, this.maxY].join(', ') + ')'; return '(' + [this.minX, this.minY, this.maxX, this.maxY].join(', ') + ')';
}; };
/**
* @param {number} value Value.
*/
ol.Rectangle.prototype.scale = function(value) {
var deltaX = (this.getWidth() / 2.0) * (value - 1);
var deltaY = (this.getHeight() / 2.0) * (value - 1);
this.minX -= deltaX;
this.minY -= deltaY;
this.maxX += deltaX;
this.maxY += deltaY;
};

View File

@@ -98,6 +98,17 @@ describe('ol.Rectangle', function() {
}); });
}); });
describe('scale', function() {
it('scales the extent', function() {
var rectangle = new ol.Rectangle(1, 1, 3, 3);
rectangle.scale(2);
expect(rectangle.minX).toEqual(0);
expect(rectangle.minY).toEqual(0);
expect(rectangle.maxX).toEqual(4);
expect(rectangle.maxY).toEqual(4);
});
});
}); });
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');