OpenLayers OpenLayers

Changeset 1529

Show
Ignore:
Timestamp:
10/02/06 19:49:19 (2 years ago)
Author:
euzuro
Message:

add Bounds.intersectsBounds() function and tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes.js

    r1506 r1529  
    475475        return contains; 
    476476    }, 
    477   
     477 
     478    /** 
     479     * @param {OpenLayers.Bounds} bounds 
     480     * @param {Boolean} inclusive Whether or not to include the border.  
     481     *                            Default is true 
     482     * 
     483     * @return Whether or not the passed-in OpenLayers.Bounds object intersects 
     484     *         this bounds. Simple math just check if either contains the other,  
     485     *         allowing for partial. 
     486     * @type Boolean 
     487     */ 
     488    intersectsBounds:function(bounds, inclusive) { 
     489 
     490        if (inclusive == null) { 
     491            inclusive = true; 
     492        } 
     493 
     494        return (this.containsBounds(bounds, true, inclusive) || 
     495                bounds.containsBounds(this, true, inclusive)); 
     496    }, 
     497     
    478498    /** 
    479499    * @param {OpenLayers.Bounds} bounds 
  • trunk/openlayers/tests/test_Bounds.html

    r1506 r1529  
    108108     } 
    109109 
    110      function test_08_Bounds_containsBounds(t) { 
     110     function test_08a_Bounds_intersectsBounds(t) { 
     111         t.plan( 15 ); 
     112 
     113        var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90); 
     114 
     115        //inside 
     116        var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10); 
     117        t.eq( aBounds.intersectsBounds(bBounds),        true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); 
     118        t.eq( aBounds.intersectsBounds(bBounds, true),  true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); 
     119        t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); 
     120 
     121        //outside 
     122        bBounds = new OpenLayers.Bounds(-181, -91, 181, 91); 
     123        t.eq( aBounds.intersectsBounds(bBounds),        true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); 
     124        t.eq( aBounds.intersectsBounds(bBounds, true),  true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); 
     125        t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); 
     126 
     127        //total intersect 
     128        bBounds = new OpenLayers.Bounds(-185, -100, 20, 50); 
     129        t.eq( aBounds.intersectsBounds(bBounds),        true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); 
     130        t.eq( aBounds.intersectsBounds(bBounds, true),  true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); 
     131        t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); 
     132 
     133        //border intersect 
     134        bBounds = new OpenLayers.Bounds(-360, -180, -180, -90); 
     135        t.eq( aBounds.intersectsBounds(bBounds),        true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); 
     136        t.eq( aBounds.intersectsBounds(bBounds, true),  true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); 
     137        t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); 
     138 
     139        //no intersect 
     140        bBounds = new OpenLayers.Bounds(-360, -180, -185, -95); 
     141        t.eq( aBounds.intersectsBounds(bBounds),        false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + ")" ); 
     142        t.eq( aBounds.intersectsBounds(bBounds, true),  false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is true" ); 
     143        t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); 
     144 
     145     } 
     146      
     147     function test_08b_Bounds_containsBounds(t) { 
    111148         t.plan( 35 ); 
    112149         containerBounds = new OpenLayers.Bounds(10,10,40,40);