MercatorProjection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 2
b 0
f 0
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMaxX() 0 3 1
A getMaxLatitude() 0 3 1
A getX() 0 3 1
A getMaxY() 0 3 1
A getY() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrinsFrank\PhpGeoSVG\Projection;
6
7
use PrinsFrank\PhpGeoSVG\Geometry\Position\Position;
8
9
class MercatorProjection implements Projection
10
{
11 1
    public function getX(Position $position): float
12
    {
13 1
        return ($position->longitude + 180) * (Position::TOTAL_LONGITUDE * .5 / 360);
14
    }
15
16 1
    public function getY(Position $position): float
17
    {
18 1
        $latitude = $position->latitude;
19 1
        if ($latitude > $this->getMaxLatitude() - 0.001) {
20 1
            $latitude = $this->getMaxLatitude() - 0.001;
21
        }
22
23 1
        if ($latitude < (-$this->getMaxLatitude()) + 0.001) {
24 1
            $latitude = (-$this->getMaxLatitude()) + 0.001;
25
        }
26
27 1
        return (Position::TOTAL_LATITUDE / 2) - (Position::TOTAL_LONGITUDE * .5 * log(tan((M_PI / 4) + (($latitude*M_PI / 180) / 2))) / (2 * M_PI));
28
    }
29
30 1
    public function getMaxX(): float
31
    {
32 1
        return Position::TOTAL_LONGITUDE * .5;
33
    }
34
35 1
    public function getMaxY(): float
36
    {
37 1
        return Position::TOTAL_LATITUDE;
38
    }
39
40 1
    public function getMaxLatitude(): float
41
    {
42 1
        return 85;
43
    }
44
}
45