Total Complexity | 9 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class Cluster implements ClusterInterface |
||
11 | { |
||
12 | private PointInterface $centroid; |
||
13 | private PointCollectionInterface $points; |
||
14 | |||
15 | public function __construct(PointInterface $centroid, PointCollectionInterface $points = null) |
||
16 | { |
||
17 | $this->points = $points ?? new PointCollection($centroid->getSpace()); |
||
18 | $this->setCentroid($centroid); |
||
19 | } |
||
20 | |||
21 | public function getSpace(): SpaceInterface |
||
22 | { |
||
23 | return $this->points->getSpace(); |
||
24 | } |
||
25 | |||
26 | public function belongsTo(SpaceInterface $space): bool |
||
27 | { |
||
28 | return $this->getSpace()->isEqualTo($space); |
||
29 | } |
||
30 | |||
31 | public function getCentroid(): PointInterface |
||
32 | { |
||
33 | return $this->centroid; |
||
34 | } |
||
35 | |||
36 | public function setCentroid(PointInterface $point): void |
||
37 | { |
||
38 | if (! $point->belongsTo($this->getSpace())) { |
||
39 | throw new \LogicException("Cannot set centroid: invalid point space"); |
||
40 | } |
||
41 | |||
42 | $this->centroid = $point; |
||
43 | } |
||
44 | |||
45 | public function getPoints(): PointCollectionInterface |
||
48 | } |
||
49 | |||
50 | public function attach(PointInterface $point): void |
||
53 | } |
||
54 | |||
55 | public function detach(PointInterface $point): void |
||
56 | { |
||
58 | } |
||
59 | } |
||
60 |