Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:32

0001 // Boost.Geometry Index
0002 //
0003 // This view makes possible to treat some simple primitives as its bounding geometry
0004 // e.g. box, nsphere, etc.
0005 //
0006 // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
0007 //
0008 // This file was modified by Oracle on 2019-2020.
0009 // Modifications copyright (c) 2019-2020 Oracle and/or its affiliates.
0010 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0011 //
0012 // Use, modification and distribution is subject to the Boost Software License,
0013 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0014 // http://www.boost.org/LICENSE_1_0.txt)
0015 
0016 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP
0017 #define BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP
0018 
0019 
0020 #include <boost/geometry/algorithms/envelope.hpp>
0021 #include <boost/geometry/core/static_assert.hpp>
0022 #include <boost/geometry/strategies/default_strategy.hpp>
0023 #include <boost/geometry/strategies/index/services.hpp>
0024 
0025 
0026 namespace boost { namespace geometry {
0027 
0028 namespace index { namespace detail {
0029 
0030 
0031 template <typename Geometry, typename BoundingGeometry, typename Strategy>
0032 struct bounded_view_base_cs_tag
0033 {
0034     typedef typename Strategy::cs_tag type;
0035 };
0036 
0037 template <typename Geometry, typename BoundingGeometry>
0038 struct bounded_view_base_cs_tag<Geometry, BoundingGeometry, default_strategy>
0039     : geometry::cs_tag<Geometry>
0040 {};
0041 
0042 
0043 template
0044 <
0045     typename Geometry,
0046     typename BoundingGeometry,
0047     typename Strategy,
0048     typename Tag = typename geometry::tag<Geometry>::type,
0049     typename BoundingTag = typename geometry::tag<BoundingGeometry>::type,
0050     typename CSTag = typename bounded_view_base_cs_tag
0051                         <
0052                             Geometry, BoundingGeometry, Strategy
0053                         >::type
0054 >
0055 struct bounded_view_base
0056 {
0057     BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
0058         "Not implemented for these Geometries.",
0059         Geometry, BoundingGeometry, Strategy, Tag, BoundingTag, CSTag);
0060 };
0061 
0062 
0063 // Segment -> Box
0064 
0065 template <typename Segment, typename Box, typename Strategy>
0066 struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, cartesian_tag>
0067 {
0068 public:
0069     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0070 
0071     bounded_view_base(Segment const& segment, Strategy const& )
0072         : m_segment(segment)
0073     {}
0074 
0075     template <std::size_t Dimension>
0076     inline coordinate_type get_min() const
0077     {
0078         return boost::numeric_cast<coordinate_type>(
0079                 (std::min)( geometry::get<0, Dimension>(m_segment),
0080                             geometry::get<1, Dimension>(m_segment) ) );
0081     }
0082 
0083     template <std::size_t Dimension>
0084     inline coordinate_type get_max() const
0085     {
0086         return boost::numeric_cast<coordinate_type>(
0087                 (std::max)( geometry::get<0, Dimension>(m_segment),
0088                             geometry::get<1, Dimension>(m_segment) ) );
0089     }
0090 
0091 private:
0092     Segment const& m_segment;
0093 };
0094 
0095 template <typename Segment, typename Box, typename Strategy, typename CSTag>
0096 struct bounded_view_base<Segment, Box, Strategy, segment_tag, box_tag, CSTag>
0097 {
0098     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0099 
0100     bounded_view_base(Segment const& segment, Strategy const& strategy)
0101     {
0102         geometry::envelope(segment, m_box, strategy);
0103     }
0104 
0105     template <std::size_t Dimension>
0106     inline coordinate_type get_min() const
0107     {
0108         return geometry::get<min_corner, Dimension>(m_box);
0109     }
0110 
0111     template <std::size_t Dimension>
0112     inline coordinate_type get_max() const
0113     {
0114         return geometry::get<max_corner, Dimension>(m_box);
0115     }
0116 
0117 private:
0118     Box m_box;
0119 };
0120 
0121 // Box -> Box
0122 
0123 template <typename BoxIn, typename Box, typename Strategy, typename CSTag>
0124 struct bounded_view_base<BoxIn, Box, Strategy, box_tag, box_tag, CSTag>
0125 {
0126 public:
0127     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0128 
0129     bounded_view_base(BoxIn const& box, Strategy const& )
0130         : m_box(box)
0131     {}
0132 
0133     template <std::size_t Dimension>
0134     inline coordinate_type get_min() const
0135     {
0136         return boost::numeric_cast<coordinate_type>(
0137                 geometry::get<min_corner, Dimension>(m_box) );
0138     }
0139 
0140     template <std::size_t Dimension>
0141     inline coordinate_type get_max() const
0142     {
0143         return boost::numeric_cast<coordinate_type>(
0144                 geometry::get<max_corner, Dimension>(m_box) );
0145     }
0146 
0147 private:
0148     BoxIn const& m_box;
0149 };
0150 
0151 // Point -> Box
0152 
0153 template <typename Point, typename Box, typename Strategy, typename CSTag>
0154 struct bounded_view_base<Point, Box, Strategy, point_tag, box_tag, CSTag>
0155 {
0156 public:
0157     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0158 
0159     bounded_view_base(Point const& point, Strategy const& )
0160         : m_point(point)
0161     {}
0162 
0163     template <std::size_t Dimension>
0164     inline coordinate_type get_min() const
0165     {
0166         return boost::numeric_cast<coordinate_type>(
0167                 geometry::get<Dimension>(m_point) );
0168     }
0169 
0170     template <std::size_t Dimension>
0171     inline coordinate_type get_max() const
0172     {
0173         return boost::numeric_cast<coordinate_type>(
0174                 geometry::get<Dimension>(m_point) );
0175     }
0176 
0177 private:
0178     Point const& m_point;
0179 };
0180 
0181 
0182 template <typename Geometry,
0183           typename BoundingGeometry,
0184           typename Strategy,
0185           typename Tag = typename geometry::tag<Geometry>::type,
0186           typename BoundingTag = typename geometry::tag<BoundingGeometry>::type>
0187 struct bounded_view
0188     : bounded_view_base<Geometry, BoundingGeometry, Strategy>
0189 {
0190     typedef bounded_view_base<Geometry, BoundingGeometry, Strategy> base_type;
0191 
0192     bounded_view(Geometry const& geometry, Strategy const& strategy)
0193         : base_type(geometry, strategy)
0194     {}
0195 };
0196 
0197 template <typename Geometry,
0198           typename BoundingGeometry,
0199           typename Tag,
0200           typename BoundingTag>
0201 struct bounded_view<Geometry, BoundingGeometry, default_strategy, Tag, BoundingTag>
0202     : bounded_view_base
0203         <
0204             Geometry,
0205             BoundingGeometry,
0206             typename strategies::index::services::default_strategy<Geometry>::type
0207         >
0208 {
0209     typedef typename strategies::index::services::default_strategy
0210         <
0211             Geometry
0212         >::type strategy_type;
0213 
0214     typedef bounded_view_base
0215         <
0216             Geometry,
0217             BoundingGeometry,
0218             strategy_type
0219         > base_type;
0220 
0221     explicit bounded_view(Geometry const& geometry, default_strategy const& )
0222         : base_type(geometry, strategy_type())
0223     {}
0224 };
0225 
0226 
0227 }} // namespace index::detail
0228 
0229 // XXX -> Box
0230 
0231 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0232 namespace traits
0233 {
0234 
0235 template <typename Geometry, typename Box, typename Strategy, typename Tag>
0236 struct tag< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> >
0237 {
0238     typedef box_tag type;
0239 };
0240 
0241 template <typename Geometry, typename Box, typename Strategy, typename Tag>
0242 struct point_type< index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> >
0243 {
0244     typedef typename point_type<Box>::type type;
0245 };
0246 
0247 template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension>
0248 struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>,
0249                       min_corner, Dimension>
0250 {
0251     typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type;
0252     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0253 
0254     static inline coordinate_type get(box_type const& b)
0255     {
0256         return b.template get_min<Dimension>();
0257     }
0258 
0259     //static inline void set(box_type & b, coordinate_type const& value)
0260     //{
0261     //    BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view");
0262     //}
0263 };
0264 
0265 template <typename Geometry, typename Box, typename Strategy, typename Tag, std::size_t Dimension>
0266 struct indexed_access<index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag>,
0267                       max_corner, Dimension>
0268 {
0269     typedef index::detail::bounded_view<Geometry, Box, Strategy, Tag, box_tag> box_type;
0270     typedef typename geometry::coordinate_type<Box>::type coordinate_type;
0271 
0272     static inline coordinate_type get(box_type const& b)
0273     {
0274         return b.template get_max<Dimension>();
0275     }
0276 
0277     //static inline void set(box_type & b, coordinate_type const& value)
0278     //{
0279     //    BOOST_GEOMETRY_INDEX_ASSERT(false, "unable to modify a box through view");
0280     //}
0281 };
0282 
0283 } // namespace traits
0284 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0285 
0286 }} // namespace boost::geometry
0287 
0288 #endif // BOOST_GEOMETRY_INDEX_DETAIL_BOUNDED_VIEW_HPP