// 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. // // 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 namespace boost { namespace geometry { namespace index { namespace detail { template ::type, typename BoundingTag = typename geometry::tag::type, typename CSystem = typename geometry::coordinate_system::type> struct bounded_view { BOOST_MPL_ASSERT_MSG( (false), NOT_IMPLEMENTED_FOR_THOSE_GEOMETRIES, (BoundingTag, Tag)); }; // Segment -> Box template struct bounded_view { public: typedef typename geometry::coordinate_type::type coordinate_type; explicit bounded_view(Segment const& segment) : 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 { public: typedef typename geometry::coordinate_type::type coordinate_type; explicit bounded_view(Segment const& segment) { geometry::envelope(segment, m_box); } 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 { public: typedef typename geometry::coordinate_type::type coordinate_type; explicit bounded_view(BoxIn const& box) : 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 { public: typedef typename geometry::coordinate_type::type coordinate_type; explicit bounded_view(Point const& point) : 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; }; }} // namespace index::detail // XXX -> Box #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS namespace traits { template struct tag< index::detail::bounded_view > { typedef box_tag type; }; template struct point_type< index::detail::bounded_view > { typedef typename point_type::type type; }; template struct indexed_access, min_corner, Dimension> { typedef index::detail::bounded_view box_type; typedef typename geometry::coordinate_type::type coordinate_type; 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; typedef typename geometry::coordinate_type::type coordinate_type; 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