Changeset 3731
- Timestamp:
- 07/13/07 11:41:33 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/BaseTypes/LonLat.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/BaseTypes/Pixel.js (modified) (1 diff)
- trunk/openlayers/tests/BaseTypes/test_Bounds.html (modified) (1 diff)
- trunk/openlayers/tests/BaseTypes/test_LonLat.html (modified) (1 diff)
- trunk/openlayers/tests/BaseTypes/test_Pixel.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js
r3686 r3731 192 192 */ 193 193 add:function(x, y) { 194 if ( (x == null) || (y == null) ) { 195 var msg = "You must pass both x and y values to the add function."; 196 OpenLayers.Console.error(msg); 197 return null; 198 } 194 199 return new OpenLayers.Bounds(this.left + x, this.bottom + y, 195 200 this.right + x, this.top + y); trunk/openlayers/lib/OpenLayers/BaseTypes/LonLat.js
r3708 r3731 85 85 */ 86 86 add:function(lon, lat) { 87 if ( (lon == null) || (lat == null) ) { 88 var msg = "You must pass both lon and lat values " + 89 "to the add function."; 90 OpenLayers.Console.error(msg); 91 return null; 92 } 87 93 return new OpenLayers.LonLat(this.lon + lon, this.lat + lat); 88 94 }, trunk/openlayers/lib/OpenLayers/BaseTypes/Pixel.js
r3601 r3731 92 92 */ 93 93 add:function(x, y) { 94 if ( (x == null) || (y == null) ) { 95 var msg = "You must pass both x and y values to the add function."; 96 OpenLayers.Console.error(msg); 97 return null; 98 } 94 99 return new OpenLayers.Pixel(this.x + x, this.y + y); 95 100 }, trunk/openlayers/tests/BaseTypes/test_Bounds.html
r3323 r3731 473 473 } 474 474 475 function test_17_Bounds_add(t) { 476 t.plan( 8 ); 477 478 origBounds = new OpenLayers.Bounds(1,2,3,4); 479 testBounds = origBounds.clone(); 480 481 var bounds = testBounds.add(5, 50); 482 t.ok( testBounds.equals(origBounds), "testBounds is not modified by add operation"); 483 484 var b = new OpenLayers.Bounds(6,52,8,54); 485 t.ok( bounds.equals(b), "bounds is set correctly"); 486 487 //null values 488 var desiredMsg = "You must pass both x and y values to the add function."; 489 OpenLayers.Console.error = function(msg) { 490 t.eq(msg, desiredMsg, "error correctly reported"); 491 } 492 493 bounds = testBounds.add(null, 50); 494 t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null x)"); 495 t.ok(bounds == null, "returns null on erroneous add operation (null x)"); 496 497 bounds = testBounds.add(5, null); 498 t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null y)"); 499 t.ok(bounds == null, "returns null on erroneous add operation (null y)"); 500 } 501 475 502 // --> 476 503 </script> trunk/openlayers/tests/BaseTypes/test_LonLat.html
r3323 r3731 48 48 49 49 function test_04_LonLat_add(t) { 50 t.plan( 2);50 t.plan( 8 ); 51 51 52 lonlatA = new OpenLayers.LonLat(10,100); 52 origLL = new OpenLayers.LonLat(10,100); 53 lonlatA = origLL.clone(); 53 54 54 55 addpx = lonlatA.add(5, 50); 55 var ll = new OpenLayers.LonLat(10,100); 56 t.ok( lonlatA.equals(ll), "lonlatA is not modified by add operation"); 56 t.ok( lonlatA.equals(origLL), "lonlatA is not modified by add operation"); 57 57 58 58 var ll = new OpenLayers.LonLat(15,150); 59 59 t.ok( addpx.equals(ll), "addpx is set correctly"); 60 61 //null values 62 var desiredMsg = "You must pass both lon and lat values to the add function."; 63 OpenLayers.Console.error = function(msg) { 64 t.eq(msg, desiredMsg, "error correctly reported"); 65 } 66 67 addpx = lonlatA.add(null, 50); 68 t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lon)"); 69 t.ok(addpx == null, "returns null on erroneous add operation (null lon)"); 70 71 addpx = lonlatA.add(5, null); 72 t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lat)"); 73 t.ok(addpx == null, "returns null on erroneous add operation (null lat)"); 60 74 } 61 75 trunk/openlayers/tests/BaseTypes/test_Pixel.html
r2803 r3731 62 62 63 63 function test_07_Pixel_add(t) { 64 t.plan( 4 ); 65 oldPixel = new OpenLayers.Pixel(5,6); 64 t.plan( 8 ); 66 65 67 pixel = oldPixel.add(10,20); 66 var origPX = new OpenLayers.Pixel(5,6); 67 var oldPixel = origPX.clone(); 68 68 69 t.eq( oldPixel.x, 5, "oldPixel.x not modified by add operation"); 70 t.eq( oldPixel.y, 6, "oldPixel.y not modified by add operation"); 69 var pixel = oldPixel.add(10,20); 70 71 t.ok( oldPixel.equals(origPX), "oldPixel not modified by add operation"); 72 73 var px = new OpenLayers.Pixel(15,26); 74 t.ok( pixel.equals(px), "returned pixel is correct"); 71 75 72 t.eq( pixel.x, 15, "pixel.x is set correctly"); 73 t.eq( pixel.y, 26, "pixel.y is set correctly"); 76 //null values 77 var desiredMsg = "You must pass both x and y values to the add function."; 78 OpenLayers.Console.error = function(msg) { 79 t.eq(msg, desiredMsg, "error correctly reported"); 80 } 81 82 pixel = oldPixel.add(null, 50); 83 t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null x)"); 84 t.ok(pixel == null, "returns null on erroneous add operation (null x)"); 85 86 addpx = oldPixel.add(5, null); 87 t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null y)"); 88 t.ok(pixel == null, "returns null on erroneous add operation (null y)"); 74 89 } 75 90
