Skip to content

Commit a1ecf6a

Browse files
authored
Merge pull request #1120 from vissarion/fix/buffer_tests
Fix buffer tests by using more accurate area computation
2 parents 47d29f9 + 792fbf9 commit a1ecf6a

File tree

5 files changed

+62
-17
lines changed

5 files changed

+62
-17
lines changed

test/algorithms/buffer/buffer_gc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void test_gc()
3737
bg::strategy::buffer::join_round join;
3838
bg::strategy::buffer::end_round end;
3939
bg::strategy::buffer::point_circle circle;
40-
40+
4141
mpo_t result_mpo;
4242
bg::buffer(gc, result_mpo, distance, side, join, end, circle);
4343

test/algorithms/buffer/buffer_geo_spheroid.cpp

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Unit Test
33

44
// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.
5+
// Copyright (c) 2023, Oracle and/or its affiliates.
6+
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
57

68
// Use, modification and distribution is subject to the Boost Software License,
79
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -16,6 +18,38 @@ namespace
1618
std::string const torg = "POINT(10.3937759 63.4302323)";
1719
}
1820

21+
template
22+
<
23+
typename FormulaPolicy,
24+
typename Spheroid,
25+
typename CalculationType
26+
>
27+
struct geo_buffer_accurate_area
28+
: public bg::strategies::buffer::geographic<FormulaPolicy, Spheroid, CalculationType>
29+
{
30+
using base_t = bg::strategies::buffer::geographic<FormulaPolicy, Spheroid, CalculationType>;
31+
32+
public:
33+
34+
geo_buffer_accurate_area() = default;
35+
36+
explicit geo_buffer_accurate_area(Spheroid const& spheroid)
37+
: base_t(spheroid)
38+
{}
39+
40+
template <typename Geometry>
41+
auto area(Geometry const&,
42+
std::enable_if_t<! bg::util::is_box<Geometry>::value> * = nullptr) const
43+
{
44+
return bg::strategy::area::geographic
45+
<
46+
bg::strategy::karney,
47+
bg::strategy::default_order<bg::strategy::karney>::value,
48+
Spheroid, CalculationType
49+
>(base_t::m_spheroid);
50+
}
51+
};
52+
1953
template <typename Formula, bool Clockwise, typename Point, typename Spheroid>
2054
void test_linestring(std::string const& label, Spheroid const& spheroid,
2155
double expected_area_round, double expected_area_miter)
@@ -25,7 +59,9 @@ void test_linestring(std::string const& label, Spheroid const& spheroid,
2559

2660
ut_settings settings(0.1);
2761

28-
bg::strategies::buffer::geographic<Formula, Spheroid> strategy(spheroid);
62+
using CT = typename bg::coordinate_type<Point>::type;
63+
geo_buffer_accurate_area<Formula, Spheroid, CT> strategy(spheroid);
64+
2965
bg::strategy::buffer::geographic_side_straight<Formula, Spheroid> side(spheroid);
3066
bg::strategy::buffer::geographic_join_miter<Formula, Spheroid> join_miter(spheroid);
3167
bg::strategy::buffer::geographic_join_round<Formula, Spheroid> join_round(spheroid, points_per_circle);
@@ -45,7 +81,9 @@ void test_point(std::string const& label, Spheroid const& spheroid, double expec
4581

4682
ut_settings settings(0.01);
4783

48-
bg::strategies::buffer::geographic<Formula, Spheroid> strategy(spheroid);
84+
using CT = typename bg::coordinate_type<Point>::type;
85+
geo_buffer_accurate_area<Formula, Spheroid, CT> strategy(spheroid);
86+
4987
bg::strategy::buffer::geographic_point_circle<Formula, Spheroid> circle(spheroid, points_per_circle);
5088

5189
// All are ignored for points
@@ -57,24 +95,31 @@ void test_point(std::string const& label, Spheroid const& spheroid, double expec
5795
test_one_geo<Point, polygon>(label, torg, strategy, side, circle, join_round, end_round, expected_area, 100.0, settings);
5896
}
5997

60-
int test_main(int, char* [])
98+
template <typename test_type>
99+
void test_all()
61100
{
62-
BoostGeometryWriteTestConfiguration();
63-
64-
using test_type = default_test_type;
65-
66101
using point_t = bg::model::point<test_type, 2, bg::cs::geographic<bg::degree>>;
102+
using strategy = bg::strategy::andoyer;
67103

68104
// Use the default spheroid
69105
bg::srs::spheroid<test_type> def_spheroid;
70-
test_linestring<bg::strategy::andoyer, true, point_t>("line_def", def_spheroid, 7996.0, 8093.0);
71-
test_point<bg::strategy::andoyer, true, point_t>("point_def", def_spheroid, 31450.0);
106+
test_linestring<strategy, true, point_t>("line_def", def_spheroid, 8046.26, 8143.37);
107+
test_point<strategy, true, point_t>("point_def", def_spheroid, 31414.36);
72108

73109
// Call it with a quite different spheroid (a near sphere), this changes internal geographic calculations
74110
// and should result in different areas. Using CSV creation, it's visible in QGis.
75111
bg::srs::spheroid<test_type> alt_spheroid(6378000.0, 6375000.0);
76-
test_linestring<bg::strategy::andoyer, true, point_t>("line_alt", alt_spheroid, 8097.0, 8115.3);
77-
test_point<bg::strategy::andoyer, true, point_t>("point_alt", alt_spheroid, 31409.0);
112+
test_linestring<strategy, true, point_t>("line_alt", alt_spheroid, 8030.53, 8127.61);
113+
test_point<strategy, true, point_t>("point_alt", alt_spheroid, 31414.33);
114+
}
115+
116+
int test_main(int, char* [])
117+
{
118+
BoostGeometryWriteTestConfiguration();
119+
120+
// There are several issues with float type such as invalid geometries as output and assertion fails
121+
//test_all<float>();
122+
test_all<default_test_type>();
78123

79124
return 0;
80125
}

test/algorithms/buffer/buffer_multi_linestring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static std::string const mysql_2015_04_10a = "MULTILINESTRING((-58 19, 61 88),(1
3737
static std::string const mysql_2015_04_10b = "MULTILINESTRING((-58 19, 61 88), (-63 -5, -262141 -536870908, -3 87, 77 -69))";
3838

3939
static std::string const mysql_2015_09_08a = "MULTILINESTRING((7 -4, -3 -5), (72057594037927936 15, 72057594037927940 70368744177660, 32771 36028797018963964, 8589934589 2305843009213693953, 7 2, 9.300367e+307 9.649737e+307, -4092 -274877906946, 5 10, -3 4))";
40-
static std::string const mysql_2015_09_08b = "MULTILINESTRING((-9 -10, 0 -1, 5 -10, -6 7, -7 7, 5.041061e+307 9.926906e+307, 6.870356e+307 1.064454e+307, 35184372088830 288230376151711743, 183673728842483250000000000000000000000.000000 244323751784861950000000000000000000000.000000), (-23530 -7131, -6 1, 1 1, 2 -6, 32766 -4194302, -4 -6), (134217725 0, 50336782742294697000000000000000000000.000000 36696596077212901000000000000000000000.000000, 7434 16486, 3.025467e+307 8.926790e+307), (2147483646 67108868, 71328904281592545000000000000000000000.000000 225041650340452780000000000000000000000.000000, -7 4, 1.667154e+307 3.990414e+307))";
40+
static std::string const mysql_2015_09_08b = "MULTILINESTRING((-9 -10, 0 -1, 5 -10, -6 7, -7 7, 5.041061e+307 9.926906e+307, 6.870356e+307 1.064454e+307, 35184372088830 288230376151711743, 183673728842483250000000000000000000000.000000 244323751784861950000000000000000000000.000000), (-23530 -7131, -6 1, 1 1, 2 -6, 32766 -4194302, -4 -6), (134217725 0, 50336782742294697000000000000000000000.000000 36696596077212901000000000000000000000.000000, 7434 16486, 3.025467e+307 8.926790e+307), (2147483646 67108868, 71328904281592545000000000000000000000.000000 225041650340452780000000000000000000000.000000, -7 4, 1.667154e+307 3.990414e+307))";
4141

4242
static std::string const mysql_23023665_1 = "MULTILINESTRING((-5 15, 7 15, 19 -10, -11 -2),(2 13, 2 -9))";
4343

test/algorithms/buffer/buffer_multi_polygon_geo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ std::string select_within_box(const std::string& wkt, const std::string& wkt_box
4747
geometry.erase(geometry.begin(), geometry.begin() + 1);
4848
}
4949

50-
geometry.erase(std::remove_if(boost::begin(geometry), boost::end(geometry),
50+
geometry.erase(std::remove_if(boost::begin(geometry), boost::end(geometry),
5151
[&poly](const auto& p) { return ! bg::within(p, poly); }), boost::end(geometry));
5252

5353
std::ostringstream out;
@@ -77,15 +77,15 @@ void test_geometry(const std::string& base_folder, bool test_all = false, bool g
7777
if (generate_cases)
7878
{
7979
const std::string gr = read_from_wkt_file<multi_polygon>(base_folder + "gr_ll.wkt");
80-
80+
8181
test_one_geo<multi_polygon, polygon>("gr", gr, strategy, _s, _c, join, _e, 222719122493.0, 10000.0, settings);
8282

8383
std::cout << "cyclades = " << select_within_box<multi_polygon>(gr, "BOX(24.1395 36.0147,26.1382 38.1464)") << std::endl;
8484
std::cout << "aegeans = " << select_within_box<multi_polygon>(gr, "BOX(22.6207 38.0017,26.6756 40.9638)") << std::endl;
8585
std::cout << "dodecaneses = " << select_within_box<multi_polygon>(gr, "BOX(25.8740 35.1906,28.4227 38.0700)") << std::endl;
8686
std::cout << "ionians = " << select_within_box<multi_polygon>(gr, "BOX(18.9540 37.2072,22.4337 40.6295)") << std::endl;
8787
std::cout << "crete = " << select_within_box<multi_polygon>(gr, "BOX(23.0592 34.4105,26.5606 35.9347)") << std::endl;
88-
88+
8989
std::cout << "aegeans = " << aegeans << std::endl;
9090
}
9191

test/algorithms/buffer/test_buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct ut_settings : public ut_base_settings
156156

157157
// Number of points in a circle. Not used for geo tests.
158158
int points_per_circle;
159-
159+
160160
double multiplier_min_area = 0.95;
161161
double multiplier_max_area = 1.05;
162162
double fraction_buffered_points_too_close = 0.10;

0 commit comments

Comments
 (0)