1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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_GEOMETRIES_BOX_HPP
15 #define BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
19 #include <boost/concept/assert.hpp>
20 #include <boost/config.hpp>
22 #include <boost/geometry/algorithms/convert.hpp>
23 #include <boost/geometry/geometries/concepts/point_concept.hpp>
25 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
26 #include <boost/geometry/core/assert.hpp>
30 namespace boost { namespace geometry
37 \brief Class box: defines a box made of two describing points
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
42 are implemented for box. Boxes are also used in Spatial Indexes.
43 \tparam Point point type. The box takes a point type as template parameter.
44 The point type can be any point type.
45 It can be 2D but can also be 3D or more dimensional.
46 The box can also take a latlong point type as template parameter.
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]}
53 template<typename Point>
56 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
60 #if !defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
61 #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
62 /// \constructor_default_no_init
65 /// \constructor_default_no_init
69 #else // defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
81 \brief Constructor taking the minimum corner point and the maximum corner point
83 inline box(Point const& min_corner, Point const& max_corner)
85 geometry::convert(min_corner, m_min_corner);
86 geometry::convert(max_corner, m_max_corner);
88 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
93 inline Point const& min_corner() const
95 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
96 BOOST_GEOMETRY_ASSERT(m_created == 1);
100 inline Point const& max_corner() const
102 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
103 BOOST_GEOMETRY_ASSERT(m_created == 1);
108 inline Point& min_corner()
110 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
111 BOOST_GEOMETRY_ASSERT(m_created == 1);
115 inline Point& max_corner()
117 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
118 BOOST_GEOMETRY_ASSERT(m_created == 1);
128 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
137 // Traits specializations for box above
138 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
142 template <typename Point>
143 struct tag<model::box<Point> >
145 typedef box_tag type;
148 template <typename Point>
149 struct point_type<model::box<Point> >
154 template <typename Point, std::size_t Dimension>
155 struct indexed_access<model::box<Point>, min_corner, Dimension>
157 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
159 static inline coordinate_type get(model::box<Point> const& b)
161 return geometry::get<Dimension>(b.min_corner());
164 static inline void set(model::box<Point>& b, coordinate_type const& value)
166 geometry::set<Dimension>(b.min_corner(), value);
170 template <typename Point, std::size_t Dimension>
171 struct indexed_access<model::box<Point>, max_corner, Dimension>
173 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
175 static inline coordinate_type get(model::box<Point> const& b)
177 return geometry::get<Dimension>(b.max_corner());
180 static inline void set(model::box<Point>& b, coordinate_type const& value)
182 geometry::set<Dimension>(b.max_corner(), value);
186 } // namespace traits
187 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
189 }} // namespace boost::geometry
191 #endif // BOOST_GEOMETRY_GEOMETRIES_BOX_HPP