123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POINTS_HPP
- #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_INTERSECTION_POINTS_HPP
- #include <algorithm>
- #include <string>
- #include <boost/geometry/algorithms/assign.hpp>
- #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
- #include <boost/geometry/core/access.hpp>
- #include <boost/geometry/core/assert.hpp>
- #include <boost/geometry/strategies/side_info.hpp>
- namespace boost { namespace geometry
- {
- namespace policies { namespace relate
- {
- template
- <
- typename ReturnType
- >
- struct segments_intersection_points
- {
- typedef ReturnType return_type;
- template
- <
- typename Segment1,
- typename Segment2,
- typename SegmentIntersectionInfo
- >
- static inline return_type segments_crosses(side_info const&,
- SegmentIntersectionInfo const& sinfo,
- Segment1 const& s1, Segment2 const& s2)
- {
- return_type result;
- result.count = 1;
- sinfo.calculate(result.intersections[0], s1, s2);
-
- result.fractions[0].assign(sinfo);
- return result;
- }
- template<typename SegmentIntersectionInfo, typename Point>
- static inline return_type
- segments_share_common_point(side_info const&, SegmentIntersectionInfo const& sinfo,
- Point const& p)
- {
- return_type result;
- result.count = 1;
- boost::geometry::assign(result.intersections[0], p);
-
- result.fractions[0].assign(sinfo);
- return result;
- }
- template <typename Segment1, typename Segment2, typename Ratio>
- static inline return_type segments_collinear(
- Segment1 const& a, Segment2 const& b, bool ,
- int a1_wrt_b, int a2_wrt_b, int b1_wrt_a, int b2_wrt_a,
- Ratio const& ra_from_wrt_b, Ratio const& ra_to_wrt_b,
- Ratio const& rb_from_wrt_a, Ratio const& rb_to_wrt_a)
- {
- return_type result;
- unsigned int index = 0;
- Ratio on_a[2];
-
-
-
- if (a1_wrt_b >= 1 && a1_wrt_b <= 3
- && index < 2)
- {
-
-
-
-
-
- detail::assign_point_from_index<0>(a, result.intersections[index]);
- result.fractions[index].assign(Ratio::zero(), ra_from_wrt_b);
- on_a[index] = Ratio::zero();
- index++;
- }
- if (b1_wrt_a == 2
- && index < 2)
- {
-
-
-
-
-
-
- detail::assign_point_from_index<0>(b, result.intersections[index]);
- result.fractions[index].assign(rb_from_wrt_a, Ratio::zero());
- on_a[index] = rb_from_wrt_a;
- index++;
- }
- if (a2_wrt_b >= 1 && a2_wrt_b <= 3
- && index < 2)
- {
-
-
-
- detail::assign_point_from_index<1>(a, result.intersections[index]);
- result.fractions[index].assign(Ratio::one(), ra_to_wrt_b);
- on_a[index] = Ratio::one();
- index++;
- }
- if (b2_wrt_a == 2
- && index < 2)
- {
- detail::assign_point_from_index<1>(b, result.intersections[index]);
- result.fractions[index].assign(rb_to_wrt_a, Ratio::one());
- on_a[index] = rb_to_wrt_a;
- index++;
- }
-
-
-
-
- if (index == 2 && on_a[1] < on_a[0])
- {
- std::swap(result.fractions[0], result.fractions[1]);
- std::swap(result.intersections[0], result.intersections[1]);
- }
- result.count = index;
- return result;
- }
- static inline return_type disjoint()
- {
- return return_type();
- }
- static inline return_type error(std::string const&)
- {
- return return_type();
- }
-
- template <typename Segment>
- static inline return_type degenerate(Segment const& segment, bool)
- {
- return_type result;
- result.count = 1;
- set<0>(result.intersections[0], get<0, 0>(segment));
- set<1>(result.intersections[0], get<0, 1>(segment));
- return result;
- }
-
- template <typename Segment, typename Ratio>
- static inline return_type one_degenerate(Segment const& degenerate_segment,
- Ratio const& ratio, bool a_degenerate)
- {
- return_type result;
- result.count = 1;
- set<0>(result.intersections[0], get<0, 0>(degenerate_segment));
- set<1>(result.intersections[0], get<0, 1>(degenerate_segment));
- if (a_degenerate)
- {
-
- result.fractions[0].assign(Ratio::zero(), ratio);
- }
- else
- {
- result.fractions[0].assign(ratio, Ratio::zero());
- }
- return result;
- }
- };
- }}
- }}
- #endif
|