Bounds: Added extendXY() method
This is a simpler variant of the extend() method, but with less overhead.
This commit is contained in:
@@ -392,6 +392,32 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: extendXY
|
||||
* Extend the bounds to include the XY coordinate specified.
|
||||
*
|
||||
* Parameters:
|
||||
* x - {number} The X part of the the coordinate.
|
||||
* y - {number} The Y part of the the coordinate.
|
||||
*/
|
||||
extendXY:function(x, y) {
|
||||
// clear cached center location
|
||||
this.centerLonLat = null;
|
||||
|
||||
if ((this.left == null) || (x < this.left)) {
|
||||
this.left = x;
|
||||
}
|
||||
if ((this.bottom == null) || (y < this.bottom)) {
|
||||
this.bottom = y;
|
||||
}
|
||||
if ((this.right == null) || (x > this.right)) {
|
||||
this.right = x;
|
||||
}
|
||||
if ((this.top == null) || (y > this.top)) {
|
||||
this.top = y;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: containsLonLat
|
||||
* Returns whether the bounds object contains the given <OpenLayers.LonLat>.
|
||||
|
||||
@@ -539,6 +539,39 @@
|
||||
}
|
||||
|
||||
|
||||
function test_Bounds_extendXY(t) {
|
||||
t.plan(3);
|
||||
|
||||
// null bounds to start
|
||||
var originalBounds = new OpenLayers.Bounds();
|
||||
|
||||
var bounds = originalBounds.clone();
|
||||
bounds.extendXY(4, 5);
|
||||
|
||||
t.ok(bounds.equals(new OpenLayers.Bounds(4,5,4,5)), "uninitialized bounds can be safely extended");
|
||||
|
||||
// left, bottom
|
||||
originalBounds = new OpenLayers.Bounds(10,20,50,80);
|
||||
|
||||
bounds = originalBounds.clone();
|
||||
bounds.extendXY(5, 10);
|
||||
|
||||
t.ok( ((bounds.left == 5) &&
|
||||
(bounds.bottom == 10) &&
|
||||
(bounds.right == originalBounds.right) &&
|
||||
(bounds.top == originalBounds.top)), "extendXY correctly modifies left and bottom");
|
||||
|
||||
// right, top
|
||||
bounds = originalBounds.clone();
|
||||
bounds.extendXY(60, 90);
|
||||
|
||||
t.ok( ((bounds.left == originalBounds.left) &&
|
||||
(bounds.bottom == originalBounds.bottom) &&
|
||||
(bounds.right == 60) &&
|
||||
(bounds.top == 90)), "extendXY correctly modifies right and top");
|
||||
}
|
||||
|
||||
|
||||
function test_Bounds_wrapDateLine(t) {
|
||||
t.plan( 13 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user