]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/set_operations/union/union_other_types.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / set_operations / union / union_other_types.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <boost/multiprecision/cpp_bin_float.hpp>
11 #include <boost/multiprecision/cpp_dec_float.hpp>
12
13 #include <geometry_test_common.hpp>
14 #include <algorithms/overlay/multi_overlay_cases.hpp>
15
16 #include <boost/geometry/algorithms/correct.hpp>
17 #include <boost/geometry/algorithms/union.hpp>
18 #include <boost/geometry/io/wkt/wkt.hpp>
19 #include <boost/geometry/geometries/geometries.hpp>
20
21 #include <algorithms/overlay/multi_overlay_cases.hpp>
22
23 #include <boost/geometry/geometries/point_xy.hpp>
24 #include <boost/geometry/geometries/multi_polygon.hpp>
25
26 #include <boost/geometry/util/rational.hpp>
27
28 #include <set>
29
30 enum class exclude { all, rectangular, diagonal, hard, fp };
31
32 template <typename Geometry, typename Expected>
33 void test_one(std::string const& case_id,
34 std::string const& wkt1, std::string const& wkt2,
35 bool debug,
36 Expected const& expected_area,
37 Expected const& expected_max = -1)
38 {
39 using coor_t = typename bg::coordinate_type<Geometry>::type;
40 Geometry g1, g2, clip;
41
42 bg::read_wkt(wkt1, g1);
43 bg::read_wkt(wkt2, g2);
44
45 bg::correct(g1);
46 bg::correct(g2);
47
48 bg::union_(g1, g2, clip);
49
50 auto const area = bg::area(clip);
51 if (debug)
52 {
53 std::cout << "AREA: " << std::setprecision(64) << area
54 << " expected " << expected_area
55 << " types coordinate " << string_from_type<coor_t>::name()
56 << " area " << typeid(decltype(area)).name()
57 << " expected " << typeid(Expected).name()
58 << " size " << sizeof(coor_t)
59 << std::endl;
60 }
61
62 // Check areas, they always have to be specified in integer for this test
63 // and therefore the checking (including a tolerance) is different
64 bool const ok = expected_max == -1
65 ? bg::math::equals(area, expected_area)
66 : bg::math::larger_or_equals(area, expected_area)
67 && bg::math::smaller_or_equals(area, expected_max);
68 BOOST_CHECK_MESSAGE(ok,
69 "union: " << case_id
70 << " area: expected: " << expected_area
71 << " detected: " << area
72 << " type: " << (string_from_type<coor_t>::name())
73 << " (" << (typeid(coor_t).name()) << ")");
74 }
75
76 template <typename Point>
77 void test_areal(std::set<exclude> const& exclude = {}, bool debug = false)
78 {
79 using polygon = bg::model::polygon<Point>;
80 using multi_polygon = bg::model::multi_polygon<polygon>;
81
82 // Intended tests: only 3:
83 // - simple case having only horizontal/vertical lines ("rectangular")
84 // - simple case on integer grid but also having diagonals ("diagonal")
85 // - case going wrong for <float> ("hard")
86
87 if (exclude.count(exclude::rectangular)
88 + exclude.count(exclude::all) == 0)
89 {
90 test_one<multi_polygon>("case_multi_rectangular",
91 case_multi_rectangular[0], case_multi_rectangular[1], debug, 33125);
92 }
93 if (exclude.count(exclude::diagonal)
94 + exclude.count(exclude::all) == 0)
95 {
96 test_one<multi_polygon>("case_multi_diagonal",
97 case_multi_diagonal[0], case_multi_diagonal[1], debug, 5350);
98 }
99 if (exclude.count(exclude::hard)
100 + exclude.count(exclude::fp)
101 + exclude.count(exclude::all) == 0)
102 {
103 test_one<multi_polygon>("case_multi_hard",
104 case_multi_hard[0], case_multi_hard[1], debug, 21, 23);
105 }
106 }
107
108 int test_main(int, char* [])
109 {
110 namespace bm = boost::multiprecision;
111
112 using bg::model::d2::point_xy;
113
114 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
115 // Standard floating point types
116 test_areal<point_xy<float>>({exclude::hard});
117 test_areal<point_xy<double>>({});
118 test_areal<point_xy<long double>>({});
119
120 // Standard integer types
121 test_areal<point_xy<std::int16_t>>({exclude::fp});
122 test_areal<point_xy<std::int32_t>>({exclude::fp});
123 #endif
124 test_areal<point_xy<std::int64_t>>({exclude::fp});
125
126 // Boost multi precision (integer)
127 test_areal<point_xy<bm::int128_t>>({exclude::fp});
128 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
129 test_areal<point_xy<bm::checked_int128_t>>({exclude::fp});
130 #endif
131
132 // Boost multi precision (floating point)
133 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
134 test_areal<point_xy<bm::number<bm::cpp_bin_float<5>>>>();
135 test_areal<point_xy<bm::number<bm::cpp_bin_float<10>>>>();
136 test_areal<point_xy<bm::number<bm::cpp_bin_float<50>>>>();
137 #endif
138 test_areal<point_xy<bm::number<bm::cpp_bin_float<100>>>>();
139
140 test_areal<point_xy<bm::number<bm::cpp_dec_float<50>>>>({});
141
142 // Boost multi precision (rational)
143 test_areal<point_xy<bm::cpp_rational>>({exclude::fp});
144 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
145 test_areal<point_xy<bm::checked_cpp_rational>>({exclude::fp});
146 #endif
147
148 // Boost multi precision float128 wrapper, is currently NOT supported
149 // and it is limited to certain compilers anyway
150 // test_areal<point_xy<bm::float128>>();
151
152 // Boost rational (tests compilation)
153 // (the rectangular case is correct; other input might give wrong results)
154 // The int16 version throws a <zero denominator> exception
155 #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
156 test_areal<point_xy<boost::rational<std::int16_t>>>({exclude::all});
157 test_areal<point_xy<boost::rational<std::int32_t>>>({exclude::fp});
158 #endif
159 test_areal<point_xy<boost::rational<std::int64_t>>>({exclude::fp});
160
161 return 0;
162 }