219 lines
12 KiB
C++
219 lines
12 KiB
C++
#include "testing/testing.hpp"
|
|
|
|
#include "generator/srtm_parser.hpp"
|
|
|
|
#include "coding/endianness.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
namespace srtm_parser_test
|
|
{
|
|
using namespace generator;
|
|
using namespace geometry;
|
|
|
|
inline std::string GetBase(ms::LatLon const & coord)
|
|
{
|
|
return SrtmTile::GetBase(coord);
|
|
}
|
|
|
|
inline SrtmTile::LatLonKey GetKey(ms::LatLon const & coord)
|
|
{
|
|
return SrtmTile::GetKey(coord);
|
|
}
|
|
|
|
UNIT_TEST(SRTM_FilenameTest)
|
|
{
|
|
auto name = GetBase({56.4566, 37.3467});
|
|
TEST_EQUAL(name, "N56E037", ());
|
|
|
|
name = GetBase({34.077433, -118.304569});
|
|
TEST_EQUAL(name, "N34W119", ());
|
|
|
|
name = GetBase({1.0, 1.0});
|
|
TEST_EQUAL(name, "N01E001", ());
|
|
|
|
name = GetBase({0.1, 0.1});
|
|
TEST_EQUAL(name, "N00E000", ());
|
|
|
|
TEST_NOT_EQUAL(GetKey({0.1, 0.1}), GetKey({1.0, 1.0}), ());
|
|
|
|
name = GetBase({-0.1, -0.1});
|
|
TEST_EQUAL(name, "S01W001", ());
|
|
|
|
TEST_NOT_EQUAL(GetKey({0.1, 0.1}), GetKey({-0.1, -0.1}), ());
|
|
|
|
name = GetBase({-0.9, -0.9});
|
|
TEST_EQUAL(name, "S01W001", ());
|
|
|
|
TEST_EQUAL(GetKey({-0.9, -0.9}), GetKey({-0.1, -0.1}), ());
|
|
|
|
name = GetBase({-1.0, -1.0});
|
|
TEST_EQUAL(name, "S01W001", ());
|
|
|
|
TEST_EQUAL(GetKey({-0.9, -0.9}), GetKey({-1.0, -1.0}), ());
|
|
|
|
name = GetBase({-1.9, -1.1});
|
|
TEST_EQUAL(name, "S02W002", ());
|
|
|
|
TEST_NOT_EQUAL(GetKey({-1.1, -1.1}), GetKey({-1.0, -1.0}), ());
|
|
|
|
name = GetBase({-35.35, -12.1});
|
|
TEST_EQUAL(name, "S36W013", ());
|
|
|
|
name = GetBase({-34.622358, -58.383654});
|
|
TEST_EQUAL(name, "S35W059", ());
|
|
}
|
|
|
|
UNIT_TEST(SRTM_TileTest)
|
|
{
|
|
SrtmTile tile;
|
|
size_t sz;
|
|
Altitude * data = tile.DataForTests(sz);
|
|
|
|
// Fill 5 last rows:
|
|
// -4 -4 -4
|
|
// -2 -2 -2
|
|
// 0 0 0
|
|
// 2 2 2
|
|
// 4 4 4
|
|
size_t row = sz - 1;
|
|
for (Altitude a = 4; a >= -4; a -= 2)
|
|
{
|
|
for (size_t i = row * sz; i < (row + 1) * sz; ++i)
|
|
data[i] = ReverseByteOrder(a);
|
|
--row;
|
|
}
|
|
|
|
double const len = 1.0 / (sz - 1);
|
|
|
|
TEST_EQUAL(tile.GetHeight({0, 0}), 4, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetTriangleHeight({0, 0}), 4.0, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetBilinearHeight({0, 0}), 4.0, ());
|
|
TEST_EQUAL(tile.GetHeight({len, len}), 2, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetTriangleHeight({len, len}), 2.0, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetBilinearHeight({len, len}), 2.0, ());
|
|
|
|
double l = len / 2;
|
|
Altitude h = tile.GetHeight({l, l});
|
|
TEST(h == 4 || h == 2, (h));
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetTriangleHeight({l, l}), 3.0, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetBilinearHeight({l, l}), 3.0, ());
|
|
|
|
l = 3 * len + len / 2;
|
|
h = tile.GetHeight({l, l});
|
|
TEST(h == -4 || h == -2, (h));
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetTriangleHeight({l, l}), -3.0, ());
|
|
TEST_ALMOST_EQUAL_ULPS(tile.GetBilinearHeight({l, l}), -3.0, ());
|
|
}
|
|
|
|
/*
|
|
UNIT_TEST(SRTM_SamplesTest)
|
|
{
|
|
SrtmTileManager manager("/Users/vng/SRTM");
|
|
|
|
std::initializer_list<ms::LatLon> arr[] = {
|
|
{{ 41.899802800880578957, 12.498703841110341273}, { 41.899748897914214751, 12.498642150302543996},
|
|
{ 41.899315676124750496, 12.498172763721441925}, { 41.899207869324136766, 12.498057428732948893 }},
|
|
{{ 41.900315874986389986, 12.499267105007675127}, { 41.900234022973513959, 12.499175909900486658},
|
|
{ 41.899802800880578957, 12.498703841110341273 }},
|
|
{{ 41.899317672545265623, 12.499556783583443575}, { 41.899704976945002954, 12.498910371206022774},
|
|
{ 41.899716955394147533, 12.49888623132471821}, { 41.899730930248637151, 12.498862091443413647},
|
|
{ 41.899744905100071435, 12.49882990493497914}, { 41.899760876355117034, 12.498797718426573056},
|
|
{ 41.899772854793766896, 12.498768214127181864}, { 41.899788826041820755, 12.498736027618775779},
|
|
{ 41.899802800880578957, 12.498703841110341273 }},
|
|
{{ 41.900297907480371862, 12.497869674100513748}, { 41.900259976062137923, 12.497931364908311025},
|
|
{ 41.899866685818835776, 12.498593870539906447}, { 41.899834743357700972, 12.498647514720602203},
|
|
{ 41.899818772121129484, 12.498674336810950081}, { 41.899802800880578957, 12.498703841110341273 }},
|
|
{{ 41.899728933841061007, 12.497309092412223208}, { 41.900224041013551357, 12.497850898637267392},
|
|
{ 41.90023202658165502, 12.49786430968242712}, { 41.900224041013551357, 12.497888449563731683},
|
|
{ 41.899826757739916161, 12.498548272986312213}, { 41.899808790096251698, 12.498556319613442156},
|
|
{ 41.899802800880578957, 12.498550955195355527}, { 41.89979281885320006, 12.498545590777297321},
|
|
{ 41.899307690442057606, 12.498009148970311344}, { 41.899301701179375357, 12.497995737925151616},
|
|
{ 41.899309686862821422, 12.497976962461905259}, { 41.899716955394147533, 12.497311774621238101},
|
|
{ 41.899728933841061007, 12.497309092412223208 }},
|
|
{{ 41.899802800880578957, 12.498550955195355527}, { 41.899748897914214751, 12.498642150302543996},
|
|
{ 41.899681020039992063, 12.498754803082022136 }},
|
|
{{ 41.899912603078725226, 12.498650196929645517}, { 41.899866685818835776, 12.498593870539906447},
|
|
{ 41.899826757739916161, 12.498548272986312213 }},
|
|
{{ 41.899994455503602353, 12.498516086477906128}, { 41.899912603078725226, 12.498650196929645517},
|
|
{ 41.899912603078725226, 12.498685065647094916}, { 41.900285929140210328, 12.499090079211356397},
|
|
{ 41.90030589303923847, 12.499111536883646068}, { 41.90070516970908443, 12.498435620206862495},
|
|
{ 41.900711158840110215, 12.49842489137071766}, { 41.900715151593857399, 12.498408798116514618},
|
|
{ 41.900713155217019334, 12.498398069280369782}, { 41.90056342677709722, 12.498237136738282516},
|
|
{ 41.900327853320931126, 12.497979644670920152}, { 41.900317871375655443, 12.497976962461905259},
|
|
{ 41.900307889428788144, 12.497982326879963466}, { 41.899994455503602353, 12.498516086477906128 }},
|
|
|
|
{{ 44.759886801735603967, 34.316046940654871378 }, { 44.759500178870737841, 34.315553414192436321 },
|
|
{ 44.759132599068138347, 34.315443443622029918 }, { 44.758765016927078761, 34.315430032576841768 },
|
|
{ 44.758071746835689453, 34.315253006780551459 }, { 44.758037464032938146, 34.315255688989566352 },
|
|
{ 44.757483222565575431, 34.315306650961247215 }, { 44.756708037437867631, 34.315676795808059296 },
|
|
{ 44.756323297960172169, 34.315652655926726311 }, { 44.755963316624225001, 34.315430032576841768 },
|
|
{ 44.755833798981250027, 34.315153765046261469 }, { 44.755789991477485046, 34.314949917159594861 }},
|
|
{{ 44.759886801735603967, 34.316046940654871378 }, { 44.760006787615907342, 34.315175222718522718 },
|
|
{ 44.760048687388419353, 34.315011607967392138 }, { 44.760260090322724125, 34.314772891363304552 },
|
|
{ 44.760437211104594724, 34.314665603001913041 }, { 44.760572431981174191, 34.314383971053246114 },
|
|
{ 44.760701939002856875, 34.314300822573159166 }, { 44.761223773178279828, 34.314088928059419459 },
|
|
{ 44.761292334982400121, 34.314091610268434351 }, { 44.761376132632506142, 34.314011143997390718 },
|
|
{ 44.761667518969709079, 34.313895809008897686 }, { 44.761739889204726239, 34.31379924948365101 },
|
|
{ 44.761739889204726239, 34.313705372167419227 }, { 44.76183130410882427, 34.313568579506636524 },
|
|
{ 44.761930336758403826, 34.313549804043390168 }, { 44.761981757490261202, 34.313442515681998657 },
|
|
{ 44.762050318394869919, 34.313396918128404423 }, { 44.762176013175370315, 34.313391553710346216 },
|
|
{ 44.762316943361625476, 34.313359367201911709 }, { 44.762610229403847484, 34.313332545111563832 },
|
|
{ 44.762627369451166714, 34.313343273947708667 }, { 44.762663553978839559, 34.313313769648317475 },
|
|
{ 44.762673076219179791, 34.313278900930868076 }, { 44.762678789562635018, 34.313233303377273842 },
|
|
{ 44.762692120695184883, 34.31320379907788265 }, { 44.762720687397411723, 34.313182341405621401 },
|
|
{ 44.762734018520298207, 34.313107239552635974 }, { 44.762747349640086725, 34.313091146298432932 },
|
|
{ 44.7628063874193316, 34.313101875134577767 }, { 44.76292065391750441, 34.313123332806839016 },
|
|
{ 44.762977787081830172, 34.313056277580983533 }, { 44.763063486722373341, 34.313107239552635974 },
|
|
{ 44.763282496337311045, 34.313088464089389618 }},
|
|
{{ 44.756521381971580809, 34.332137512655094724 }, { 44.756469956380023234, 34.331619846311355104 },
|
|
{ 44.756412816780184016, 34.331308710063325407 }, { 44.756359486436011252, 34.331040489159818208 },
|
|
{ 44.75633282124546497, 34.330965387306861203 }, { 44.756294728094793811, 34.330860781154484584 },
|
|
{ 44.756264253556160781, 34.330694484194339111 }, { 44.756294728094793811, 34.330608653505208849 },
|
|
{ 44.756323297960172169, 34.330533551652223423 }, { 44.756433767973362592, 34.330359208064976428 },
|
|
{ 44.756555665673857902, 34.330109762624715586 }, { 44.756641374840555159, 34.329940783455526798 },
|
|
{ 44.756755653531747896, 34.329755711032106547 }, { 44.757010875126020721, 34.329463350247323206 },
|
|
{ 44.757180387352946127, 34.329117345281815687 }, { 44.757266095593031707, 34.32893495506743875 },
|
|
{ 44.757448939413642108, 34.328564810220626669 }, { 44.757591785745901802, 34.328301953735206098 },
|
|
{ 44.757746059388104243, 34.327797698436654628 }, { 44.757807006886359602, 34.327470468934393466 },
|
|
{ 44.75787366813893442, 34.327239798957407402 }, { 44.757986039790637278, 34.327089595251464971 },
|
|
{ 44.758026036427494887, 34.326995717935233188 }, { 44.758113648011466523, 34.326907205037088033 },
|
|
{ 44.75817078592944398, 34.326783823421465058 }, { 44.758237446762365153, 34.326400267529493249 },
|
|
{ 44.758264111073970071, 34.3263519877668557 }, { 44.758357436067782942, 34.326177644179608706 },
|
|
{ 44.758412669156371066, 34.325909423276101506 }, { 44.758505993910240761, 34.325775312824362118 },
|
|
{ 44.758526944344453113, 34.325598287028071809 }, { 44.758479329710219474, 34.325461494367289106 },
|
|
{ 44.758391718680712756, 34.325370299260100637 }, { 44.758429810449001707, 34.32524423543546277 },
|
|
{ 44.75854789477109108, 34.325085985102390396 }, { 44.758637410144764601, 34.324914323724158294 },
|
|
{ 44.758685024648755757, 34.324734615718824671 }, { 44.758707879596705936, 34.324613916312273432 },
|
|
{ 44.758766921503791991, 34.324568318758679197 }, { 44.758749780311177346, 34.32444225493404133 },
|
|
{ 44.758799299298182461, 34.324206220538968637 }, { 44.75882786792522694, 34.323988961607142301 },
|
|
{ 44.758825963350531651, 34.323667096522939346 }, { 44.758843104520543932, 34.323423015500765132 },
|
|
{ 44.758862150259034252, 34.323181616687634232 }, { 44.758915478293424428, 34.322983133219054253 },
|
|
{ 44.758944046863021526, 34.322875844857662742 }, { 44.759084984933011242, 34.322862433812474592 },
|
|
{ 44.758966901708539865, 34.32266126813487972 }, { 44.758865959405987667, 34.32256202640058973 },
|
|
{ 44.758753589465527511, 34.322331356423575244 }, { 44.75867359717138072, 34.322089957610444344 },
|
|
{ 44.758690738386590624, 34.321875380887661322 }, { 44.758690738386590624, 34.321754681481081661 },
|
|
{ 44.758698356702829813, 34.321642028701631943 }, { 44.758643123887310367, 34.321379172216211373 },
|
|
{ 44.758641219306547043, 34.321231650719283834 }, { 44.758665978851873035, 34.321027802832645648 },
|
|
{ 44.758732639113461005, 34.320837365991167189 }, { 44.75867359717138072, 34.320502089861804507 },
|
|
{ 44.75867931091034535, 34.320392119291369681 }, { 44.758808822175438991, 34.320268737675775128 },
|
|
{ 44.758793585571083895, 34.320099758506557919 }, { 44.758978329127899087, 34.319783257840441593 },
|
|
{ 44.759109744288181787, 34.319584774371861613 }, { 44.75926782299799811, 34.31950430810081798 },
|
|
{ 44.759357337256332698, 34.319305824632238 }, { 44.759387810163708821, 34.319016146056469552 },
|
|
{ 44.759481133342561066, 34.318686234345193498 }, { 44.75951351073673834, 34.318530666221164438 },
|
|
{ 44.759524938047988485, 34.318332182752584458 }, { 44.759637306488322395, 34.317903029306989993 },
|
|
{ 44.759671588341880977, 34.317436324934931235 }, { 44.759871565415501493, 34.317044722415829483 },
|
|
{ 44.759902038051663453, 34.316647755478669524 }, { 44.759915369824923914, 34.316167640061422617 },
|
|
{ 44.759886801735603967, 34.316046940654871378 }},
|
|
};
|
|
|
|
using namespace std;
|
|
for (auto const & points : arr)
|
|
{
|
|
for (auto const & p : points)
|
|
cout << manager.GetTriangleHeight(p) << ", ";
|
|
cout << endl;
|
|
}
|
|
}
|
|
*/
|
|
} // namespace srtm_parser_test
|