From e115d6c6aa99c6f9c925c16aa82bee489b82971c Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Mon, 1 Oct 2018 08:48:30 +0200 Subject: [PATCH 1/3] Add rounding test --- tests/Integration/Parser/CoordinatesTest.php | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Integration/Parser/CoordinatesTest.php b/tests/Integration/Parser/CoordinatesTest.php index c7a5a110d..21522267c 100644 --- a/tests/Integration/Parser/CoordinatesTest.php +++ b/tests/Integration/Parser/CoordinatesTest.php @@ -65,4 +65,32 @@ public function testGivenInvalidFormat_defaultFormatGetsUsed() { ); } + public function testRoundingWhenFormattingAsFloat() { + $this->assertContains( + '52.136944444444 N, 0.46672222222222 W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=float}}' ) + ); + } + + public function testRoundingWhenFormattingAsDMS() { + $this->assertContains( + '52° 8\' 13.00" N, 0° 28\' 0.20" W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dms}}' ) + ); + } + + public function testRoundingWhenFormattingAsDD() { + $this->assertContains( + '52.136944° N, 0.466722° W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dd}}' ) + ); + } + + public function testRoundingWhenFormattingAsDM() { + $this->assertContains( + '52° 8.2167\' N, 0° 28.0033\' W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dm}}' ) + ); + } + } \ No newline at end of file From 68580fc412547c80d5a65e9cd12af306e24735ab Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Mon, 1 Oct 2018 08:55:45 +0200 Subject: [PATCH 2/3] Use a sensible precision for float and DD coordinates Fixes https://github.com/JeroenDeDauw/Maps/issues/474 --- src/CoordinateFormatter.php | 9 ++++++++- tests/Integration/Parser/CoordinatesTest.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/CoordinateFormatter.php b/src/CoordinateFormatter.php index 47794d5c4..5e72754b5 100644 --- a/src/CoordinateFormatter.php +++ b/src/CoordinateFormatter.php @@ -14,12 +14,19 @@ */ class CoordinateFormatter { + private const PRECISION_MAP = [ + 'dms' => 1 / 360000, + 'dm' => 1 / 600000, + 'dd' => 1 / 1000000, + 'float' => 1 / 1000000, + ]; + public function format( LatLongValue $latLong, string $format, bool $directional ) { $formatter = new LatLongFormatter( new FormatterOptions( [ LatLongFormatter::OPT_FORMAT => $format, LatLongFormatter::OPT_DIRECTIONAL => $directional, - LatLongFormatter::OPT_PRECISION => 1 / 360000 + LatLongFormatter::OPT_PRECISION => self::PRECISION_MAP[$format] ] ) ); diff --git a/tests/Integration/Parser/CoordinatesTest.php b/tests/Integration/Parser/CoordinatesTest.php index 21522267c..4ec716303 100644 --- a/tests/Integration/Parser/CoordinatesTest.php +++ b/tests/Integration/Parser/CoordinatesTest.php @@ -67,7 +67,7 @@ public function testGivenInvalidFormat_defaultFormatGetsUsed() { public function testRoundingWhenFormattingAsFloat() { $this->assertContains( - '52.136944444444 N, 0.46672222222222 W', + '52.136945 N, 0.466722 W', $this->parse( '{{#coordinates:52.136945,-0.466722|format=float}}' ) ); } @@ -81,7 +81,7 @@ public function testRoundingWhenFormattingAsDMS() { public function testRoundingWhenFormattingAsDD() { $this->assertContains( - '52.136944° N, 0.466722° W', + '52.136945° N, 0.466722° W', $this->parse( '{{#coordinates:52.136945,-0.466722|format=dd}}' ) ); } From ef76b4addad3c7114f53a12a00e8edbc3283d0d9 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Mon, 1 Oct 2018 08:58:01 +0200 Subject: [PATCH 3/3] Update release notes --- RELEASE-NOTES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3d0451c44..c1f79f340 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -5,8 +5,9 @@ different releases and which versions of PHP and MediaWiki they support, see the ## Maps 6.0.2 -Under development +Released on October 1st, 2018. +* Coordinates formatted as Decimal Degrees or Float are now rounded sensibly * The `smgQPCoodDirectional` setting is no longer ignored ## Maps 6.0.1