]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/include/boost/geometry/algorithms/detail/overlay/get_relative_order.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / algorithms / detail / overlay / get_relative_order.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2007-2012 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_OVERLAY_GET_RELATIVE_ORDER_HPP
10#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RELATIVE_ORDER_HPP
11
12
13#include <boost/geometry/strategies/intersection_strategies.hpp>
14
15
16namespace boost { namespace geometry
17{
18
19
20#ifndef DOXYGEN_NO_DETAIL
21namespace detail { namespace overlay
22{
23
24
25/*!
26 \brief Get relative order
27 \details Can indicate which of two segments R and S,
28 both crossing a common segment P, comes first.
29 If the two segments cross P very close (e.g. in a spike),
30 the distance between the intersection points can be zero,
31 but we still need to know which comes first.
32 Therefore, it is useful that using sides we are able to discover this.
33 */
34template <typename Point1>
35struct get_relative_order
36{
37 typedef typename strategy::side::services::default_strategy
38 <
39 typename cs_tag<Point1>::type
40 >::type strategy;
41
42 template <typename Point>
43 static inline int value_via_product(Point const& ti, Point const& tj,
44 Point const& ui, Point const& uj, int factor)
45 {
46 int const side_ti_u = strategy::apply(ti, tj, ui);
47 int const side_tj_u = strategy::apply(ti, tj, uj);
48
49#ifdef BOOST_GEOMETRY_DEBUG_RELATIVE_ORDER
50 std::cout << (factor == 1 ? " r//s " : " s//r ")
51 << side_ti_u << " / " << side_tj_u;
52#endif
53
54 return side_ti_u * side_tj_u >= 0
55 ? factor * (side_ti_u != 0 ? side_ti_u : side_tj_u)
56 : 0;
57 }
58
59
60 static inline int apply(
61 Point1 const& pi, Point1 const& pj,
62 Point1 const& ri, Point1 const& rj,
63 Point1 const& si, Point1 const& sj)
64 {
65 int const side_ri_p = strategy::apply(pi, pj, ri);
66 int const side_si_p = strategy::apply(pi, pj, si);
67
68#ifdef BOOST_GEOMETRY_DEBUG_RELATIVE_ORDER
69 int const side_rj_p = strategy::apply(pi, pj, rj);
70 int const side_sj_p = strategy::apply(pi, pj, sj);
71 std::cout << "r//p: " << side_ri_p << " / " << side_rj_p;
72 std::cout << " s//p: " << side_si_p << " / " << side_sj_p;
73#endif
74
75 int value = value_via_product(si, sj, ri, rj, 1);
76 if (value == 0)
77 {
78 value = value_via_product(ri, rj, si, sj, -1);
79 }
80
81 int const order = side_ri_p * side_ri_p * side_si_p * value;
82
83#ifdef BOOST_GEOMETRY_DEBUG_RELATIVE_ORDER
84 std::cout
85 << " o: " << order
86 << std::endl << std::endl;
87#endif
88
89 return order;
90 }
91};
92
93
94}} // namespace detail::overlay
95#endif //DOXYGEN_NO_DETAIL
96
97
98}} // namespace boost::geometry
99
100
101#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RELATIVE_ORDER_HPP