]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/envelope_expand/test_envelope.hpp
add subtree-ish sources for 12.0.3
[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 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 #ifndef BOOST_GEOMETRY_TEST_ENVELOPE_HPP
10 #define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
11
12
13 #include <boost/variant/variant.hpp>
14
15 #include <geometry_test_common.hpp>
16
17 #include <boost/geometry/algorithms/envelope.hpp>
18 #include <boost/geometry/geometries/box.hpp>
19 #include <boost/geometry/strategies/strategies.hpp>
20
21 #include <boost/geometry/io/wkt/read.hpp>
22
23
24 template<typename Box, std::size_t DimensionCount>
25 struct check_result
26 {};
27
28 template <typename Box>
29 struct check_result<Box, 2>
30 {
31 typedef typename bg::coordinate_type<Box>::type ctype;
32 typedef typename boost::mpl::if_
33 <
34 boost::is_arithmetic<ctype>,
35 double,
36 ctype
37 >::type type;
38
39 static void apply(Box const& b, const type& x1, const type& y1, const type& /*z1*/,
40 const type& x2, const type& y2, const type& /*z2*/)
41 {
42 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
43 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
44
45 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
46 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
47 }
48 };
49
50 template <typename Box>
51 struct check_result<Box, 3>
52 {
53 typedef typename bg::coordinate_type<Box>::type ctype;
54 typedef typename boost::mpl::if_
55 <
56 boost::is_arithmetic<ctype>,
57 double,
58 ctype
59 >::type type;
60
61 static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
62 const type& x2, const type& y2, const type& z2)
63 {
64 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
65 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
66 BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 2>(b)), z1, 0.001);
67
68 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
69 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
70 BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 2>(b)), z2, 0.001);
71 }
72 };
73
74
75 template <typename Geometry, typename T>
76 void test_envelope(std::string const& wkt,
77 const T& x1, const T& x2,
78 const T& y1, const T& y2,
79 const T& z1 = 0, const T& z2 = 0)
80 {
81 typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
82 box_type b;
83
84 Geometry geometry;
85 bg::read_wkt(wkt, geometry);
86 bg::envelope(geometry, b);
87 check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
88
89 boost::variant<Geometry> v(geometry);
90 bg::envelope(v, b);
91 check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
92 }
93
94
95 #endif