From 66a5d90965bd2ae4d8aceb11607404e34416e902 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 3 Oct 2006 01:05:42 +0000 Subject: [PATCH] Fix broken test of new Bounds.intersectBounds, add test to ensure it doesn't break again in the future. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1530 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes.js | 13 +++++++++++-- tests/test_Bounds.html | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 3a412bb233..c2c22cc5a6 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -490,9 +490,18 @@ OpenLayers.Bounds.prototype = { if (inclusive == null) { inclusive = true; } + var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ? + true : (bounds.bottom > this.bottom) && (bounds.bottom < this.top); + var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ? + true : (bounds.top > this.bottom) && (bounds.top < this.top); + var inRight = (bounds.right == this.right && bounds.left == this.left) ? + true : (bounds.right > this.left) && (bounds.right < this.right); + var inLeft = (bounds.right == this.right && bounds.left == this.left) ? + true : (bounds.left > this.left) && (bounds.left < this.right); return (this.containsBounds(bounds, true, inclusive) || - bounds.containsBounds(this, true, inclusive)); + bounds.containsBounds(this, true, inclusive) || + (inTop || inBottom ) && (inLeft || inRight )); }, /** @@ -535,7 +544,7 @@ OpenLayers.Bounds.prototype = { inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top); } - return (partial) ? (inTop || inBottom) && (inLeft || inRight ) + return (partial) ? (inTop || inBottom ) && (inLeft || inRight ) : (inTop && inLeft && inBottom && inRight); }, diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 9ada4d4a74..77d20b4fb6 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -108,15 +108,17 @@ } function test_08a_Bounds_intersectsBounds(t) { - t.plan( 15 ); + t.plan( 16 ); var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90); //inside var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10); + var cBounds = new OpenLayers.Bounds(-181,-90,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), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); + t.eq( cBounds.intersectsBounds(aBounds, false), true, "cBounds with aBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." ); //outside bBounds = new OpenLayers.Bounds(-181, -91, 181, 91);