Skip to content

Commit 37af97c

Browse files
committed
#66 Truncate, don't round
1 parent 25938ac commit 37af97c

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- Updates to data for USA and WGS84
88
- Support for Irish polynomial transformation in the ETRS89 to TM75 direction (TM75 to ETRS89 was already supported)
99

10+
### Fixed
11+
- British and Irish Grid references were rounding rather than truncating causing a sometimes off-by-1 error
12+
1013
## [5.9.0] - 2024-08-04
1114
### Changed
1215
- Updates to data for Czechia, Denmark, ETRS89, Germany, Martinique, Portugal, St Helena, UK and WGS84

src/Point/BritishNationalGridPoint.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use function strlen;
2222
use function strpos;
2323
use function substr;
24-
use function round;
2524

2625
use const STR_PAD_LEFT;
2726

@@ -97,8 +96,8 @@ protected function gridReference(int $length): array
9796

9897
$x = $this->easting->asMetres()->getValue();
9998
$y = $this->northing->asMetres()->getValue();
100-
$easting = str_pad((string) round($x), $halfLength, '0', STR_PAD_LEFT);
101-
$northing = str_pad((string) round($y), $halfLength, '0', STR_PAD_LEFT);
99+
$easting = str_pad((string) (int) $x, $halfLength, '0', STR_PAD_LEFT);
100+
$northing = str_pad((string) (int) $y, $halfLength, '0', STR_PAD_LEFT);
102101

103102
$adjustedX = $x + 1000000;
104103
$adjustedY = $y + 500000;

src/Point/IrishGridPoint.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use function strlen;
2222
use function strpos;
2323
use function substr;
24-
use function round;
2524

2625
use const STR_PAD_LEFT;
2726

@@ -96,8 +95,8 @@ protected function gridReference(int $length): array
9695

9796
$x = $this->easting->asMetres()->getValue();
9897
$y = $this->northing->asMetres()->getValue();
99-
$easting = str_pad((string) round($x), $halfLength, '0', STR_PAD_LEFT);
100-
$northing = str_pad((string) round($y), $halfLength, '0', STR_PAD_LEFT);
98+
$easting = str_pad((string) (int) $x, $halfLength, '0', STR_PAD_LEFT);
99+
$northing = str_pad((string) (int) $y, $halfLength, '0', STR_PAD_LEFT);
101100

102101
// second (minor) letter is 100km grid sq, origin at 0,0 of this square
103102
$minorSquaresEast = (int) $easting[0] % 5;

0 commit comments

Comments
 (0)