point.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2015, 2016, 2017.
  6. // Modifications copyright (c) 2015-2016, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Distributed under the Boost Software License, Version 1.0.
  11. // (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_POINT_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_POINT_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/core/access.hpp>
  17. #include <boost/geometry/core/cs.hpp>
  18. #include <boost/geometry/core/coordinate_dimension.hpp>
  19. #include <boost/geometry/core/coordinate_system.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/views/detail/indexed_point_view.hpp>
  22. #include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
  23. #include <boost/geometry/algorithms/detail/normalize.hpp>
  24. #include <boost/geometry/algorithms/detail/envelope/transform_units.hpp>
  25. #include <boost/geometry/algorithms/dispatch/envelope.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail { namespace envelope
  30. {
  31. template <std::size_t Dimension, std::size_t DimensionCount>
  32. struct envelope_one_point
  33. {
  34. template <std::size_t Index, typename Point, typename Box>
  35. static inline void apply(Point const& point, Box& mbr)
  36. {
  37. detail::indexed_point_view<Box, Index> box_corner(mbr);
  38. detail::conversion::point_to_point
  39. <
  40. Point,
  41. detail::indexed_point_view<Box, Index>,
  42. Dimension,
  43. DimensionCount
  44. >::apply(point, box_corner);
  45. }
  46. template <typename Point, typename Box, typename Strategy>
  47. static inline void apply(Point const& point, Box& mbr, Strategy const&)
  48. {
  49. apply<min_corner>(point, mbr);
  50. apply<max_corner>(point, mbr);
  51. }
  52. };
  53. struct envelope_point_on_spheroid
  54. {
  55. template<typename Point, typename Box, typename Strategy>
  56. static inline void apply(Point const& point, Box& mbr, Strategy const& strategy)
  57. {
  58. Point normalized_point = detail::return_normalized<Point>(point);
  59. typename point_type<Box>::type box_point;
  60. // transform units of input point to units of a box point
  61. transform_units(normalized_point, box_point);
  62. geometry::set<min_corner, 0>(mbr, geometry::get<0>(box_point));
  63. geometry::set<min_corner, 1>(mbr, geometry::get<1>(box_point));
  64. geometry::set<max_corner, 0>(mbr, geometry::get<0>(box_point));
  65. geometry::set<max_corner, 1>(mbr, geometry::get<1>(box_point));
  66. envelope_one_point
  67. <
  68. 2, dimension<Point>::value
  69. >::apply(normalized_point, mbr, strategy);
  70. }
  71. };
  72. }} // namespace detail::envelope
  73. #endif // DOXYGEN_NO_DETAIL
  74. #ifndef DOXYGEN_NO_DISPATCH
  75. namespace dispatch
  76. {
  77. template <typename Point>
  78. struct envelope<Point, point_tag, cartesian_tag>
  79. : detail::envelope::envelope_one_point<0, dimension<Point>::value>
  80. {};
  81. template <typename Point>
  82. struct envelope<Point, point_tag, spherical_polar_tag>
  83. : detail::envelope::envelope_point_on_spheroid
  84. {};
  85. template <typename Point>
  86. struct envelope<Point, point_tag, spherical_equatorial_tag>
  87. : detail::envelope::envelope_point_on_spheroid
  88. {};
  89. template <typename Point>
  90. struct envelope<Point, point_tag, geographic_tag>
  91. : detail::envelope::envelope_point_on_spheroid
  92. {};
  93. } // namespace dispatch
  94. #endif // DOXYGEN_NO_DISPATCH
  95. }} // namespace boost::geometry
  96. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ENVELOPE_POINT_HPP