// Boost.Geometry // Copyright (c) 2021, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_BACKWARD_COMPATIBILITY_HPP #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_BACKWARD_COMPATIBILITY_HPP #include #include #include #include #include namespace boost { namespace geometry { namespace strategies { namespace distance { #ifndef DOXYGEN_NO_DETAIL namespace detail { template < typename Strategy, typename CSTag, typename StrategyTag = typename strategy::distance::services::tag::type > struct custom_strategy { BOOST_GEOMETRY_STATIC_ASSERT_FALSE( "Not implemented for this Strategy.", Strategy); }; // NOTES: // - There is no guarantee that any of the custom strategies are compatible with other // strategies. // - In many cases it is not possible to pass the custom strategy into other strategies. // - The old backward compatibility code creating default Pt/Seg strategy from custom // Pt/Pt strategy worked the same way. The custom strategy is default-created. // - There are two versions of algorithm for Polyseg/Box, one for Seg/Box strategy the // other one for Pt/Seg strategy. However there is only one version of algorithm for // Seg/Box taking Seg/Box strategy. // - Geographic strategies are default-created which means WGS84 spheroid is used. // - Currently only Pt/Pt custom strategies are supported because this is what the old // backward compatibility code was addressing. template struct custom_strategy : cartesian<> { custom_strategy(Strategy const& strategy) : m_strategy(strategy) {} template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pp_t * = nullptr) const { return m_strategy; } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_ps_t * = nullptr) const { return strategy::distance::projected_point(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pb_t * = nullptr) const { return strategy::distance::pythagoras_point_box<>(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_sb_t * = nullptr) const { return strategy::distance::cartesian_segment_box(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_bb_t * = nullptr) const { return strategy::distance::pythagoras_box_box<>(); } private: Strategy const& m_strategy; }; template struct custom_strategy : detail::spherical { custom_strategy(Strategy const& strategy) : m_strategy(strategy) {} template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pp_t * = nullptr) const { return m_strategy; } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_ps_t * = nullptr) const { return strategy::distance::cross_track(m_strategy); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pb_t * = nullptr) const { return strategy::distance::cross_track_point_box(m_strategy); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_sb_t * = nullptr) const { return strategy::distance::spherical_segment_box(m_strategy); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_bb_t * = nullptr) const { return strategy::distance::cross_track_box_box(m_strategy); } private: Strategy const& m_strategy; }; template struct custom_strategy : geographic<> { custom_strategy(Strategy const& strategy) : m_strategy(strategy) {} template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pp_t * = nullptr) const { return m_strategy; } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_ps_t * = nullptr) const { return strategy::distance::geographic_cross_track<>(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_pb_t * = nullptr) const { return strategy::distance::geographic_cross_track_point_box<>(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_sb_t * = nullptr) const { return strategy::distance::geographic_segment_box<>(); } template auto distance(Geometry1 const&, Geometry2 const&, enable_if_bb_t * = nullptr) const { return strategy::distance::geographic_cross_track_box_box<>(); } private: Strategy const& m_strategy; }; } // namespace detail #endif // DOXYGEN_NO_DETAIL namespace services { template struct custom_strategy_converter { static auto get(Strategy const& strategy) { return detail::custom_strategy(strategy); } }; template struct custom_strategy_converter { static auto get(Strategy const& strategy) { return detail::custom_strategy(strategy); } }; template struct custom_strategy_converter { static auto get(Strategy const& strategy) { return detail::custom_strategy(strategy); } }; } // namespace services }} // namespace strategies::distance }} // namespace boost::geometry #endif // BOOST_GEOMETRY_STRATEGIES_DISTANCE_BACKWARD_COMPATIBILITY_HPP