// Boost.Geometry Index // // This view makes possible to treat some simple primitives as its bounding geometry // e.g. box, nsphere, etc. // // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland. // // This file was modified by Oracle on 2019-2020. // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP #include #include #include #include namespace boost { namespace geometry { namespace index { namespace detail { template struct bounded_view_base_cs_tag { using type = typename Strategy::cs_tag; }; template struct bounded_view_base_cs_tag : geometry::cs_tag {}; template < typename Geometry, typename BoundingGeometry, typename Strategy, typename Tag = geometry::tag_t, typename BoundingTag = geometry::tag_t, typename CSTag = typename bounded_view_base_cs_tag < Geometry, BoundingGeometry, Strategy >::type > struct bounded_view_base { BOOST_GEOMETRY_STATIC_ASSERT_FALSE( "Not implemented for these Geometries.", Geometry, BoundingGeometry, Strategy, Tag, BoundingTag, CSTag); }; // Segment -> Box template struct bounded_view_base { public: using coordinate_type = geometry::coordinate_type_t; bounded_view_base(Segment const& segment, Strategy const& ) : m_segment(segment) {} template inline coordinate_type get_min() const { return boost::numeric_cast( (std::min)( geometry::get<0, Dimension>(m_segment), geometry::get<1, Dimension>(m_segment) ) ); } template inline coordinate_type get_max() const { return boost::numeric_cast( (std::max)( geometry::get<0, Dimension>(m_segment), geometry::get<1, Dimension>(m_segment) ) ); } private: Segment const& m_segment; }; template struct bounded_view_base { using coordinate_type = geometry::coordinate_type_t; bounded_view_base(Segment const& segment, Strategy const& strategy) { geometry::envelope(segment, m_box, strategy); } template inline coordinate_type get_min() const { return geometry::get(m_box); } template inline coordinate_type get_max() const { return geometry::get(m_box); } private: Box m_box; }; // Box -> Box template struct bounded_view_base { public: using coordinate_type = geometry::coordinate_type_t; bounded_view_base(BoxIn const& box, Strategy const& ) : m_box(box) {} template inline coordinate_type get_min() const { return boost::numeric_cast( geometry::get(m_box) ); } template inline coordinate_type get_max() const { return boost::numeric_cast( geometry::get(m_box) ); } private: BoxIn const& m_box; }; // Point -> Box template struct bounded_view_base { public: using coordinate_type = geometry::coordinate_type_t; bounded_view_base(Point const& point, Strategy const& ) : m_point(point) {} template inline coordinate_type get_min() const { return boost::numeric_cast( geometry::get(m_point) ); } template inline coordinate_type get_max() const { return boost::numeric_cast( geometry::get(m_point) ); } private: Point const& m_point; }; template , typename BoundingTag = geometry::tag_t> struct bounded_view : bounded_view_base { typedef bounded_view_base base_type; bounded_view(Geometry const& geometry, Strategy const& strategy) : base_type(geometry, strategy) {} }; template struct bounded_view : bounded_view_base < Geometry, BoundingGeometry, typename strategies::index::services::default_strategy::type > { typedef typename strategies::index::services::default_strategy < Geometry >::type strategy_type; typedef bounded_view_base < Geometry, BoundingGeometry, strategy_type > base_type; explicit bounded_view(Geometry const& geometry, default_strategy const& ) : base_type(geometry, strategy_type()) {} }; }} // namespace index::detail // XXX -> Box #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS namespace traits { template struct tag< index::detail::bounded_view > { using type = box_tag; }; template struct point_type< index::detail::bounded_view > { using type = point_type_t; }; template struct indexed_access, min_corner, Dimension> { typedef index::detail::bounded_view box_type; using coordinate_type = geometry::coordinate_type_t; static inline coordinate_type get(box_type const& b) { return b.template get_min(); } //static inline void set(box_type & b, coordinate_type const& value) //{ // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); //} }; template struct indexed_access, max_corner, Dimension> { typedef index::detail::bounded_view box_type; using coordinate_type = geometry::coordinate_type_t; static inline coordinate_type get(box_type const& b) { return b.template get_max(); } //static inline void set(box_type & b, coordinate_type const& value) //{ // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); //} }; } // namespace traits #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS }} // namespace boost::geometry #endif // BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP