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