Passed
Push — 4.x ( 739b15...17e0c5 )
by Doug
04:36 queued 02:58
created

VerticalPoint::calculateDistance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
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 PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem;
12
use PHPCoord\CoordinateReferenceSystem\Vertical;
13
use PHPCoord\UnitOfMeasure\Length\Length;
14
use PHPCoord\UnitOfMeasure\Length\Metre;
15
use PHPCoord\UnitOfMeasure\UnitOfMeasureFactory;
16
17
/**
18
 * Coordinate representing a vertical dimension.
19
 * @author Doug Wright
20
 */
21
class VerticalPoint extends Point
22
{
23
    /**
24
     * Height.
25
     * @var Length
26
     */
27
    protected $height;
28
29
    /**
30
     * Coordinate reference system.
31
     * @var CoordinateReferenceSystem
32
     */
33
    protected $crs;
34
35
    /**
36
     * Constructor.
37
     * @param Length $height refer to CRS for preferred unit of measure, but any length unit accepted
38
     */
39 3
    public function __construct(Length $height, Vertical $crs)
40
    {
41 3
        $this->height = UnitOfMeasureFactory::convertLength($height, $crs->getCoordinateSystem()->getAxes()[1]->getUnitOfMeasureId());
42 3
        $this->crs = $crs;
43 3
    }
44
45 2
    public function getHeight(): Length
46
    {
47 2
        return $this->height;
48
    }
49
50 1
    public function getCRS(): CoordinateReferenceSystem
51
    {
52 1
        return $this->crs;
53
    }
54
55 1
    public function calculateDistance(Point $to): Length
56
    {
57
        /* @var self $to */
58 1
        return new Metre(abs($this->height->asMetres()->getValue() - $to->height->asMetres()->getValue()));
59
    }
60
61 1
    public function __toString(): string
62
    {
63 1
        return "({$this->height})";
64
    }
65
}
66