123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #ifndef BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
- #define BOOST_GEOMETRY_GEOMETRIES_BOX_HPP
- #include <cstddef>
- #include <type_traits>
- #include <boost/concept/assert.hpp>
- #include <boost/geometry/algorithms/convert.hpp>
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/make.hpp>
- #include <boost/geometry/core/point_type.hpp>
- #include <boost/geometry/core/tag.hpp>
- #include <boost/geometry/core/tags.hpp>
- #include <boost/geometry/geometries/concepts/point_concept.hpp>
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- #include <boost/geometry/core/assert.hpp>
- #endif
- namespace boost { namespace geometry
- {
- namespace model
- {
- template<typename Point>
- class box
- {
- BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
- public:
-
-
-
- #if !defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
-
- constexpr box() = default;
- #else
- box()
- {
- m_created = 1;
- }
- ~box()
- {
- m_created = 0;
- }
- #endif
-
- template
- <
- typename P = Point,
- std::enable_if_t
- <
- ! std::is_copy_constructible<P>::value,
- int
- > = 0
- >
- box(Point const& min_corner, Point const& max_corner)
- {
- geometry::convert(min_corner, m_min_corner);
- geometry::convert(max_corner, m_max_corner);
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- m_created = 1;
- #endif
- }
-
- template
- <
- typename P = Point,
- std::enable_if_t
- <
- std::is_copy_constructible<P>::value,
- int
- > = 0
- >
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- box(Point const& min_corner, Point const& max_corner)
- : m_min_corner(min_corner)
- , m_max_corner(max_corner)
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- m_created = 1;
- #endif
- }
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- Point const& min_corner() const
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- #endif
- return m_min_corner;
- }
- #if ! defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- constexpr
- #endif
- Point const& max_corner() const
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- #endif
- return m_max_corner;
- }
- Point& min_corner()
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- #endif
- return m_min_corner;
- }
- Point& max_corner()
- {
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- BOOST_GEOMETRY_ASSERT(m_created == 1);
- #endif
- return m_max_corner;
- }
- private:
- Point m_min_corner;
- Point m_max_corner;
- #if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
- int m_created;
- #endif
- };
- }
- #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
- namespace traits
- {
- template <typename Point>
- struct tag<model::box<Point> >
- {
- typedef box_tag type;
- };
- template <typename Point>
- struct point_type<model::box<Point> >
- {
- typedef Point type;
- };
- template <typename Point, std::size_t Dimension>
- struct indexed_access<model::box<Point>, min_corner, Dimension>
- {
- typedef typename geometry::coordinate_type<Point>::type coordinate_type;
- static constexpr coordinate_type get(model::box<Point> const& b)
- {
- return geometry::get<Dimension>(b.min_corner());
- }
- static void set(model::box<Point>& b, coordinate_type const& value)
- {
- geometry::set<Dimension>(b.min_corner(), value);
- }
- };
- template <typename Point, std::size_t Dimension>
- struct indexed_access<model::box<Point>, max_corner, Dimension>
- {
- typedef typename geometry::coordinate_type<Point>::type coordinate_type;
- static constexpr coordinate_type get(model::box<Point> const& b)
- {
- return geometry::get<Dimension>(b.max_corner());
- }
- static void set(model::box<Point>& b, coordinate_type const& value)
- {
- geometry::set<Dimension>(b.max_corner(), value);
- }
- };
- template <typename Point>
- struct make<model::box<Point> >
- {
- typedef model::box<Point> box_type;
- static const bool is_specialized = true;
- static constexpr box_type apply(Point const& min_corner, Point const& max_corner)
- {
- return box_type(min_corner, max_corner);
- }
- };
- }
- #endif
- }}
- #endif
|