From bc1328528aad30615de64e56e1baa2b3d33491f6 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:41:06 -0600 Subject: [PATCH 01/15] Remove unused sphere.crossTrackDistance() method --- src/ol/sphere/sphere.js | 17 ----------------- test/spec/ol/sphere/sphere.test.js | 1 - 2 files changed, 18 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 11beda86f3..4175c046ff 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -87,23 +87,6 @@ ol.Sphere.prototype.geodesicArea = function(coordinates) { }; -/** - * Returns the distance of c3 from the great circle path defined by c1 and c2. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @param {ol.Coordinate} c3 Coordinate 3. - * @return {number} Cross-track distance. - */ -ol.Sphere.prototype.crossTrackDistance = function(c1, c2, c3) { - var d13 = this.cosineDistance(c1, c2); - var theta12 = goog.math.toRadians(this.initialBearing(c1, c2)); - var theta13 = goog.math.toRadians(this.initialBearing(c1, c3)); - return this.radius * - Math.asin(Math.sin(d13 / this.radius) * Math.sin(theta13 - theta12)); -}; - - /** * Returns the distance from c1 to c2 using Pythagoras's theorem on an * equirectangular projection. diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 465a42bcbe..13259f9f5f 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -1,5 +1,4 @@ // See http://www.movable-type.co.uk/scripts/latlong.html -// FIXME add tests for crossTrackDistance // FIXME add tests for maximumLatitude // FIXME add tests for offset From c74277cae87842d07a4f2e5a620e7953ca8f34d4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:43:26 -0600 Subject: [PATCH 02/15] Remove unused sphere.cosineDistance() method --- src/ol/sphere/sphere.js | 17 ----------------- test/spec/ol/sphere/sphere.test.js | 28 ---------------------------- 2 files changed, 45 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 4175c046ff..580bd033d8 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -40,23 +40,6 @@ ol.Sphere = function(radius) { }; -/** - * Returns the distance from c1 to c2 using the spherical law of cosines. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @return {number} Spherical law of cosines distance. - */ -ol.Sphere.prototype.cosineDistance = function(c1, c2) { - var lat1 = goog.math.toRadians(c1[1]); - var lat2 = goog.math.toRadians(c2[1]); - var deltaLon = goog.math.toRadians(c2[0] - c1[0]); - return this.radius * Math.acos( - Math.sin(lat1) * Math.sin(lat2) + - Math.cos(lat1) * Math.cos(lat2) * Math.cos(deltaLon)); -}; - - /** * Returns the geodesic area for a list of coordinates. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 13259f9f5f..a3c59ee7b4 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -12,7 +12,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [0, 0], - cosineDistance: 0, equirectangularDistance: 0, finalBearing: 180, haversineDistance: 0, @@ -22,7 +21,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [45, 45], - cosineDistance: 6671.695598673524, equirectangularDistance: 6812.398372654371, finalBearing: 54.735610317245346, haversineDistance: 6671.695598673525, @@ -32,7 +30,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [-45, 45], - cosineDistance: 6671.695598673524, equirectangularDistance: 6812.398372654371, finalBearing: 305.26438968275465, haversineDistance: 6671.695598673525, @@ -42,7 +39,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [-45, -45], - cosineDistance: 6671.695598673524, equirectangularDistance: 6812.398372654371, finalBearing: 234.73561031724535, haversineDistance: 6671.695598673525, @@ -52,7 +48,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [45, -45], - cosineDistance: 6671.695598673524, equirectangularDistance: 6812.398372654371, finalBearing: 125.26438968275465, haversineDistance: 6671.695598673525, @@ -62,7 +57,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [45, 45], - cosineDistance: 0, equirectangularDistance: 0, finalBearing: 180, haversineDistance: 0, @@ -72,7 +66,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [-45, 45], - cosineDistance: 6671.695598673525, equirectangularDistance: 7076.401799751738, finalBearing: 234.73561031724535, haversineDistance: 6671.695598673525, @@ -82,7 +75,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [-45, -45], - cosineDistance: 13343.391197347048, equirectangularDistance: 14152.803599503475, finalBearing: 234.73561031724535, haversineDistance: 13343.391197347048, @@ -92,7 +84,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [45, -45], - cosineDistance: 10007.543398010284, equirectangularDistance: 10007.543398010286, finalBearing: 180, haversineDistance: 10007.543398010286, @@ -102,7 +93,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [-45, 45], - cosineDistance: 0, equirectangularDistance: 0, finalBearing: 180, haversineDistance: 0, @@ -112,7 +102,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [-45, -45], - cosineDistance: 10007.543398010284, equirectangularDistance: 10007.543398010286, finalBearing: 180, haversineDistance: 10007.543398010286, @@ -122,7 +111,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [45, -45], - cosineDistance: 13343.391197347048, equirectangularDistance: 14152.803599503475, finalBearing: 125.26438968275465, haversineDistance: 13343.391197347048, @@ -132,7 +120,6 @@ describe('ol.Sphere', function() { { c1: [-45, -45], c2: [-45, -45], - cosineDistance: 0, equirectangularDistance: 0, finalBearing: 180, haversineDistance: 0, @@ -142,7 +129,6 @@ describe('ol.Sphere', function() { { c1: [-45, -45], c2: [45, -45], - cosineDistance: 6671.695598673525, equirectangularDistance: 7076.401799751738, finalBearing: 54.735610317245346, haversineDistance: 6671.695598673525, @@ -152,7 +138,6 @@ describe('ol.Sphere', function() { { c1: [45, -45], c2: [45, -45], - cosineDistance: 0, equirectangularDistance: 0, finalBearing: 180, haversineDistance: 0, @@ -161,19 +146,6 @@ describe('ol.Sphere', function() { } ]; - describe('cosineDistance', function() { - - it('results match Chris Veness\'s reference implementation', function() { - var e, i; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - expect(sphere.cosineDistance(e.c1, e.c2)).to.roughlyEqual( - e.cosineDistance, 1e-3); - } - }); - - }); - describe('equirectangularDistance', function() { it('results match Chris Veness\'s reference implementation', function() { From 8ec2bcef17cb9826ae6c396579549928f6336f8f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:46:20 -0600 Subject: [PATCH 03/15] Remove unused sphere.finalBearing() method --- src/ol/sphere/sphere.js | 12 ------------ test/spec/ol/sphere/sphere.test.js | 28 ---------------------------- 2 files changed, 40 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 580bd033d8..86a3d9a7f9 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -88,18 +88,6 @@ ol.Sphere.prototype.equirectangularDistance = function(c1, c2) { }; -/** - * Returns the final bearing from c1 to c2. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @return {number} Initial bearing. - */ -ol.Sphere.prototype.finalBearing = function(c1, c2) { - return (this.initialBearing(c2, c1) + 180) % 360; -}; - - /** * Returns the distance from c1 to c2 using the haversine formula. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index a3c59ee7b4..d127266db7 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -13,7 +13,6 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [0, 0], equirectangularDistance: 0, - finalBearing: 180, haversineDistance: 0, initialBearing: 0, midpoint: [0, 0] @@ -22,7 +21,6 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [45, 45], equirectangularDistance: 6812.398372654371, - finalBearing: 54.735610317245346, haversineDistance: 6671.695598673525, initialBearing: 35.264389682754654, midpoint: [18.434948822922006, 24.0948425521107] @@ -31,7 +29,6 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [-45, 45], equirectangularDistance: 6812.398372654371, - finalBearing: 305.26438968275465, haversineDistance: 6671.695598673525, initialBearing: -35.264389682754654, midpoint: [-18.434948822922006, 24.0948425521107] @@ -40,7 +37,6 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [-45, -45], equirectangularDistance: 6812.398372654371, - finalBearing: 234.73561031724535, haversineDistance: 6671.695598673525, initialBearing: -144.73561031724535, midpoint: [-18.434948822922006, -24.0948425521107] @@ -49,7 +45,6 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [45, -45], equirectangularDistance: 6812.398372654371, - finalBearing: 125.26438968275465, haversineDistance: 6671.695598673525, initialBearing: 144.73561031724535, midpoint: [18.434948822922006, -24.0948425521107] @@ -58,7 +53,6 @@ describe('ol.Sphere', function() { c1: [45, 45], c2: [45, 45], equirectangularDistance: 0, - finalBearing: 180, haversineDistance: 0, initialBearing: 0, midpoint: [45.00000000000005, 45] @@ -67,7 +61,6 @@ describe('ol.Sphere', function() { c1: [45, 45], c2: [-45, 45], equirectangularDistance: 7076.401799751738, - finalBearing: 234.73561031724535, haversineDistance: 6671.695598673525, initialBearing: -54.73561031724535, midpoint: [0, 54.735610317245346] @@ -76,7 +69,6 @@ describe('ol.Sphere', function() { c1: [45, 45], c2: [-45, -45], equirectangularDistance: 14152.803599503475, - finalBearing: 234.73561031724535, haversineDistance: 13343.391197347048, initialBearing: -125.26438968275465, midpoint: [0, 0] @@ -85,7 +77,6 @@ describe('ol.Sphere', function() { c1: [45, 45], c2: [45, -45], equirectangularDistance: 10007.543398010286, - finalBearing: 180, haversineDistance: 10007.543398010286, initialBearing: 180, midpoint: [45.00000000000005, 0] @@ -94,7 +85,6 @@ describe('ol.Sphere', function() { c1: [-45, 45], c2: [-45, 45], equirectangularDistance: 0, - finalBearing: 180, haversineDistance: 0, initialBearing: 0, midpoint: [-45.00000000000005, 45] @@ -103,7 +93,6 @@ describe('ol.Sphere', function() { c1: [-45, 45], c2: [-45, -45], equirectangularDistance: 10007.543398010286, - finalBearing: 180, haversineDistance: 10007.543398010286, initialBearing: 180, midpoint: [-45.00000000000005, 0] @@ -112,7 +101,6 @@ describe('ol.Sphere', function() { c1: [-45, 45], c2: [45, -45], equirectangularDistance: 14152.803599503475, - finalBearing: 125.26438968275465, haversineDistance: 13343.391197347048, initialBearing: 125.26438968275465, midpoint: [0, 0] @@ -121,7 +109,6 @@ describe('ol.Sphere', function() { c1: [-45, -45], c2: [-45, -45], equirectangularDistance: 0, - finalBearing: 180, haversineDistance: 0, initialBearing: 0, midpoint: [-45.00000000000005, -45] @@ -130,7 +117,6 @@ describe('ol.Sphere', function() { c1: [-45, -45], c2: [45, -45], equirectangularDistance: 7076.401799751738, - finalBearing: 54.735610317245346, haversineDistance: 6671.695598673525, initialBearing: 125.26438968275465, midpoint: [0, -54.735610317245346] @@ -139,7 +125,6 @@ describe('ol.Sphere', function() { c1: [45, -45], c2: [45, -45], equirectangularDistance: 0, - finalBearing: 180, haversineDistance: 0, initialBearing: 0, midpoint: [45.00000000000005, -45] @@ -159,19 +144,6 @@ describe('ol.Sphere', function() { }); - describe('finalBearing', function() { - - it('results match Chris Veness\'s reference implementation', function() { - var e, i; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - expect(sphere.finalBearing(e.c1, e.c2)).to.roughlyEqual( - e.finalBearing, 1e-9); - } - }); - - }); - describe('haversineDistance', function() { it('results match Chris Veness\'s reference implementation', function() { From daa47810722e2f9814c48728abd5d34051c7cbd8 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:48:09 -0600 Subject: [PATCH 04/15] Remove unused sphere.equirectangularDistance() method --- src/ol/sphere/sphere.js | 18 ------------------ test/spec/ol/sphere/sphere.test.js | 28 ---------------------------- 2 files changed, 46 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 86a3d9a7f9..662f56fd83 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -70,24 +70,6 @@ ol.Sphere.prototype.geodesicArea = function(coordinates) { }; -/** - * Returns the distance from c1 to c2 using Pythagoras's theorem on an - * equirectangular projection. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @return {number} Equirectangular distance. - */ -ol.Sphere.prototype.equirectangularDistance = function(c1, c2) { - var lat1 = goog.math.toRadians(c1[1]); - var lat2 = goog.math.toRadians(c2[1]); - var deltaLon = goog.math.toRadians(c2[0] - c1[0]); - var x = deltaLon * Math.cos((lat1 + lat2) / 2); - var y = lat2 - lat1; - return this.radius * Math.sqrt(x * x + y * y); -}; - - /** * Returns the distance from c1 to c2 using the haversine formula. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index d127266db7..8b89ab85cf 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -12,7 +12,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [0, 0], - equirectangularDistance: 0, haversineDistance: 0, initialBearing: 0, midpoint: [0, 0] @@ -20,7 +19,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [45, 45], - equirectangularDistance: 6812.398372654371, haversineDistance: 6671.695598673525, initialBearing: 35.264389682754654, midpoint: [18.434948822922006, 24.0948425521107] @@ -28,7 +26,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [-45, 45], - equirectangularDistance: 6812.398372654371, haversineDistance: 6671.695598673525, initialBearing: -35.264389682754654, midpoint: [-18.434948822922006, 24.0948425521107] @@ -36,7 +33,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [-45, -45], - equirectangularDistance: 6812.398372654371, haversineDistance: 6671.695598673525, initialBearing: -144.73561031724535, midpoint: [-18.434948822922006, -24.0948425521107] @@ -44,7 +40,6 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [45, -45], - equirectangularDistance: 6812.398372654371, haversineDistance: 6671.695598673525, initialBearing: 144.73561031724535, midpoint: [18.434948822922006, -24.0948425521107] @@ -52,7 +47,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [45, 45], - equirectangularDistance: 0, haversineDistance: 0, initialBearing: 0, midpoint: [45.00000000000005, 45] @@ -60,7 +54,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [-45, 45], - equirectangularDistance: 7076.401799751738, haversineDistance: 6671.695598673525, initialBearing: -54.73561031724535, midpoint: [0, 54.735610317245346] @@ -68,7 +61,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [-45, -45], - equirectangularDistance: 14152.803599503475, haversineDistance: 13343.391197347048, initialBearing: -125.26438968275465, midpoint: [0, 0] @@ -76,7 +68,6 @@ describe('ol.Sphere', function() { { c1: [45, 45], c2: [45, -45], - equirectangularDistance: 10007.543398010286, haversineDistance: 10007.543398010286, initialBearing: 180, midpoint: [45.00000000000005, 0] @@ -84,7 +75,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [-45, 45], - equirectangularDistance: 0, haversineDistance: 0, initialBearing: 0, midpoint: [-45.00000000000005, 45] @@ -92,7 +82,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [-45, -45], - equirectangularDistance: 10007.543398010286, haversineDistance: 10007.543398010286, initialBearing: 180, midpoint: [-45.00000000000005, 0] @@ -100,7 +89,6 @@ describe('ol.Sphere', function() { { c1: [-45, 45], c2: [45, -45], - equirectangularDistance: 14152.803599503475, haversineDistance: 13343.391197347048, initialBearing: 125.26438968275465, midpoint: [0, 0] @@ -108,7 +96,6 @@ describe('ol.Sphere', function() { { c1: [-45, -45], c2: [-45, -45], - equirectangularDistance: 0, haversineDistance: 0, initialBearing: 0, midpoint: [-45.00000000000005, -45] @@ -116,7 +103,6 @@ describe('ol.Sphere', function() { { c1: [-45, -45], c2: [45, -45], - equirectangularDistance: 7076.401799751738, haversineDistance: 6671.695598673525, initialBearing: 125.26438968275465, midpoint: [0, -54.735610317245346] @@ -124,26 +110,12 @@ describe('ol.Sphere', function() { { c1: [45, -45], c2: [45, -45], - equirectangularDistance: 0, haversineDistance: 0, initialBearing: 0, midpoint: [45.00000000000005, -45] } ]; - describe('equirectangularDistance', function() { - - it('results match Chris Veness\'s reference implementation', function() { - var e, i; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - expect(sphere.equirectangularDistance(e.c1, e.c2)).to.roughlyEqual( - e.equirectangularDistance, 1e-9); - } - }); - - }); - describe('haversineDistance', function() { it('results match Chris Veness\'s reference implementation', function() { From 3852be0d7edeb3e136c29b5eced23f49657c8503 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:50:00 -0600 Subject: [PATCH 05/15] Remove unused sphere.initialBearing() method --- src/ol/sphere/sphere.js | 18 ------------------ test/spec/ol/sphere/sphere.test.js | 28 ---------------------------- 2 files changed, 46 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 662f56fd83..7bbd2a4a3e 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -126,24 +126,6 @@ ol.Sphere.prototype.interpolate = function(c1, c2, fraction) { }; -/** - * Returns the initial bearing from c1 to c2. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @return {number} Initial bearing. - */ -ol.Sphere.prototype.initialBearing = function(c1, c2) { - var lat1 = goog.math.toRadians(c1[1]); - var lat2 = goog.math.toRadians(c2[1]); - var deltaLon = goog.math.toRadians(c2[0] - c1[0]); - var y = Math.sin(deltaLon) * Math.cos(lat2); - var x = Math.cos(lat1) * Math.sin(lat2) - - Math.sin(lat1) * Math.cos(lat2) * Math.cos(deltaLon); - return goog.math.toDegrees(Math.atan2(y, x)); -}; - - /** * Returns the maximum latitude of the great circle defined by bearing and * latitude. diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 8b89ab85cf..7b97f870ec 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -13,105 +13,90 @@ describe('ol.Sphere', function() { c1: [0, 0], c2: [0, 0], haversineDistance: 0, - initialBearing: 0, midpoint: [0, 0] }, { c1: [0, 0], c2: [45, 45], haversineDistance: 6671.695598673525, - initialBearing: 35.264389682754654, midpoint: [18.434948822922006, 24.0948425521107] }, { c1: [0, 0], c2: [-45, 45], haversineDistance: 6671.695598673525, - initialBearing: -35.264389682754654, midpoint: [-18.434948822922006, 24.0948425521107] }, { c1: [0, 0], c2: [-45, -45], haversineDistance: 6671.695598673525, - initialBearing: -144.73561031724535, midpoint: [-18.434948822922006, -24.0948425521107] }, { c1: [0, 0], c2: [45, -45], haversineDistance: 6671.695598673525, - initialBearing: 144.73561031724535, midpoint: [18.434948822922006, -24.0948425521107] }, { c1: [45, 45], c2: [45, 45], haversineDistance: 0, - initialBearing: 0, midpoint: [45.00000000000005, 45] }, { c1: [45, 45], c2: [-45, 45], haversineDistance: 6671.695598673525, - initialBearing: -54.73561031724535, midpoint: [0, 54.735610317245346] }, { c1: [45, 45], c2: [-45, -45], haversineDistance: 13343.391197347048, - initialBearing: -125.26438968275465, midpoint: [0, 0] }, { c1: [45, 45], c2: [45, -45], haversineDistance: 10007.543398010286, - initialBearing: 180, midpoint: [45.00000000000005, 0] }, { c1: [-45, 45], c2: [-45, 45], haversineDistance: 0, - initialBearing: 0, midpoint: [-45.00000000000005, 45] }, { c1: [-45, 45], c2: [-45, -45], haversineDistance: 10007.543398010286, - initialBearing: 180, midpoint: [-45.00000000000005, 0] }, { c1: [-45, 45], c2: [45, -45], haversineDistance: 13343.391197347048, - initialBearing: 125.26438968275465, midpoint: [0, 0] }, { c1: [-45, -45], c2: [-45, -45], haversineDistance: 0, - initialBearing: 0, midpoint: [-45.00000000000005, -45] }, { c1: [-45, -45], c2: [45, -45], haversineDistance: 6671.695598673525, - initialBearing: 125.26438968275465, midpoint: [0, -54.735610317245346] }, { c1: [45, -45], c2: [45, -45], haversineDistance: 0, - initialBearing: 0, midpoint: [45.00000000000005, -45] } ]; @@ -129,19 +114,6 @@ describe('ol.Sphere', function() { }); - describe('initialBearing', function() { - - it('results match Chris Veness\'s reference implementation', function() { - var e, i; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - expect(sphere.initialBearing(e.c1, e.c2)).to.roughlyEqual( - e.initialBearing, 1e-9); - } - }); - - }); - describe('interpolate', function() { it('results match at the start, midpoint, and end', function() { From 9cccbd071266d1d05ffa5399bc752b4462921367 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:51:00 -0600 Subject: [PATCH 06/15] Remove unused sphere.maximumLatitude() method --- src/ol/sphere/sphere.js | 14 -------------- test/spec/ol/sphere/sphere.test.js | 1 - 2 files changed, 15 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 7bbd2a4a3e..ccd65073cb 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -126,20 +126,6 @@ ol.Sphere.prototype.interpolate = function(c1, c2, fraction) { }; -/** - * Returns the maximum latitude of the great circle defined by bearing and - * latitude. - * - * @param {number} bearing Bearing. - * @param {number} latitude Latitude. - * @return {number} Maximum latitude. - */ -ol.Sphere.prototype.maximumLatitude = function(bearing, latitude) { - return Math.cos(Math.abs(Math.sin(goog.math.toRadians(bearing)) * - Math.cos(goog.math.toRadians(latitude)))); -}; - - /** * Returns the midpoint between c1 and c2. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 7b97f870ec..16eb6665bc 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -1,5 +1,4 @@ // See http://www.movable-type.co.uk/scripts/latlong.html -// FIXME add tests for maximumLatitude // FIXME add tests for offset goog.provide('ol.test.Sphere'); From b724ce6c0dc021e6bec4fae111f752ece83dd2a6 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:54:08 -0600 Subject: [PATCH 07/15] Remove unused sphere.interpolate() method --- src/ol/sphere/sphere.js | 36 ------------------------------ test/spec/ol/sphere/sphere.test.js | 20 ----------------- 2 files changed, 56 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index ccd65073cb..9a93569879 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -90,42 +90,6 @@ ol.Sphere.prototype.haversineDistance = function(c1, c2) { }; -/** - * Returns the point at `fraction` along the segment of the great circle passing - * through c1 and c2. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @param {number} fraction Fraction. - * @return {ol.Coordinate} Coordinate between c1 and c2. - */ -ol.Sphere.prototype.interpolate = function(c1, c2, fraction) { - var lat1 = goog.math.toRadians(c1[1]); - var lon1 = goog.math.toRadians(c1[0]); - var lat2 = goog.math.toRadians(c2[1]); - var lon2 = goog.math.toRadians(c2[0]); - var cosLat1 = Math.cos(lat1); - var sinLat1 = Math.sin(lat1); - var cosLat2 = Math.cos(lat2); - var sinLat2 = Math.sin(lat2); - var cosDeltaLon = Math.cos(lon2 - lon1); - var d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon; - if (1 <= d) { - return c2.slice(); - } - d = fraction * Math.acos(d); - var cosD = Math.cos(d); - var sinD = Math.sin(d); - var y = Math.sin(lon2 - lon1) * cosLat2; - var x = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDeltaLon; - var theta = Math.atan2(y, x); - var lat = Math.asin(sinLat1 * cosD + cosLat1 * sinD * Math.cos(theta)); - var lon = lon1 + Math.atan2(Math.sin(theta) * sinD * cosLat1, - cosD - sinLat1 * Math.sin(lat)); - return [goog.math.toDegrees(lon), goog.math.toDegrees(lat)]; -}; - - /** * Returns the midpoint between c1 and c2. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index 16eb6665bc..c35bcebe2d 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -113,26 +113,6 @@ describe('ol.Sphere', function() { }); - describe('interpolate', function() { - - it('results match at the start, midpoint, and end', function() { - var e, i; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - var c1 = sphere.interpolate(e.c1, e.c2, 0); - expect(c1[0]).to.roughlyEqual(e.c1[0], 1e-9); - expect(c1[1]).to.roughlyEqual(e.c1[1], 1e-9); - var midpoint = sphere.interpolate(e.c1, e.c2, 0.5); - expect(midpoint[0]).to.roughlyEqual(e.midpoint[0], 1e-9); - expect(midpoint[1]).to.roughlyEqual(e.midpoint[1], 1e-5); - var c2 = sphere.interpolate(e.c1, e.c2, 1); - expect(c2[0]).to.roughlyEqual(e.c2[0], 1e-9); - expect(c2[1]).to.roughlyEqual(e.c2[1], 1e-5); - } - }); - - }); - describe('midpoint', function() { it('results match Chris Veness\'s reference implementation', function() { From 90ec289c895284a33d0cbbb42ee3ef5f8c5273b7 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:56:23 -0600 Subject: [PATCH 08/15] Remove unused sphere.midpoint() method --- src/ol/sphere/sphere.js | 22 ----------- test/spec/ol/sphere/sphere.test.js | 62 ++++++++---------------------- 2 files changed, 15 insertions(+), 69 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index 9a93569879..e33b56624c 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -90,28 +90,6 @@ ol.Sphere.prototype.haversineDistance = function(c1, c2) { }; -/** - * Returns the midpoint between c1 and c2. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 2. - * @return {ol.Coordinate} Midpoint. - */ -ol.Sphere.prototype.midpoint = function(c1, c2) { - var lat1 = goog.math.toRadians(c1[1]); - var lat2 = goog.math.toRadians(c2[1]); - var lon1 = goog.math.toRadians(c1[0]); - var deltaLon = goog.math.toRadians(c2[0] - c1[0]); - var Bx = Math.cos(lat2) * Math.cos(deltaLon); - var By = Math.cos(lat2) * Math.sin(deltaLon); - var cosLat1PlusBx = Math.cos(lat1) + Bx; - var lat = Math.atan2(Math.sin(lat1) + Math.sin(lat2), - Math.sqrt(cosLat1PlusBx * cosLat1PlusBx + By * By)); - var lon = lon1 + Math.atan2(By, cosLat1PlusBx); - return [goog.math.toDegrees(lon), goog.math.toDegrees(lat)]; -}; - - /** * Returns the coordinate at the given distance and bearing from `c1`. * diff --git a/test/spec/ol/sphere/sphere.test.js b/test/spec/ol/sphere/sphere.test.js index c35bcebe2d..3544a47c10 100644 --- a/test/spec/ol/sphere/sphere.test.js +++ b/test/spec/ol/sphere/sphere.test.js @@ -11,92 +11,77 @@ describe('ol.Sphere', function() { { c1: [0, 0], c2: [0, 0], - haversineDistance: 0, - midpoint: [0, 0] + haversineDistance: 0 }, { c1: [0, 0], c2: [45, 45], - haversineDistance: 6671.695598673525, - midpoint: [18.434948822922006, 24.0948425521107] + haversineDistance: 6671.695598673525 }, { c1: [0, 0], c2: [-45, 45], - haversineDistance: 6671.695598673525, - midpoint: [-18.434948822922006, 24.0948425521107] + haversineDistance: 6671.695598673525 }, { c1: [0, 0], c2: [-45, -45], - haversineDistance: 6671.695598673525, - midpoint: [-18.434948822922006, -24.0948425521107] + haversineDistance: 6671.695598673525 }, { c1: [0, 0], c2: [45, -45], - haversineDistance: 6671.695598673525, - midpoint: [18.434948822922006, -24.0948425521107] + haversineDistance: 6671.695598673525 }, { c1: [45, 45], c2: [45, 45], - haversineDistance: 0, - midpoint: [45.00000000000005, 45] + haversineDistance: 0 }, { c1: [45, 45], c2: [-45, 45], - haversineDistance: 6671.695598673525, - midpoint: [0, 54.735610317245346] + haversineDistance: 6671.695598673525 }, { c1: [45, 45], c2: [-45, -45], - haversineDistance: 13343.391197347048, - midpoint: [0, 0] + haversineDistance: 13343.391197347048 }, { c1: [45, 45], c2: [45, -45], - haversineDistance: 10007.543398010286, - midpoint: [45.00000000000005, 0] + haversineDistance: 10007.543398010286 }, { c1: [-45, 45], c2: [-45, 45], - haversineDistance: 0, - midpoint: [-45.00000000000005, 45] + haversineDistance: 0 }, { c1: [-45, 45], c2: [-45, -45], - haversineDistance: 10007.543398010286, - midpoint: [-45.00000000000005, 0] + haversineDistance: 10007.543398010286 }, { c1: [-45, 45], c2: [45, -45], - haversineDistance: 13343.391197347048, - midpoint: [0, 0] + haversineDistance: 13343.391197347048 }, { c1: [-45, -45], c2: [-45, -45], - haversineDistance: 0, - midpoint: [-45.00000000000005, -45] + haversineDistance: 0 }, { c1: [-45, -45], c2: [45, -45], - haversineDistance: 6671.695598673525, - midpoint: [0, -54.735610317245346] + haversineDistance: 6671.695598673525 }, { c1: [45, -45], c2: [45, -45], - haversineDistance: 0, - midpoint: [45.00000000000005, -45] + haversineDistance: 0 } ]; @@ -113,23 +98,6 @@ describe('ol.Sphere', function() { }); - describe('midpoint', function() { - - it('results match Chris Veness\'s reference implementation', function() { - var e, i, midpoint; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - midpoint = sphere.midpoint(e.c1, e.c2); - // Test modulo 360 to avoid unnecessary expensive modulo operations - // in our implementation. - expect(goog.math.modulo(midpoint[0], 360)).to.roughlyEqual( - goog.math.modulo(e.midpoint[0], 360), 1e-9); - expect(midpoint[1]).to.roughlyEqual(e.midpoint[1], 1e-9); - } - }); - - }); - describe('Vincenty area', function() { var geometry; before(function(done) { From 0ba7856d4913ce9adfafef3ec7a30fce13785da7 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 11:59:39 -0600 Subject: [PATCH 09/15] Remove FIXMEs --- src/ol/sphere/sphere.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ol/sphere/sphere.js b/src/ol/sphere/sphere.js index e33b56624c..259e6d3bfb 100644 --- a/src/ol/sphere/sphere.js +++ b/src/ol/sphere/sphere.js @@ -5,9 +5,6 @@ * Licensed under CC-BY-3.0. */ -// FIXME add intersection of two paths given start points and bearings -// FIXME add rhumb lines - goog.provide('ol.Sphere'); goog.require('goog.math'); From 6bbc41152150f239d48123046ea5b1372810b771 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:06:31 -0600 Subject: [PATCH 10/15] Remove unused ellipsoid.vincentyInitialBearing() method --- src/ol/ellipsoid/ellipsoid.js | 16 ------- test/spec/ol/ellipsoid/ellipsoid.test.js | 58 ------------------------ 2 files changed, 74 deletions(-) diff --git a/src/ol/ellipsoid/ellipsoid.js b/src/ol/ellipsoid/ellipsoid.js index 88ef01335f..1602a075fc 100644 --- a/src/ol/ellipsoid/ellipsoid.js +++ b/src/ol/ellipsoid/ellipsoid.js @@ -167,19 +167,3 @@ ol.Ellipsoid.prototype.vincentyFinalBearing = var vincenty = this.vincenty(c1, c2, opt_minDeltaLambda, opt_maxIterations); return vincenty.finalBearing; }; - - -/** - * Returns the initial bearing from c1 to c2 using Vincenty. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 1. - * @param {number=} opt_minDeltaLambda Minimum delta lambda for convergence. - * @param {number=} opt_maxIterations Maximum iterations. - * @return {number} Initial bearing. - */ -ol.Ellipsoid.prototype.vincentyInitialBearing = - function(c1, c2, opt_minDeltaLambda, opt_maxIterations) { - var vincenty = this.vincenty(c1, c2, opt_minDeltaLambda, opt_maxIterations); - return vincenty.initialBearing; -}; diff --git a/test/spec/ol/ellipsoid/ellipsoid.test.js b/test/spec/ol/ellipsoid/ellipsoid.test.js index 1573c1ec3c..e3886e1d47 100644 --- a/test/spec/ol/ellipsoid/ellipsoid.test.js +++ b/test/spec/ol/ellipsoid/ellipsoid.test.js @@ -8,280 +8,240 @@ describe('ol.Ellipsoid', function() { c1: [0, 0], c2: [0, 0], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [0, 0], c2: [45, 45], vincentyFinalBearing: 54.890773827979565, - vincentyInitialBearing: 35.41005890511814, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [45, -45], vincentyFinalBearing: 125.10922617202044, - vincentyInitialBearing: 144.58994109488185, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [-45, -45], vincentyFinalBearing: -125.10922617202044, - vincentyInitialBearing: -144.58994109488185, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [-45, 45], vincentyFinalBearing: -54.890773827979565, - vincentyInitialBearing: -35.41005890511814, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [180, 90], vincentyFinalBearing: 180, - vincentyInitialBearing: 4.296211503097554e-31, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [180, -90], vincentyFinalBearing: 7.0164775638926606e-15, - vincentyInitialBearing: 180, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [-180, 90], vincentyFinalBearing: -180, - vincentyInitialBearing: -4.296211503097554e-31, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [-180, 90], vincentyFinalBearing: -180, - vincentyInitialBearing: -4.296211503097554e-31, vincentyDistance: 10001965.729311794 }, { c1: [45, 45], c2: [45, 45], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [45, 45], c2: [45, -45], vincentyFinalBearing: 180, - vincentyInitialBearing: 180, vincentyDistance: 9969888.755957305 }, { c1: [45, 45], c2: [-45, -45], vincentyFinalBearing: -125.10922617202044, - vincentyInitialBearing: -125.10922617202044, vincentyDistance: 13324945.436434371 }, { c1: [45, 45], c2: [-45, 45], vincentyFinalBearing: -125.27390277185786, - vincentyInitialBearing: -54.726097228142166, vincentyDistance: 6690232.932559058 }, { c1: [45, 45], c2: [180, 90], vincentyFinalBearing: 135, - vincentyInitialBearing: 3.5023624896823797e-15, vincentyDistance: 5017021.35133314 }, { c1: [45, 45], c2: [180, -90], vincentyFinalBearing: 45.00000000000001, - vincentyInitialBearing: 180, vincentyDistance: 14986910.107290443 }, { c1: [45, 45], c2: [-180, 90], vincentyFinalBearing: 135.00000000000003, - vincentyInitialBearing: 3.5023624896823793e-15, vincentyDistance: 5017021.35133314 }, { c1: [45, 45], c2: [-180, 90], vincentyFinalBearing: 135.00000000000003, - vincentyInitialBearing: 3.5023624896823793e-15, vincentyDistance: 5017021.35133314 }, { c1: [45, -45], c2: [45, -45], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [45, -45], c2: [-45, -45], vincentyFinalBearing: -54.726097228142166, - vincentyInitialBearing: -125.27390277185786, vincentyDistance: 6690232.932559058 }, { c1: [45, -45], c2: [-45, 45], vincentyFinalBearing: -54.890773827979565, - vincentyInitialBearing: -54.890773827979565, vincentyDistance: 13324945.436434371 }, { c1: [45, -45], c2: [180, 90], vincentyFinalBearing: 135, - vincentyInitialBearing: 3.5023624896823797e-15, vincentyDistance: 14986910.107290443 }, { c1: [45, -45], c2: [180, -90], vincentyFinalBearing: 45.00000000000001, - vincentyInitialBearing: 180, vincentyDistance: 5017021.35133314 }, { c1: [45, -45], c2: [-180, 90], vincentyFinalBearing: 135.00000000000003, - vincentyInitialBearing: 3.5023624896823793e-15, vincentyDistance: 14986910.107290443 }, { c1: [45, -45], c2: [-180, 90], vincentyFinalBearing: 135.00000000000003, - vincentyInitialBearing: 3.5023624896823793e-15, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [-45, -45], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [-45, -45], c2: [-45, 45], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 9969888.755957305 }, { c1: [-45, -45], c2: [180, 90], vincentyFinalBearing: -135.00000000000003, - vincentyInitialBearing: -3.5023624896823793e-15, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [180, -90], vincentyFinalBearing: -44.999999999999986, - vincentyInitialBearing: -180, vincentyDistance: 5017021.35133314 }, { c1: [-45, -45], c2: [-180, 90], vincentyFinalBearing: -135, - vincentyInitialBearing: -3.5023624896823797e-15, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [-180, 90], vincentyFinalBearing: -135, - vincentyInitialBearing: -3.5023624896823797e-15, vincentyDistance: 14986910.107290443 }, { c1: [-45, 45], c2: [-45, 45], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [-45, 45], c2: [180, 90], vincentyFinalBearing: -135.00000000000003, - vincentyInitialBearing: -3.5023624896823793e-15, vincentyDistance: 5017021.35133314 }, { c1: [-45, 45], c2: [180, -90], vincentyFinalBearing: -44.999999999999986, - vincentyInitialBearing: -180, vincentyDistance: 14986910.107290443 }, { c1: [-45, 45], c2: [-180, 90], vincentyFinalBearing: -135, - vincentyInitialBearing: -3.5023624896823797e-15, vincentyDistance: 5017021.35133314 }, { c1: [-45, 45], c2: [-180, 90], vincentyFinalBearing: -135, - vincentyInitialBearing: -3.5023624896823797e-15, vincentyDistance: 5017021.35133314 }, { c1: [180, 90], c2: [180, 90], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [180, -90], c2: [180, -90], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], vincentyFinalBearing: 0, - vincentyInitialBearing: 0, vincentyDistance: 0 } ]; @@ -297,8 +257,6 @@ describe('ol.Ellipsoid', function() { expect(v.distance).to.roughlyEqual(e.vincentyDistance, 1e-8); expect(v.finalBearing).to.roughlyEqual( e.vincentyFinalBearing, 1e-9); - expect(v.initialBearing).to.roughlyEqual( - e.vincentyInitialBearing, 1e-9); } }); @@ -335,22 +293,6 @@ describe('ol.Ellipsoid', function() { }); - describe('vincentyInitialBearing', function() { - - it('returns the same distances as Chris Veness\'s reference implementation', - function() { - var e, i, vincentyInitialBearing; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - vincentyInitialBearing = ol.ellipsoid.WGS84.vincentyInitialBearing( - e.c1, e.c2, 1e-12, 100); - expect(vincentyInitialBearing).to.roughlyEqual( - e.vincentyInitialBearing, 1e-9); - } - }); - - }); - }); From b180149100dacc353d5026dd73a241c59e43ccce Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:08:39 -0600 Subject: [PATCH 11/15] Remove unused ellipsoid.vincentyFinalBearing() method --- src/ol/ellipsoid/ellipsoid.js | 16 ------- test/spec/ol/ellipsoid/ellipsoid.test.js | 58 ------------------------ 2 files changed, 74 deletions(-) diff --git a/src/ol/ellipsoid/ellipsoid.js b/src/ol/ellipsoid/ellipsoid.js index 1602a075fc..95722e77c1 100644 --- a/src/ol/ellipsoid/ellipsoid.js +++ b/src/ol/ellipsoid/ellipsoid.js @@ -151,19 +151,3 @@ ol.Ellipsoid.prototype.vincentyDistance = var vincenty = this.vincenty(c1, c2, opt_minDeltaLambda, opt_maxIterations); return vincenty.distance; }; - - -/** - * Returns the final bearing from c1 to c2 using Vincenty. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 1. - * @param {number=} opt_minDeltaLambda Minimum delta lambda for convergence. - * @param {number=} opt_maxIterations Maximum iterations. - * @return {number} Initial bearing. - */ -ol.Ellipsoid.prototype.vincentyFinalBearing = - function(c1, c2, opt_minDeltaLambda, opt_maxIterations) { - var vincenty = this.vincenty(c1, c2, opt_minDeltaLambda, opt_maxIterations); - return vincenty.finalBearing; -}; diff --git a/test/spec/ol/ellipsoid/ellipsoid.test.js b/test/spec/ol/ellipsoid/ellipsoid.test.js index e3886e1d47..3e7175b966 100644 --- a/test/spec/ol/ellipsoid/ellipsoid.test.js +++ b/test/spec/ol/ellipsoid/ellipsoid.test.js @@ -7,241 +7,201 @@ describe('ol.Ellipsoid', function() { { c1: [0, 0], c2: [0, 0], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [0, 0], c2: [45, 45], - vincentyFinalBearing: 54.890773827979565, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [45, -45], - vincentyFinalBearing: 125.10922617202044, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [-45, -45], - vincentyFinalBearing: -125.10922617202044, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [-45, 45], - vincentyFinalBearing: -54.890773827979565, vincentyDistance: 6662472.718217184 }, { c1: [0, 0], c2: [180, 90], - vincentyFinalBearing: 180, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [180, -90], - vincentyFinalBearing: 7.0164775638926606e-15, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [-180, 90], - vincentyFinalBearing: -180, vincentyDistance: 10001965.729311794 }, { c1: [0, 0], c2: [-180, 90], - vincentyFinalBearing: -180, vincentyDistance: 10001965.729311794 }, { c1: [45, 45], c2: [45, 45], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [45, 45], c2: [45, -45], - vincentyFinalBearing: 180, vincentyDistance: 9969888.755957305 }, { c1: [45, 45], c2: [-45, -45], - vincentyFinalBearing: -125.10922617202044, vincentyDistance: 13324945.436434371 }, { c1: [45, 45], c2: [-45, 45], - vincentyFinalBearing: -125.27390277185786, vincentyDistance: 6690232.932559058 }, { c1: [45, 45], c2: [180, 90], - vincentyFinalBearing: 135, vincentyDistance: 5017021.35133314 }, { c1: [45, 45], c2: [180, -90], - vincentyFinalBearing: 45.00000000000001, vincentyDistance: 14986910.107290443 }, { c1: [45, 45], c2: [-180, 90], - vincentyFinalBearing: 135.00000000000003, vincentyDistance: 5017021.35133314 }, { c1: [45, 45], c2: [-180, 90], - vincentyFinalBearing: 135.00000000000003, vincentyDistance: 5017021.35133314 }, { c1: [45, -45], c2: [45, -45], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [45, -45], c2: [-45, -45], - vincentyFinalBearing: -54.726097228142166, vincentyDistance: 6690232.932559058 }, { c1: [45, -45], c2: [-45, 45], - vincentyFinalBearing: -54.890773827979565, vincentyDistance: 13324945.436434371 }, { c1: [45, -45], c2: [180, 90], - vincentyFinalBearing: 135, vincentyDistance: 14986910.107290443 }, { c1: [45, -45], c2: [180, -90], - vincentyFinalBearing: 45.00000000000001, vincentyDistance: 5017021.35133314 }, { c1: [45, -45], c2: [-180, 90], - vincentyFinalBearing: 135.00000000000003, vincentyDistance: 14986910.107290443 }, { c1: [45, -45], c2: [-180, 90], - vincentyFinalBearing: 135.00000000000003, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [-45, -45], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [-45, -45], c2: [-45, 45], - vincentyFinalBearing: 0, vincentyDistance: 9969888.755957305 }, { c1: [-45, -45], c2: [180, 90], - vincentyFinalBearing: -135.00000000000003, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [180, -90], - vincentyFinalBearing: -44.999999999999986, vincentyDistance: 5017021.35133314 }, { c1: [-45, -45], c2: [-180, 90], - vincentyFinalBearing: -135, vincentyDistance: 14986910.107290443 }, { c1: [-45, -45], c2: [-180, 90], - vincentyFinalBearing: -135, vincentyDistance: 14986910.107290443 }, { c1: [-45, 45], c2: [-45, 45], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [-45, 45], c2: [180, 90], - vincentyFinalBearing: -135.00000000000003, vincentyDistance: 5017021.35133314 }, { c1: [-45, 45], c2: [180, -90], - vincentyFinalBearing: -44.999999999999986, vincentyDistance: 14986910.107290443 }, { c1: [-45, 45], c2: [-180, 90], - vincentyFinalBearing: -135, vincentyDistance: 5017021.35133314 }, { c1: [-45, 45], c2: [-180, 90], - vincentyFinalBearing: -135, vincentyDistance: 5017021.35133314 }, { c1: [180, 90], c2: [180, 90], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [180, -90], c2: [180, -90], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], - vincentyFinalBearing: 0, vincentyDistance: 0 }, { c1: [-180, 90], c2: [-180, 90], - vincentyFinalBearing: 0, vincentyDistance: 0 } ]; @@ -255,8 +215,6 @@ describe('ol.Ellipsoid', function() { e = expected[i]; v = ol.ellipsoid.WGS84.vincenty(e.c1, e.c2, 1e-12, 100); expect(v.distance).to.roughlyEqual(e.vincentyDistance, 1e-8); - expect(v.finalBearing).to.roughlyEqual( - e.vincentyFinalBearing, 1e-9); } }); @@ -277,22 +235,6 @@ describe('ol.Ellipsoid', function() { }); - describe('vincentyFinalBearing', function() { - - it('returns the same distances as Chris Veness\'s reference implementation', - function() { - var e, i, vincentyFinalBearing; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - vincentyFinalBearing = - ol.ellipsoid.WGS84.vincentyFinalBearing(e.c1, e.c2, 1e-12, 100); - expect(vincentyFinalBearing).to.roughlyEqual( - e.vincentyFinalBearing, 1e-9); - } - }); - - }); - }); From d91f5ecc4825fd06c18ba90a5dbb8447cbfe8279 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:11:46 -0600 Subject: [PATCH 12/15] Remove unused ellipsoid.vincentyDistance() method --- src/ol/ellipsoid/ellipsoid.js | 16 ---------------- test/spec/ol/ellipsoid/ellipsoid.test.js | 15 --------------- 2 files changed, 31 deletions(-) diff --git a/src/ol/ellipsoid/ellipsoid.js b/src/ol/ellipsoid/ellipsoid.js index 95722e77c1..38086eb644 100644 --- a/src/ol/ellipsoid/ellipsoid.js +++ b/src/ol/ellipsoid/ellipsoid.js @@ -135,19 +135,3 @@ ol.Ellipsoid.prototype.vincenty = finalBearing: goog.math.toDegrees(alpha2) }; }; - - -/** - * Returns the distance from c1 to c2 using Vincenty. - * - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 1. - * @param {number=} opt_minDeltaLambda Minimum delta lambda for convergence. - * @param {number=} opt_maxIterations Maximum iterations. - * @return {number} Vincenty distance. - */ -ol.Ellipsoid.prototype.vincentyDistance = - function(c1, c2, opt_minDeltaLambda, opt_maxIterations) { - var vincenty = this.vincenty(c1, c2, opt_minDeltaLambda, opt_maxIterations); - return vincenty.distance; -}; diff --git a/test/spec/ol/ellipsoid/ellipsoid.test.js b/test/spec/ol/ellipsoid/ellipsoid.test.js index 3e7175b966..843d2d2205 100644 --- a/test/spec/ol/ellipsoid/ellipsoid.test.js +++ b/test/spec/ol/ellipsoid/ellipsoid.test.js @@ -220,21 +220,6 @@ describe('ol.Ellipsoid', function() { }); - describe('vincentyDistance', function() { - - it('returns the same distances as Chris Veness\'s reference implementation', - function() { - var e, i, vincentyDistance; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - vincentyDistance = - ol.ellipsoid.WGS84.vincentyDistance(e.c1, e.c2, 1e-12, 100); - expect(vincentyDistance).to.roughlyEqual(e.vincentyDistance, 1e-8); - } - }); - - }); - }); From 13a9d2f6af6b17886a138f05415abc097b39f630 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:15:13 -0600 Subject: [PATCH 13/15] Remove unused ellipsoid.vincenty() method --- src/ol/ellipsoid/ellipsoid.js | 95 ---------- test/spec/ol/ellipsoid/ellipsoid.test.js | 227 ----------------------- 2 files changed, 322 deletions(-) delete mode 100644 test/spec/ol/ellipsoid/ellipsoid.test.js diff --git a/src/ol/ellipsoid/ellipsoid.js b/src/ol/ellipsoid/ellipsoid.js index 38086eb644..ad266f644c 100644 --- a/src/ol/ellipsoid/ellipsoid.js +++ b/src/ol/ellipsoid/ellipsoid.js @@ -1,8 +1,5 @@ goog.provide('ol.Ellipsoid'); -goog.require('goog.math'); -goog.require('ol.Coordinate'); - /** @@ -43,95 +40,3 @@ ol.Ellipsoid = function(a, flattening) { this.e = Math.sqrt(this.eSquared); }; - - -/** - * @param {ol.Coordinate} c1 Coordinate 1. - * @param {ol.Coordinate} c2 Coordinate 1. - * @param {number=} opt_minDeltaLambda Minimum delta lambda for convergence. - * @param {number=} opt_maxIterations Maximum iterations. - * @return {{distance: number, initialBearing: number, finalBearing: number}} - * Vincenty. - */ -ol.Ellipsoid.prototype.vincenty = - function(c1, c2, opt_minDeltaLambda, opt_maxIterations) { - var minDeltaLambda = goog.isDef(opt_minDeltaLambda) ? - opt_minDeltaLambda : 1e-12; - var maxIterations = goog.isDef(opt_maxIterations) ? - opt_maxIterations : 100; - var f = this.flattening; - var lat1 = goog.math.toRadians(c1[1]); - var lat2 = goog.math.toRadians(c2[1]); - var deltaLon = goog.math.toRadians(c2[0] - c1[0]); - var U1 = Math.atan((1 - f) * Math.tan(lat1)); - var cosU1 = Math.cos(U1); - var sinU1 = Math.sin(U1); - var U2 = Math.atan((1 - f) * Math.tan(lat2)); - var cosU2 = Math.cos(U2); - var sinU2 = Math.sin(U2); - var lambda = deltaLon; - var cosSquaredAlpha, sinAlpha; - var cosLambda, deltaLambda = Infinity, sinLambda; - var cos2SigmaM, cosSigma, sigma, sinSigma; - var i; - for (i = maxIterations; i > 0; --i) { - cosLambda = Math.cos(lambda); - sinLambda = Math.sin(lambda); - var x = cosU2 * sinLambda; - var y = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda; - sinSigma = Math.sqrt(x * x + y * y); - if (sinSigma === 0) { - return { - distance: 0, - initialBearing: 0, - finalBearing: 0 - }; - } - cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda; - sigma = Math.atan2(sinSigma, cosSigma); - sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma; - cosSquaredAlpha = 1 - sinAlpha * sinAlpha; - cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSquaredAlpha; - if (isNaN(cos2SigmaM)) { - cos2SigmaM = 0; - } - var C = f / 16 * cosSquaredAlpha * (4 + f * (4 - 3 * cosSquaredAlpha)); - var lambdaPrime = deltaLon + (1 - C) * f * sinAlpha * (sigma + - C * sinSigma * (cos2SigmaM + - C * cosSigma * (2 * cos2SigmaM * cos2SigmaM - 1))); - deltaLambda = Math.abs(lambdaPrime - lambda); - lambda = lambdaPrime; - if (deltaLambda < minDeltaLambda) { - break; - } - } - if (i === 0) { - return { - distance: NaN, - finalBearing: NaN, - initialBearing: NaN - }; - } - var aSquared = this.a * this.a; - var bSquared = this.b * this.b; - var uSquared = cosSquaredAlpha * (aSquared - bSquared) / bSquared; - var A = 1 + uSquared / 16384 * - (4096 + uSquared * (uSquared * (320 - 175 * uSquared) - 768)); - var B = uSquared / 1024 * - (256 + uSquared * (uSquared * (74 - 47 * uSquared) - 128)); - var deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * - (cosSigma * (2 * cos2SigmaM * cos2SigmaM - 1) - - B / 6 * cos2SigmaM * (4 * sinSigma * sinSigma - 3) * - (4 * cos2SigmaM * cos2SigmaM - 3))); - cosLambda = Math.cos(lambda); - sinLambda = Math.sin(lambda); - var alpha1 = Math.atan2(cosU2 * sinLambda, - cosU1 * sinU2 - sinU1 * cosU2 * cosLambda); - var alpha2 = Math.atan2(cosU1 * sinLambda, - cosU1 * sinU2 * cosLambda - sinU1 * cosU2); - return { - distance: this.b * A * (sigma - deltaSigma), - initialBearing: goog.math.toDegrees(alpha1), - finalBearing: goog.math.toDegrees(alpha2) - }; -}; diff --git a/test/spec/ol/ellipsoid/ellipsoid.test.js b/test/spec/ol/ellipsoid/ellipsoid.test.js deleted file mode 100644 index 843d2d2205..0000000000 --- a/test/spec/ol/ellipsoid/ellipsoid.test.js +++ /dev/null @@ -1,227 +0,0 @@ -goog.provide('ol.test.Ellipsoid'); - - -describe('ol.Ellipsoid', function() { - - var expected = [ - { - c1: [0, 0], - c2: [0, 0], - vincentyDistance: 0 - }, - { - c1: [0, 0], - c2: [45, 45], - vincentyDistance: 6662472.718217184 - }, - { - c1: [0, 0], - c2: [45, -45], - vincentyDistance: 6662472.718217184 - }, - { - c1: [0, 0], - c2: [-45, -45], - vincentyDistance: 6662472.718217184 - }, - { - c1: [0, 0], - c2: [-45, 45], - vincentyDistance: 6662472.718217184 - }, - { - c1: [0, 0], - c2: [180, 90], - vincentyDistance: 10001965.729311794 - }, - { - c1: [0, 0], - c2: [180, -90], - vincentyDistance: 10001965.729311794 - }, - { - c1: [0, 0], - c2: [-180, 90], - vincentyDistance: 10001965.729311794 - }, - { - c1: [0, 0], - c2: [-180, 90], - vincentyDistance: 10001965.729311794 - }, - { - c1: [45, 45], - c2: [45, 45], - vincentyDistance: 0 - }, - { - c1: [45, 45], - c2: [45, -45], - vincentyDistance: 9969888.755957305 - }, - { - c1: [45, 45], - c2: [-45, -45], - vincentyDistance: 13324945.436434371 - }, - { - c1: [45, 45], - c2: [-45, 45], - vincentyDistance: 6690232.932559058 - }, - { - c1: [45, 45], - c2: [180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [45, 45], - c2: [180, -90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [45, 45], - c2: [-180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [45, 45], - c2: [-180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [45, -45], - c2: [45, -45], - vincentyDistance: 0 - }, - { - c1: [45, -45], - c2: [-45, -45], - vincentyDistance: 6690232.932559058 - }, - { - c1: [45, -45], - c2: [-45, 45], - vincentyDistance: 13324945.436434371 - }, - { - c1: [45, -45], - c2: [180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [45, -45], - c2: [180, -90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [45, -45], - c2: [-180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [45, -45], - c2: [-180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [-45, -45], - c2: [-45, -45], - vincentyDistance: 0 - }, - { - c1: [-45, -45], - c2: [-45, 45], - vincentyDistance: 9969888.755957305 - }, - { - c1: [-45, -45], - c2: [180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [-45, -45], - c2: [180, -90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [-45, -45], - c2: [-180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [-45, -45], - c2: [-180, 90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [-45, 45], - c2: [-45, 45], - vincentyDistance: 0 - }, - { - c1: [-45, 45], - c2: [180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [-45, 45], - c2: [180, -90], - vincentyDistance: 14986910.107290443 - }, - { - c1: [-45, 45], - c2: [-180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [-45, 45], - c2: [-180, 90], - vincentyDistance: 5017021.35133314 - }, - { - c1: [180, 90], - c2: [180, 90], - vincentyDistance: 0 - }, - { - c1: [180, -90], - c2: [180, -90], - vincentyDistance: 0 - }, - { - c1: [-180, 90], - c2: [-180, 90], - vincentyDistance: 0 - }, - { - c1: [-180, 90], - c2: [-180, 90], - vincentyDistance: 0 - }, - { - c1: [-180, 90], - c2: [-180, 90], - vincentyDistance: 0 - } - ]; - - describe('vincenty', function() { - - it('returns the same distances as Chris Veness\'s reference implementation', - function() { - var e, i, v; - for (i = 0; i < expected.length; ++i) { - e = expected[i]; - v = ol.ellipsoid.WGS84.vincenty(e.c1, e.c2, 1e-12, 100); - expect(v.distance).to.roughlyEqual(e.vincentyDistance, 1e-8); - } - }); - - }); - -}); - - -goog.require('ol.Ellipsoid'); -goog.require('ol.ellipsoid.WGS84'); From d09506f5b1150900dc568a48f4ef9fd167023e35 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:17:14 -0600 Subject: [PATCH 14/15] Remove unused ol.ellipsoid.WGS84 --- src/ol/ellipsoid/wgs84ellipsoid.js | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/ol/ellipsoid/wgs84ellipsoid.js diff --git a/src/ol/ellipsoid/wgs84ellipsoid.js b/src/ol/ellipsoid/wgs84ellipsoid.js deleted file mode 100644 index e5244b80d7..0000000000 --- a/src/ol/ellipsoid/wgs84ellipsoid.js +++ /dev/null @@ -1,10 +0,0 @@ -goog.provide('ol.ellipsoid.WGS84'); - -goog.require('ol.Ellipsoid'); - - -/** - * @const - * @type {ol.Ellipsoid} - */ -ol.ellipsoid.WGS84 = new ol.Ellipsoid(6378137, 1 / 298.257223563); From 980dbc121a931d32e5cc918d74045ce76f63737c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 23 Aug 2015 12:18:45 -0600 Subject: [PATCH 15/15] Remove unused ol.Ellipsoid --- src/ol/ellipsoid/ellipsoid.js | 42 ----------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/ol/ellipsoid/ellipsoid.js diff --git a/src/ol/ellipsoid/ellipsoid.js b/src/ol/ellipsoid/ellipsoid.js deleted file mode 100644 index ad266f644c..0000000000 --- a/src/ol/ellipsoid/ellipsoid.js +++ /dev/null @@ -1,42 +0,0 @@ -goog.provide('ol.Ellipsoid'); - - - -/** - * @constructor - * @param {number} a Major radius. - * @param {number} flattening Flattening. - */ -ol.Ellipsoid = function(a, flattening) { - - /** - * @const - * @type {number} - */ - this.a = a; - - /** - * @const - * @type {number} - */ - this.flattening = flattening; - - /** - * @const - * @type {number} - */ - this.b = this.a * (1 - this.flattening); - - /** - * @const - * @type {number} - */ - this.eSquared = 2 * flattening - flattening * flattening; - - /** - * @const - * @type {number} - */ - this.e = Math.sqrt(this.eSquared); - -};