bounds.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Boost.Geometry Index
  2. //
  3. // n-dimensional bounds
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
  12. #include <boost/geometry/index/detail/bounded_view.hpp>
  13. namespace boost { namespace geometry { namespace index { namespace detail {
  14. namespace dispatch {
  15. template <typename Geometry,
  16. typename Bounds,
  17. typename TagGeometry = typename geometry::tag<Geometry>::type,
  18. typename TagBounds = typename geometry::tag<Bounds>::type>
  19. struct bounds
  20. {
  21. static inline void apply(Geometry const& g, Bounds & b)
  22. {
  23. geometry::convert(g, b);
  24. }
  25. };
  26. template <typename Geometry, typename Bounds>
  27. struct bounds<Geometry, Bounds, segment_tag, box_tag>
  28. {
  29. static inline void apply(Geometry const& g, Bounds & b)
  30. {
  31. index::detail::bounded_view<Geometry, Bounds> v(g);
  32. geometry::convert(v, b);
  33. }
  34. };
  35. } // namespace dispatch
  36. template <typename Geometry, typename Bounds>
  37. inline void bounds(Geometry const& g, Bounds & b)
  38. {
  39. concepts::check_concepts_and_equal_dimensions<Geometry const, Bounds>();
  40. dispatch::bounds<Geometry, Bounds>::apply(g, b);
  41. }
  42. namespace dispatch {
  43. template <typename Geometry,
  44. typename TagGeometry = typename geometry::tag<Geometry>::type>
  45. struct return_ref_or_bounds
  46. {
  47. typedef Geometry const& result_type;
  48. static inline result_type apply(Geometry const& g)
  49. {
  50. return g;
  51. }
  52. };
  53. template <typename Geometry>
  54. struct return_ref_or_bounds<Geometry, segment_tag>
  55. {
  56. typedef typename point_type<Geometry>::type point_type;
  57. typedef geometry::model::box<point_type> bounds_type;
  58. typedef index::detail::bounded_view<Geometry, bounds_type> result_type;
  59. static inline result_type apply(Geometry const& g)
  60. {
  61. return result_type(g);
  62. }
  63. };
  64. } // namespace dispatch
  65. template <typename Geometry>
  66. inline
  67. typename dispatch::return_ref_or_bounds<Geometry>::result_type
  68. return_ref_or_bounds(Geometry const& g)
  69. {
  70. return dispatch::return_ref_or_bounds<Geometry>::apply(g);
  71. }
  72. }}}} // namespace boost::geometry::index::detail
  73. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP