| 53 | | function test_02_Bounds_toBBOX(t) { |
|---|
| 54 | | t.plan( 5 ); |
|---|
| 55 | | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 56 | | t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." ); |
|---|
| 57 | | bounds = new OpenLayers.Bounds(1.00000001,2,3,4); |
|---|
| 58 | | t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() rounds off small differences." ); |
|---|
| 59 | | bounds = new OpenLayers.Bounds(1.00000001,2.5,3,4); |
|---|
| 60 | | t.eq( bounds.toBBOX(), "1,2.5,3,4", "toBBOX() returns correct value. for a half number" ); |
|---|
| 61 | | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| 62 | | t.eq( bounds.toBBOX(), "1,2.555556,3,4", "toBBOX() rounds to correct value." ); |
|---|
| 63 | | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| 64 | | t.eq( bounds.toBBOX(1), "1,2.6,3,4", "toBBOX() rounds to correct value with power provided." ); |
|---|
| 65 | | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | function test_03_Bounds_toString(t) { |
|---|
| 69 | | t.plan( 1 ); |
|---|
| 70 | | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 71 | | t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." ); |
|---|
| 72 | | } |
|---|
| 73 | | function test_Bounds_toArray(t) { |
|---|
| 74 | | t.plan( 1 ); |
|---|
| 75 | | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 76 | | t.eq( bounds.toArray(), [1,2,3,4], "toArray() returns correct value." ); |
|---|
| 77 | | } |
|---|
| 78 | | |
|---|
| 79 | | function test_04_Bounds_contains(t) { |
|---|
| 80 | | t.plan( 6 ); |
|---|
| 81 | | bounds = new OpenLayers.Bounds(10,10,40,40); |
|---|
| 82 | | t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); |
|---|
| 83 | | t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" ); |
|---|
| 84 | | t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" ); |
|---|
| 85 | | t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" ); |
|---|
| 86 | | |
|---|
| 87 | | var px = new OpenLayers.Pixel(15,30); |
|---|
| 88 | | t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works"); |
|---|
| 89 | | |
|---|
| 90 | | var ll = new OpenLayers.LonLat(15,30); |
|---|
| 91 | | t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works"); |
|---|
| 92 | | |
|---|
| 93 | | } |
|---|
| 94 | | |
|---|
| 95 | | function test_05_Bounds_fromString(t) { |
|---|
| 96 | | t.plan( 10 ); |
|---|
| 97 | | bounds = OpenLayers.Bounds.fromString("1,2,3,4"); |
|---|
| 98 | | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| 99 | | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| 100 | | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| 101 | | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| 102 | | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| 103 | | |
|---|
| 104 | | bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4"); |
|---|
| 105 | | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| 106 | | t.eq( bounds.left, 1.1, "bounds.left is set correctly" ); |
|---|
| 107 | | t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" ); |
|---|
| 108 | | t.eq( bounds.right, 3.3, "bounds.right is set correctly" ); |
|---|
| 109 | | t.eq( bounds.top, 4.4, "bounds.top is set correctly" ); |
|---|
| 110 | | |
|---|
| 111 | | } |
|---|
| 112 | | |
|---|
| 113 | | function test_06_Bounds_getSize(t) { |
|---|
| 114 | | t.plan( 1 ); |
|---|
| 115 | | var bounds = new OpenLayers.Bounds(0,10,100,120); |
|---|
| 116 | | |
|---|
| 117 | | t.ok( bounds.getSize().equals(new OpenLayers.Size(100, 110)), "getCenterPixel() works correctly"); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | function test_07_Bounds_clone(t) { |
|---|
| | 53 | function test_02_Bounds_toBBOX(t) { |
|---|
| | 54 | t.plan( 5 ); |
|---|
| | 55 | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 56 | t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." ); |
|---|
| | 57 | bounds = new OpenLayers.Bounds(1.00000001,2,3,4); |
|---|
| | 58 | t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() rounds off small differences." ); |
|---|
| | 59 | bounds = new OpenLayers.Bounds(1.00000001,2.5,3,4); |
|---|
| | 60 | t.eq( bounds.toBBOX(), "1,2.5,3,4", "toBBOX() returns correct value. for a half number" ); |
|---|
| | 61 | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| | 62 | t.eq( bounds.toBBOX(), "1,2.555556,3,4", "toBBOX() rounds to correct value." ); |
|---|
| | 63 | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| | 64 | t.eq( bounds.toBBOX(1), "1,2.6,3,4", "toBBOX() rounds to correct value with power provided." ); |
|---|
| | 65 | bounds = new OpenLayers.Bounds(1,2.5555555,3,4); |
|---|
| | 66 | } |
|---|
| | 67 | |
|---|
| | 68 | function test_03_Bounds_toString(t) { |
|---|
| | 69 | t.plan( 1 ); |
|---|
| | 70 | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 71 | t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." ); |
|---|
| | 72 | } |
|---|
| | 73 | function test_Bounds_toArray(t) { |
|---|
| | 74 | t.plan( 1 ); |
|---|
| | 75 | bounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 76 | t.eq( bounds.toArray(), [1,2,3,4], "toArray() returns correct value." ); |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| | 79 | function test_04_Bounds_contains(t) { |
|---|
| 122 | | var oldBounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 123 | | var bounds = oldBounds.clone(); |
|---|
| 124 | | t.ok( bounds instanceof OpenLayers.Bounds, "clone returns new OpenLayers.Bounds object" ); |
|---|
| 125 | | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| 126 | | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| 127 | | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| 128 | | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| 129 | | |
|---|
| 130 | | oldBounds.left = 100; |
|---|
| 131 | | t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" ); |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | function test_08a_Bounds_intersectsBounds(t) { |
|---|
| 135 | | t.plan( 17 ); |
|---|
| 136 | | |
|---|
| 137 | | var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90); |
|---|
| 138 | | |
|---|
| 139 | | //inside |
|---|
| 140 | | var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10); |
|---|
| 141 | | var cBounds = new OpenLayers.Bounds(-181,-90,180,90); |
|---|
| 142 | | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| 143 | | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| 144 | | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| 145 | | t.eq( aBounds.intersectsBounds(cBounds, false), true, "aBounds with cBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." ); |
|---|
| 146 | | t.eq( cBounds.intersectsBounds(aBounds, false), true, "cBounds with aBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." ); |
|---|
| 147 | | |
|---|
| 148 | | //outside |
|---|
| 149 | | bBounds = new OpenLayers.Bounds(-181, -91, 181, 91); |
|---|
| 150 | | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| 151 | | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| 152 | | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| 153 | | |
|---|
| 154 | | //total intersect |
|---|
| 155 | | bBounds = new OpenLayers.Bounds(-185, -100, 20, 50); |
|---|
| 156 | | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| 157 | | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| 158 | | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| 159 | | |
|---|
| 160 | | //border intersect |
|---|
| 161 | | bBounds = new OpenLayers.Bounds(-360, -180, -180, -90); |
|---|
| 162 | | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| 163 | | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| 164 | | t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| 165 | | |
|---|
| 166 | | //no intersect |
|---|
| 167 | | bBounds = new OpenLayers.Bounds(-360, -180, -185, -95); |
|---|
| 168 | | t.eq( aBounds.intersectsBounds(bBounds), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + ")" ); |
|---|
| 169 | | t.eq( aBounds.intersectsBounds(bBounds, true), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| 170 | | t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| 171 | | |
|---|
| 172 | | } |
|---|
| 173 | | |
|---|
| 174 | | function test_08b_Bounds_containsBounds(t) { |
|---|
| 175 | | t.plan( 35 ); |
|---|
| 176 | | containerBounds = new OpenLayers.Bounds(10,10,40,40); |
|---|
| 177 | | |
|---|
| 178 | | //totally outside |
|---|
| 179 | | bounds = new OpenLayers.Bounds(0,0,5,5); |
|---|
| 180 | | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| 181 | | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| 182 | | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| 183 | | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| 184 | | t.eq( containerBounds.containsBounds(bounds, true) , false , "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| 185 | | t.eq( containerBounds.containsBounds(bounds, true, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| 186 | | t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| 187 | | |
|---|
| 188 | | //totally outside on border |
|---|
| 189 | | bounds = new OpenLayers.Bounds(15,0,30,10); |
|---|
| 190 | | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| 191 | | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| 192 | | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| 193 | | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| 194 | | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| 195 | | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| 196 | | t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| 197 | | |
|---|
| 198 | | //partially inside |
|---|
| 199 | | bounds = new OpenLayers.Bounds(20,20,50,30); |
|---|
| 200 | | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| 201 | | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| 202 | | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| 203 | | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| 204 | | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| 205 | | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| 206 | | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| 207 | | |
|---|
| 208 | | //totally inside on border |
|---|
| 209 | | bounds = new OpenLayers.Bounds(10,20,30,30); |
|---|
| 210 | | t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); |
|---|
| 211 | | t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| 212 | | t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| 213 | | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| 214 | | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| 215 | | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| 216 | | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| 217 | | |
|---|
| 218 | | //totally inside |
|---|
| 219 | | bounds = new OpenLayers.Bounds(20,20,30,30); |
|---|
| 220 | | t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); |
|---|
| 221 | | t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| 222 | | t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| 223 | | t.eq( containerBounds.containsBounds(bounds, false, false), true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| 224 | | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| 225 | | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| 226 | | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| 227 | | } |
|---|
| 228 | | |
|---|
| 229 | | function test_09_Bounds_determineQuadrant(t) { |
|---|
| 230 | | |
|---|
| 231 | | t.plan( 4 ); |
|---|
| 232 | | var bounds = new OpenLayers.Bounds(0,0,100,100); |
|---|
| 233 | | |
|---|
| 234 | | var tl = new OpenLayers.LonLat(25, 75); |
|---|
| 235 | | var tr = new OpenLayers.LonLat(75, 75); |
|---|
| 236 | | var bl = new OpenLayers.LonLat(25, 25); |
|---|
| 237 | | var br = new OpenLayers.LonLat(75, 25); |
|---|
| 238 | | |
|---|
| 239 | | t.eq( bounds.determineQuadrant(tl), "tl", "bounds.determineQuadrant correctly identifies a coordinate in the top left quadrant"); |
|---|
| 240 | | t.eq( bounds.determineQuadrant(tr), "tr", "bounds.determineQuadrant correctly identifies a coordinate in the top right quadrant"); |
|---|
| 241 | | t.eq( bounds.determineQuadrant(bl), "bl", "bounds.determineQuadrant correctly identifies a coordinate in the bottom left quadrant"); |
|---|
| 242 | | t.eq( bounds.determineQuadrant(br), "br", "bounds.determineQuadrant correctly identifies a coordinate in the bottom right quadrant"); |
|---|
| 243 | | } |
|---|
| 244 | | |
|---|
| 245 | | function test_10_Bounds_oppositeQuadrant(t) { |
|---|
| 246 | | |
|---|
| 247 | | t.plan( 4 ); |
|---|
| 248 | | |
|---|
| 249 | | t.eq( OpenLayers.Bounds.oppositeQuadrant("tl"), "br", "OpenLayers.Bounds.oppositeQuadrant returns 'br' for 'tl'"); |
|---|
| 250 | | t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'"); |
|---|
| 251 | | t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'"); |
|---|
| 252 | | t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'"); |
|---|
| 253 | | } |
|---|
| 254 | | |
|---|
| 255 | | function test_11_Bounds_equals(t) { |
|---|
| 256 | | t.plan( 3 ); |
|---|
| 257 | | var boundsA = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 258 | | var boundsB = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 259 | | var boundsC = new OpenLayers.Bounds(1,5,3,4); |
|---|
| 260 | | |
|---|
| 261 | | t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." ); |
|---|
| 262 | | t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." ); |
|---|
| 263 | | t.ok( !boundsA.equals(null), "equals() returns false on comparison to null"); |
|---|
| 264 | | } |
|---|
| 265 | | |
|---|
| 266 | | function test_12_Bounds_getHeight_getWidth(t) { |
|---|
| 267 | | t.plan( 2 ); |
|---|
| 268 | | var bounds = new OpenLayers.Bounds(10,20,100,120); |
|---|
| 269 | | |
|---|
| 270 | | t.eq( bounds.getWidth(), 90, "getWidth() works" ); |
|---|
| 271 | | t.eq( bounds.getHeight(), 100, "getHeight() works" ); |
|---|
| 272 | | |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|
| 275 | | function test_13_Bounds_getCenters(t) { |
|---|
| 276 | | t.plan( 2 ); |
|---|
| 277 | | var bounds = new OpenLayers.Bounds(0,20,100,120); |
|---|
| 278 | | |
|---|
| 279 | | t.ok( bounds.getCenterPixel().equals(new OpenLayers.Pixel(50, 70)), "getCenterPixel() works correctly"); |
|---|
| 280 | | t.ok( bounds.getCenterLonLat().equals(new OpenLayers.LonLat(50, 70)), "getCenterLonLat() works correctly"); |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | function test_14_Bounds_fromArray(t) { |
|---|
| 284 | | t.plan( 5 ); |
|---|
| 285 | | |
|---|
| 286 | | var bbox = [1,2,3,4]; |
|---|
| 287 | | bounds = OpenLayers.Bounds.fromArray(bbox); |
|---|
| 288 | | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| 289 | | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| 290 | | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| 291 | | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| 292 | | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| 293 | | } |
|---|
| 294 | | |
|---|
| 295 | | function test_15_Bounds_fromSize(t) { |
|---|
| 296 | | t.plan( 5 ); |
|---|
| 297 | | |
|---|
| 298 | | var height = 15; |
|---|
| 299 | | var width = 16; |
|---|
| 300 | | var size = new OpenLayers.Size(width, height); |
|---|
| 301 | | bounds = OpenLayers.Bounds.fromSize(size); |
|---|
| 302 | | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| 303 | | t.eq( bounds.left, 0, "bounds.left is set correctly" ); |
|---|
| 304 | | t.eq( bounds.bottom, height, "bounds.bottom is set correctly" ); |
|---|
| 305 | | t.eq( bounds.right, width, "bounds.right is set correctly" ); |
|---|
| 306 | | t.eq( bounds.top, 0, "bounds.top is set correctly" ); |
|---|
| 307 | | } |
|---|
| 308 | | |
|---|
| 309 | | |
|---|
| 310 | | function test_16_Bounds_extend(t) { |
|---|
| | 81 | bounds = new OpenLayers.Bounds(10,10,40,40); |
|---|
| | 82 | t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); |
|---|
| | 83 | t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" ); |
|---|
| | 84 | t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" ); |
|---|
| | 85 | t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" ); |
|---|
| | 86 | |
|---|
| | 87 | var px = new OpenLayers.Pixel(15,30); |
|---|
| | 88 | t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works"); |
|---|
| | 89 | |
|---|
| | 90 | var ll = new OpenLayers.LonLat(15,30); |
|---|
| | 91 | t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works"); |
|---|
| | 92 | |
|---|
| | 93 | } |
|---|
| | 94 | |
|---|
| | 95 | function test_05_Bounds_fromString(t) { |
|---|
| | 96 | t.plan( 10 ); |
|---|
| | 97 | bounds = OpenLayers.Bounds.fromString("1,2,3,4"); |
|---|
| | 98 | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| | 99 | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| | 100 | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| | 101 | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| | 102 | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| | 103 | |
|---|
| | 104 | bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4"); |
|---|
| | 105 | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| | 106 | t.eq( bounds.left, 1.1, "bounds.left is set correctly" ); |
|---|
| | 107 | t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" ); |
|---|
| | 108 | t.eq( bounds.right, 3.3, "bounds.right is set correctly" ); |
|---|
| | 109 | t.eq( bounds.top, 4.4, "bounds.top is set correctly" ); |
|---|
| | 110 | |
|---|
| | 111 | } |
|---|
| | 112 | |
|---|
| | 113 | function test_06_Bounds_getSize(t) { |
|---|
| | 114 | t.plan( 1 ); |
|---|
| | 115 | var bounds = new OpenLayers.Bounds(0,10,100,120); |
|---|
| | 116 | |
|---|
| | 117 | t.ok( bounds.getSize().equals(new OpenLayers.Size(100, 110)), "getCenterPixel() works correctly"); |
|---|
| | 118 | } |
|---|
| | 119 | |
|---|
| | 120 | function test_07_Bounds_clone(t) { |
|---|
| | 121 | t.plan( 6 ); |
|---|
| | 122 | var oldBounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 123 | var bounds = oldBounds.clone(); |
|---|
| | 124 | t.ok( bounds instanceof OpenLayers.Bounds, "clone returns new OpenLayers.Bounds object" ); |
|---|
| | 125 | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| | 126 | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| | 127 | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| | 128 | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| | 129 | |
|---|
| | 130 | oldBounds.left = 100; |
|---|
| | 131 | t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" ); |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | function test_08a_Bounds_intersectsBounds(t) { |
|---|
| | 135 | t.plan( 17 ); |
|---|
| | 136 | |
|---|
| | 137 | var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90); |
|---|
| | 138 | |
|---|
| | 139 | //inside |
|---|
| | 140 | var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10); |
|---|
| | 141 | var cBounds = new OpenLayers.Bounds(-181,-90,180,90); |
|---|
| | 142 | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| | 143 | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| | 144 | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| | 145 | t.eq( aBounds.intersectsBounds(cBounds, false), true, "aBounds with cBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." ); |
|---|
| | 146 | t.eq( cBounds.intersectsBounds(aBounds, false), true, "cBounds with aBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." ); |
|---|
| | 147 | |
|---|
| | 148 | //outside |
|---|
| | 149 | bBounds = new OpenLayers.Bounds(-181, -91, 181, 91); |
|---|
| | 150 | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| | 151 | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| | 152 | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| | 153 | |
|---|
| | 154 | //total intersect |
|---|
| | 155 | bBounds = new OpenLayers.Bounds(-185, -100, 20, 50); |
|---|
| | 156 | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| | 157 | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| | 158 | t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| | 159 | |
|---|
| | 160 | //border intersect |
|---|
| | 161 | bBounds = new OpenLayers.Bounds(-360, -180, -180, -90); |
|---|
| | 162 | t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" ); |
|---|
| | 163 | t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| | 164 | t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| | 165 | |
|---|
| | 166 | //no intersect |
|---|
| | 167 | bBounds = new OpenLayers.Bounds(-360, -180, -185, -95); |
|---|
| | 168 | t.eq( aBounds.intersectsBounds(bBounds), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + ")" ); |
|---|
| | 169 | t.eq( aBounds.intersectsBounds(bBounds, true), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is true" ); |
|---|
| | 170 | t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" ); |
|---|
| | 171 | |
|---|
| | 172 | } |
|---|
| | 173 | |
|---|
| | 174 | function test_08b_Bounds_containsBounds(t) { |
|---|
| | 175 | t.plan( 35 ); |
|---|
| | 176 | containerBounds = new OpenLayers.Bounds(10,10,40,40); |
|---|
| | 177 | |
|---|
| | 178 | //totally outside |
|---|
| | 179 | bounds = new OpenLayers.Bounds(0,0,5,5); |
|---|
| | 180 | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| | 181 | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| | 182 | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| | 183 | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| | 184 | t.eq( containerBounds.containsBounds(bounds, true) , false , "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| | 185 | t.eq( containerBounds.containsBounds(bounds, true, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| | 186 | t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| | 187 | |
|---|
| | 188 | //totally outside on border |
|---|
| | 189 | bounds = new OpenLayers.Bounds(15,0,30,10); |
|---|
| | 190 | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| | 191 | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| | 192 | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| | 193 | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| | 194 | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| | 195 | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| | 196 | t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| | 197 | |
|---|
| | 198 | //partially inside |
|---|
| | 199 | bounds = new OpenLayers.Bounds(20,20,50,30); |
|---|
| | 200 | t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); |
|---|
| | 201 | t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| | 202 | t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| | 203 | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| | 204 | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| | 205 | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| | 206 | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| | 207 | |
|---|
| | 208 | //totally inside on border |
|---|
| | 209 | bounds = new OpenLayers.Bounds(10,20,30,30); |
|---|
| | 210 | t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); |
|---|
| | 211 | t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| | 212 | t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| | 213 | t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| | 214 | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| | 215 | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| | 216 | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| | 217 | |
|---|
| | 218 | //totally inside |
|---|
| | 219 | bounds = new OpenLayers.Bounds(20,20,30,30); |
|---|
| | 220 | t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); |
|---|
| | 221 | t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); |
|---|
| | 222 | t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); |
|---|
| | 223 | t.eq( containerBounds.containsBounds(bounds, false, false), true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); |
|---|
| | 224 | t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); |
|---|
| | 225 | t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); |
|---|
| | 226 | t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); |
|---|
| | 227 | } |
|---|
| | 228 | |
|---|
| | 229 | function test_09_Bounds_determineQuadrant(t) { |
|---|
| | 230 | |
|---|
| | 231 | t.plan( 4 ); |
|---|
| | 232 | var bounds = new OpenLayers.Bounds(0,0,100,100); |
|---|
| | 233 | |
|---|
| | 234 | var tl = new OpenLayers.LonLat(25, 75); |
|---|
| | 235 | var tr = new OpenLayers.LonLat(75, 75); |
|---|
| | 236 | var bl = new OpenLayers.LonLat(25, 25); |
|---|
| | 237 | var br = new OpenLayers.LonLat(75, 25); |
|---|
| | 238 | |
|---|
| | 239 | t.eq( bounds.determineQuadrant(tl), "tl", "bounds.determineQuadrant correctly identifies a coordinate in the top left quadrant"); |
|---|
| | 240 | t.eq( bounds.determineQuadrant(tr), "tr", "bounds.determineQuadrant correctly identifies a coordinate in the top right quadrant"); |
|---|
| | 241 | t.eq( bounds.determineQuadrant(bl), "bl", "bounds.determineQuadrant correctly identifies a coordinate in the bottom left quadrant"); |
|---|
| | 242 | t.eq( bounds.determineQuadrant(br), "br", "bounds.determineQuadrant correctly identifies a coordinate in the bottom right quadrant"); |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | function test_10_Bounds_oppositeQuadrant(t) { |
|---|
| | 246 | |
|---|
| | 247 | t.plan( 4 ); |
|---|
| | 248 | |
|---|
| | 249 | t.eq( OpenLayers.Bounds.oppositeQuadrant("tl"), "br", "OpenLayers.Bounds.oppositeQuadrant returns 'br' for 'tl'"); |
|---|
| | 250 | t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'"); |
|---|
| | 251 | t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'"); |
|---|
| | 252 | t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'"); |
|---|
| | 253 | } |
|---|
| | 254 | |
|---|
| | 255 | function test_11_Bounds_equals(t) { |
|---|
| | 256 | t.plan( 3 ); |
|---|
| | 257 | var boundsA = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 258 | var boundsB = new OpenLayers.Bounds(1,2,3,4); |
|---|
| | 259 | var boundsC = new OpenLayers.Bounds(1,5,3,4); |
|---|
| | 260 | |
|---|
| | 261 | t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." ); |
|---|
| | 262 | t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." ); |
|---|
| | 263 | t.ok( !boundsA.equals(null), "equals() returns false on comparison to null"); |
|---|
| | 264 | } |
|---|
| | 265 | |
|---|
| | 266 | function test_12_Bounds_getHeight_getWidth(t) { |
|---|
| | 267 | t.plan( 2 ); |
|---|
| | 268 | var bounds = new OpenLayers.Bounds(10,20,100,120); |
|---|
| | 269 | |
|---|
| | 270 | t.eq( bounds.getWidth(), 90, "getWidth() works" ); |
|---|
| | 271 | t.eq( bounds.getHeight(), 100, "getHeight() works" ); |
|---|
| | 272 | |
|---|
| | 273 | } |
|---|
| | 274 | |
|---|
| | 275 | function test_13_Bounds_getCenters(t) { |
|---|
| | 276 | t.plan( 2 ); |
|---|
| | 277 | var bounds = new OpenLayers.Bounds(0,20,100,120); |
|---|
| | 278 | |
|---|
| | 279 | t.ok( bounds.getCenterPixel().equals(new OpenLayers.Pixel(50, 70)), "getCenterPixel() works correctly"); |
|---|
| | 280 | t.ok( bounds.getCenterLonLat().equals(new OpenLayers.LonLat(50, 70)), "getCenterLonLat() works correctly"); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | function test_14_Bounds_fromArray(t) { |
|---|
| | 284 | t.plan( 5 ); |
|---|
| | 285 | |
|---|
| | 286 | var bbox = [1,2,3,4]; |
|---|
| | 287 | bounds = OpenLayers.Bounds.fromArray(bbox); |
|---|
| | 288 | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| | 289 | t.eq( bounds.left, 1, "bounds.left is set correctly" ); |
|---|
| | 290 | t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); |
|---|
| | 291 | t.eq( bounds.right, 3, "bounds.right is set correctly" ); |
|---|
| | 292 | t.eq( bounds.top, 4, "bounds.top is set correctly" ); |
|---|
| | 293 | } |
|---|
| | 294 | |
|---|
| | 295 | function test_15_Bounds_fromSize(t) { |
|---|
| | 296 | t.plan( 5 ); |
|---|
| | 297 | |
|---|
| | 298 | var height = 15; |
|---|
| | 299 | var width = 16; |
|---|
| | 300 | var size = new OpenLayers.Size(width, height); |
|---|
| | 301 | bounds = OpenLayers.Bounds.fromSize(size); |
|---|
| | 302 | t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); |
|---|
| | 303 | t.eq( bounds.left, 0, "bounds.left is set correctly" ); |
|---|
| | 304 | t.eq( bounds.bottom, height, "bounds.bottom is set correctly" ); |
|---|
| | 305 | t.eq( bounds.right, width, "bounds.right is set correctly" ); |
|---|
| | 306 | t.eq( bounds.top, 0, "bounds.top is set correctly" ); |
|---|
| | 307 | } |
|---|
| | 308 | |
|---|
| | 309 | |
|---|
| | 310 | function test_16_Bounds_extend(t) { |
|---|