Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:36

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // Use, modification and distribution is subject to the Boost Software License,
0006 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP
0010 #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP
0011 
0012 
0013 #include <algorithm>
0014 #include <string>
0015 
0016 #include <boost/concept_check.hpp>
0017 #include <boost/numeric/conversion/cast.hpp>
0018 
0019 #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
0020 #include <boost/geometry/core/access.hpp>
0021 #include <boost/geometry/strategies/side_info.hpp>
0022 
0023 
0024 namespace boost { namespace geometry
0025 {
0026 
0027 namespace policies { namespace relate
0028 {
0029 
0030 
0031 /*!
0032 \brief Policy returning segment ratios
0033 \note Template argument FractionType should be a fraction_type<SegmentRatio>
0034  */
0035 template
0036 <
0037     typename FractionType
0038 >
0039 struct segments_intersection_ratios
0040 {
0041     typedef FractionType return_type;
0042 
0043     template
0044     <
0045         typename Segment1,
0046         typename Segment2,
0047         typename SegmentIntersectionInfo
0048     >
0049     static inline return_type segments_crosses(side_info const&,
0050                     SegmentIntersectionInfo const& sinfo,
0051                     Segment1 const& , Segment2 const& )
0052     {
0053         return_type result;
0054         result.assign(sinfo);
0055         return result;
0056     }
0057 
0058     template <typename Segment1, typename Segment2, typename Ratio>
0059     static inline return_type segments_collinear(
0060         Segment1 const& , Segment2 const& ,
0061         Ratio const& ra_from_wrt_b, Ratio const& ra_to_wrt_b,
0062         Ratio const& rb_from_wrt_a, Ratio const& rb_to_wrt_a)
0063     {
0064         // We have only one result, for (potentially) two IP's,
0065         // so we take a first one
0066         return_type result;
0067 
0068         if (ra_from_wrt_b.on_segment())
0069         {
0070             result.assign(Ratio::zero(), ra_from_wrt_b);
0071         }
0072         else if (rb_from_wrt_a.in_segment())
0073         {
0074             result.assign(rb_from_wrt_a, Ratio::zero());
0075         }
0076         else if (ra_to_wrt_b.on_segment())
0077         {
0078             result.assign(Ratio::one(), ra_to_wrt_b);
0079         }
0080         else if (rb_to_wrt_a.in_segment())
0081         {
0082             result.assign(rb_to_wrt_a, Ratio::one());
0083         }
0084 
0085         return result;
0086     }
0087 
0088     static inline return_type disjoint()
0089     {
0090         return return_type();
0091     }
0092     static inline return_type error(std::string const&)
0093     {
0094         return return_type();
0095     }
0096 
0097     template <typename Segment>
0098     static inline return_type degenerate(Segment const& segment, bool)
0099     {
0100         return return_type();
0101     }
0102 
0103     template <typename Segment, typename Ratio>
0104     static inline return_type one_degenerate(Segment const& ,
0105             Ratio const& ratio, bool a_degenerate)
0106     {
0107         return_type result;
0108         if (a_degenerate)
0109         {
0110             // IP lies on ratio w.r.t. segment b
0111             result.assign(Ratio::zero(), ratio);
0112         }
0113         else
0114         {
0115             result.assign(ratio, Ratio::zero());
0116         }
0117         return result;
0118     }
0119 
0120 };
0121 
0122 
0123 }} // namespace policies::relate
0124 
0125 }} // namespace boost::geometry
0126 
0127 #endif // BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_RATIOS_HPP