Passed
Push — 4.x ( f9780c...a64886 )
by Doug
05:20
created

VerticalPoint::changeOfVerticalUnit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

116
        /** @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...
117
    ) {
118
        // units are auto-converted, don't need to use the supplied param
119 1
        return static::create($this->height, $to, $this->epoch);
120
    }
121
}
122