From 9b355b76dcffcdb0aa761834139f7fc69e6c3a9e Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 7 Sep 2006 18:18:06 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/BaseTypes.js | 16 ++++++++-------- tests/test_Bounds.html | 12 ++++++++++++ tests/test_LonLat.html | 8 +++++--- tests/test_Pixel.html | 9 +++++++++ tests/test_Size.html | 9 +++++++++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 0ee6c75eb5..6602d76439 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -31,8 +31,8 @@ OpenLayers.Pixel.prototype = { * @param {float} y */ initialize: function(x, y) { - this.x = x; - this.y = y; + this.x = parseFloat(x); + this.y = parseFloat(y); }, /** @@ -123,8 +123,8 @@ OpenLayers.Size.prototype = { * @param {float} h */ initialize: function(w, h) { - this.w = w; - this.h = h; + this.w = parseFloat(w); + this.h = parseFloat(h); }, /** @@ -315,10 +315,10 @@ OpenLayers.Bounds.prototype = { * */ initialize: function(left, bottom, right, top) { - this.left = left; - this.bottom = bottom; - this.right = right; - this.top = top; + this.left = parseFloat(left); + this.bottom = parseFloat(bottom); + this.right = parseFloat(right); + this.top = parseFloat(top); }, /** diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 8bcd684c64..2a0561c9fe 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -28,6 +28,18 @@ 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) { t.plan( 1 ); bounds = new OpenLayers.Bounds(1,2,3,4); diff --git a/tests/test_LonLat.html b/tests/test_LonLat.html index 29ff3f0de8..aa9f8d18da 100644 --- a/tests/test_LonLat.html +++ b/tests/test_LonLat.html @@ -6,19 +6,21 @@ var lonlat; function test_01_LonLat_constructor (t) { - t.plan( 8 ); + t.plan( 4 ); lonlat = new OpenLayers.LonLat(6, 5); 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.lon, 6, "lonlat.lon 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"); 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.lon, 6, "lonlat.lon is set correctly"); t.eq( lonlat.lat, 5, "lonlat.lat is set correctly"); - } function test_02_LonLat_toString(t) { diff --git a/tests/test_Pixel.html b/tests/test_Pixel.html index f636d377a1..43acf9ce6c 100644 --- a/tests/test_Pixel.html +++ b/tests/test_Pixel.html @@ -13,6 +13,15 @@ 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) { t.plan( 1 ); pixel = new OpenLayers.Pixel(5,6); diff --git a/tests/test_Size.html b/tests/test_Size.html index 89a2e99194..104680e254 100644 --- a/tests/test_Size.html +++ b/tests/test_Size.html @@ -13,6 +13,15 @@ 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) { t.plan( 1 ); size = new OpenLayers.Size(5,6);