]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/algorithms/detail/direction_code.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / algorithms / detail / direction_code.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2015.
6 // Modifications copyright (c) 2015 Oracle and/or its affiliates.
7
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DIRECITON_CODE_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DIRECITON_CODE_HPP
16
17
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/util/math.hpp>
20
21 namespace boost { namespace geometry
22 {
23
24 #ifndef DOXYGEN_NO_DETAIL
25 namespace detail
26 {
27
28 template <std::size_t Index, typename Point1, typename Point2>
29 inline int sign_of_difference(Point1 const& point1, Point2 const& point2)
30 {
31 return
32 math::equals(geometry::get<Index>(point1), geometry::get<Index>(point2))
33 ?
34 0
35 :
36 (geometry::get<Index>(point1) > geometry::get<Index>(point2) ? 1 : -1);
37 }
38
39
40 // Gives sense of direction for point p, collinear w.r.t. segment (a,b)
41 // Returns -1 if p goes backward w.r.t (a,b), so goes from b in direction of a
42 // Returns 1 if p goes forward, so extends (a,b)
43 // Returns 0 if p is equal with b, or if (a,b) is degenerate
44 // Note that it does not do any collinearity test, that should be done before
45 template <typename Point1, typename Point2>
46 inline int direction_code(Point1 const& segment_a, Point1 const& segment_b,
47 const Point2& p)
48 {
49 // Suppose segment = (4 3,4 4) and p =(4 2)
50 // Then sign_a1 = 1 and sign_p1 = 1 -> goes backward -> return -1
51
52 int const sign_a0 = sign_of_difference<0>(segment_b, segment_a);
53 int const sign_a1 = sign_of_difference<1>(segment_b, segment_a);
54
55 if (sign_a0 == 0 && sign_a1 == 0)
56 {
57 return 0;
58 }
59
60 int const sign_p0 = sign_of_difference<0>(segment_b, p);
61 int const sign_p1 = sign_of_difference<1>(segment_b, p);
62
63 if (sign_p0 == 0 && sign_p1 == 0)
64 {
65 return 0;
66 }
67
68 return sign_a0 == sign_p0 && sign_a1 == sign_p1 ? -1 : 1;
69 }
70
71
72 } // namespace detail
73 #endif //DOXYGEN_NO_DETAIL
74
75
76
77 }} // namespace boost::geometry
78
79 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DIRECITON_CODE_HPP