Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Point
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
6.17
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCoordinates
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCoordinate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCoordinate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isEquals
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Algorithm\Clustering
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Algorithm\Clustering;
16
17/**
18 * Point for clustering
19 *
20 * @package phpOMS\Algorithm\Clustering
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25class Point implements PointInterface
26{
27    /**
28     * Coordinates of the point
29     *
30     * @var array<int, int|float>
31     * @sicne 1.0.0
32     */
33    public array $coordinates = [];
34
35    /**
36     * Group or cluster this point belongs to
37     *
38     * @var int
39     * @since 1.0.0
40     */
41    public int $group = 0;
42
43    /**
44     * Name of the point
45     *
46     * @var string
47     * @since 1.0.0
48     */
49    public string $name = '';
50
51    /**
52     * Constructor.
53     *
54     * @param array<int, int|float> $coordinates Coordinates of the point
55     * @param string                $name        Name of the point
56     *
57     * @since 1.0.0
58     */
59    public function __construct(array $coordinates, string $name = '')
60    {
61        $this->coordinates = $coordinates;
62        $this->name        = $name;
63    }
64
65    /**
66     * {@inheritdoc}
67     */
68    public function getCoordinates() : array
69    {
70        return $this->coordinates;
71    }
72
73    /**
74     * {@inheritdoc}
75     */
76    public function getCoordinate(int $index) : int | float
77    {
78        return $this->coordinates[$index];
79    }
80
81    /**
82     * {@inheritdoc}
83     */
84    public function setCoordinate(int $index, int | float $value) : void
85    {
86        $this->coordinates[$index] = $value;
87    }
88
89    /**
90     * {@inheritdoc}
91     */
92    public function isEquals(PointInterface $point) : bool
93    {
94        return $this->name === $point->name && $this->coordinates === $point->coordinates;
95    }
96}