Passed
Push — master ( fd93b5...48e916 )
by Doug
40:26 queued 29:39
created

GeographicGrid   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 31
ccs 17
cts 18
cp 0.9444
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyReverseAdjustment() 0 16 5
A applyForwardAdjustment() 0 9 3
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateOperation;
10
11
use function abs;
12
use PHPCoord\CoordinateReferenceSystem\Geographic;
13
use PHPCoord\GeographicPoint;
14
use PHPCoord\UnitOfMeasure\Angle\ArcSecond;
15
16
abstract class GeographicGrid extends Grid
17
{
18
    protected const ITERATION_CONVERGENCE = 0.0001;
19
20 7
    public function applyForwardAdjustment(GeographicPoint $point, Geographic $to): GeographicPoint
21
    {
22 7
        $shifts = $this->getValues($point->getLongitude()->getValue(), $point->getLatitude()->getValue());
23
24 7
        $latitude = $point->getLatitude()->add($shifts[0]);
25 7
        $longitude = $point->getLongitude()->add($shifts[1]);
26 7
        $height = $point->getHeight() && $shifts[2] ? $point->getHeight()->add($shifts[2]) : null;
27
28 7
        return GeographicPoint::create($latitude, $longitude, $height, $to, $point->getCoordinateEpoch());
29
    }
30
31 5
    public function applyReverseAdjustment(GeographicPoint $point, Geographic $to): GeographicPoint
32
    {
33 5
        $shifts = [new ArcSecond(0), new ArcSecond(0)];
34 5
        $latitude = $point->getLatitude();
35 5
        $longitude = $point->getLongitude();
36
37
        do {
38 5
            $prevShifts = $shifts;
39 5
            $shifts = $this->getValues($longitude->getValue(), $latitude->getValue());
40 5
            $latitude = $point->getLatitude()->subtract($shifts[0]);
41 5
            $longitude = $point->getLongitude()->subtract($shifts[1]);
42 5
        } while (abs($shifts[0]->subtract($prevShifts[0])->getValue()) > self::ITERATION_CONVERGENCE && abs($shifts[1]->subtract($prevShifts[1])->getValue()) > self::ITERATION_CONVERGENCE);
43
44 5
        $height = $point->getHeight() && $shifts[2] ? $point->getHeight()->subtract($shifts[2]) : null;
45
46 5
        return GeographicPoint::create($latitude, $longitude, $height, $to, $point->getCoordinateEpoch());
47
    }
48
}
49