Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / algorithms / detail / buffer / line_line_intersection.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2012-2019 Barend Gehrels, Amsterdam, the Netherlands.
4
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)
8
9 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP
10 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP
11
12
13 #include <boost/geometry/arithmetic/infinite_line_functions.hpp>
14 #include <boost/geometry/algorithms/detail/make/make.hpp>
15 #include <boost/geometry/strategies/buffer.hpp>
16
17 namespace boost { namespace geometry
18 {
19
20
21 #ifndef DOXYGEN_NO_DETAIL
22 namespace detail { namespace buffer
23 {
24
25 // TODO: it might once be changed this to proper strategy
26 struct line_line_intersection
27 {
28     template <typename Point>
29     static inline strategy::buffer::join_selector
30     apply(Point const& pi, Point const& pj,
31           Point const& qi, Point const& qj,
32           Point& ip)
33     {
34         typedef typename coordinate_type<Point>::type ct;
35         typedef model::infinite_line<ct> line_type;
36
37         line_type const p = detail::make::make_infinite_line<ct>(pi, pj);
38         line_type const q = detail::make::make_infinite_line<ct>(qi, qj);
39
40         if (arithmetic::intersection_point(p, q, ip))
41         {
42             return strategy::buffer::join_convex;
43         }
44
45         // The lines do not intersect.
46         // Distinguish between continuing lines (having a similar direction)
47         // and spikes (having the opposite direction).
48         return arithmetic::similar_direction(p, q)
49             ? strategy::buffer::join_continue
50             : strategy::buffer::join_spike
51             ;
52     }
53 };
54
55
56 }} // namespace detail::buffer
57 #endif // DOXYGEN_NO_DETAIL
58
59
60 }} // namespace boost::geometry
61
62
63 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_LINE_LINE_INTERSECTION_HPP