line_line_intersection.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2012-2019 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP
  8. #include <boost/geometry/arithmetic/infinite_line_functions.hpp>
  9. #include <boost/geometry/algorithms/detail/make/make.hpp>
  10. #include <boost/geometry/strategies/buffer.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. #ifndef DOXYGEN_NO_DETAIL
  14. namespace detail { namespace buffer
  15. {
  16. // TODO: it might once be changed this to proper strategy
  17. struct line_line_intersection
  18. {
  19. template <typename Point>
  20. static inline strategy::buffer::join_selector
  21. apply(Point const& pi, Point const& pj,
  22. Point const& qi, Point const& qj,
  23. Point& ip)
  24. {
  25. typedef typename coordinate_type<Point>::type ct;
  26. typedef model::infinite_line<ct> line_type;
  27. line_type const p = detail::make::make_infinite_line<ct>(pi, pj);
  28. line_type const q = detail::make::make_infinite_line<ct>(qi, qj);
  29. if (arithmetic::intersection_point(p, q, ip))
  30. {
  31. return strategy::buffer::join_convex;
  32. }
  33. // The lines do not intersect.
  34. // Distinguish between continuing lines (having a similar direction)
  35. // and spikes (having the opposite direction).
  36. return arithmetic::similar_direction(p, q)
  37. ? strategy::buffer::join_continue
  38. : strategy::buffer::join_spike
  39. ;
  40. }
  41. };
  42. }} // namespace detail::buffer
  43. #endif // DOXYGEN_NO_DETAIL
  44. }} // namespace boost::geometry
  45. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP