|
2 | 2 |
|
3 | 3 | namespace Kmeans\Gps; |
4 | 4 |
|
5 | | -use Kmeans\Euclidean\Point as BasePoint; |
| 5 | +use Kmeans\Concerns\HasDataTrait; |
| 6 | +use Kmeans\Concerns\HasSpaceTrait; |
| 7 | +use Kmeans\Interfaces\PointInterface; |
6 | 8 |
|
7 | 9 | /** |
8 | 10 | * @method array{0: float, 1: float} getCoordinates() |
9 | 11 | */ |
10 | | -class Point extends BasePoint |
| 12 | +class Point implements PointInterface |
11 | 13 | { |
12 | | - /** |
13 | | - * @param array<float> $coordinates |
14 | | - */ |
15 | | - public function __construct(array $coordinates) |
16 | | - { |
17 | | - $this->validateCoordinates($coordinates); |
| 14 | + use HasDataTrait; |
| 15 | + use HasSpaceTrait; |
| 16 | + |
| 17 | + private float $lat; |
18 | 18 |
|
19 | | - parent::__construct(new Space(), $coordinates); |
| 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; |
20 | 27 | } |
21 | 28 |
|
22 | 29 | /** |
23 | | - * @param array<float> $coordinates |
| 30 | + * @return array{0: float, 1: float} |
24 | 31 | */ |
25 | | - private function validateCoordinates(array $coordinates): void |
| 32 | + public function getCoordinates(): array |
26 | 33 | { |
27 | | - if (count($coordinates) != 2) { |
28 | | - throw new \InvalidArgumentException( |
29 | | - "Invalid GPS coordinates" |
30 | | - ); |
31 | | - } |
32 | | - |
33 | | - list($lat, $long) = $coordinates; |
| 34 | + return [$this->lat, $this->long]; |
| 35 | + } |
34 | 36 |
|
| 37 | + private function validateCoordinates(float $lat, float $long): void |
| 38 | + { |
35 | 39 | if ($lat < -90 || $lat > 90 || $long < -180 || $long > 180) { |
36 | 40 | throw new \InvalidArgumentException( |
37 | 41 | "Invalid GPS coordinates" |
|
0 commit comments