cartesian.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Boost.Geometry
  2. // Copyright (c) 2020, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_INDEX_CARTESIAN_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_INDEX_CARTESIAN_HPP
  8. // TODO: move to strategy directory
  9. #include <boost/geometry/strategies/cartesian/distance_projected_point.hpp>
  10. #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
  11. #include <boost/geometry/strategies/cartesian/distance_segment_box.hpp>
  12. #include <boost/geometry/strategies/index/services.hpp>
  13. #include <boost/geometry/strategies/relate/cartesian.hpp>
  14. namespace boost { namespace geometry { namespace strategies { namespace index
  15. {
  16. template <typename CalculationType = void>
  17. class cartesian
  18. : public relate::cartesian<CalculationType>
  19. {
  20. public:
  21. template <typename Geometry1, typename Geometry2>
  22. static auto comparable_distance(Geometry1 const&, Geometry2 const&,
  23. std::enable_if_t
  24. <
  25. util::is_pointlike<Geometry1>::value
  26. && util::is_pointlike<Geometry2>::value
  27. > * = nullptr)
  28. {
  29. //return geometry::strategy::distance::comparable::pythagoras<CalculationType>();
  30. return geometry::strategy::distance::pythagoras<CalculationType>();
  31. }
  32. template <typename Geometry1, typename Geometry2>
  33. static auto comparable_distance(Geometry1 const&, Geometry2 const&,
  34. std::enable_if_t
  35. <
  36. (util::is_pointlike<Geometry1>::value
  37. && util::is_segment<Geometry2>::value)
  38. || (util::is_segment<Geometry1>::value
  39. && util::is_pointlike<Geometry2>::value)
  40. > * = nullptr)
  41. {
  42. return geometry::strategy::distance::projected_point
  43. <
  44. CalculationType,
  45. //geometry::strategy::distance::comparable::pythagoras<CalculationType>
  46. geometry::strategy::distance::pythagoras<CalculationType>
  47. >();
  48. }
  49. template <typename Geometry1, typename Geometry2>
  50. static auto comparable_distance(Geometry1 const&, Geometry2 const&,
  51. std::enable_if_t
  52. <
  53. (util::is_pointlike<Geometry1>::value
  54. && util::is_box<Geometry2>::value)
  55. || (util::is_box<Geometry1>::value
  56. && util::is_pointlike<Geometry2>::value)
  57. > * = nullptr)
  58. {
  59. //return geometry::strategy::distance::comparable::pythagoras_point_box<CalculationType>();
  60. return geometry::strategy::distance::pythagoras_point_box<CalculationType>();
  61. }
  62. template <typename Geometry1, typename Geometry2>
  63. static auto comparable_distance(Geometry1 const&, Geometry2 const&,
  64. std::enable_if_t
  65. <
  66. (util::is_segment<Geometry1>::value
  67. && util::is_box<Geometry2>::value)
  68. || (util::is_box<Geometry1>::value
  69. && util::is_segment<Geometry2>::value)
  70. > * = nullptr)
  71. {
  72. return geometry::strategy::distance::cartesian_segment_box
  73. <
  74. CalculationType,
  75. //geometry::strategy::distance::comparable::pythagoras<CalculationType>
  76. geometry::strategy::distance::pythagoras<CalculationType>
  77. >();
  78. }
  79. template <typename Geometry1, typename Geometry2>
  80. static auto comparable_distance(Geometry1 const&, Geometry2 const&,
  81. std::enable_if_t
  82. <
  83. util::is_segment<Geometry1>::value
  84. && util::is_segment<Geometry2>::value
  85. > * = nullptr)
  86. {
  87. return strategy::distance::projected_point
  88. <
  89. CalculationType,
  90. //strategy::distance::comparable::pythagoras<CalculationType>
  91. strategy::distance::pythagoras<CalculationType>
  92. >();
  93. }
  94. };
  95. namespace services
  96. {
  97. template <typename Geometry>
  98. struct default_strategy<Geometry, cartesian_tag>
  99. {
  100. using type = strategies::index::cartesian<>;
  101. };
  102. // TEMP - needed in distance until umbrella strategies are supported
  103. template <typename CalculationType, typename SubStrategy>
  104. struct strategy_converter<strategy::distance::projected_point<CalculationType, SubStrategy>>
  105. {
  106. static auto get(strategy::distance::projected_point<CalculationType, SubStrategy> const& )
  107. {
  108. return strategies::index::cartesian<CalculationType>();
  109. }
  110. };
  111. // TEMP - needed in distance until umbrella strategies are supported
  112. template <typename CalculationType>
  113. struct strategy_converter<strategy::distance::comparable::pythagoras<CalculationType>>
  114. {
  115. static auto get(strategy::distance::comparable::pythagoras<CalculationType> const&)
  116. {
  117. return strategies::index::cartesian<CalculationType>();
  118. }
  119. };
  120. } // namespace services
  121. }}}} // namespace boost::geometry::strategy::index
  122. #endif // BOOST_GEOMETRY_STRATEGIES_INDEX_CARTESIAN_HPP