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 // This file was modified by Oracle on 2020.
8 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
19 #define BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
22 #include <type_traits>
24 #include <boost/concept/assert.hpp>
26 #include <boost/geometry/algorithms/convert.hpp>
28 #include <boost/geometry/core/access.hpp>
29 #include <boost/geometry/core/make.hpp>
30 #include <boost/geometry/core/point_type.hpp>
31 #include <boost/geometry/core/tag.hpp>
32 #include <boost/geometry/core/tags.hpp>
34 #include <boost/geometry/geometries/concepts/point_concept.hpp>
36 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
37 #include <boost/geometry/core/assert.hpp>
41 namespace boost { namespace geometry
48 \brief Class box: defines a box made of two describing points
50 \details Box is always described by a min_corner() and a max_corner() point. If another
51 rectangle is used, use linear_ring or polygon.
52 \note Boxes are for selections and for calculating the envelope of geometries. Not all algorithms
53 are implemented for box. Boxes are also used in Spatial Indexes.
54 \tparam Point point type. The box takes a point type as template parameter.
55 The point type can be any point type.
56 It can be 2D but can also be 3D or more dimensional.
57 The box can also take a latlong point type as template parameter.
59 \qbk{[include reference/geometries/box.qbk]}
60 \qbk{before.synopsis, [heading Model of]}
61 \qbk{before.synopsis, [link geometry.reference.concepts.concept_box Box Concept]}
64 template<typename Point>
67 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
71 // TODO: constexpr requires LiteralType and until C++20
72 // it has to have trivial destructor which makes access
73 // debugging impossible with constexpr.
75 #if !defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
76 /// \constructor_default_no_init
77 constexpr box() = default;
78 #else // defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
90 \brief Constructor taking the minimum corner point and the maximum corner point
97 ! std::is_copy_constructible<P>::value,
101 box(Point const& min_corner, Point const& max_corner)
103 geometry::convert(min_corner, m_min_corner);
104 geometry::convert(max_corner, m_max_corner);
106 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
112 \brief Constructor taking the minimum corner point and the maximum corner point
119 std::is_copy_constructible<P>::value,
123 #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
126 box(Point const& min_corner, Point const& max_corner)
127 : m_min_corner(min_corner)
128 , m_max_corner(max_corner)
130 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
135 #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
138 Point const& min_corner() const
140 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
141 BOOST_GEOMETRY_ASSERT(m_created == 1);
146 #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
149 Point const& max_corner() const
151 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
152 BOOST_GEOMETRY_ASSERT(m_created == 1);
159 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
160 BOOST_GEOMETRY_ASSERT(m_created == 1);
167 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
168 BOOST_GEOMETRY_ASSERT(m_created == 1);
178 #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
187 // Traits specializations for box above
188 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
192 template <typename Point>
193 struct tag<model::box<Point> >
195 typedef box_tag type;
198 template <typename Point>
199 struct point_type<model::box<Point> >
204 template <typename Point, std::size_t Dimension>
205 struct indexed_access<model::box<Point>, min_corner, Dimension>
207 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
209 static constexpr coordinate_type get(model::box<Point> const& b)
211 return geometry::get<Dimension>(b.min_corner());
214 static void set(model::box<Point>& b, coordinate_type const& value)
216 geometry::set<Dimension>(b.min_corner(), value);
220 template <typename Point, std::size_t Dimension>
221 struct indexed_access<model::box<Point>, max_corner, Dimension>
223 typedef typename geometry::coordinate_type<Point>::type coordinate_type;
225 static constexpr coordinate_type get(model::box<Point> const& b)
227 return geometry::get<Dimension>(b.max_corner());
230 static void set(model::box<Point>& b, coordinate_type const& value)
232 geometry::set<Dimension>(b.max_corner(), value);
236 template <typename Point>
237 struct make<model::box<Point> >
239 typedef model::box<Point> box_type;
241 static const bool is_specialized = true;
243 static constexpr box_type apply(Point const& min_corner, Point const& max_corner)
245 return box_type(min_corner, max_corner);
250 } // namespace traits
251 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
253 }} // namespace boost::geometry
255 #endif // BOOST_GEOMETRY_GEOMETRIES_BOX_HPP