update all base types to deal with any kind of input. a continuation of r1412 and a resolution for #245.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1413 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-09-07 18:18:06 +00:00
parent 00e354511e
commit 9b355b76dc
5 changed files with 43 additions and 11 deletions
+8 -8
View File
@@ -31,8 +31,8 @@ OpenLayers.Pixel.prototype = {
* @param {float} y * @param {float} y
*/ */
initialize: function(x, y) { initialize: function(x, y) {
this.x = x; this.x = parseFloat(x);
this.y = y; this.y = parseFloat(y);
}, },
/** /**
@@ -123,8 +123,8 @@ OpenLayers.Size.prototype = {
* @param {float} h * @param {float} h
*/ */
initialize: function(w, h) { initialize: function(w, h) {
this.w = w; this.w = parseFloat(w);
this.h = h; this.h = parseFloat(h);
}, },
/** /**
@@ -315,10 +315,10 @@ OpenLayers.Bounds.prototype = {
* *
*/ */
initialize: function(left, bottom, right, top) { initialize: function(left, bottom, right, top) {
this.left = left; this.left = parseFloat(left);
this.bottom = bottom; this.bottom = parseFloat(bottom);
this.right = right; this.right = parseFloat(right);
this.top = top; this.top = parseFloat(top);
}, },
/** /**
+12
View File
@@ -28,6 +28,18 @@
t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" ); t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" );
} }
function test_01a_Bounds_constructorFromStrings(t) {
t.plan( 6 );
bounds = new OpenLayers.Bounds("0","2","10","4");
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
t.eq( bounds.left, 0, "bounds.left is set correctly" );
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
t.eq( bounds.right, 10, "bounds.right is set correctly" );
t.eq( bounds.top, 4, "bounds.top is set correctly" );
}
function test_02_Bounds_toBBOX(t) { function test_02_Bounds_toBBOX(t) {
t.plan( 1 ); t.plan( 1 );
bounds = new OpenLayers.Bounds(1,2,3,4); bounds = new OpenLayers.Bounds(1,2,3,4);
+5 -3
View File
@@ -6,19 +6,21 @@
var lonlat; var lonlat;
function test_01_LonLat_constructor (t) { function test_01_LonLat_constructor (t) {
t.plan( 8 ); t.plan( 4 );
lonlat = new OpenLayers.LonLat(6, 5); lonlat = new OpenLayers.LonLat(6, 5);
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" ); t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly"); t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly"); t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly"); t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
}
function test_01a_LonLat_constructorFromStrings (t) {
t.plan( 4 );
lonlat = new OpenLayers.LonLat("6", "5"); lonlat = new OpenLayers.LonLat("6", "5");
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" ); t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly"); t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly"); t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly"); t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
} }
function test_02_LonLat_toString(t) { function test_02_LonLat_toString(t) {
+9
View File
@@ -13,6 +13,15 @@
t.eq( pixel.y, 6, "pixel.y is set correctly"); t.eq( pixel.y, 6, "pixel.y is set correctly");
} }
function test_01a_Pixel_constructorFromString (t) {
t.plan( 4 );
pixel = new OpenLayers.Pixel("5","6");
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
t.eq( pixel.x, 5, "pixel.x is set correctly");
t.eq( pixel.y, 6, "pixel.y is set correctly");
}
function test_02_Pixel_toString(t) { function test_02_Pixel_toString(t) {
t.plan( 1 ); t.plan( 1 );
pixel = new OpenLayers.Pixel(5,6); pixel = new OpenLayers.Pixel(5,6);
+9
View File
@@ -13,6 +13,15 @@
t.eq( size.h, 6, "size.h is set correctly"); t.eq( size.h, 6, "size.h is set correctly");
} }
function test_01a_Size_constructorFromString (t) {
t.plan( 4 );
size = new OpenLayers.Size("5","6");
t.ok( size instanceof OpenLayers.Size, "new OpenLayers.Size returns size object" );
t.eq( size.CLASS_NAME, "OpenLayers.Size", "size.CLASS_NAME is set correctly");
t.eq( size.w, 5, "size.w is set correctly");
t.eq( size.h, 6, "size.h is set correctly");
}
function test_02_Size_toString(t) { function test_02_Size_toString(t) {
t.plan( 1 ); t.plan( 1 );
size = new OpenLayers.Size(5,6); size = new OpenLayers.Size(5,6);