Passed
Push — master ( 3e5121...8c57bf )
by Doug
27:00
created

BiquadraticInterpolation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A interpolateQuadratic() 0 9 2
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 assert;
12
13
trait BiquadraticInterpolation
14
{
15
    protected float $startX;
16
    protected float $endX;
17
    protected float $startY;
18
    protected float $endY;
19
    protected int $numberOfColumns;
20
    protected int $numberOfRows;
21
    protected float $columnGridInterval;
22
    protected float $rowGridInterval;
23
24
    /**
25
     * Quadratic interpolation at point p, where p is between 0 and 2.
26
     * Converted from NOAA FORTRAN implementation, this function apparently uses Newton-Gregory forward polynomial.
27
     */
28 7
    private function interpolateQuadratic(float $p, float $valueAt0, float $valueAt1, float $valueAt2): float
29
    {
30 7
        assert($p >= 0 && $p <= 2);
31
32 7
        $difference1 = $valueAt1 - $valueAt0;
33 7
        $difference2 = $valueAt2 - $valueAt1;
34 7
        $differenceDifferences = $difference2 - $difference1;
35
36 7
        return $valueAt0 + $p * $difference1 + $p / 2 * ($p - 1) * $differenceDifferences;
37
    }
38
}
39