1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Runalyze DEM Reader. |
5
|
|
|
* |
6
|
|
|
* (c) RUNALYZE <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Runalyze\DEM\tests\Interpolation; |
13
|
|
|
|
14
|
|
|
use Runalyze\DEM\Interpolation\BilinearInterpolation; |
15
|
|
|
|
16
|
|
|
class BilinearInterpolationTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** @var BilinearInterpolation */ |
19
|
|
|
protected $Interpolation; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->Interpolation = new BilinearInterpolation(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testBoundaryPoints() |
27
|
|
|
{ |
28
|
|
|
$boundingBox = [3, 42, 1337, 666]; |
29
|
|
|
|
30
|
|
|
$this->assertEquals(3.0, $this->Interpolation->interpolate(0.0, 0.0, $boundingBox)); |
31
|
|
|
$this->assertEquals(42.0, $this->Interpolation->interpolate(1.0, 0.0, $boundingBox)); |
32
|
|
|
$this->assertEquals(1337.0, $this->Interpolation->interpolate(0.0, 1.0, $boundingBox)); |
33
|
|
|
$this->assertEquals(666.0, $this->Interpolation->interpolate(1.0, 1.0, $boundingBox)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testPointsOnBoundaryLines() |
37
|
|
|
{ |
38
|
|
|
$boundingBox = [10, 20, 30, 40]; |
39
|
|
|
|
40
|
|
|
$this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.0, $boundingBox)); |
41
|
|
|
$this->assertEquals(20, $this->Interpolation->interpolate(0.0, 0.5, $boundingBox)); |
42
|
|
|
$this->assertEquals(30, $this->Interpolation->interpolate(1.0, 0.5, $boundingBox)); |
43
|
|
|
$this->assertEquals(35, $this->Interpolation->interpolate(0.5, 1.0, $boundingBox)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCenter() |
47
|
|
|
{ |
48
|
|
|
$this->assertEquals(20, $this->Interpolation->interpolate(0.5, 0.5, [20, 20, 20, 20])); |
49
|
|
|
$this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [10, 10, 20, 20])); |
50
|
|
|
$this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [20, 20, 10, 10])); |
51
|
|
|
$this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [10, 20, 10, 20])); |
52
|
|
|
$this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [20, 10, 20, 10])); |
53
|
|
|
$this->assertEquals(75, $this->Interpolation->interpolate(0.5, 0.5, [100, 100, 100, 0])); |
54
|
|
|
$this->assertEquals(38, $this->Interpolation->interpolate(0.5, 0.5, [10, 42, 31, 69])); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|