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_GEOMETRIES_BOX_HPP
15#define BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
16
17#include <cstddef>
18
19#include <boost/concept/assert.hpp>
20#include <boost/config.hpp>
21
22#include <boost/geometry/algorithms/convert.hpp>
23#include <boost/geometry/geometries/concepts/point_concept.hpp>
24
25#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
26#include <boost/geometry/core/assert.hpp>
27#endif
28
29
30namespace boost { namespace geometry
31{
32
33namespace model
34{
35
36/*!
37\brief Class box: defines a box made of two describing points
38\ingroup geometries
39\details Box is always described by a min_corner() and a max_corner() point. If another
40 rectangle is used, use linear_ring or polygon.
41\note Boxes are for selections and for calculating the envelope of geometries. Not all algorithms
42are implemented for box. Boxes are also used in Spatial Indexes.
43\tparam Point point type. The box takes a point type as template parameter.
44The point type can be any point type.
45It can be 2D but can also be 3D or more dimensional.
46The box can also take a latlong point type as template parameter.
47
48\qbk{[include reference/geometries/box.qbk]}
49\qbk{before.synopsis, [heading Model of]}
50\qbk{before.synopsis, [link geometry.reference.concepts.concept_box Box Concept]}
51 */
52
53template<typename Point>
54class box
55{
56 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
57
58public:
59
60#if !defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
61#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
62 /// \constructor_default_no_init
63 box() = default;
64#else
65 /// \constructor_default_no_init
66 inline box()
67 {}
68#endif
69#else // defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
70 inline box()
71 {
72 m_created = 1;
73 }
74 ~box()
75 {
76 m_created = 0;
77 }
78#endif
79
80 /*!
81 \brief Constructor taking the minimum corner point and the maximum corner point
82 */
83 inline box(Point const& min_corner, Point const& max_corner)
84 {
85 geometry::convert(min_corner, m_min_corner);
86 geometry::convert(max_corner, m_max_corner);
87
88#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
89 m_created = 1;
90#endif
91 }
92
93 inline Point const& min_corner() const
94 {
95#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
96 BOOST_GEOMETRY_ASSERT(m_created == 1);
97#endif
98 return m_min_corner;
99 }
100 inline Point const& max_corner() const
101 {
102#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
103 BOOST_GEOMETRY_ASSERT(m_created == 1);
104#endif
105 return m_max_corner;
106 }
107
108 inline Point& min_corner()
109 {
110#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
111 BOOST_GEOMETRY_ASSERT(m_created == 1);
112#endif
113 return m_min_corner;
114 }
115 inline Point& max_corner()
116 {
117#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
118 BOOST_GEOMETRY_ASSERT(m_created == 1);
119#endif
120 return m_max_corner;
121 }
122
123private:
124
125 Point m_min_corner;
126 Point m_max_corner;
127
128#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
129 int m_created;
130#endif
131};
132
133
134} // namespace model
135
136
137// Traits specializations for box above
138#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
139namespace traits
140{
141
142template <typename Point>
143struct tag<model::box<Point> >
144{
145 typedef box_tag type;
146};
147
148template <typename Point>
149struct point_type<model::box<Point> >
150{
151 typedef Point type;
152};
153
154template <typename Point, std::size_t Dimension>
155struct indexed_access<model::box<Point>, min_corner, Dimension>
156{
157 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
158
159 static inline coordinate_type get(model::box<Point> const& b)
160 {
161 return geometry::get<Dimension>(b.min_corner());
162 }
163
164 static inline void set(model::box<Point>& b, coordinate_type const& value)
165 {
166 geometry::set<Dimension>(b.min_corner(), value);
167 }
168};
169
170template <typename Point, std::size_t Dimension>
171struct indexed_access<model::box<Point>, max_corner, Dimension>
172{
173 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
174
175 static inline coordinate_type get(model::box<Point> const& b)
176 {
177 return geometry::get<Dimension>(b.max_corner());
178 }
179
180 static inline void set(model::box<Point>& b, coordinate_type const& value)
181 {
182 geometry::set<Dimension>(b.max_corner(), value);
183 }
184};
185
186} // namespace traits
187#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
188
189}} // namespace boost::geometry
190
191#endif // BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
192

source code of boost/boost/geometry/geometries/box.hpp