From bfc42ffa621c2b5d0e8d64ef583ebdf0f4f541c1 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 24 Feb 2014 15:54:17 -0700 Subject: [PATCH] More realistic precision for cosine distance results Chris Veness' discussion of using the spherical law of cosines (http://www.movable-type.co.uk/scripts/latlong.html) suggests it gives well-conditioned results "around 1 metre" in JavaScript (this assumes a sphere with 6,371km radius). In Chrome 33, Math.pow(Math.cos(Math.PI / 4), 2) yields 0.4999999999999999. When we take the arccosine of twice this, we get something significantly different than zero. Multiplying by 6371 means we can't assert that this is within 1e-9 of zero. --- test/spec/ol/sphere/sphere.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 54db8c139d..b90eca57d9 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -379,7 +379,7 @@ describe('ol.Sphere', function() { for (i = 0; i < expected.length; ++i) { e = expected[i]; expect(sphere.cosineDistance(e.c1, e.c2)).to.roughlyEqual( - e.cosineDistance, 1e-9); + e.cosineDistance, 1e-3); } });