get_turn_info.cpp 32 KB

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