• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2017.
7 // Modifications copyright (c) 2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, 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 
15 #include <iostream>
16 
17 #include <geometry_test_common.hpp>
18 
19 
20 #include <boost/foreach.hpp>
21 
22 #include <boost/geometry/algorithms/intersection.hpp>
23 
24 #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
25 #include <boost/geometry/algorithms/detail/overlay/get_relative_order.hpp>
26 #include <boost/geometry/algorithms/make.hpp>
27 
28 #include <boost/geometry/geometries/point_xy.hpp>
29 
30 #if defined(TEST_WITH_SVG)
31 #  include <boost/geometry/io/svg/svg_mapper.hpp>
32 #endif
33 
34 #include <boost/geometry/strategies/side.hpp>
35 #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
36 
37 
38 template <typename P, typename T>
test_with_point(std::string const &,T pi_x,T pi_y,T pj_x,T pj_y,T ri_x,T ri_y,T rj_x,T rj_y,T si_x,T si_y,T sj_x,T sj_y,int expected_order)39 void test_with_point(std::string const& /*caseid*/,
40                 T pi_x, T pi_y, T pj_x, T pj_y,
41                 T ri_x, T ri_y, T rj_x, T rj_y,
42                 T si_x, T si_y, T sj_x, T sj_y,
43                 int expected_order)
44 {
45     P pi = bg::make<P>(pi_x, pi_y);
46     P pj = bg::make<P>(pj_x, pj_y);
47     P ri = bg::make<P>(ri_x, ri_y);
48     P rj = bg::make<P>(rj_x, rj_y);
49     P si = bg::make<P>(si_x, si_y);
50     P sj = bg::make<P>(sj_x, sj_y);
51 
52     typedef typename bg::strategy::side::services::default_strategy
53         <
54             typename bg::cs_tag<P>::type
55         >::type strategy_type;
56 
57     int order = bg::detail::overlay::get_relative_order::apply(pi, pj, ri, rj, si, sj, strategy_type());
58 
59     BOOST_CHECK_EQUAL(order, expected_order);
60 
61 
62 
63 
64     /*
65     std::cout << caseid
66         << (caseid.find("_") == std::string::npos ? "  " : "")
67         << " " << method
68         << " " << detected
69         << " " << order
70         << std::endl;
71     */
72 
73 
74 
75 /*#if defined(TEST_WITH_SVG)
76     {
77         std::ostringstream filename;
78         filename << "get_turn_info_" << caseid
79             << "_" << string_from_type<typename bg::coordinate_type<P>::type>::name()
80             << ".svg";
81 
82         std::ofstream svg(filename.str().c_str());
83 
84         bg::svg_mapper<P> mapper(svg, 500, 500);
85         mapper.add(bg::make<P>(0, 0));
86         mapper.add(bg::make<P>(10, 10));
87 
88         bg::model::linestring<P> p; p.push_back(pi); p.push_back(pj); p.push_back(pk);
89         bg::model::linestring<P> q; q.push_back(qi); q.push_back(qj); q.push_back(qk);
90         mapper.map(p, "opacity:0.8;stroke:rgb(0,192,0);stroke-width:3");
91         mapper.map(q, "opacity:0.8;stroke:rgb(0,0,255);stroke-width:3");
92 
93         std::string style =  ";font-family='Verdana';font-weight:bold";
94         std::string align = ";text-anchor:end;text-align:end";
95         int offset = 8;
96 
97         mapper.text(pi, "pi", "fill:rgb(0,192,0)" + style, offset, offset);
98         mapper.text(pj, "pj", "fill:rgb(0,192,0)" + style, offset, offset);
99         mapper.text(pk, "pk", "fill:rgb(0,192,0)" + style, offset, offset);
100 
101         mapper.text(qi, "qi", "fill:rgb(0,0,255)" + style + align, -offset, offset);
102         mapper.text(qj, "qj", "fill:rgb(0,0,255)" + style + align, -offset, offset);
103         mapper.text(qk, "qk", "fill:rgb(0,0,255)" + style + align, -offset, offset);
104 
105 
106         int factor = 1; // second info, if any, will go left by factor -1
107         int ch = '1';
108         for (typename tp_vector::const_iterator it = info.begin();
109             it != info.end();
110             ++it, factor *= -1, ch++)
111         {
112             bool at_j = it->method == bg::detail::overlay::method_crosses;
113             std::string op;
114             op += operation_char(it->operations[0].operation);
115             align = ";text-anchor:middle;text-align:center";
116             mapper.text(at_j ? pj : pk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
117 
118             op.clear();
119             op += operation_char(it->operations[1].operation);
120             mapper.text(at_j ? qj : qk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
121 
122             // Map intersection point + method
123             mapper.map(it->point, "opacity:0.8;fill:rgb(255,0,0);stroke:rgb(0,0,100);stroke-width:1");
124 
125             op.clear();
126             op += method_char(it->method);
127             if (info.size() != 1)
128             {
129                 op += ch;
130                 op += " p:"; op += operation_char(it->operations[0].operation);
131                 op += " q:"; op += operation_char(it->operations[1].operation);
132             }
133             mapper.text(it->point, op, "fill:rgb(255,0,0)" + style, offset, -offset);
134         }
135     }
136 #endif
137 */
138 }
139 
140 
141 
142 template <typename P>
test_all()143 void test_all()
144 {
145     test_with_point<P, double>("OLR1",
146             5, 1,   5, 8, // p
147             3, 5,   7, 5, // r
148             3, 3,   7, 2, // s
149             1);
150     test_with_point<P, double>("OLR2",
151             5, 1,   5, 8, // p
152             3, 5,   7, 5, // r
153             3, 7,   7, 6, // s
154             -1);
155     test_with_point<P, double>("OLR3",
156             5, 1,   5, 8, // p
157             3, 5,   7, 5, // r
158             4, 2,   9, 6, // s
159             1);
160     test_with_point<P, double>("OLR4",
161             5, 1,   5, 8, // p
162             3, 5,   7, 5, // r
163             3, 8,   9, 4, // s
164             -1);
165     test_with_point<P, double>("OLR5",
166             5, 1,   5, 8, // p
167             3, 5,   7, 5, // r
168             4, 2,   8, 6, // s
169             1);
170     test_with_point<P, double>("OLR6",
171             5, 1,   5, 8, // p
172             3, 5,   7, 5, // r
173             3, 7,   9, 4, // s
174             -1);
175     test_with_point<P, double>("OLR7",
176             5, 1,   5, 8, // p
177             3, 5,   7, 5, // r
178             1, 4,   7, 7, // s
179             -1);
180     test_with_point<P, double>("OLR8",
181             5, 1,   5, 8, // p
182             3, 5,   7, 5, // r
183             1, 6,   7, 3, // s
184             1);
185 
186 
187     test_with_point<P, double>("OD1",
188             5, 1,   5, 8, // p
189             3, 5,   7, 5, // r
190             7, 2,   3, 3, // s
191             1);
192 
193     test_with_point<P, double>("OD9",
194             5, 1,   5, 8, // p
195             3, 5,   7, 5, // r
196             7, 5,   3, 3, // s
197             1);
198     test_with_point<P, double>("OD10",
199             5, 1,   5, 8, // p
200             3, 5,   7, 5, // r
201             7, 5,   3, 7, // s
202             -1);
203     test_with_point<P, double>("OD11",
204             5, 1,   5, 8, // p
205             7, 5,   3, 5, // r
206             3, 5,   7, 7, // s
207             -1);
208     test_with_point<P, double>("OD12",
209             5, 1,   5, 8, // p
210             7, 5,   3, 5, // r
211             3, 5,   7, 3, // s
212             1);
213 }
214 
215 
test_main(int,char * [])216 int test_main(int, char* [])
217 {
218     test_all<bg::model::d2::point_xy<double> >();
219     return 0;
220 }
221