Add scale to ol.Rectangle
This commit is contained in:
@@ -124,3 +124,16 @@ ol.Rectangle.prototype.normalize = function(coordinate) {
|
||||
ol.Rectangle.prototype.toString = function() {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user