1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
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
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)
14 #ifndef BOOST_GEOMETRY_TEST_ENVELOPE_HPP
15 #define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
18 #include <boost/variant/variant.hpp>
20 #include <geometry_test_common.hpp>
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>
27 #include <boost/geometry/io/wkt/read.hpp>
30 template<typename Box, std::size_t DimensionCount>
34 template <typename Box>
35 struct check_result<Box, 2>
37 using ctype = typename bg::coordinate_type<Box>::type;
38 using type = std::conditional_t
40 (std::is_integral<ctype>::value || std::is_floating_point<ctype>::value),
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*/)
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);
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);
56 template <typename Box>
57 struct check_result<Box, 3>
59 using ctype = typename bg::coordinate_type<Box>::type;
60 using type = std::conditional_t
62 (std::is_integral<ctype>::value || std::is_floating_point<ctype>::value),
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)
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);
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);
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)
87 typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
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);
96 boost::variant<Geometry> v(geometry);
98 check_result<box_type, bg::dimension<Geometry>::type::value>
99 ::apply(b, x1, y1, z1, x2, y2, z2);
101 bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
103 check_result<box_type, bg::dimension<Geometry>::type::value>
104 ::apply(b, x1, y1, z1, x2, y2, z2);