use Samsara\Exceptions\UsageError\IntegrityConstraint;
6
use Samsara\Fermat\Numbers;
7
use Samsara\Fermat\Types\Tuple;
8
use Samsara\Fermat\Values\Base\CoordinateInterface;
9
10
class CartesianCoordinate extends Tuple implements CoordinateInterface
11
{
12
13
public function distanceTo(CoordinateInterface $coordinate): ImmutableNumber
14
{
15
if (!($coordinate instanceof CartesianCoordinate)) {
16
throw new IntegrityConstraint(
17
'Must be the same coordinate system',
18
'Only attempt to get distance between coordinates that use the same coordinate system',
19
'Distance cannot be calculated between coordinates that use different coordinate systems because the properties necessary to convert them cannot be assumed'
20
);
21
}
22
23
if ($this->size() != $coordinate->size()) {
24
throw new IntegrityConstraint(
25
'Must have same dimensionality',
26
'Check dimensionality of both coordinates before getting distance',
27
'Coordinates must share the same number of axes in order for a distance to be calculated'