123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_DISTANCE_MEASURE_HPP
- #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_DISTANCE_MEASURE_HPP
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/coordinate_system.hpp>
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/arithmetic/infinite_line_functions.hpp>
- #include <boost/geometry/algorithms/detail/make/make.hpp>
- #include <boost/geometry/algorithms/not_implemented.hpp>
- #include <boost/geometry/util/select_coordinate_type.hpp>
- #include <cmath>
- namespace boost { namespace geometry
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
- template <typename T>
- struct distance_measure
- {
- T measure;
- distance_measure()
- : measure(T())
- {}
-
- bool is_zero() const
- {
- return ! is_positive() && ! is_negative();
- }
-
-
- bool is_positive() const { return measure > T(0); }
-
-
- bool is_negative() const { return measure < T(0); }
- };
- }
- namespace detail_dispatch
- {
- template <typename CalculationType, typename CsTag>
- struct get_distance_measure
- : not_implemented<CsTag>
- {};
- template <typename CalculationType>
- struct get_distance_measure<CalculationType, spherical_tag>
- {
-
- using result_type = detail::distance_measure<CalculationType>;
- template <typename SegmentPoint, typename Point>
- static result_type apply(SegmentPoint const& , SegmentPoint const& ,
- Point const& )
- {
- result_type const result;
- return result;
- }
- };
- template <typename CalculationType>
- struct get_distance_measure<CalculationType, geographic_tag>
- : get_distance_measure<CalculationType, spherical_tag>
- {};
- template <typename CalculationType>
- struct get_distance_measure<CalculationType, cartesian_tag>
- {
- using result_type = detail::distance_measure<CalculationType>;
- template <typename SegmentPoint, typename Point>
- static result_type apply(SegmentPoint const& p1, SegmentPoint const& p2,
- Point const& p)
- {
-
-
-
- auto const line = detail::make::make_infinite_line<CalculationType>(p1, p2);
- result_type result;
- result.measure = arithmetic::side_value(line, p);
- return result;
- }
- };
- }
- namespace detail
- {
- template <typename SegmentPoint, typename Point, typename Strategies>
- inline auto get_distance_measure(SegmentPoint const& p1, SegmentPoint const& p2, Point const& p,
- Strategies const&)
- {
- using calc_t = typename select_coordinate_type<SegmentPoint, Point>::type;
-
-
-
- auto identical = [](auto const& point1, auto const& point2)
- {
- return geometry::get<0>(point1) == geometry::get<0>(point2)
- && geometry::get<1>(point1) == geometry::get<1>(point2);
- };
- if (identical(p1, p) || identical(p2, p))
- {
- detail::distance_measure<calc_t> const result;
- return result;
- }
- return detail_dispatch::get_distance_measure
- <
- calc_t,
- typename Strategies::cs_tag
- >::apply(p1, p2, p);
- }
- }
- #endif
- }}
- #endif
|