#### /Src/Dependencies/Boost/libs/geometry/test/algorithms/test_envelope.hpp

C++ Header | 107 lines | 77 code | 24 blank | 6 comment | 0 complexity | 1b8f55bb0cb70442d7428c3d567b8f39 MD5 | raw file
```  1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2007-2011 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
8
9#ifndef BOOST_GEOMETRY_TEST_ENVELOPE_HPP
10#define BOOST_GEOMETRY_TEST_ENVELOPE_HPP
11
12
13#include <geometry_test_common.hpp>
14
15#include <boost/geometry/algorithms/envelope.hpp>
16#include <boost/geometry/geometries/box.hpp>
17#include <boost/geometry/strategies/strategies.hpp>
18
20
21
22template<typename Box, std::size_t DimensionCount>
23struct check_result
24{};
25
26template <typename Box>
27struct check_result<Box, 2>
28{
29    typedef typename bg::coordinate_type<Box>::type ctype;
30    typedef typename boost::mpl::if_
31            <
32                boost::is_arithmetic<ctype>,
33                double,
34                ctype
35            >::type type;
36
37    static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
38                const type& x2, const type& y2, const type& z2)
39    {
40        BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
41        BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
42
43        BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
44        BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
45    }
46};
47
48template <typename Box>
49struct check_result<Box, 3>
50{
51    typedef typename bg::coordinate_type<Box>::type ctype;
52    typedef typename boost::mpl::if_
53            <
54                boost::is_arithmetic<ctype>,
55                double,
56                ctype
57            >::type type;
58
59    static void apply(Box const& b, const type& x1, const type& y1, const type& z1,
60                const type& x2, const type& y2, const type& z2)
61    {
62        BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001);
63        BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001);
64        BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 2>(b)), z1, 0.001);
65
66        BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001);
67        BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001);
68        BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 2>(b)), z2, 0.001);
69    }
70};
71
72
73template <typename Geometry, typename T>
74void test_envelope(std::string const& wkt,
75                   const T& x1, const T& x2,
76                   const T& y1, const T& y2,
77                   const T& z1 = 0, const T& z2 = 0)
78{
79    typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
80
81    Geometry geometry;
83    box_type b;
84    bg::envelope(geometry, b);
85
86    check_result<box_type, bg::dimension<Geometry>::type::value>::apply(b, x1, y1, z1, x2, y2, z2);
87}
88
89template <typename Geometry, typename T>
90void test_envelope_strategy(std::string const& wkt,
91                   const T& x1, const T& x2,
92                   const T& y1, const T& y2,
93                   const T& z1 = 0, const T& z2 = 0)
94{
95    typedef bg::model::box<typename bg::point_type<Geometry>::type > box_type;
96
97    Geometry geometry;