| 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 | // 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 |
| 10 | |
| 11 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library |
| 12 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. |
| 13 | |
| 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) |
| 17 | |
| 18 | #ifndef BOOST_GEOMETRY_GEOMETRIES_BOX_HPP |
| 19 | #define BOOST_GEOMETRY_GEOMETRIES_BOX_HPP |
| 20 | |
| 21 | #include <cstddef> |
| 22 | #include <type_traits> |
| 23 | |
| 24 | #include <boost/concept/assert.hpp> |
| 25 | |
| 26 | #include <boost/geometry/algorithms/convert.hpp> |
| 27 | |
| 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> |
| 33 | |
| 34 | #include <boost/geometry/geometries/concepts/point_concept.hpp> |
| 35 | |
| 36 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 37 | #include <boost/geometry/core/assert.hpp> |
| 38 | #endif |
| 39 | |
| 40 | |
| 41 | namespace boost { namespace geometry |
| 42 | { |
| 43 | |
| 44 | namespace model |
| 45 | { |
| 46 | |
| 47 | /*! |
| 48 | \brief Class box: defines a box made of two describing points |
| 49 | \ingroup geometries |
| 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. |
| 58 | |
| 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]} |
| 62 | */ |
| 63 | |
| 64 | template<typename Point> |
| 65 | class box |
| 66 | { |
| 67 | BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); |
| 68 | |
| 69 | public: |
| 70 | |
| 71 | // TODO: constexpr requires LiteralType and until C++20 |
| 72 | // it has to have trivial destructor which makes access |
| 73 | // debugging impossible with constexpr. |
| 74 | |
| 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) |
| 79 | box() |
| 80 | { |
| 81 | m_created = 1; |
| 82 | } |
| 83 | ~box() |
| 84 | { |
| 85 | m_created = 0; |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | /*! |
| 90 | \brief Constructor taking the minimum corner point and the maximum corner point |
| 91 | */ |
| 92 | template |
| 93 | < |
| 94 | typename P = Point, |
| 95 | std::enable_if_t |
| 96 | < |
| 97 | ! std::is_copy_constructible<P>::value, |
| 98 | int |
| 99 | > = 0 |
| 100 | > |
| 101 | box(Point const& min_corner, Point const& max_corner) |
| 102 | { |
| 103 | geometry::convert(min_corner, m_min_corner); |
| 104 | geometry::convert(max_corner, m_max_corner); |
| 105 | |
| 106 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 107 | m_created = 1; |
| 108 | #endif |
| 109 | } |
| 110 | |
| 111 | /*! |
| 112 | \brief Constructor taking the minimum corner point and the maximum corner point |
| 113 | */ |
| 114 | template |
| 115 | < |
| 116 | typename P = Point, |
| 117 | std::enable_if_t |
| 118 | < |
| 119 | std::is_copy_constructible<P>::value, |
| 120 | int |
| 121 | > = 0 |
| 122 | > |
| 123 | #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 124 | constexpr |
| 125 | #endif |
| 126 | box(Point const& min_corner, Point const& max_corner) |
| 127 | : m_min_corner(min_corner) |
| 128 | , m_max_corner(max_corner) |
| 129 | { |
| 130 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 131 | m_created = 1; |
| 132 | #endif |
| 133 | } |
| 134 | |
| 135 | #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 136 | constexpr |
| 137 | #endif |
| 138 | Point const& min_corner() const |
| 139 | { |
| 140 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 141 | BOOST_GEOMETRY_ASSERT(m_created == 1); |
| 142 | #endif |
| 143 | return m_min_corner; |
| 144 | } |
| 145 | |
| 146 | #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 147 | constexpr |
| 148 | #endif |
| 149 | Point const& max_corner() const |
| 150 | { |
| 151 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 152 | BOOST_GEOMETRY_ASSERT(m_created == 1); |
| 153 | #endif |
| 154 | return m_max_corner; |
| 155 | } |
| 156 | |
| 157 | Point& min_corner() |
| 158 | { |
| 159 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 160 | BOOST_GEOMETRY_ASSERT(m_created == 1); |
| 161 | #endif |
| 162 | return m_min_corner; |
| 163 | } |
| 164 | |
| 165 | Point& max_corner() |
| 166 | { |
| 167 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 168 | BOOST_GEOMETRY_ASSERT(m_created == 1); |
| 169 | #endif |
| 170 | return m_max_corner; |
| 171 | } |
| 172 | |
| 173 | private: |
| 174 | |
| 175 | Point m_min_corner; |
| 176 | Point m_max_corner; |
| 177 | |
| 178 | #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING) |
| 179 | int m_created; |
| 180 | #endif |
| 181 | }; |
| 182 | |
| 183 | |
| 184 | } // namespace model |
| 185 | |
| 186 | |
| 187 | // Traits specializations for box above |
| 188 | #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS |
| 189 | namespace traits |
| 190 | { |
| 191 | |
| 192 | template <typename Point> |
| 193 | struct tag<model::box<Point> > |
| 194 | { |
| 195 | typedef box_tag type; |
| 196 | }; |
| 197 | |
| 198 | template <typename Point> |
| 199 | struct point_type<model::box<Point> > |
| 200 | { |
| 201 | typedef Point type; |
| 202 | }; |
| 203 | |
| 204 | template <typename Point, std::size_t Dimension> |
| 205 | struct indexed_access<model::box<Point>, min_corner, Dimension> |
| 206 | { |
| 207 | typedef typename geometry::coordinate_type<Point>::type coordinate_type; |
| 208 | |
| 209 | static constexpr coordinate_type get(model::box<Point> const& b) |
| 210 | { |
| 211 | return geometry::get<Dimension>(b.min_corner()); |
| 212 | } |
| 213 | |
| 214 | static void set(model::box<Point>& b, coordinate_type const& value) |
| 215 | { |
| 216 | geometry::set<Dimension>(b.min_corner(), value); |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | template <typename Point, std::size_t Dimension> |
| 221 | struct indexed_access<model::box<Point>, max_corner, Dimension> |
| 222 | { |
| 223 | typedef typename geometry::coordinate_type<Point>::type coordinate_type; |
| 224 | |
| 225 | static constexpr coordinate_type get(model::box<Point> const& b) |
| 226 | { |
| 227 | return geometry::get<Dimension>(b.max_corner()); |
| 228 | } |
| 229 | |
| 230 | static void set(model::box<Point>& b, coordinate_type const& value) |
| 231 | { |
| 232 | geometry::set<Dimension>(b.max_corner(), value); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | template <typename Point> |
| 237 | struct make<model::box<Point> > |
| 238 | { |
| 239 | typedef model::box<Point> box_type; |
| 240 | |
| 241 | static const bool is_specialized = true; |
| 242 | |
| 243 | static constexpr box_type apply(Point const& min_corner, Point const& max_corner) |
| 244 | { |
| 245 | return box_type(min_corner, max_corner); |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | |
| 250 | } // namespace traits |
| 251 | #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS |
| 252 | |
| 253 | }} // namespace boost::geometry |
| 254 | |
| 255 | #endif // BOOST_GEOMETRY_GEOMETRIES_BOX_HPP |
| 256 | |