Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / overlay / get_turn_info.cpp
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 #include <iostream>
15
16 #include <geometry_test_common.hpp>
17
18
19 #include <boost/foreach.hpp>
20
21 #include <boost/geometry/algorithms/intersection.hpp>
22
23 #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
24 #include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
25 #include <boost/geometry/geometries/point_xy.hpp>
26
27 #if defined(TEST_WITH_SVG)
28 #  include <boost/geometry/io/svg/svg_mapper.hpp>
29 #endif
30
31
32
33 template <typename P, typename T>
34 void test_with_point(std::string const& caseid,
35                 T pi_x, T pi_y, T pj_x, T pj_y, T pk_x, T pk_y,
36                 T qi_x, T qi_y, T qj_x, T qj_y, T qk_x, T qk_y,
37                 bg::detail::overlay::method_type expected_method,
38                 T ip_x, T ip_y,
39                 std::string const& expected,
40                 T ip_x2, T ip_y2)
41 {
42     P pi = bg::make<P>(pi_x, pi_y);
43     P pj = bg::make<P>(pj_x, pj_y);
44     P pk = bg::make<P>(pk_x, pk_y);
45     P qi = bg::make<P>(qi_x, qi_y);
46     P qj = bg::make<P>(qj_x, qj_y);
47     P qk = bg::make<P>(qk_x, qk_y);
48
49     typedef typename bg::strategy::intersection::services::default_strategy
50         <
51             typename bg::cs_tag<P>::type
52         >::type strategy_type;
53
54     typedef typename bg::detail::no_rescale_policy rescale_policy_type;
55
56     typedef bg::detail::overlay::turn_info
57         <
58             P,
59             typename bg::segment_ratio_type<P, rescale_policy_type>::type
60         > turn_info;
61     typedef std::vector<turn_info> tp_vector;
62     turn_info model;
63     tp_vector info;
64     strategy_type strategy;
65     rescale_policy_type rescale_policy;
66     bg::detail::overlay::get_turn_info
67         <
68             bg::detail::overlay::assign_null_policy
69         >::apply(pi, pj, pk, qi, qj, qk,
70                  false, false, false, false, // dummy parameters
71         model, strategy, rescale_policy, std::back_inserter(info));
72
73
74     if (info.size() == 0)
75     {
76         BOOST_CHECK_EQUAL(expected_method,
77                 bg::detail::overlay::method_none);
78     }
79
80     std::string detected;
81     std::string method;
82     for (typename tp_vector::const_iterator it = info.begin(); it != info.end(); ++it)
83     {
84         for (int t = 0; t < 2; t++)
85         {
86             detected += bg::operation_char(it->operations[t].operation);
87             method += bg::method_char(it->method);
88         }
89     }
90
91     BOOST_CHECK_MESSAGE(detected == expected,
92         caseid
93             << (caseid.find("_") == std::string::npos ? "  " : "")
94             << " method: " << method
95             << " detected: " << detected
96             << " expected: " << expected);
97
98
99     if (! info.empty())
100     {
101         BOOST_CHECK_EQUAL(info[0].method, expected_method);
102         BOOST_CHECK_CLOSE(bg::get<0>(info[0].point), ip_x, 0.001);
103         BOOST_CHECK_CLOSE(bg::get<1>(info[0].point), ip_y, 0.001);
104
105         if (info.size() > 1)
106         {
107             BOOST_CHECK_EQUAL(info.size(), 2u);
108             BOOST_CHECK_EQUAL(info[1].method, expected_method);
109             BOOST_CHECK_CLOSE(bg::get<0>(info[1].point), ip_x2, 0.001);
110             BOOST_CHECK_CLOSE(bg::get<1>(info[1].point), ip_y2, 0.001);
111         }
112     }
113
114 #if defined(TEST_WITH_SVG)
115     {
116         std::ostringstream filename;
117         filename << "get_turn_info_" << caseid
118             << "_" << string_from_type<typename bg::coordinate_type<P>::type>::name()
119             << ".svg";
120
121         std::ofstream svg(filename.str().c_str());
122
123         bg::svg_mapper<P> mapper(svg, 500, 500);
124         mapper.add(bg::make<P>(0, 0));
125         mapper.add(bg::make<P>(10, 10));
126
127         bg::model::linestring<P> p; p.push_back(pi); p.push_back(pj); p.push_back(pk);
128         bg::model::linestring<P> q; q.push_back(qi); q.push_back(qj); q.push_back(qk);
129         mapper.map(p, "opacity:0.8;stroke:rgb(0,192,0);stroke-width:3");
130         mapper.map(q, "opacity:0.8;stroke:rgb(0,0,255);stroke-width:3");
131
132         std::string style =  ";font-family='Verdana';font-weight:bold";
133         std::string align = ";text-anchor:end;text-align:end";
134         int offset = 8;
135
136         mapper.text(pi, "pi", "fill:rgb(0,192,0)" + style, offset, offset);
137         mapper.text(pj, "pj", "fill:rgb(0,192,0)" + style, offset, offset);
138         mapper.text(pk, "pk", "fill:rgb(0,192,0)" + style, offset, offset);
139
140         mapper.text(qi, "qi", "fill:rgb(0,0,255)" + style + align, -offset, offset);
141         mapper.text(qj, "qj", "fill:rgb(0,0,255)" + style + align, -offset, offset);
142         mapper.text(qk, "qk", "fill:rgb(0,0,255)" + style + align, -offset, offset);
143
144
145         int factor = 1; // second info, if any, will go left by factor -1
146         int ch = '1';
147         for (typename tp_vector::const_iterator it = info.begin();
148             it != info.end();
149             ++it, factor *= -1, ch++)
150         {
151             bool at_j = it->method == bg::detail::overlay::method_crosses;
152             std::string op;
153             op += bg::operation_char(it->operations[0].operation);
154             align = ";text-anchor:middle;text-align:center";
155             mapper.text(at_j ? pj : pk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
156
157             op.clear();
158             op += bg::operation_char(it->operations[1].operation);
159             mapper.text(at_j ? qj : qk, op, "fill:rgb(255,128,0)" + style + align, offset * factor, -offset);
160
161             // Map intersection point + method
162             mapper.map(it->point, "opacity:0.8;fill:rgb(255,0,0);stroke:rgb(0,0,100);stroke-width:1");
163
164             op.clear();
165             op += bg::method_char(it->method);
166             if (info.size() != 1)
167             {
168                 op += ch;
169                 op += " p:"; op += bg::operation_char(it->operations[0].operation);
170                 op += " q:"; op += bg::operation_char(it->operations[1].operation);
171             }
172             mapper.text(it->point, op, "fill:rgb(255,0,0)" + style, offset, -offset);
173         }
174     }
175 #endif
176
177 }
178
179 template <typename P, typename T>
180 void test_both(std::string const& caseid,
181                 T pi_x, T pi_y, T pj_x, T pj_y, T pk_x, T pk_y,
182                 T qi_x, T qi_y, T qj_x, T qj_y, T qk_x, T qk_y,
183                 bg::detail::overlay::method_type method
184                     = bg::detail::overlay::method_none,
185                 T ip_x = -1, T ip_y = -1,
186                 std::string const& expected = "",
187                 T ip_x2 = -1, T ip_y2 = -1)
188 {
189     test_with_point<P, double>(caseid,
190             pi_x, pi_y, pj_x, pj_y, pk_x, pk_y,
191             qi_x, qi_y, qj_x, qj_y, qk_x, qk_y,
192             method, ip_x, ip_y, expected, ip_x2, ip_y2);
193
194     //return;
195
196     std::string reversed(expected.rbegin(), expected.rend());
197     
198     if (ip_x2 >= 0 && ip_y2 >= 0)
199     {
200         std::swap(ip_x, ip_x2);
201         std::swap(ip_y, ip_y2);
202     }
203
204     test_with_point<P, double>(caseid + "_r",
205             qi_x, qi_y, qj_x, qj_y, qk_x, qk_y, // q
206             pi_x, pi_y, pj_x, pj_y, pk_x, pk_y, // p
207             method, ip_x, ip_y, reversed, ip_x2, ip_y2);
208 }
209
210
211 template <typename P>
212 void test_all()
213 {
214     using namespace bg::detail::overlay;
215
216     // See powerpoint "doc/testcases/get_turn_info.ppt"
217
218
219     // ------------------------------------------------------------------------
220     // "Real" intersections ("i"), or, crossing
221     // ------------------------------------------------------------------------
222     test_both<P, double>("il1",
223             5, 1,   5, 6,   7, 8, // p
224             3, 3,   7, 5,   8, 3, // q
225             method_crosses, 5, 4, "ui");
226
227     test_both<P, double>("il2",
228             5, 1,   5, 6,   7, 8, // p
229             3, 5,   7, 5,   3, 3, // q
230             method_crosses, 5, 5, "ui");
231
232     test_both<P, double>("il3",
233             5, 1,   5, 6,   7, 8, // p
234             3, 3,   7, 5,   3, 5, // q
235             method_crosses, 5, 4, "ui");
236
237     test_both<P, double>("il4",
238             5, 1,   5, 6,   7, 8, // p
239             3, 3,   7, 5,   4, 8, // q
240             method_crosses, 5, 4, "ui");
241
242     test_both<P, double>("ir1",
243             5, 1,   5, 6,   7, 8, // p
244             7, 5,   3, 3,   2, 5, // q
245             method_crosses, 5, 4, "iu");
246
247
248     // ------------------------------------------------------------------------
249     // TOUCH INTERIOR or touch in the middle ("m")
250     // ------------------------------------------------------------------------
251     test_both<P, double>("ml1",
252             5, 1,   5, 6,   7, 8, // p
253             3, 3,   5, 4,   7, 3, // q
254             method_touch_interior, 5, 4, "ui");
255
256     test_both<P, double>("ml2",
257             5, 1,   5, 6,   7, 8, // p
258             3, 3,   5, 4,   3, 6, // q
259             method_touch_interior, 5, 4, "iu");
260
261     test_both<P, double>("ml3",
262             5, 1,   5, 6,   7, 8, // p
263             3, 6,   5, 4,   3, 3, // q
264             method_touch_interior, 5, 4, "uu");
265
266     test_both<P, double>("mr1",
267             5, 1,   5, 6,   7, 8, // p
268             7, 3,   5, 4,   3, 3, // q
269             method_touch_interior, 5, 4, "iu");
270
271     test_both<P, double>("mr2",
272             5, 1,   5, 6,   7, 8, // p
273             7, 3,   5, 4,   7, 6, // q
274             method_touch_interior, 5, 4, "ui");
275
276     test_both<P, double>("mr3",
277             5, 1,   5, 6,   7, 8, // p
278             7, 6,   5, 4,   7, 3, // q
279             method_touch_interior, 5, 4, "ii");
280
281     test_both<P, double>("mcl",
282             5, 1,   5, 6,   7, 8, // p
283             3, 2,   5, 3,   5, 5, // q
284             method_touch_interior, 5, 3, "cc");
285
286     test_both<P, double>("mcr",
287             5, 1,   5, 6,   7, 8, // p
288             7, 2,   5, 3,   5, 5, // q
289             method_touch_interior, 5, 3, "cc");
290
291     test_both<P, double>("mclo",
292             5, 1,   5, 6,   7, 8, // p
293             3, 4,   5, 5,   5, 3, // q
294             method_touch_interior, 5, 5, "ux");
295
296     test_both<P, double>("mcro",
297             5, 1,   5, 6,   7, 8, // p
298             7, 4,   5, 5,   5, 3, // q
299             method_touch_interior, 5, 5, "ix");
300
301     // ------------------------------------------------------------------------
302     // COLLINEAR
303     // ------------------------------------------------------------------------
304     test_both<P, double>("cll1",
305             5, 1,   5, 6,   3, 8, // p
306             5, 5,   5, 7,   3, 8, // q
307             method_collinear, 5, 6, "ui");
308     test_both<P, double>("cll2",
309             5, 1,   5, 6,   3, 8, // p
310             5, 3,   5, 5,   3, 6, // q
311             method_collinear, 5, 5, "iu");
312     test_both<P, double>("clr1",
313             5, 1,   5, 6,   3, 8, // p
314             5, 5,   5, 7,   6, 8, // q
315             method_collinear, 5, 6, "ui");
316     test_both<P, double>("clr2",
317             5, 1,   5, 6,   3, 8, // p
318             5, 3,   5, 5,   6, 6, // q
319             method_collinear, 5, 5, "ui");
320
321     test_both<P, double>("crl1",
322             5, 1,   5, 6,   7, 8, // p
323             5, 5,   5, 7,   3, 8, // q
324             method_collinear, 5, 6, "iu");
325     test_both<P, double>("crl2",
326             5, 1,   5, 6,   7, 8, // p
327             5, 3,   5, 5,   3, 6, // q
328             method_collinear, 5, 5, "iu");
329     test_both<P, double>("crr1",
330             5, 1,   5, 6,   7, 8, // p
331             5, 5,   5, 7,   6, 8, // q
332             method_collinear, 5, 6, "iu");
333     test_both<P, double>("crr2",
334             5, 1,   5, 6,   7, 8, // p
335             5, 3,   5, 5,   6, 6, // q
336             method_collinear, 5, 5, "ui");
337
338     // The next two cases are changed (BSG 2013-09-24), they contain turn info (#buffer_rt_g)
339     // In new approach they are changed back (BSG 2013-10-20)
340     test_both<P, double>("ccx1",
341             5, 1,   5, 6,   5, 8, // p
342             5, 5,   5, 7,   3, 8, // q
343             method_collinear, 5, 6, "cc"); // "iu");
344     test_both<P, double>("cxc1",
345             5, 1,   5, 6,   7, 8, // p
346             5, 3,   5, 5,   5, 7, // q
347             method_collinear, 5, 5, "cc"); // "iu");
348
349     // Bug in case #54 of "overlay_cases.hpp"
350     test_both<P, double>("c_bug1",
351             5, 0,   2, 0,   2, 2, // p
352             4, 0,   1, 0,   1, 2, // q
353             method_collinear, 2, 0, "iu");
354
355
356     // ------------------------------------------------------------------------
357     // COLLINEAR OPPOSITE
358     // ------------------------------------------------------------------------
359
360     test_both<P, double>("clo1",
361             5, 2,   5, 6,   3, 8, // p
362             5, 7,   5, 5,   3, 3, // q
363             method_collinear, 5, 6, "ixxu", 5, 5);
364     test_both<P, double>("clo2",
365             5, 2,   5, 6,   3, 8, // p
366             5, 7,   5, 5,   5, 2, // q
367             method_collinear, 5, 6, "ix");
368                 // actually "xxix", xx is skipped everywhere
369     test_both<P, double>("clo3",
370             5, 2,   5, 6,   3, 8, // p
371             5, 7,   5, 5,   7, 3, // q
372             method_collinear, 5, 6, "ixxi", 5, 5);
373
374     test_both<P, double>("cco1",
375             5, 2,   5, 6,   5, 8, // p
376             5, 7,   5, 5,   3, 3, // q
377             method_collinear, 5, 5, "xu"); // "xuxx"
378     test_both<P, double>("cco2",
379             5, 2,   5, 6,   5, 8, // p
380             5, 7,   5, 5,   5, 2); // q "xxxx"
381     test_both<P, double>("cco3",
382             5, 2,   5, 6,   5, 8, // p
383             5, 7,   5, 5,   7, 3, // q
384             method_collinear, 5, 5, "xi"); // "xixx"
385
386
387     test_both<P, double>("cro1",
388             5, 2,   5, 6,   7, 8, // p
389             5, 7,   5, 5,   3, 3, // q
390             method_collinear, 5, 6, "uxxu", 5, 5);
391     test_both<P, double>("cro2",
392             5, 2,   5, 6,   7, 8, // p
393             5, 7,   5, 5,   5, 2, // q
394             method_collinear, 5, 6, "ux"); // "xxux"
395     test_both<P, double>("cro3",
396             5, 2,   5, 6,   7, 8, // p
397             5, 7,   5, 5,   7, 3, // q
398             method_collinear, 5, 6, "uxxi", 5, 5);
399
400     test_both<P, double>("cxo1",
401             5, 2,   5, 6,   3, 8, // p
402             5, 5,   5, 3,   3, 1, // q
403             method_collinear, 5, 3, "xu");
404     test_both<P, double>("cxo2",
405             5, 2,   5, 6,   3, 8, // p
406             5, 5,   5, 3,   5, 0); // q   "xx"
407     test_both<P, double>("cxo3",
408             5, 2,   5, 6,   3, 8, // p
409             5, 5,   5, 3,   7, 1, // q
410             method_collinear, 5, 3, "xi");
411
412     test_both<P, double>("cxo4",
413             5, 2,   5, 6,   3, 8, // p
414             5, 7,   5, 1,   3, 0, // q
415             method_collinear, 5, 6, "ix");
416     test_both<P, double>("cxo5",
417             5, 2,   5, 6,   5, 8, // p
418             5, 7,   5, 1,   3, 0); // q  "xx"
419     test_both<P, double>("cxo6",
420             5, 2,   5, 6,   7, 8, // p
421             5, 7,   5, 1,   3, 0, // q
422             method_collinear, 5, 6, "ux");
423
424
425     // Verify
426     test_both<P, double>("cvo1",
427             5, 3,   5, 7,   7, 9, // p
428             5, 5,   5, 3,   3, 1 // q
429             );
430     test_both<P, double>("cvo2",
431             5, 3,   5, 7,   7, 9, // p
432             5, 4,   5, 2,   3, 0 // q
433             );
434
435
436     // ------------------------------------------------------------------------
437     // TOUCH - both same
438     // ------------------------------------------------------------------------
439     // Both left, Q turns right
440     test_both<P, double>("blr1",
441             5, 1,   5, 6,   4, 4, // p
442             3, 7,   5, 6,   3, 5, // q
443             method_touch, 5, 6, "ui");
444     test_both<P, double>("blr2",
445             5, 1,   5, 6,   1, 4, // p
446             3, 7,   5, 6,   3, 5, // q
447             method_touch, 5, 6, "cc");
448     test_both<P, double>("blr3",
449             5, 1,   5, 6,   3, 6, // p
450             3, 7,   5, 6,   3, 5, // q
451             method_touch, 5, 6, "iu");
452     test_both<P, double>("blr4",
453             5, 1,   5, 6,   1, 8, // p
454             3, 7,   5, 6,   3, 5, // q
455             method_touch, 5, 6, "xu");
456     test_both<P, double>("blr5",
457             5, 1,   5, 6,   4, 8, // p
458             3, 7,   5, 6,   3, 5, // q
459             method_touch, 5, 6, "uu");
460     test_both<P, double>("blr6",
461             5, 1,   5, 6,   6, 4, // p
462             3, 7,   5, 6,   3, 5, // q
463             method_touch, 5, 6, "uu");
464
465     test_both<P, double>("blr7",
466             5, 1,   5, 6,   3, 6, // p
467             3, 7,   5, 6,   5, 3, // q
468             method_touch, 5, 6, "ix");
469     test_both<P, double>("blr8",
470             5, 1,   5, 6,   3, 6, // p
471             3, 6,   5, 6,   5, 3, // q
472             method_touch, 5, 6, "xx");
473     test_both<P, double>("blr9",
474             5, 1,   5, 6,   3, 6, // p
475             3, 5,   5, 6,   5, 3, // q
476             method_touch, 5, 6, "ux");
477
478     // Variants
479     test_both<P, double>("blr7-a",
480             5, 1,   5, 6,   3, 6, // p
481             5, 8,   5, 6,   5, 3, // q
482             method_touch, 5, 6, "ix");
483     test_both<P, double>("blr7-b", // in fact NOT "both-left"
484             5, 1,   5, 6,   3, 6, // p
485             6, 8,   5, 6,   5, 3, // q
486             method_touch, 5, 6, "ix");
487
488     // To check if "collinear-check" on other side
489     // does not apply to this side
490     test_both<P, double>("blr6-c1",
491             5, 1,   5, 6,   7, 5, // p
492             3, 7,   5, 6,   3, 5, // q
493             method_touch, 5, 6, "uu");
494     test_both<P, double>("blr6-c2",
495             5, 1,   5, 6,   7, 7, // p
496             3, 7,   5, 6,   3, 5, // q
497             method_touch, 5, 6, "uu");
498
499
500
501     // Both right, Q turns right
502     test_both<P, double>("brr1",
503             5, 1,   5, 6,   6, 4, // p
504             7, 5,   5, 6,   7, 7, // q
505             method_touch, 5, 6, "uu");
506     test_both<P, double>("brr2",
507             5, 1,   5, 6,   9, 4, // p
508             7, 5,   5, 6,   7, 7, // q
509             method_touch, 5, 6, "xu");
510     test_both<P, double>("brr3",
511             5, 1,   5, 6,   7, 6, // p
512             7, 5,   5, 6,   7, 7, // q
513             method_touch, 5, 6, "iu");
514     test_both<P, double>("brr4",
515             5, 1,   5, 6,   9, 8, // p
516             7, 5,   5, 6,   7, 7, // q
517             method_touch, 5, 6, "cc");
518     test_both<P, double>("brr5",
519             5, 1,   5, 6,   6, 8, // p
520             7, 5,   5, 6,   7, 7, // q
521             method_touch, 5, 6, "ui");
522     test_both<P, double>("brr6",
523             5, 1,   5, 6,   4, 4, // p
524             7, 5,   5, 6,   7, 7, // q
525             method_touch, 5, 6, "ui");
526
527     // Both right, Q turns left
528     test_both<P, double>("brl1",
529             5, 1,   5, 6,   6, 4, // p
530             7, 7,   5, 6,   7, 5, // q
531             method_touch, 5, 6, "iu");
532     test_both<P, double>("brl2",
533             5, 1,   5, 6,   9, 4, // p
534             7, 7,   5, 6,   7, 5, // q
535             method_touch, 5, 6, "cc");
536     test_both<P, double>("brl3",
537             5, 1,   5, 6,   7, 6, // p
538             7, 7,   5, 6,   7, 5, // q
539             method_touch, 5, 6, "ui");
540     test_both<P, double>("brl4",
541             5, 1,   5, 6,   9, 8, // p
542             7, 7,   5, 6,   7, 5, // q
543             method_touch, 5, 6, "xi");
544     test_both<P, double>("brl5",
545             5, 1,   5, 6,   6, 8, // p
546             7, 7,   5, 6,   7, 5, // q
547             method_touch, 5, 6, "ii");
548     test_both<P, double>("brl6",
549             5, 1,   5, 6,   4, 4, // p
550             7, 7,   5, 6,   7, 5, // q
551             method_touch, 5, 6, "ii");
552     test_both<P, double>("brl7",
553             5, 1,   5, 6,   7, 6, // p
554             7, 7,   5, 6,   5, 3, // q
555             method_touch, 5, 6, "ux");
556     test_both<P, double>("brl8",
557             5, 1,   5, 6,   7, 6, // p
558             7, 6,   5, 6,   5, 3, // q
559             method_touch, 5, 6, "xx");
560     test_both<P, double>("brl9",
561             5, 1,   5, 6,   7, 6, // p
562             7, 5,   5, 6,   5, 3, // q
563             method_touch, 5, 6, "ix");
564
565     // Variants
566     test_both<P, double>("brl7-a",
567             5, 1,   5, 6,   7, 6, // p
568             5, 8,   5, 6,   5, 3, // q
569             method_touch, 5, 6, "ux");
570     test_both<P, double>("brl7-b", // in fact NOT "both right"
571             5, 1,   5, 6,   7, 6, // p
572             4, 8,   5, 6,   5, 3, // q
573             method_touch, 5, 6, "ux");
574
575
576
577     // Both left, Q turns left
578     test_both<P, double>("bll1",
579             5, 1,   5, 6,   4, 4, // p
580             3, 5,   5, 6,   3, 7, // q
581             method_touch, 5, 6, "ii");
582     test_both<P, double>("bll2",
583             5, 1,   5, 6,   1, 4, // p
584             3, 5,   5, 6,   3, 7, // q
585             method_touch, 5, 6, "xi");
586     test_both<P, double>("bll3",
587             5, 1,   5, 6,   3, 6, // p
588             3, 5,   5, 6,   3, 7, // q
589             method_touch, 5, 6, "ui");
590     test_both<P, double>("bll4",
591             5, 1,   5, 6,   1, 8, // p
592             3, 5,   5, 6,   3, 7, // q
593             method_touch, 5, 6, "cc");
594     test_both<P, double>("bll5",
595             5, 1,   5, 6,   4, 8, // p
596             3, 5,   5, 6,   3, 7, // q
597             method_touch, 5, 6, "iu");
598     test_both<P, double>("bll6",
599             5, 1,   5, 6,   6, 4, // p
600             3, 5,   5, 6,   3, 7, // q
601             method_touch, 5, 6, "iu");
602
603     // TOUCH - COLLINEAR + one side
604     // Collinear/left, Q turns right
605     test_both<P, double>("t-clr1",
606             5, 1,   5, 6,   4, 4, // p
607             5, 8,   5, 6,   3, 5, // q
608             method_touch, 5, 6, "ui");
609     test_both<P, double>("t-clr2",
610             5, 1,   5, 6,   1, 4, // p
611             5, 8,   5, 6,   3, 5, // q
612             method_touch, 5, 6, "cc");
613     test_both<P, double>("t-clr3",
614             5, 1,   5, 6,   3, 6, // p
615             5, 8,   5, 6,   3, 5, // q
616             method_touch, 5, 6, "iu");
617     test_both<P, double>("t-clr4",
618             5, 1,   5, 6,   5, 8, // p
619             5, 8,   5, 6,   3, 5, // q
620             method_touch, 5, 6, "xu");
621     // 5 n.a.
622     test_both<P, double>("t-clr6",
623             5, 1,   5, 6,   6, 4, // p
624             5, 8,   5, 6,   3, 5, // q
625             method_touch, 5, 6, "uu");
626
627     // Collinear/right, Q turns right
628     test_both<P, double>("t-crr1",
629             5, 1,   5, 6,   6, 4, // p
630             7, 5,   5, 6,   5, 8, // q
631             method_touch, 5, 6, "uu");
632     test_both<P, double>("t-crr2",
633             5, 1,   5, 6,   9, 4, // p
634             7, 5,   5, 6,   5, 8, // q
635             method_touch, 5, 6, "xu");
636     test_both<P, double>("t-crr3",
637             5, 1,   5, 6,   7, 6, // p
638             7, 5,   5, 6,   5, 8, // q
639             method_touch, 5, 6, "iu");
640     test_both<P, double>("t-crr4",
641             5, 1,   5, 6,   5, 9, // p
642             7, 5,   5, 6,   5, 8, // q
643             method_touch, 5, 6, "cc");
644     // 5 n.a.
645     test_both<P, double>("t-crr6",
646             5, 1,   5, 6,   4, 4, // p
647             7, 5,   5, 6,   5, 8, // q
648             method_touch, 5, 6, "ui");
649
650     // Collinear/right, Q turns left
651     test_both<P, double>("t-crl1",
652             5, 1,   5, 6,   6, 4, // p
653             5, 7,   5, 6,   7, 5, // q
654             method_touch, 5, 6, "iu");
655     test_both<P, double>("t-crl2",
656             5, 1,   5, 6,   9, 4, // p
657             5, 7,   5, 6,   7, 5, // q
658             method_touch, 5, 6, "cc");
659     test_both<P, double>("t-crl3",
660             5, 1,   5, 6,   7, 6, // p
661             5, 7,   5, 6,   7, 5, // q
662             method_touch, 5, 6, "ui");
663     test_both<P, double>("t-crl4",
664             5, 1,   5, 6,   5, 8, // p
665             5, 7,   5, 6,   7, 5, // q
666             method_touch, 5, 6, "xi");
667     // 5 n.a.
668     test_both<P, double>("t-crl6",
669             5, 1,   5, 6,   4, 4, // p
670             5, 7,   5, 6,   7, 5, // q
671             method_touch, 5, 6, "ii");
672
673     // Collinear/left, Q turns left
674     test_both<P, double>("t-cll1",
675             5, 1,   5, 6,   4, 4, // p
676             3, 5,   5, 6,   5, 8, // q
677             method_touch, 5, 6, "ii");
678     test_both<P, double>("t-cll2",
679             5, 1,   5, 6,   1, 4, // p
680             3, 5,   5, 6,   5, 8, // q
681             method_touch, 5, 6, "xi");
682     test_both<P, double>("t-cll3",
683             5, 1,   5, 6,   3, 6, // p
684             3, 5,   5, 6,   5, 8, // q
685             method_touch, 5, 6, "ui");
686     test_both<P, double>("t-cll4",
687             5, 1,   5, 6,   5, 9, // p
688             3, 5,   5, 6,   5, 8, // q
689             method_touch, 5, 6, "cc");
690     // 5 n.a.
691     test_both<P, double>("t-cll6",
692             5, 1,   5, 6,   6, 4, // p
693             3, 5,   5, 6,   5, 8, // q
694             method_touch, 5, 6, "iu");
695
696     // Left to right
697     test_both<P, double>("lr1",
698             5, 1,   5, 6,   3, 3, // p
699             1, 5,   5, 6,   9, 5, // q
700             method_touch, 5, 6, "ii");
701     test_both<P, double>("lr2",
702             5, 1,   5, 6,   1, 5, // p
703             1, 5,   5, 6,   9, 5, // q
704             method_touch, 5, 6, "xi");
705     test_both<P, double>("lr3",
706             5, 1,   5, 6,   4, 8, // p
707             1, 5,   5, 6,   9, 5, // q
708             method_touch, 5, 6, "ui");
709     test_both<P, double>("lr4",
710             5, 1,   5, 6,   9, 5, // p
711             1, 5,   5, 6,   9, 5, // q
712             method_touch, 5, 6, "cc");
713     test_both<P, double>("lr5",
714             5, 1,   5, 6,   7, 3, // p
715             1, 5,   5, 6,   9, 5, // q
716             method_touch, 5, 6, "iu");
717     // otherwise case more thoroughly
718     test_both<P, double>("lr3a",
719             5, 1,   5, 6,   1, 6, // p
720             1, 5,   5, 6,   9, 5, // q
721             method_touch, 5, 6, "ui");
722     test_both<P, double>("lr3b",
723             5, 1,   5, 6,   5, 10, // p
724             1, 5,   5, 6,   9, 5, // q
725             method_touch, 5, 6, "ui");
726     test_both<P, double>("lr3c",
727             5, 1,   5, 6,   8, 9, // p
728             1, 5,   5, 6,   9, 5, // q
729             method_touch, 5, 6, "ui");
730     test_both<P, double>("lr3d",
731             5, 1,   5, 6,   9, 7, // p
732             1, 5,   5, 6,   9, 5, // q
733             method_touch, 5, 6, "ui");
734     test_both<P, double>("lr3e",
735             5, 1,   5, 6,   9, 6, // p
736             1, 5,   5, 6,   9, 5, // q
737             method_touch, 5, 6, "ui");
738
739     // Right to left
740     test_both<P, double>("rl1",
741             5, 1,   5, 6,   3, 3, // p
742             9, 5,   5, 6,   1, 5, // q
743             method_touch, 5, 6, "ui");
744     test_both<P, double>("rl2",
745             5, 1,   5, 6,   1, 5, // p
746             9, 5,   5, 6,   1, 5, // q
747             method_touch, 5, 6, "cc");
748     test_both<P, double>("rl3",
749             5, 1,   5, 6,   4, 8, // p
750             9, 5,   5, 6,   1, 5, // q
751             method_touch, 5, 6, "iu");
752     test_both<P, double>("rl4",
753             5, 1,   5, 6,   9, 5, // p
754             9, 5,   5, 6,   1, 5, // q
755             method_touch, 5, 6, "xu");
756     test_both<P, double>("rl5",
757             5, 1,   5, 6,   7, 3, // p
758             9, 5,   5, 6,   1, 5, // q
759             method_touch, 5, 6, "uu");
760
761     // Equal (p1/q1 are equal)
762     test_both<P, double>("ebl1",
763             5, 1,   5, 6,   3, 4, // p
764             5, 1,   5, 6,   3, 8, // q
765             method_equal, 5, 6, "ui");
766     test_both<P, double>("ebl2",
767             5, 1,   5, 6,   3, 8, // p
768             5, 1,   5, 6,   3, 4, // q
769             method_equal, 5, 6, "iu");
770     test_both<P, double>("ebl3",
771             5, 1,   5, 6,   3, 8, // p
772             5, 1,   5, 6,   3, 8, // q
773             method_equal, 5, 6, "cc");
774
775     test_both<P, double>("ebl3-c1",
776             5, 1,   5, 6,   10, 1, // p
777             5, 1,   5, 6,   3, 8, // q
778             method_equal, 5, 6, "iu");
779
780     test_both<P, double>("ebr1",
781             5, 1,   5, 6,   7, 4, // p
782             5, 1,   5, 6,   7, 8, // q
783             method_equal, 5, 6, "iu");
784     test_both<P, double>("ebr2",
785             5, 1,   5, 6,   7, 8, // p
786             5, 1,   5, 6,   7, 4, // q
787             method_equal, 5, 6, "ui");
788     test_both<P, double>("ebr3",
789             5, 1,   5, 6,   7, 8, // p
790             5, 1,   5, 6,   7, 8, // q
791             method_equal, 5, 6, "cc");
792
793     test_both<P, double>("ebr3-c1",
794             5, 1,   5, 6,   0, 1, // p
795             5, 1,   5, 6,   7, 8, // q
796             method_equal, 5, 6, "ui");
797
798     test_both<P, double>("elr1",
799             5, 1,   5, 6,   7, 8, // p
800             5, 1,   5, 6,   3, 8, // q
801             method_equal, 5, 6, "iu");
802     test_both<P, double>("elr2",
803             5, 1,   5, 6,   3, 8, // p
804             5, 1,   5, 6,   7, 8, // q
805             method_equal, 5, 6, "ui");
806     test_both<P, double>("ec1",
807             5, 1,   5, 6,   5, 8, // p
808             5, 1,   5, 6,   5, 8, // q
809             method_equal, 5, 6, "cc");
810     test_both<P, double>("ec2",
811             5, 1,   5, 6,   5, 8, // p
812             5, 1,   5, 6,   5, 7, // q
813             method_equal, 5, 6, "cc");
814
815     test_both<P, double>("snl-1",
816             0, 3,   2, 3,   4, 3, // p
817             4, 3,   2, 3,   0, 3, // q
818             method_touch, 2, 3, "xx");
819
820     // BSG 2012-05-26 to be decided what's the problem here and what it tests...
821     // Anyway, test results are not filled out.
822     //test_both<P, double>("issue_buffer_mill",
823     //        5.1983614873206241 , 6.7259025813913107 , 5.0499999999999998 , 6.4291796067500622 , 5.1983614873206241 , 6.7259025813913107, // p
824     //        5.0499999999999998 , 6.4291796067500622 , 5.0499999999999998 , 6.4291796067500622 , 5.1983614873206241 , 6.7259025813913107, // q
825     //        method_collinear, 2, 0, "tt");
826
827 }
828
829
830 /***
831 #include <boost/geometry/geometries/adapted/c_array.hpp>
832 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
833
834 template <typename G>
835 void test2(G const& geometry)
836 {
837     typedef typename bg::point_type<G>::type P;
838     typedef typename bg::tag<G>::type T;
839     typedef typename bg::tag<P>::type PT;
840     std::cout << typeid(G).name() << std::endl;
841     std::cout << typeid(T).name() << std::endl;
842     std::cout << typeid(P).name() << std::endl;
843     std::cout << typeid(PT).name() << std::endl;
844
845
846     std::cout << bg::length(geometry) << std::endl;
847
848     typedef bg::model::point<float, 3, bg::cs::cartesian> P2;
849     bg::model::linestring<P2> out;
850     bg::strategy::transform::scale_transformer<float[3], P2> scaler(5);
851     bg::transform(geometry, out, scaler);
852     std::cout << bg::dsv(out) << std::endl;
853 }
854
855 void test_f3()
856 {
857     float vertices[][3] = {
858         {-1, -1,  1}, {1, -1,  1}, {1, 1,  1}, {-1, 1,  1},
859         {-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}
860         };
861     test2(vertices);
862 }
863 ***/
864
865 int test_main(int, char* [])
866 {
867     test_all<bg::model::d2::point_xy<double> >();
868     return 0;
869 }