Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / set_operations / check_turn_less.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2015, Oracle and/or its affiliates.
4
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
7
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
9
10 #ifndef BOOST_GEOMETRY_TEST_CHECK_TURN_LESS_HPP
11 #define BOOST_GEOMETRY_TEST_CHECK_TURN_LESS_HPP
12
13 #include <boost/range.hpp>
14
15 #include "test_set_ops_linear_linear.hpp"
16
17
18 // check less functor for turns
19 template <typename Turns, typename Less>
20 inline void verify_less_for_turns(Turns turns, Less const& less)
21 {
22     typedef typename boost::range_iterator<Turns const>::type iterator_type;
23
24     if (boost::size(turns) < 2)
25     {
26         return;
27     }
28
29     iterator_type last = --boost::end(turns);
30     for (iterator_type it1 = boost::begin(turns); it1 != last; ++it1)
31     {
32         iterator_type it2 = it1;
33         ++it2;
34         for (; it2 != boost::end(turns); ++it2)
35         {
36             if (less(*it1, *it2))
37             {
38                 BOOST_CHECK(! less(*it2, *it1));
39             }
40             if (less(*it2, *it1))
41             {
42                 BOOST_CHECK(! less(*it1, *it2));
43             }
44         }
45     }
46 }
47
48
49 struct check_turn_less
50 {
51     template <bool EnableDegenerateTurns = true>
52     struct assign_policy
53     {
54         static bool const include_no_turn = false;
55         static bool const include_degenerate = EnableDegenerateTurns;
56         static bool const include_opposite = false;
57
58         template
59         <
60             typename Info,
61             typename Point1,
62             typename Point2,
63             typename IntersectionInfo
64         >
65         static inline void apply(Info& , Point1 const& , Point2 const& ,
66                                  IntersectionInfo const& )
67         {
68         }
69     };
70
71     template <typename Geometry1, typename Geometry2>
72     static inline void apply(Geometry1 const& geometry1,
73                              Geometry2 const& geometry2)
74     {
75         typedef typename bg::strategy::intersection::services::default_strategy
76             <
77                 typename bg::cs_tag<Geometry1>::type
78             >::type strategy_type;
79
80         typedef bg::detail::no_rescale_policy robust_policy_type;
81
82         typedef bg::detail::relate::turns::get_turns
83             <
84                 Geometry1,
85                 Geometry2,
86                 bg::detail::get_turns::get_turn_info_type
87                     <
88                         Geometry1, Geometry2, assign_policy<>
89                     >,
90                 robust_policy_type
91             > get_turns_type;
92
93         typedef typename get_turns_type::turn_info turn_info;
94
95         typedef std::vector<turn_info> turns_container;
96
97         turns_container turns;
98
99         bg::detail::get_turns::no_interrupt_policy interrupt_policy;
100
101         get_turns_type::apply(turns, geometry1, geometry2,
102                               interrupt_policy,
103                               strategy_type(), robust_policy_type());
104
105
106         typedef bg::detail::turns::less_seg_fraction_other_op<> turn_less_type;
107
108         verify_less_for_turns(turns, turn_less_type());
109     }
110 };
111
112 #endif // BOOST_GEOMETRY_TEST_CHECK_TURN_LESS_HPP