Passed
Push — master ( 9abb61...fb6dbd )
by Doug
08:29
created

VerticalPoint::getHeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord;
10
11
use function abs;
12
use DateTime;
13
use DateTimeImmutable;
14
use DateTimeInterface;
15
use PHPCoord\CoordinateReferenceSystem\Vertical;
16
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException;
17
use PHPCoord\UnitOfMeasure\Length\Length;
18
use PHPCoord\UnitOfMeasure\Length\Metre;
19
use PHPCoord\UnitOfMeasure\Scale\Scale;
20
21
/**
22
 * Coordinate representing a vertical dimension.
23
 */
24
class VerticalPoint extends Point
25
{
26
    /**
27
     * Height.
28
     */
29
    protected Length $height;
30
31
    /**
32
     * Coordinate reference system.
33
     */
34
    protected Vertical $crs;
35
36
    /**
37
     * Coordinate epoch (date for which the specified coordinates represented this point).
38
     */
39
    protected ?DateTimeImmutable $epoch;
40
41
    /**
42
     * Constructor.
43
     * @param Length $height refer to CRS for preferred unit of measure, but any length unit accepted
44
     */
45 16
    protected function __construct(Length $height, Vertical $crs, ?DateTimeInterface $epoch = null)
46
    {
47 16
        $this->height = Length::convert($height, $crs->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId());
48 16
        $this->crs = $crs;
49
50 16
        if ($epoch instanceof DateTime) {
51 1
            $epoch = DateTimeImmutable::createFromMutable($epoch);
52
        }
53 16
        $this->epoch = $epoch;
54 16
    }
55
56
    /**
57
     * Constructor.
58
     * @param Length $height refer to CRS for preferred unit of measure, but any length unit accepted
59
     */
60 16
    public static function create(Length $height, Vertical $crs, ?DateTimeInterface $epoch = null): self
61
    {
62 16
        return new static($height, $crs, $epoch);
63
    }
64
65 12
    public function getHeight(): Length
66
    {
67 12
        return $this->height;
68
    }
69
70 5
    public function getCRS(): Vertical
71
    {
72 5
        return $this->crs;
73
    }
74
75 3
    public function getCoordinateEpoch(): ?DateTimeImmutable
76
    {
77 3
        return $this->epoch;
78
    }
79
80 1
    public function calculateDistance(Point $to): Length
81
    {
82 1
        if ($to->getCRS()->getSRID() !== $this->crs->getSRID()) {
83
            throw new InvalidCoordinateReferenceSystemException('Can only calculate distances between two points in the same CRS');
84
        }
85
86
        /* @var self $to */
87 1
        return new Metre(abs($this->height->asMetres()->getValue() - $to->height->asMetres()->getValue()));
88
    }
89
90 6
    public function __toString(): string
91
    {
92 6
        return "({$this->height})";
93
    }
94
95
    /**
96
     * Vertical Offset
97
     * This transformation allows calculation of height (or depth) in the target system by adding the parameter value
98
     * to the height (or depth)-value of the point in the source system.
99
     */
100 1
    public function verticalOffset(
101
        Vertical $to,
102
        Length $verticalOffset
103
    ): self {
104 1
        return static::create($this->height->add($verticalOffset), $to);
105
    }
106
107
    /**
108
     * Height Depth Reversal.
109
     */
110 1
    public function heightDepthReversal(
111
        Vertical $to
112
    ): self {
113 1
        return static::create($this->height->multiply(-1), $to);
114
    }
115
116
    /**
117
     * Change of Vertical Unit.
118
     */
119 1
    public function changeOfVerticalUnit(
120
        Vertical $to,
121
        Scale $unitConversionScalar
0 ignored issues
show
Unused Code introduced by
The parameter $unitConversionScalar is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

121
        /** @scrutinizer ignore-unused */ Scale $unitConversionScalar

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
    ) {
123
        // units are auto-converted, don't need to use the supplied param
124 1
        return static::create($this->height, $to, $this->epoch);
125
    }
126
}
127