1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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_ALGORITHMS_DETAIL_ASSIGN_BOX_CORNERS_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_BOX_CORNERS_HPP
16 
17 
18 #include <cstddef>
19 
20 #include <boost/geometry/geometries/concepts/check.hpp>
21 #include <boost/geometry/algorithms/detail/assign_values.hpp>
22 #include <boost/geometry/util/range.hpp>
23 
24 
25 namespace boost { namespace geometry
26 {
27 
28 #ifndef DOXYGEN_NO_DETAIL
29 namespace detail
30 {
31 // Note: this is moved to namespace detail because the names and parameter orders
32 // are not yet 100% clear.
33 
34 /*!
35 \brief Assign the four points of a 2D box
36 \ingroup assign
37 \note The order is crucial. Most logical is LOWER, UPPER and sub-order LEFT, RIGHT
38     so this is how it is implemented.
39 \tparam Box \tparam_box
40 \tparam Point \tparam_point
41 \param box \param_box
42 \param lower_left point being assigned to lower left coordinates of the box
43 \param lower_right point being assigned to lower right coordinates of the box
44 \param upper_left point being assigned to upper left coordinates of the box
45 \param upper_right point being assigned to upper right coordinates of the box
46 
47 \qbk{
48 [heading Example]
49 [assign_box_corners] [assign_box_corners_output]
50 }
51 */
52 template <typename Box, typename Point>
assign_box_corners(Box const & box,Point & lower_left,Point & lower_right,Point & upper_left,Point & upper_right)53 inline void assign_box_corners(Box const& box,
54         Point& lower_left, Point& lower_right,
55         Point& upper_left, Point& upper_right)
56 {
57     concepts::check<Box const>();
58     concepts::check<Point>();
59 
60     detail::assign::assign_box_2d_corner
61             <min_corner, min_corner>(box, lower_left);
62     detail::assign::assign_box_2d_corner
63             <max_corner, min_corner>(box, lower_right);
64     detail::assign::assign_box_2d_corner
65             <min_corner, max_corner>(box, upper_left);
66     detail::assign::assign_box_2d_corner
67             <max_corner, max_corner>(box, upper_right);
68 }
69 
70 // Silence warning C4127: conditional expression is constant
71 #if defined(_MSC_VER)
72 #pragma warning(push)
73 #pragma warning(disable : 4127)
74 #endif
75 
76 
77 template <bool Reverse, typename Box, typename Range>
assign_box_corners_oriented(Box const & box,Range & corners)78 inline void assign_box_corners_oriented(Box const& box, Range& corners)
79 {
80     if (Reverse)
81     {
82         // make counterclockwise ll,lr,ur,ul
83         assign_box_corners(box,
84                            range::at(corners, 0), range::at(corners, 1),
85                            range::at(corners, 3), range::at(corners, 2));
86     }
87     else
88     {
89         // make clockwise ll,ul,ur,lr
90         assign_box_corners(box,
91                            range::at(corners, 0), range::at(corners, 3),
92                            range::at(corners, 1), range::at(corners, 2));
93     }
94 }
95 #if defined(_MSC_VER)
96 #pragma warning(pop)
97 #endif
98 
99 
100 } // namespace detail
101 #endif // DOXYGEN_NO_DETAIL
102 
103 
104 }} // namespace boost::geometry
105 
106 
107 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_BOX_CORNERS_HPP
108