1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodecsTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_coordinates\CoordinatesException; |
8
|
|
|
use kalanis\kw_coordinates\Support; |
9
|
|
|
use kalanis\kw_coordinates\Codecs; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class DegreesTest extends CommonTestClass |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param float $coordLon |
16
|
|
|
* @param float $coordLat |
17
|
|
|
* @param float $coordAlt |
18
|
|
|
* @param string $x |
19
|
|
|
* @param string $y |
20
|
|
|
* @param string $z |
21
|
|
|
* @param bool $useAlt |
22
|
|
|
* @throws CoordinatesException |
23
|
|
|
* @dataProvider transferFromProvider |
24
|
|
|
*/ |
25
|
|
|
public function testFromDegToCoord(float $coordLon, float $coordLat, float $coordAlt, string $x, string $y, string $z, bool $useAlt = true): void |
26
|
|
|
{ |
27
|
|
|
$lib = new Codecs\Degrees(); |
28
|
|
|
$transport = new Support\Position(); |
29
|
|
|
$result = $lib->fromLonLat($transport->setData($coordLon, $coordLat, $useAlt ? $coordAlt : 0.0), []); |
30
|
|
|
|
31
|
|
|
$this->assertEquals($x, $result->getLongitude()); |
32
|
|
|
$this->assertEquals($y, $result->getLatitude()); |
33
|
|
|
if ($useAlt) $this->assertEquals($z, $result->getAltitude()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function transferFromProvider(): array |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
[48.1417237, 17.1000319, 305, '48°8\'30.20532"E', '17°6\'0.11484"N', '305', false], // bratislavsky hrad |
43
|
|
|
[-548.1417237, -17.1000319, 305, '171°51\'29.79468"E', '17°6\'0.11484"S', '305', true], // nekde jinde |
44
|
|
|
[12.8069888666667, -49.4522626972222, 512.30, '12°48\'25.15992"E', '49°27\'8.14571"S', '512.3', true], // testovaci bod 109 |
45
|
|
|
[-12.8069888666667, 4995.4522626972222, 559.417, '12°48\'25.15992"W', '44°32\'51.85429"S', '0.0', false], // zase jinde |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param float $coordLon |
51
|
|
|
* @param float $coordLat |
52
|
|
|
* @param float $coordAlt |
53
|
|
|
* @param string $x |
54
|
|
|
* @param string $y |
55
|
|
|
* @param string $z |
56
|
|
|
* @param bool $useAlt |
57
|
|
|
* @throws CoordinatesException |
58
|
|
|
* @dataProvider transferToProvider |
59
|
|
|
*/ |
60
|
|
|
public function testFromCoordToDeg(float $coordLon, float $coordLat, float $coordAlt, string $x, string $y, string $z, bool $useAlt = true): void |
61
|
|
|
{ |
62
|
|
|
$lib = new Codecs\Degrees(); |
63
|
|
|
$transport = new Support\DegreesObject(); |
64
|
|
|
$result = $lib->toLonLat($transport->setData($x, $y, $useAlt ? $z : 0.0), []); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(sprintf('%01.6f', $coordLon), sprintf('%01.6f', $result->getLongitude())); |
67
|
|
|
$this->assertEquals(sprintf('%01.6f', $coordLat), sprintf('%01.6f', $result->getLatitude())); |
68
|
|
|
if ($useAlt) $this->assertEquals($coordAlt, $result->getAltitude()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function transferToProvider(): array |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
[48.1417237, 17.1000319, 305, '48°8\'30.20532"E', '17°6\'0.11484"N', '305', false], // bratislavsky hrad |
78
|
|
|
[171.8582763, -17.1000319, 305, '171°51\'29.79468"E', '17°6\'0.11484"S', '305', true], // nekde jinde |
79
|
|
|
[-7.1930111333333, -49.4522626972222, 512.30, '352°48\'25.15992"E', '49°27\'8.14571"S', '512.3', true], // testovaci bod 109 |
80
|
|
|
[-12.8069888666667, 24.452262697222068, 0.0, '12°48\'25.15992"W', '4475°32\'51.85429"S', '559.417', false], // zase jinde |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @throws CoordinatesException |
86
|
|
|
*/ |
87
|
|
|
public function testFromCoordDied(): void |
88
|
|
|
{ |
89
|
|
|
$lib = new Codecs\Degrees(); |
90
|
|
|
$transport = new Support\DegreesObject(); |
91
|
|
|
$this->expectException(CoordinatesException::class); |
92
|
|
|
$lib->toLonLat($transport->setData('not-a-numbers', 'not-any-number'), []); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|