cartesian.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Boost.Geometry
  2. // Copyright (c) 2021, 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_SIMPLIFY_CARTESIAN_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_CARTESIAN_HPP
  8. #include <boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp>
  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/point_in_point.hpp>
  12. #include <boost/geometry/strategies/detail.hpp>
  13. #include <boost/geometry/strategies/distance/comparable.hpp>
  14. #include <boost/geometry/strategies/distance/detail.hpp>
  15. #include <boost/geometry/strategies/simplify/services.hpp>
  16. #include <boost/geometry/strategy/cartesian/area.hpp>
  17. #include <boost/geometry/util/type_traits.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace strategies { namespace simplify
  21. {
  22. template <typename CalculationType = void>
  23. struct cartesian
  24. : public strategies::detail::cartesian_base
  25. {
  26. // TODO: Replace this if calculate_point_order() is used in simplify
  27. template <typename Geometry>
  28. static auto area(Geometry const&)
  29. {
  30. return strategy::area::cartesian<CalculationType>();
  31. }
  32. // For perimeter()
  33. template <typename Geometry1, typename Geometry2>
  34. static auto distance(Geometry1 const&, Geometry2 const&,
  35. distance::detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr)
  36. {
  37. return strategy::distance::pythagoras<CalculationType>();
  38. }
  39. // For douglas_peucker
  40. template <typename Geometry1, typename Geometry2>
  41. static auto distance(Geometry1 const&, Geometry2 const&,
  42. distance::detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr)
  43. {
  44. return strategy::distance::projected_point
  45. <
  46. CalculationType,
  47. strategy::distance::pythagoras<CalculationType>
  48. >();
  49. }
  50. // For equals()
  51. template <typename Geometry1, typename Geometry2>
  52. static auto relate(Geometry1 const&, Geometry2 const&,
  53. std::enable_if_t
  54. <
  55. util::is_pointlike<Geometry1>::value
  56. && util::is_pointlike<Geometry2>::value
  57. > * = nullptr)
  58. {
  59. return strategy::within::cartesian_point_point();
  60. }
  61. };
  62. namespace services
  63. {
  64. template <typename Geometry>
  65. struct default_strategy<Geometry, cartesian_tag>
  66. {
  67. using type = strategies::simplify::cartesian<>;
  68. };
  69. template <typename P, typename CT, typename S>
  70. struct strategy_converter
  71. <
  72. strategy::simplify::douglas_peucker
  73. <
  74. P,
  75. strategy::distance::projected_point<CT, S>
  76. >
  77. >
  78. {
  79. template <typename Strategy>
  80. static auto get(Strategy const& )
  81. {
  82. typedef strategies::simplify::cartesian<CT> strategy_type;
  83. return std::conditional_t
  84. <
  85. std::is_same
  86. <
  87. S,
  88. typename strategy::distance::services::comparable_type<S>::type
  89. >::value,
  90. strategies::distance::detail::comparable<strategy_type>,
  91. strategy_type
  92. >();
  93. }
  94. };
  95. } // namespace services
  96. }} // namespace strategies::simplify
  97. }} // namespace boost::geometry
  98. #endif // BOOST_GEOMETRY_STRATEGIES_SIMPLIFY_CARTESIAN_HPP