]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/test_is_simple.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / test_is_simple.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
11
12
13 #include <iostream>
14 #include <string>
15
16 #include <boost/assert.hpp>
17 #include <boost/variant/variant.hpp>
18
19 #include <boost/test/included/unit_test.hpp>
20
21 #include <boost/geometry/geometries/point_xy.hpp>
22 #include <boost/geometry/geometries/segment.hpp>
23 #include <boost/geometry/geometries/linestring.hpp>
24 #include <boost/geometry/geometries/polygon.hpp>
25 #include <boost/geometry/geometries/box.hpp>
26 #include <boost/geometry/geometries/multi_point.hpp>
27 #include <boost/geometry/geometries/multi_linestring.hpp>
28 #include <boost/geometry/geometries/multi_polygon.hpp>
29
30 #include <boost/geometry/strategies/strategies.hpp>
31
32 #include <boost/geometry/io/wkt/wkt.hpp>
33
34 #include <boost/geometry/algorithms/intersection.hpp>
35 #include <boost/geometry/algorithms/is_valid.hpp>
36 #include <boost/geometry/algorithms/is_simple.hpp>
37
38 #include <from_wkt.hpp>
39
40 #ifdef BOOST_GEOMETRY_TEST_DEBUG
41 #include "pretty_print_geometry.hpp"
42 #endif
43
44 namespace bg = ::boost::geometry;
45
46 template <typename Geometry, typename Strategy>
47 void test_simple_s(Geometry const& geometry,
48 Strategy const& strategy,
49 bool expected_result,
50 bool check_validity = true)
51 {
52 bool simple = bg::is_simple(geometry, strategy);
53 bool valid = ! check_validity || bg::is_valid(geometry, strategy);
54
55 BOOST_CHECK_MESSAGE( valid == true,
56 "Expected valid geometry, "
57 << " wkt: " << bg::wkt(geometry) );
58
59 BOOST_CHECK_MESSAGE( simple == expected_result,
60 "Expected: " << expected_result
61 << " detected: " << simple
62 << " wkt: " << bg::wkt(geometry) );
63 }
64
65 template <typename CSTag, typename Geometry>
66 void test_simple(Geometry const& geometry, bool expected_result,
67 bool check_validity = true)
68 {
69 #ifdef BOOST_GEOMETRY_TEST_DEBUG
70 std::cout << "=======" << std::endl;
71 #endif
72
73 bool simple = bg::is_simple(geometry);
74 bool valid = ! check_validity || bg::is_valid(geometry);
75
76 BOOST_CHECK_MESSAGE( valid == true,
77 "Expected valid geometry, "
78 << " wkt: " << bg::wkt(geometry) );
79
80 BOOST_CHECK_MESSAGE( simple == expected_result,
81 "Expected: " << expected_result
82 << " detected: " << simple
83 << " wkt: " << bg::wkt(geometry) );
84
85 typedef typename bg::strategy::intersection::services::default_strategy
86 <
87 CSTag
88 >::type strategy_type;
89
90 test_simple_s(geometry, strategy_type(), expected_result, check_validity);
91
92 #ifdef BOOST_GEOMETRY_TEST_DEBUG
93 std::cout << "Geometry: ";
94 pretty_print_geometry<Geometry>::apply(std::cout, geometry);
95 std::cout << std::endl;
96 std::cout << std::boolalpha;
97 std::cout << "is simple: " << simple << std::endl;
98 std::cout << "expected result: " << expected_result << std::endl;
99 std::cout << "=======" << std::endl;
100 std::cout << std::endl << std::endl;
101 std::cout << std::noboolalpha;
102 #endif
103 }
104
105 template <typename Geometry>
106 void test_simple(Geometry const& geometry,
107 bool expected_result,
108 bool check_validity = true)
109 {
110 typedef typename bg::cs_tag<Geometry>::type cs_tag;
111 test_simple<cs_tag>(geometry, expected_result, check_validity);
112 }
113
114 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
115 void test_simple(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& variant_geometry,
116 bool expected_result,
117 bool check_validity = true)
118 {
119 typedef typename bg::cs_tag<T0>::type cs_tag;
120 test_simple<cs_tag>(variant_geometry, expected_result, check_validity);
121 }