Skip to content

Commit

Permalink
#66 Truncate, don't round
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Aug 15, 2024
1 parent 25938ac commit 37af97c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/Point/BritishNationalGridPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function strlen;
use function strpos;
use function substr;
use function round;

use const STR_PAD_LEFT;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/Point/IrishGridPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function strlen;
use function strpos;
use function substr;
use function round;

use const STR_PAD_LEFT;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 37af97c

Please sign in to comment.