]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/set_operations/union/union_other_types.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands.
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)
10 #include <boost/multiprecision/cpp_bin_float.hpp>
11 #include <boost/multiprecision/cpp_dec_float.hpp>
13 #include <geometry_test_common.hpp>
14 #include <algorithms/overlay/multi_overlay_cases.hpp>
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>
21 #include <algorithms/overlay/multi_overlay_cases.hpp>
23 #include <boost/geometry/geometries/point_xy.hpp>
24 #include <boost/geometry/geometries/multi_polygon.hpp>
26 #include <boost/geometry/util/rational.hpp>
30 enum class exclude
{ all
, rectangular
, diagonal
, hard
, fp
};
32 template <typename Geometry
, typename Expected
>
33 void test_one(std::string
const& case_id
,
34 std::string
const& wkt1
, std::string
const& wkt2
,
36 Expected
const& expected_area
,
37 Expected
const& expected_max
= -1)
39 using coor_t
= typename
bg::coordinate_type
<Geometry
>::type
;
40 Geometry g1
, g2
, clip
;
42 bg::read_wkt(wkt1
, g1
);
43 bg::read_wkt(wkt2
, g2
);
48 bg::union_(g1
, g2
, clip
);
50 auto const area
= bg::area(clip
);
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
)
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
,
70 << " area: expected: " << expected_area
71 << " detected: " << area
72 << " type: " << (string_from_type
<coor_t
>::name())
73 << " (" << (typeid(coor_t
).name()) << ")");
76 template <typename Point
>
77 void test_areal(std::set
<exclude
> const& exclude
= {}, bool debug
= false)
79 using polygon
= bg::model::polygon
<Point
>;
80 using multi_polygon
= bg::model::multi_polygon
<polygon
>;
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")
87 if (exclude
.count(exclude::rectangular
)
88 + exclude
.count(exclude::all
) == 0)
90 test_one
<multi_polygon
>("case_multi_rectangular",
91 case_multi_rectangular
[0], case_multi_rectangular
[1], debug
, 33125);
93 if (exclude
.count(exclude::diagonal
)
94 + exclude
.count(exclude::all
) == 0)
96 test_one
<multi_polygon
>("case_multi_diagonal",
97 case_multi_diagonal
[0], case_multi_diagonal
[1], debug
, 5350);
99 if (exclude
.count(exclude::hard
)
100 + exclude
.count(exclude::fp
)
101 + exclude
.count(exclude::all
) == 0)
103 test_one
<multi_polygon
>("case_multi_hard",
104 case_multi_hard
[0], case_multi_hard
[1], debug
, 21, 23);
108 int test_main(int, char* [])
110 namespace bm
= boost::multiprecision
;
112 using bg::model::d2::point_xy
;
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>>({});
120 // Standard integer types
121 test_areal
<point_xy
<std::int16_t>>({exclude::fp
});
122 test_areal
<point_xy
<std::int32_t>>({exclude::fp
});
124 test_areal
<point_xy
<std::int64_t>>({exclude::fp
});
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
});
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>>>>();
138 test_areal
<point_xy
<bm::number
<bm::cpp_bin_float
<100>>>>();
140 test_areal
<point_xy
<bm::number
<bm::cpp_dec_float
<50>>>>({});
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
});
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>>();
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
});
159 test_areal
<point_xy
<boost::rational
<std::int64_t>>>({exclude::fp
});