Fix #1951 by rounding all floats passed to Bounds.initialize() and

LonLat.initialize() to 14 significant figures.

Added an OpenLayers.Util.toFloat() function, and changed the LonLat constructor
and the Bounds constructor to truncate all float parameters to 14 significant
figures to avoid numeric comparison errors caused by floating point precision
loss. See the comments around the definition of
OpenLayers.Util.DEFAULT_PRECISION for how it works.

Also refactored Bounds.intersectBounds() for readability, and added a
Bounds.touchesBounds() in the process. After tweaking the tests for
Layer.SphericalMercator and Format.WKT (because they were expecting too many
significant figures), all tests pass.



git-svn-id: http://svn.openlayers.org/trunk/openlayers@9022 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2009-03-11 22:45:32 +00:00
parent 9afcb939be
commit e89774d568
8 changed files with 135 additions and 59 deletions

View File

@@ -806,6 +806,16 @@
}
function test_toFloat(t) {
t.plan(2);
// actual possible computed Mercator tile coordinates, more or less
var a1=40075016.67999999, b1=-20037508.33999999,
a2=40075016.68, b2=-20037508.34;
t.eq(OpenLayers.Util.toFloat(a1), OpenLayers.Util.toFloat(a2),
"toFloat rounds large floats correctly #1");
t.eq(OpenLayers.Util.toFloat(b1), OpenLayers.Util.toFloat(b2),
"toFloat rounds large floats correctly #2");
}
</script>
</head>
<body>