From dc431ebc46e62ddd284e046a0b1a1d4a96998bbe Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 19 Aug 2024 22:20:41 +0200 Subject: [PATCH] Add RoundCoordinatesProjector --- CHANGELOG.md | 6 ++ src/Projector/RoundCoordinatesProjector.php | 35 ++++++++++++ .../RoundCoordinatesProjectorTest.php | 55 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/Projector/RoundCoordinatesProjector.php create mode 100644 tests/Projector/RoundCoordinatesProjectorTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index be0b384..09d806a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.11.1](https://github.com/brick/geo/releases/tag/0.11.1) - 2024-08-19 + +✨ **New features** + +- New projector: `RoundCoordinatesProjector` + ## [0.11.0](https://github.com/brick/geo/releases/tag/0.11.0) - 2024-06-07 💥 **Breaking changes** diff --git a/src/Projector/RoundCoordinatesProjector.php b/src/Projector/RoundCoordinatesProjector.php new file mode 100644 index 0000000..2351d55 --- /dev/null +++ b/src/Projector/RoundCoordinatesProjector.php @@ -0,0 +1,35 @@ + round($coord, $this->precision), + $point->toArray(), + ); + + return new Point($point->coordinateSystem(), ...$coords); + } + + public function getTargetCoordinateSystem(CoordinateSystem $sourceCoordinateSystem): CoordinateSystem + { + return $sourceCoordinateSystem; + } +} diff --git a/tests/Projector/RoundCoordinatesProjectorTest.php b/tests/Projector/RoundCoordinatesProjectorTest.php new file mode 100644 index 0000000..ef3b7b9 --- /dev/null +++ b/tests/Projector/RoundCoordinatesProjectorTest.php @@ -0,0 +1,55 @@ +project($point); + + $this->assertPointXYEquals($expectedX, $expectedY, $srid, $projected); + } + + public static function providerProject(): array + { + return [ + [1.234567, 2.345678, 1234, 0, 1, 2], + [1.234567, 2.345678, 2345, 1, 1.2, 2.3], + [1.234567, 2.345678, 3456, 2, 1.23, 2.35], + [1.234567, 2.345678, 4567, 3, 1.235, 2.346], + ]; + } + + #[DataProvider('providerGetTargetCoordinateSystem')] + public function testGetTargetCoordinateSystem(CoordinateSystem $sourceCoordinateSystem): void + { + $projector = new RoundCoordinatesProjector(2); + $targetCoordinateSystem = $projector->getTargetCoordinateSystem($sourceCoordinateSystem); + + $this->assertSame($sourceCoordinateSystem, $targetCoordinateSystem); + } + + public static function providerGetTargetCoordinateSystem(): array + { + return [ + [CoordinateSystem::xy(4326)], + [CoordinateSystem::xyz(2154)], + ]; + } +}