Modifying bounds.intersectsBounds to it catches bounds intersections where corners of one bounds are not contains in the other bounds. Thanks for the review. r=sderle (closes #1951)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9052 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-15 03:44:22 +00:00
parent 49d6463f4e
commit f9e9eb61ae
2 changed files with 49 additions and 33 deletions

View File

@@ -409,60 +409,68 @@ OpenLayers.Bounds = OpenLayers.Class({
return contains;
},
/**
* APIMethod: touchesBounds
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*
* Returns:
* {Boolean} The passed-in OpenLayers.Bounds object touches this bounds
* at a single edge, and therefore do not inclusively intersect.
*/
touchesBounds:function(bounds) {
return (this.left == bounds.right ||
this.right == bounds.left ||
this.top == bounds.bottom ||
this.bottom == bounds.top);
},
/**
* APIMethod: intersectsBounds
* Determine whether the target bounds intersects this bounds. Bounds are
* considered intersecting if any of their edges intersect or if one
* bounds contains the other.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* inclusive - {Boolean} Whether or not to include the border. Default
* is true.
* bounds - {<OpenLayers.Bounds>} The target bounds.
* inclusive - {Boolean} Treat coincident borders as intersecting. Default
* is true. If false, bounds that do not overlap but only touch at the
* border will not be considered as intersecting.
*
* Returns:
* {Boolean} The passed-in OpenLayers.Bounds object intersects this bounds.
* Simple math just check if either contains the other, allowing for
* partial.
* {Boolean} The passed-in bounds object intersects this bounds.
*/
intersectsBounds:function(bounds, inclusive) {
if (inclusive == null) {
inclusive = true;
}
var intersects = false;
var mightTouch = (
this.left == bounds.right ||
this.right == bounds.left ||
this.top == bounds.bottom ||
this.bottom == bounds.top
);
// if the two bounds only touch at an edge, and inclusive is false,
// then the bounds don't *really* intersect.
if (inclusive || !this.touchesBounds(bounds)) {
if (inclusive || !mightTouch) {
// otherwise, if one of the boundaries even partially contains another,
// inclusive of the edges, then they do intersect.
intersects = this.containsBounds(bounds, true, true) ||
bounds.containsBounds(this, true, true);
var inBottom = (
((bounds.bottom >= this.bottom) && (bounds.bottom <= this.top)) ||
((this.bottom >= bounds.bottom) && (this.bottom <= bounds.top))
);
var inTop = (
((bounds.top >= this.bottom) && (bounds.top <= this.top)) ||
((this.top > bounds.bottom) && (this.top < bounds.top))
);
var inLeft = (
((bounds.left >= this.left) && (bounds.left <= this.right)) ||
((this.left >= bounds.left) && (this.left <= bounds.right))
);
var inRight = (
((bounds.right >= this.left) && (bounds.right <= this.right)) ||
((this.right >= bounds.left) && (this.right <= bounds.right))
);
intersects = ((inBottom || inTop) && (inLeft || inRight));
}
return intersects;
},
/**
* APIMethod: containsBounds
* Determine whether the target bounds is contained within this bounds.
*
* bounds - {<OpenLayers.Bounds>}
* partial - {Boolean} If true, only part of passed-in bounds needs be
* within this bounds. If false, the entire passed-in bounds must be
* within. Default is false
* inclusive - {Boolean} Whether or not to include the border. Default is
* bounds - {<OpenLayers.Bounds>} The target bounds.
* partial - {Boolean} If any of the target corners is within this bounds
* consider the bounds contained. Default is false. If true, the
* entire target bounds must be contained within this bounds.
* inclusive - {Boolean} Treat shared edges as contained. Default is
* true.
*
* Returns: