From 2001244b88623e99ec25ac75d57cdc66b7048362 Mon Sep 17 00:00:00 2001 From: "alfred.jackson" Date: Fri, 27 Jan 2017 14:43:41 -0600 Subject: [PATCH 1/4] fixed the degreesToStringHDMS_() function to promote a seconds value of 60 up to the next minute --- src/ol/coordinate.js | 23 +++++++++++++++++++---- test/spec/ol/coordinate.test.js | 6 +++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ol/coordinate.js b/src/ol/coordinate.js index c683fda00a..0b3bd07916 100644 --- a/src/ol/coordinate.js +++ b/src/ol/coordinate.js @@ -112,10 +112,25 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres, opt_fraction var normalizedDegrees = ol.math.modulo(degrees + 180, 360) - 180; var x = Math.abs(3600 * normalizedDegrees); var dflPrecision = opt_fractionDigits || 0; - return Math.floor(x / 3600) + '\u00b0 ' + - ol.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' + - ol.string.padNumber((x % 60), 2, dflPrecision) + '\u2033 ' + - hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); + + var deg = Math.floor(x / 3600); + var min = Math.floor((x / 60) % 60); + var precision = Math.pow(10, dflPrecision); + var sec = Math.ceil((x * precision) % 60) / precision; + + if (60 === sec) { + sec = 0; + min += 1; + } + + if (min >= 60) { + min -= 60; + deg = deg >= 0 ? deg + 1 : deg - 1; + } + + return deg + '\u00b0 ' + ol.string.padNumber(min, 2) + '\u2032 ' + + ol.string.padNumber(sec, 2, dflPrecision) + '\u2033 ' + + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); }; diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index 215e3ee5d8..0627866cd0 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -206,13 +206,13 @@ describe('ol.coordinate', function() { it('formats with zero fractional digits as default', function() { var coord = [7.85, 47.983333]; var got = ol.coordinate.toStringHDMS(coord); - var expected = '47° 58′ 60″ N 7° 50′ 60″ E'; + var expected = '47° 59′ 00″ N 7° 51′ 00″ E'; expect(got).to.be(expected); }); it('formats with given fractional digits, if passed', function() { - var coord = [7.85, 47.983333]; + var coord = [7.85, 47.983201]; var got = ol.coordinate.toStringHDMS(coord, 3); - var expected = '47° 58′ 59.999″ N 7° 50′ 60.000″ E'; + var expected = '47° 58′ 59.524″ N 7° 51′ 0.000″ E'; expect(got).to.be(expected); }); }); From eebcccab66c4307e8c5163e164759c863634dc4f Mon Sep 17 00:00:00 2001 From: "alfred.jackson" Date: Fri, 27 Jan 2017 17:32:21 -0600 Subject: [PATCH 2/4] fixed the degreesToStringHDMS_() function to promote a seconds value of 60 up to the next minute; fixed calculation of components --- src/ol/coordinate.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ol/coordinate.js b/src/ol/coordinate.js index 0b3bd07916..223b5fd306 100644 --- a/src/ol/coordinate.js +++ b/src/ol/coordinate.js @@ -112,20 +112,21 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres, opt_fraction var normalizedDegrees = ol.math.modulo(degrees + 180, 360) - 180; var x = Math.abs(3600 * normalizedDegrees); var dflPrecision = opt_fractionDigits || 0; + var precision = Math.pow(10, dflPrecision); var deg = Math.floor(x / 3600); - var min = Math.floor((x / 60) % 60); - var precision = Math.pow(10, dflPrecision); - var sec = Math.ceil((x * precision) % 60) / precision; + var min = Math.floor((x - deg * 3600) / 60); + var sec = x - (deg * 3600) - (min * 60); + sec = Math.ceil(sec * precision) / precision; - if (60 === sec) { + if (sec >= 60) { sec = 0; min += 1; } if (min >= 60) { - min -= 60; - deg = deg >= 0 ? deg + 1 : deg - 1; + min = 0; + deg += 1; } return deg + '\u00b0 ' + ol.string.padNumber(min, 2) + '\u2032 ' + From 419c3752d23be086c0c3f6328fb2520dac8a3a19 Mon Sep 17 00:00:00 2001 From: "alfred.jackson" Date: Fri, 27 Jan 2017 17:48:02 -0600 Subject: [PATCH 3/4] fixed the degreesToStringHDMS_() function to promote a seconds value of 60 up to the next minute; fixed test to account for the padding for minutes and seconds --- test/spec/ol/coordinate.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index 0627866cd0..de2fe25236 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -212,7 +212,7 @@ describe('ol.coordinate', function() { it('formats with given fractional digits, if passed', function() { var coord = [7.85, 47.983201]; var got = ol.coordinate.toStringHDMS(coord, 3); - var expected = '47° 58′ 59.524″ N 7° 51′ 0.000″ E'; + var expected = '47° 58′ 59.524″ N 7° 51′ 00.000″ E'; expect(got).to.be(expected); }); }); From da10988ffd581ac88b62a5e16903ca9b136ae6e8 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sat, 28 Jan 2017 16:08:23 +0100 Subject: [PATCH 4/4] Restore test values --- test/spec/ol/coordinate.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index de2fe25236..526ab837c4 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -210,9 +210,9 @@ describe('ol.coordinate', function() { expect(got).to.be(expected); }); it('formats with given fractional digits, if passed', function() { - var coord = [7.85, 47.983201]; + var coord = [7.85, 47.983333]; var got = ol.coordinate.toStringHDMS(coord, 3); - var expected = '47° 58′ 59.524″ N 7° 51′ 00.000″ E'; + var expected = '47° 58′ 59.999″ N 7° 51′ 00.000″ E'; expect(got).to.be(expected); }); });