1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP
10 #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP
16 #include <boost/concept_check.hpp>
17 #include <boost/numeric/conversion/cast.hpp>
19 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/strategies/side_info.hpp>
24 namespace boost { namespace geometry
27 namespace policies { namespace relate
32 \brief Policy returning segment ratios
33 \note Template argument FractionType should be a fraction_type<SegmentRatio>
39 struct segments_intersection_ratios
41 typedef FractionType return_type;
47 typename SegmentIntersectionInfo
49 static inline return_type segments_crosses(side_info const&,
50 SegmentIntersectionInfo const& sinfo,
51 Segment1 const& , Segment2 const& )
58 template <typename Segment1, typename Segment2, typename Ratio>
59 static inline return_type segments_collinear(
60 Segment1 const& , Segment2 const& ,
61 Ratio const& ra_from_wrt_b, Ratio const& ra_to_wrt_b,
62 Ratio const& rb_from_wrt_a, Ratio const& rb_to_wrt_a)
64 // We have only one result, for (potentially) two IP's,
65 // so we take a first one
68 if (ra_from_wrt_b.on_segment())
70 result.assign(Ratio::zero(), ra_from_wrt_b);
72 else if (rb_from_wrt_a.in_segment())
74 result.assign(rb_from_wrt_a, Ratio::zero());
76 else if (ra_to_wrt_b.on_segment())
78 result.assign(Ratio::one(), ra_to_wrt_b);
80 else if (rb_to_wrt_a.in_segment())
82 result.assign(rb_to_wrt_a, Ratio::one());
88 static inline return_type disjoint()
92 static inline return_type error(std::string const&)
97 template <typename Segment>
98 static inline return_type degenerate(Segment const& segment, bool)
100 return return_type();
103 template <typename Segment, typename Ratio>
104 static inline return_type one_degenerate(Segment const& ,
105 Ratio const& ratio, bool a_degenerate)
110 // IP lies on ratio w.r.t. segment b
111 result.assign(Ratio::zero(), ratio);
115 result.assign(ratio, Ratio::zero());
123 }} // namespace policies::relate
125 }} // namespace boost::geometry
127 #endif // BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP