diff --git a/CHANGELOG.md b/CHANGELOG.md index cfb53eac..2e875d33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - Updates to data for USA and WGS84 - Support for Irish polynomial transformation in the ETRS89 to TM75 direction (TM75 to ETRS89 was already supported) +### Fixed +- British and Irish Grid references were rounding rather than truncating causing a sometimes off-by-1 error + ## [5.9.0] - 2024-08-04 ### Changed - Updates to data for Czechia, Denmark, ETRS89, Germany, Martinique, Portugal, St Helena, UK and WGS84 diff --git a/src/Point/BritishNationalGridPoint.php b/src/Point/BritishNationalGridPoint.php index bcb3552f..0af77b35 100644 --- a/src/Point/BritishNationalGridPoint.php +++ b/src/Point/BritishNationalGridPoint.php @@ -21,7 +21,6 @@ use function strlen; use function strpos; use function substr; -use function round; use const STR_PAD_LEFT; @@ -97,8 +96,8 @@ protected function gridReference(int $length): array $x = $this->easting->asMetres()->getValue(); $y = $this->northing->asMetres()->getValue(); - $easting = str_pad((string) round($x), $halfLength, '0', STR_PAD_LEFT); - $northing = str_pad((string) round($y), $halfLength, '0', STR_PAD_LEFT); + $easting = str_pad((string) (int) $x, $halfLength, '0', STR_PAD_LEFT); + $northing = str_pad((string) (int) $y, $halfLength, '0', STR_PAD_LEFT); $adjustedX = $x + 1000000; $adjustedY = $y + 500000; diff --git a/src/Point/IrishGridPoint.php b/src/Point/IrishGridPoint.php index d9208cec..fc70d8d8 100644 --- a/src/Point/IrishGridPoint.php +++ b/src/Point/IrishGridPoint.php @@ -21,7 +21,6 @@ use function strlen; use function strpos; use function substr; -use function round; use const STR_PAD_LEFT; @@ -96,8 +95,8 @@ protected function gridReference(int $length): array $x = $this->easting->asMetres()->getValue(); $y = $this->northing->asMetres()->getValue(); - $easting = str_pad((string) round($x), $halfLength, '0', STR_PAD_LEFT); - $northing = str_pad((string) round($y), $halfLength, '0', STR_PAD_LEFT); + $easting = str_pad((string) (int) $x, $halfLength, '0', STR_PAD_LEFT); + $northing = str_pad((string) (int) $y, $halfLength, '0', STR_PAD_LEFT); // second (minor) letter is 100km grid sq, origin at 0,0 of this square $minorSquaresEast = (int) $easting[0] % 5;