// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_DISTANCE_MEASURE_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_DISTANCE_MEASURE_HPP #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { template struct distance_measure { T measure; distance_measure() : measure(T()) {} bool is_small() const { return false; } bool is_zero() const { return false; } bool is_positive() const { return false; } bool is_negative() const { return false; } }; template struct distance_measure_floating { T measure; distance_measure_floating() : measure(T()) {} // Returns true if the distance measure is small. // This is an arbitrary boundary, to enable some behaviour // (for example include or exclude turns), which are checked later // with other conditions. bool is_small() const { return std::abs(measure) < 1.0e-3; } // Returns true if the distance measure is absolutely zero bool is_zero() const { return measure == 0.0; } // Returns true if the distance measure is positive. Distance measure // algorithm returns positive value if it is located on the left side. bool is_positive() const { return measure > 0.0; } // Returns true if the distance measure is negative. Distance measure // algorithm returns negative value if it is located on the right side. bool is_negative() const { return measure < 0.0; } }; template <> struct distance_measure : public distance_measure_floating {}; template <> struct distance_measure : public distance_measure_floating {}; template <> struct distance_measure : public distance_measure_floating {}; } // detail namespace detail_dispatch { // TODO: this is effectively a strategy, but for internal usage. // It might be moved to the strategies folder. template struct get_distance_measure : not_implemented {}; template struct get_distance_measure { typedef detail::distance_measure result_type; template static result_type apply(SegmentPoint const& p1, SegmentPoint const& p2, Point const& p) { // Get the distance measure / side value // It is not a real distance and purpose is // to detect small differences in collinearity typedef model::infinite_line line_type; line_type const line = detail::make::make_infinite_line(p1, p2); result_type result; result.measure = arithmetic::side_value(line, p); return result; } }; template struct get_distance_measure { typedef detail::distance_measure result_type; template static result_type apply(SegmentPoint const& , SegmentPoint const& , Point const& ) { // TODO, optional result_type result; return result; } }; template struct get_distance_measure : get_distance_measure {}; } // namespace detail_dispatch namespace detail { // Returns a (often very tiny) value to indicate its side, and distance, // 0 (absolutely 0, not even an epsilon) means collinear. Like side, // a negative means that p is to the right of p1-p2. And a positive value // means that p is to the left of p1-p2. template static distance_measure::type> get_distance_measure(SegmentPoint const& p1, SegmentPoint const& p2, Point const& p) { return detail_dispatch::get_distance_measure < typename select_coordinate_type::type, cs_tag >::apply(p1, p2, p); } } // namespace detail #endif // DOXYGEN_NO_DETAIL }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_DISTANCE_MEASURE_HPP