Chris@102: // Boost.Geometry Index Chris@102: // Chris@102: // This view makes possible to treat some simple primitives as its bounding geometry Chris@102: // e.g. box, nsphere, etc. Chris@102: // Chris@102: // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. Chris@102: // Chris@102: // Use, modification and distribution is subject to the Boost Software License, Chris@102: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP Chris@102: #define BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP Chris@102: Chris@102: namespace boost { namespace geometry { Chris@102: Chris@102: namespace index { namespace detail { Chris@102: Chris@102: template ::type, Chris@102: typename BoundingTag = typename geometry::tag::type> Chris@102: struct bounded_view Chris@102: { Chris@102: BOOST_MPL_ASSERT_MSG( Chris@102: (false), Chris@102: NOT_IMPLEMENTED_FOR_THOSE_GEOMETRIES, Chris@102: (BoundingTag, Tag)); Chris@102: }; Chris@102: Chris@102: Chris@102: // Segment -> Box Chris@102: Chris@102: template Chris@102: struct bounded_view Chris@102: { Chris@102: public: Chris@102: typedef typename geometry::coordinate_type::type coordinate_type; Chris@102: Chris@102: explicit bounded_view(Segment const& segment) Chris@102: : m_segment(segment) Chris@102: {} Chris@102: Chris@102: template Chris@102: inline coordinate_type get_min() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: (std::min)( geometry::get<0, Dimension>(m_segment), Chris@102: geometry::get<1, Dimension>(m_segment) ) ); Chris@102: } Chris@102: Chris@102: template Chris@102: inline coordinate_type get_max() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: (std::max)( geometry::get<0, Dimension>(m_segment), Chris@102: geometry::get<1, Dimension>(m_segment) ) ); Chris@102: } Chris@102: Chris@102: private: Chris@102: Segment const& m_segment; Chris@102: }; Chris@102: Chris@102: // Box -> Box Chris@102: Chris@102: template Chris@102: struct bounded_view Chris@102: { Chris@102: public: Chris@102: typedef typename geometry::coordinate_type::type coordinate_type; Chris@102: Chris@102: explicit bounded_view(BoxIn const& box) Chris@102: : m_box(box) Chris@102: {} Chris@102: Chris@102: template Chris@102: inline coordinate_type get_min() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: geometry::get(m_box) ); Chris@102: } Chris@102: Chris@102: template Chris@102: inline coordinate_type get_max() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: geometry::get(m_box) ); Chris@102: } Chris@102: Chris@102: private: Chris@102: BoxIn const& m_box; Chris@102: }; Chris@102: Chris@102: // Point -> Box Chris@102: Chris@102: template Chris@102: struct bounded_view Chris@102: { Chris@102: public: Chris@102: typedef typename geometry::coordinate_type::type coordinate_type; Chris@102: Chris@102: explicit bounded_view(Point const& point) Chris@102: : m_point(point) Chris@102: {} Chris@102: Chris@102: template Chris@102: inline coordinate_type get_min() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: geometry::get(m_point) ); Chris@102: } Chris@102: Chris@102: template Chris@102: inline coordinate_type get_max() const Chris@102: { Chris@102: return boost::numeric_cast( Chris@102: geometry::get(m_point) ); Chris@102: } Chris@102: Chris@102: private: Chris@102: Point const& m_point; Chris@102: }; Chris@102: Chris@102: }} // namespace index::detail Chris@102: Chris@102: // XXX -> Box Chris@102: Chris@102: #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@102: namespace traits Chris@102: { Chris@102: Chris@102: template Chris@102: struct tag< index::detail::bounded_view > Chris@102: { Chris@102: typedef box_tag type; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct point_type< index::detail::bounded_view > Chris@102: { Chris@102: typedef typename point_type::type type; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct indexed_access, Chris@102: min_corner, Dimension> Chris@102: { Chris@102: typedef index::detail::bounded_view box_type; Chris@102: typedef typename geometry::coordinate_type::type coordinate_type; Chris@102: Chris@102: static inline coordinate_type get(box_type const& b) Chris@102: { Chris@102: return b.template get_min(); Chris@102: } Chris@102: Chris@102: //static inline void set(box_type & b, coordinate_type const& value) Chris@102: //{ Chris@102: // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); Chris@102: //} Chris@102: }; Chris@102: Chris@102: template Chris@102: struct indexed_access, Chris@102: max_corner, Dimension> Chris@102: { Chris@102: typedef index::detail::bounded_view box_type; Chris@102: typedef typename geometry::coordinate_type::type coordinate_type; Chris@102: Chris@102: static inline coordinate_type get(box_type const& b) Chris@102: { Chris@102: return b.template get_max(); Chris@102: } Chris@102: Chris@102: //static inline void set(box_type & b, coordinate_type const& value) Chris@102: //{ Chris@102: // BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view"); Chris@102: //} Chris@102: }; Chris@102: Chris@102: } // namespace traits Chris@102: #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: #endif // BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP