1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 | #define BOOST_TEST_MODULE config
#include <boost/test/included/unit_test.hpp>
namespace utt = boost::test_tools;
namespace utf = boost::unit_test;
#include <kooling/geo/coordinate.h>
#include <kooling/geo/constants.h>
#include <kooling/geo/algorithm.h>
#include <kooling/geo/bounding-box.h>
#include <kooling/datamodel/distance.h>
#include <vector>
namespace {
using namespace kooling::datamodel::literals;
using coord_t = kooling::geo::coordinate;
using bbox_t = kooling::geo::bounding_box;
using distance_t = kooling::datamodel::distance;
const coord_t london_charing_cross { 51.507369, -0.127628 };
const coord_t london_blackfriars { 51.511585, -0.103027 };
const coord_t london_union_station { 51.503766, -0.102992 };
const coord_t london_trafalgar_square{ 51.507597, -0.129132 };
const coord_t pebble_island_airstrip { -51.30905, -59.60995 };
} // unnamed namespace
BOOST_AUTO_TEST_SUITE(test_geo)
BOOST_AUTO_TEST_CASE(test_geo_coordinate)
{
for (double lat{ -90. }; lat <= 90.; lat += 1.005)
{
for (double lon{ -180. }; lon <= 180.; lon += 1.005)
{
const coord_t coord{ lat, lon };
BOOST_TEST(lat == coord.lat(), utt::tolerance(1e-5));
BOOST_TEST(lon == coord.lon(), utt::tolerance(1e-5));
}
}
}
BOOST_AUTO_TEST_CASE(test_geo_coordinate_distance_is_commutative)
{
const auto d1{ distance(london_charing_cross, pebble_island_airstrip) };
const auto d2{ distance(pebble_island_airstrip, london_charing_cross) };
BOOST_TEST(d1.m() == d2.m(), utt::tolerance(1e-12));
}
BOOST_AUTO_TEST_CASE(test_geo_coordinate_distance_far)
{
const auto d{ distance(london_charing_cross, pebble_island_airstrip) };
BOOST_TEST(d.km() == 12720, utt::tolerance(1e-1));
}
BOOST_AUTO_TEST_CASE(test_geo_coordinate_distance_close)
{
const auto d{ distance(london_charing_cross, london_trafalgar_square) };
BOOST_TEST(d.m() == 107.13, utt::tolerance(1e-2));
}
BOOST_AUTO_TEST_CASE(test_geo_coordinate_distance_very_close)
{
const coord_t c1{ 38.737183299999998, -9.2142973999999995 };
const coord_t c2{ 38.737183100000003, -9.2142973000000001 };
const auto d{ distance(c1, c2) };
BOOST_TEST(d.m() == 0.0238, utt::tolerance(2e-2));
}
BOOST_AUTO_TEST_CASE(test_geo_bbox)
{
const std::vector<coord_t> coords{
coord_t{ 51.5074339, -0.1280059 },
coord_t{ 51.4654886, -0.0133420 } };
const distance_t border{ 100_m };
const auto bbox1{ kooling::geo::make_bounding_box(boost::make_iterator_range(coords)) };
const auto bbox2{ add_border(kooling::geo::make_bounding_box(boost::make_iterator_range(coords)), border) };
const auto dmin{ kooling::geo::distance(bbox1.min, bbox2.min) };
const auto dmax{ kooling::geo::distance(bbox1.max, bbox2.max) };
BOOST_TEST(dmin.m() == border.m() * std::sqrt(2.), utt::tolerance(1e-2));
BOOST_TEST(dmax.m() == border.m() * std::sqrt(2.), utt::tolerance(1e-2));
}
BOOST_AUTO_TEST_CASE(test_geo_intercept_inside)
{
const coord_t a{ 44.3364807, 9.2021982 };
const coord_t b{ 44.3364795, 9.2023923 };
const coord_t c{ 44.3366585, 9.2023882 };
const auto i{ kooling::geo::intercept(a, b, c) };
BOOST_TEST(i.second);
BOOST_TEST(i.first.lat() == 44.33648, utt::tolerance(1e-4));
BOOST_TEST(i.first.lon() == 9.20239, utt::tolerance(1e-4));
const auto d{ kooling::geo::distance(c, i.first) };
BOOST_TEST(d.m() == 19.9, utt::tolerance(1e-1));
}
BOOST_AUTO_TEST_CASE(test_geo_intercept_outside_east)
{
const coord_t a{ 44.3364807, 9.2021982 };
const coord_t b{ 44.3364795, 9.2023923 };
const coord_t c{ 44.3366585, 9.2025 }; // further east
const auto i{ kooling::geo::intercept(a, b, c) };
BOOST_TEST(i.first == b);
BOOST_TEST(!i.second);
}
BOOST_AUTO_TEST_CASE(test_geo_intercept_outside_west)
{
const coord_t a{ 44.3364807, 9.2021982 };
const coord_t b{ 44.3364795, 9.2023923 };
const coord_t c{ 44.3366585, 9.2005 }; // further west
const auto i{ kooling::geo::intercept(a, b, c) };
BOOST_TEST(i.first == a);
BOOST_TEST(!i.second);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(test_geo_stress, * utf::disabled())<--- There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.
BOOST_AUTO_TEST_CASE(test_geo_stress_distance)
{
for (long i = 0; i < 500000; ++i)
{
const auto d1{ distance(london_charing_cross, london_trafalgar_square) };
BOOST_TEST(d1.m() == 107.13, utt::tolerance(1e-2));
const auto d2{ distance(london_charing_cross, pebble_island_airstrip) };
BOOST_TEST(d2.km() == 12720, utt::tolerance(1e-1));
}
}
BOOST_AUTO_TEST_SUITE_END()
|