add Bounds.intersectsBounds() function and tests
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1529 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -474,7 +474,27 @@ OpenLayers.Bounds.prototype = {
|
|||||||
}
|
}
|
||||||
return contains;
|
return contains;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenLayers.Bounds} bounds
|
||||||
|
* @param {Boolean} inclusive Whether or not to include the border.
|
||||||
|
* Default is true
|
||||||
|
*
|
||||||
|
* @return Whether or not the passed-in OpenLayers.Bounds object intersects
|
||||||
|
* this bounds. Simple math just check if either contains the other,
|
||||||
|
* allowing for partial.
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
intersectsBounds:function(bounds, inclusive) {
|
||||||
|
|
||||||
|
if (inclusive == null) {
|
||||||
|
inclusive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.containsBounds(bounds, true, inclusive) ||
|
||||||
|
bounds.containsBounds(this, true, inclusive));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {OpenLayers.Bounds} bounds
|
* @param {OpenLayers.Bounds} bounds
|
||||||
* @param {Boolean} partial If true, only part of passed-in
|
* @param {Boolean} partial If true, only part of passed-in
|
||||||
|
|||||||
+38
-1
@@ -107,7 +107,44 @@
|
|||||||
t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" );
|
t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_08_Bounds_containsBounds(t) {
|
function test_08a_Bounds_intersectsBounds(t) {
|
||||||
|
t.plan( 15 );
|
||||||
|
|
||||||
|
var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90);
|
||||||
|
|
||||||
|
//inside
|
||||||
|
var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10);
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||||
|
|
||||||
|
//outside
|
||||||
|
bBounds = new OpenLayers.Bounds(-181, -91, 181, 91);
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||||
|
|
||||||
|
//total intersect
|
||||||
|
bBounds = new OpenLayers.Bounds(-185, -100, 20, 50);
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||||
|
|
||||||
|
//border intersect
|
||||||
|
bBounds = new OpenLayers.Bounds(-360, -180, -180, -90);
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||||
|
|
||||||
|
//no intersect
|
||||||
|
bBounds = new OpenLayers.Bounds(-360, -180, -185, -95);
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + ")" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, true), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||||
|
t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_08b_Bounds_containsBounds(t) {
|
||||||
t.plan( 35 );
|
t.plan( 35 );
|
||||||
containerBounds = new OpenLayers.Bounds(10,10,40,40);
|
containerBounds = new OpenLayers.Bounds(10,10,40,40);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user