]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/envelope_expand/test_envelope.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / envelope_expand / test_envelope.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // This file was modified by Oracle on 2021.
7 // Modifications copyright (c) 2021, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_TEST_ENVELOPE_HPP
15 #define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
16
17
18 #include <boost/variant/variant.hpp>
19
20 #include <geometry_test_common.hpp>
21
22 #include <boost/geometry/algorithms/envelope.hpp>
23 #include <boost/geometry/geometries/box.hpp>
24 #include <boost/geometry/geometries/geometry_collection.hpp>
25 #include <boost/geometry/strategies/strategies.hpp>
26
27 #include <boost/geometry/io/wkt/read.hpp>
28
29
30 template<typename Box, std::size_t DimensionCount>
31 struct check_result
32 {};
33
34 template <typename Box>
35 struct check_result<Box, 2>
36 {
37 using ctype = typename bg::coordinate_type<Box>::type;
38 using type = std::conditional_t
39 <
40 (std::is_integral<ctype>::value || std::is_floating_point<ctype>::value),
41 double,
42 ctype
43 >;
44
45 static void apply(Box const& b, const type& x1, const type& y1, const type& /*z1*/,
46 const type& x2, const type& y2, const type& /*z2*/)
47 {
48 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
49 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
50
51 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
52 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
53 }
54 };
55
56 template <typename Box>
57 struct check_result<Box, 3>
58 {
59 using ctype = typename bg::coordinate_type<Box>::type;
60 using type = std::conditional_t
61 <
62 (std::is_integral<ctype>::value || std::is_floating_point<ctype>::value),
63 double,
64 ctype
65 >;
66
67 static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
68 const type& x2, const type& y2, const type& z2)
69 {
70 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
71 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
72 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 2>(b)), z1, 0.001);
73
74 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
75 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
76 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 2>(b)), z2, 0.001);
77 }
78 };
79
80
81 template <typename Geometry, typename T>
82 void test_envelope(std::string const& wkt,
83 const T& x1, const T& x2,
84 const T& y1, const T& y2,
85 const T& z1 = 0, const T& z2 = 0)
86 {
87 typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
88 box_type b;
89
90 Geometry geometry;
91 bg::read_wkt(wkt, geometry);
92 bg::envelope(geometry, b);
93 check_result<box_type, bg::dimension<Geometry>::type::value>
94 ::apply(b, x1, y1, z1, x2, y2, z2);
95
96 boost::variant<Geometry> v(geometry);
97 bg::envelope(v, b);
98 check_result<box_type, bg::dimension<Geometry>::type::value>
99 ::apply(b, x1, y1, z1, x2, y2, z2);
100
101 bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
102 bg::envelope(gc, b);
103 check_result<box_type, bg::dimension<Geometry>::type::value>
104 ::apply(b, x1, y1, z1, x2, y2, z2);
105 }
106
107
108 #endif