Passed
Push — master ( 0a16ff...1038d1 )
by Doug
28:57
created

OSGM15IrelandGrid::getRecord()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 10
ccs 6
cts 6
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\CoordinateOperation;
10
11
use function explode;
12
13
use PHPCoord\UnitOfMeasure\Length\Metre;
14
15
use function preg_replace;
16
use function preg_split;
17
18
use SplFileObject;
19
use SplFixedArray;
20
21
use function trim;
22
23
class OSGM15IrelandGrid extends GeographicGeoidHeightGrid
24
{
25
    use BilinearInterpolation;
26
27
    private SplFixedArray $textData;
28
29 1
    public function __construct($filename)
30
    {
31 1
        $this->gridFile = new SplFileObject($filename);
32 1
        $this->storageOrder = self::STORAGE_ORDER_INCREASING_LONGITUDE_DECREASING_LATIITUDE;
33
34 1
        $header = preg_split('/\s+/', trim($this->gridFile->fgets()));
35
36 1
        $this->startX = (float) $header[2];
37 1
        $this->startY = (float) $header[0];
38 1
        $this->endX = (float) $header[3];
39 1
        $this->endY = (float) $header[1];
40 1
        $this->columnGridInterval = (float) $header[5];
41 1
        $this->rowGridInterval = (float) $header[4];
42 1
        $this->numberOfColumns = (int) (string) (($this->endX - $this->startX) / $this->columnGridInterval) + 1;
43 1
        $this->numberOfRows = (int) (string) (($this->endY - $this->startY) / $this->rowGridInterval) + 1;
44
45 1
        $this->textData = new SplFixedArray($this->numberOfColumns * $this->numberOfRows);
46 1
        $index = 0;
47 1
        while (!$this->gridFile->eof()) {
48 1
            $rawData = trim($this->gridFile->fgets());
49 1
            if ($rawData) {
50 1
                $values = explode(' ', trim(preg_replace('/\s+/', ' ', $rawData)));
51 1
                foreach ($values as $value) {
52 1
                    $this->textData[$index] = (float) $value;
53 1
                    ++$index;
54
                }
55
            }
56
        }
57
    }
58
59
    /**
60
     * @return Metre[]
61
     */
62 1
    public function getValues($x, $y): array
63
    {
64 1
        $shift = $this->interpolate($x, $y)[0];
65
66 1
        return [new Metre($shift)];
67
    }
68
69 1
    private function getRecord(int $longitudeIndex, int $latitudeIndex): GridValues
0 ignored issues
show
Unused Code introduced by
The method getRecord() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
70
    {
71 1
        $recordId = ($this->numberOfRows - $latitudeIndex - 1) * $this->numberOfColumns + $longitudeIndex;
72 1
        $longitude = $longitudeIndex * $this->columnGridInterval + $this->startX;
73 1
        $latitude = $latitudeIndex * $this->rowGridInterval + $this->startY;
74
75 1
        return new GridValues(
76
            $longitude,
77
            $latitude,
78 1
            [$this->textData[$recordId]]
79
        );
80
    }
81
}
82