Coordinator::getWidth()   A
last analyzed

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 0
Metric Value
eloc 1
c 0
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
declare(strict_types=1);
4
5
namespace PrinsFrank\PhpGeoSVG\Coordinator;
6
7
use PrinsFrank\PhpGeoSVG\Geometry\BoundingBox\BoundingBox;
8
use PrinsFrank\PhpGeoSVG\Geometry\Position\Position;
9
use PrinsFrank\PhpGeoSVG\Projection\Projection;
10
use PrinsFrank\PhpGeoSVG\Scale\Scale;
11
12
class Coordinator
13
{
14
    public const BASE_SCALE_FACTOR = 2;
15
16 4
    public function __construct(private Projection $projection, private BoundingBox $boundingBox, private Scale $scale)
17
    {
18
    }
19
20 1
    public function getWidth(): float
21
    {
22 1
        return ($this->boundingBox->getWidth() / Position::TOTAL_LONGITUDE * $this->projection->getMaxX()) * $this->scale->getFactorX() * self::BASE_SCALE_FACTOR;
23
    }
24
25 1
    public function getHeight(): float
26
    {
27 1
        return ($this->boundingBox->getHeight() / Position::TOTAL_LATITUDE * $this->projection->getMaxY()) * $this->scale->getFactorY() * self::BASE_SCALE_FACTOR;
28
    }
29
30 1
    public function getX(Position $position): float
31
    {
32 1
        return $this->boundingBox->boundX($position, $this->projection) * $this->scale->getFactorX() * self::BASE_SCALE_FACTOR;
33
    }
34
35 1
    public function getY(Position $position): float
36
    {
37 1
        return $this->boundingBox->boundY($position, $this->projection) * $this->scale->getFactorY() * self::BASE_SCALE_FACTOR;
38
    }
39
}
40