bdelespierre /
php-kmeans
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Kmeans\Gps; |
||
| 4 | |||
| 5 | use Kmeans\Concerns\HasDataTrait; |
||
| 6 | use Kmeans\Concerns\HasSpaceTrait; |
||
| 7 | use Kmeans\Interfaces\PointInterface; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @method array{0: float, 1: float} getCoordinates() |
||
| 11 | */ |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 12 | class Point implements PointInterface |
||
| 13 | { |
||
| 14 | use HasDataTrait; |
||
| 15 | use HasSpaceTrait; |
||
| 16 | |||
| 17 | private float $lat; |
||
| 18 | |||
| 19 | private float $long; |
||
| 20 | |||
| 21 | public function __construct(float $lat, float $long) |
||
| 22 | { |
||
| 23 | $this->validateCoordinates($lat, $long); |
||
| 24 | $this->setSpace(Space::singleton()); |
||
| 25 | $this->lat = $lat; |
||
| 26 | $this->long = $long; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return array{0: float, 1: float} |
||
| 31 | */ |
||
| 32 | public function getCoordinates(): array |
||
| 33 | { |
||
| 34 | return [$this->lat, $this->long]; |
||
| 35 | } |
||
| 36 | |||
| 37 | private function validateCoordinates(float $lat, float $long): void |
||
| 38 | { |
||
| 39 | if ($lat < -90 || $lat > 90 || $long < -180 || $long > 180) { |
||
| 40 | throw new \InvalidArgumentException( |
||
| 41 | "Invalid GPS coordinates" |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |