voronoi_predicates_test.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // Boost.Polygon library voronoi_predicates_test.cpp file
  2. // Copyright Andrii Sydorchuk 2010-2012.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for updates, documentation, and revision history.
  7. #include <boost/core/lightweight_test.hpp>
  8. #include <boost/polygon/detail/voronoi_ctypes.hpp>
  9. #include <boost/polygon/detail/voronoi_predicates.hpp>
  10. #include <boost/polygon/detail/voronoi_structures.hpp>
  11. #include <boost/polygon/voronoi_geometry_type.hpp>
  12. #include <limits>
  13. #include <map>
  14. using namespace boost::polygon::detail;
  15. using namespace boost::polygon;
  16. ulp_comparison<double> ulp_cmp;
  17. typedef voronoi_predicates< voronoi_ctype_traits<int> > VP;
  18. typedef point_2d<int> point_type;
  19. typedef site_event<int> site_type;
  20. typedef circle_event<double> circle_type;
  21. VP::event_comparison_predicate<site_type, circle_type> event_comparison;
  22. typedef beach_line_node_key<site_type> key_type;
  23. typedef VP::distance_predicate<site_type> distance_predicate_type;
  24. typedef VP::node_comparison_predicate<key_type> node_comparison_type;
  25. typedef std::map<key_type, int, node_comparison_type> beach_line_type;
  26. typedef beach_line_type::iterator bieach_line_iterator;
  27. distance_predicate_type distance_predicate;
  28. node_comparison_type node_comparison;
  29. typedef VP::circle_existence_predicate<site_type> CEP_type;
  30. typedef VP::mp_circle_formation_functor<site_type, circle_type> MP_CFF_type;
  31. typedef VP::lazy_circle_formation_functor<site_type, circle_type> lazy_CFF_type;
  32. VP::circle_formation_predicate<site_type, circle_type, CEP_type, MP_CFF_type> mp_predicate;
  33. VP::circle_formation_predicate<site_type, circle_type, CEP_type, lazy_CFF_type> lazy_predicate;
  34. #define CHECK_ORIENTATION(P1, P2, P3, R1, R2) \
  35. BOOST_TEST_EQ(VP::ot::eval(P1, P2, P3) == R1, true); \
  36. BOOST_TEST_EQ(VP::ot::eval(P1, P3, P2) == R2, true); \
  37. BOOST_TEST_EQ(VP::ot::eval(P2, P1, P3) == R2, true); \
  38. BOOST_TEST_EQ(VP::ot::eval(P2, P3, P1) == R1, true); \
  39. BOOST_TEST_EQ(VP::ot::eval(P3, P1, P2) == R1, true); \
  40. BOOST_TEST_EQ(VP::ot::eval(P3, P2, P1) == R2, true)
  41. #define CHECK_EVENT_COMPARISON(A, B, R1, R2) \
  42. BOOST_TEST_EQ(event_comparison(A, B), R1); \
  43. BOOST_TEST_EQ(event_comparison(B, A), R2)
  44. #define CHECK_DISTANCE_PREDICATE(S1, S2, P3, RES) \
  45. BOOST_TEST_EQ(distance_predicate(S1, S2, P3), RES)
  46. #define CHECK_NODE_COMPARISON(node, nodes, res, sz) \
  47. for (int i = 0; i < sz; ++i) { \
  48. BOOST_TEST_EQ(node_comparison(node, nodes[i]), res[i]); \
  49. BOOST_TEST_EQ(node_comparison(nodes[i], node), !res[i]); \
  50. }
  51. #define CHECK_CIRCLE(circle, c_x, c_y, l_x) \
  52. BOOST_TEST_EQ(ulp_cmp(c1.x(), c_x, 10), ulp_comparison<double>::EQUAL); \
  53. BOOST_TEST_EQ(ulp_cmp(c1.y(), c_y, 10), ulp_comparison<double>::EQUAL); \
  54. BOOST_TEST_EQ(ulp_cmp(c1.lower_x(), l_x, 10), ulp_comparison<double>::EQUAL)
  55. #define CHECK_CIRCLE_EXISTENCE(s1, s2, s3, RES) \
  56. { circle_type c1; \
  57. BOOST_TEST_EQ(lazy_predicate(s1, s2, s3, c1), RES); }
  58. #define CHECK_CIRCLE_FORMATION_PREDICATE(s1, s2, s3, c_x, c_y, l_x) \
  59. { circle_type c1, c2; \
  60. BOOST_TEST_EQ(mp_predicate(s1, s2, s3, c1), true); \
  61. BOOST_TEST_EQ(lazy_predicate(s1, s2, s3, c2), true); \
  62. CHECK_CIRCLE(c1, c_x, c_y, l_x); \
  63. CHECK_CIRCLE(c2, c_x, c_y, l_x); }
  64. void orientation_test()
  65. {
  66. int min_int = (std::numeric_limits<int>::min)();
  67. int max_int = (std::numeric_limits<int>::max)();
  68. point_type point1(min_int, min_int);
  69. point_type point2(0, 0);
  70. point_type point3(max_int, max_int);
  71. point_type point4(min_int, max_int);
  72. point_type point5(max_int-1, max_int);
  73. CHECK_ORIENTATION(point1, point2, point3, VP::ot::COLLINEAR, VP::ot::COLLINEAR);
  74. CHECK_ORIENTATION(point1, point4, point3, VP::ot::RIGHT, VP::ot::LEFT);
  75. CHECK_ORIENTATION(point1, point5, point3, VP::ot::RIGHT, VP::ot::LEFT);
  76. }
  77. void event_comparison_test1()
  78. {
  79. site_type site(1, 2);
  80. CHECK_EVENT_COMPARISON(site, site_type(0, 2), false, true);
  81. CHECK_EVENT_COMPARISON(site, site_type(1, 3), true, false);
  82. CHECK_EVENT_COMPARISON(site, site_type(1, 2), false, false);
  83. }
  84. void event_comparison_test2()
  85. {
  86. site_type site(0, 0, 0, 2);
  87. CHECK_EVENT_COMPARISON(site, site_type(0, 2), true, false);
  88. CHECK_EVENT_COMPARISON(site, site_type(0, 0), false, true);
  89. CHECK_EVENT_COMPARISON(site, site_type(0, -2, 0, -1), false, true);
  90. CHECK_EVENT_COMPARISON(site, site_type(0, -2, 1, 1), true, false);
  91. CHECK_EVENT_COMPARISON(site, site_type(0, 0, 1, 1), true, false);
  92. }
  93. void event_comparison_test3()
  94. {
  95. site_type site(0, 0, 10, 10);
  96. CHECK_EVENT_COMPARISON(site, site_type(0, 0), false, true);
  97. CHECK_EVENT_COMPARISON(site, site_type(0, -1), false, true);
  98. CHECK_EVENT_COMPARISON(site, site_type(0, 1), false, true);
  99. CHECK_EVENT_COMPARISON(site, site_type(0, 1, 0, 10), false, true);
  100. CHECK_EVENT_COMPARISON(site, site_type(0, -10, 0, -1), false, true);
  101. CHECK_EVENT_COMPARISON(site, site_type(0, 0, 10, 9), true, false);
  102. CHECK_EVENT_COMPARISON(site, site_type(0, 0, 9, 10), false, true);
  103. }
  104. void event_comparison_test4()
  105. {
  106. circle_type circle(1, 2, 3);
  107. CHECK_EVENT_COMPARISON(circle, circle_type(1, 2, 3), false, false);
  108. CHECK_EVENT_COMPARISON(circle, circle_type(1, 3, 3), true, false);
  109. CHECK_EVENT_COMPARISON(circle, circle_type(1, 2, 4), true, false);
  110. CHECK_EVENT_COMPARISON(circle, circle_type(0, 2, 2), false, true);
  111. CHECK_EVENT_COMPARISON(circle, circle_type(-1, 2, 3), false, false);
  112. }
  113. void event_comparison_test5()
  114. {
  115. circle_type circle(1, 2, 3);
  116. CHECK_EVENT_COMPARISON(circle, site_type(0, 100), false, true);
  117. CHECK_EVENT_COMPARISON(circle, site_type(3, 0), false, false);
  118. CHECK_EVENT_COMPARISON(circle, site_type(3, 2), false, false);
  119. CHECK_EVENT_COMPARISON(circle, site_type(3, 3), false, false);
  120. CHECK_EVENT_COMPARISON(circle, site_type(4, 2), true, false);
  121. }
  122. void distance_predicate_test1()
  123. {
  124. site_type site1(-5, 0);
  125. site1.sorted_index(1);
  126. site_type site2(-8, 9);
  127. site2.sorted_index(0);
  128. site_type site3(-2, 1);
  129. site3.sorted_index(2);
  130. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 5), false);
  131. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, 5), false);
  132. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 4), false);
  133. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, 4), false);
  134. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 6), true);
  135. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, 6), true);
  136. }
  137. void distance_predicate_test2()
  138. {
  139. site_type site1(-4, 0, -4, 20);
  140. site1.sorted_index(0);
  141. site_type site2(-2, 10);
  142. site2.sorted_index(1);
  143. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 11), false);
  144. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 9), false);
  145. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 11), true);
  146. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 9), true);
  147. }
  148. void distance_predicate_test3()
  149. {
  150. site_type site1(-5, 5, 2, -2);
  151. site1.sorted_index(0);
  152. site1.inverse();
  153. site_type site2(-2, 4);
  154. site2.sorted_index(1);
  155. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, -1), false);
  156. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, -1), false);
  157. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 1), false);
  158. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 1), false);
  159. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 4), true);
  160. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 4), false);
  161. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 5), true);
  162. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 5), false);
  163. }
  164. void distance_predicate_test4()
  165. {
  166. site_type site1(-5, 5, 2, -2);
  167. site1.sorted_index(0);
  168. site_type site2(-2, -4);
  169. site2.sorted_index(2);
  170. site_type site3(-4, 1);
  171. site3.sorted_index(1);
  172. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, 1), true);
  173. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, 1), true);
  174. CHECK_DISTANCE_PREDICATE(site1, site3, point_type(0, 1), true);
  175. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, 1), true);
  176. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, -2), true);
  177. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, -2), false);
  178. CHECK_DISTANCE_PREDICATE(site1, site3, point_type(0, -2), true);
  179. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, -2), false);
  180. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, -8), true);
  181. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, -8), false);
  182. CHECK_DISTANCE_PREDICATE(site1, site3, point_type(0, -8), true);
  183. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, -8), false);
  184. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(0, -9), true);
  185. CHECK_DISTANCE_PREDICATE(site2, site1, point_type(0, -9), false);
  186. CHECK_DISTANCE_PREDICATE(site1, site3, point_type(0, -9), true);
  187. CHECK_DISTANCE_PREDICATE(site3, site1, point_type(0, -9), false);
  188. }
  189. void distance_predicate_test5()
  190. {
  191. site_type site1(-5, 5, 2, -2);
  192. site1.sorted_index(0);
  193. site_type site2 = site1;
  194. site2.inverse();
  195. site_type site3(-2, 4);
  196. site3.sorted_index(3);
  197. site_type site4(-2, -4);
  198. site4.sorted_index(2);
  199. site_type site5(-4, 1);
  200. site5.sorted_index(1);
  201. CHECK_DISTANCE_PREDICATE(site3, site2, point_type(0, 1), false);
  202. CHECK_DISTANCE_PREDICATE(site3, site2, point_type(0, 4), false);
  203. CHECK_DISTANCE_PREDICATE(site3, site2, point_type(0, 5), false);
  204. CHECK_DISTANCE_PREDICATE(site3, site2, point_type(0, 7), true);
  205. CHECK_DISTANCE_PREDICATE(site4, site1, point_type(0, -2), false);
  206. CHECK_DISTANCE_PREDICATE(site5, site1, point_type(0, -2), false);
  207. CHECK_DISTANCE_PREDICATE(site4, site1, point_type(0, -8), false);
  208. CHECK_DISTANCE_PREDICATE(site5, site1, point_type(0, -8), false);
  209. CHECK_DISTANCE_PREDICATE(site4, site1, point_type(0, -9), false);
  210. CHECK_DISTANCE_PREDICATE(site5, site1, point_type(0, -9), false);
  211. CHECK_DISTANCE_PREDICATE(site4, site1, point_type(0, -18), false);
  212. CHECK_DISTANCE_PREDICATE(site5, site1, point_type(0, -18), false);
  213. CHECK_DISTANCE_PREDICATE(site4, site1, point_type(0, -1), true);
  214. CHECK_DISTANCE_PREDICATE(site5, site1, point_type(0, -1), true);
  215. }
  216. void distance_predicate_test6()
  217. {
  218. site_type site1(-5, 0, 2, 7);
  219. site_type site2 = site1;
  220. site2.inverse();
  221. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(2, 7), false);
  222. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(1, 5), false);
  223. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(-1, 5), true);
  224. }
  225. void distance_predicate_test7()
  226. {
  227. site_type site1(-5, 5, 2, -2);
  228. site1.sorted_index(1);
  229. site1.inverse();
  230. site_type site2(-5, 5, 0, 6);
  231. site2.sorted_index(0);
  232. site_type site3(-2, 4, 0, 4);
  233. site3.sorted_index(2);
  234. point_type site4(0, 2);
  235. point_type site5(0, 5);
  236. point_type site6(0, 6);
  237. point_type site7(0, 8);
  238. CHECK_DISTANCE_PREDICATE(site1, site2, site4, false);
  239. CHECK_DISTANCE_PREDICATE(site1, site2, site5, true);
  240. CHECK_DISTANCE_PREDICATE(site1, site2, site6, true);
  241. CHECK_DISTANCE_PREDICATE(site1, site2, site7, true);
  242. CHECK_DISTANCE_PREDICATE(site1, site3, site4, false);
  243. CHECK_DISTANCE_PREDICATE(site1, site3, site5, true);
  244. CHECK_DISTANCE_PREDICATE(site1, site3, site6, true);
  245. CHECK_DISTANCE_PREDICATE(site1, site3, site7, true);
  246. site3.inverse();
  247. CHECK_DISTANCE_PREDICATE(site3, site1, site4, false);
  248. CHECK_DISTANCE_PREDICATE(site3, site1, site5, false);
  249. CHECK_DISTANCE_PREDICATE(site3, site1, site6, false);
  250. CHECK_DISTANCE_PREDICATE(site3, site1, site7, true);
  251. }
  252. void distance_predicate_test8()
  253. {
  254. site_type site1(-5, 3, -2, 2);
  255. site1.sorted_index(0);
  256. site1.inverse();
  257. site_type site2(-5, 5, -2, 2);
  258. site2.sorted_index(1);
  259. CHECK_DISTANCE_PREDICATE(site1, site2, point_type(-4, 2), false);
  260. }
  261. void node_comparison_test1()
  262. {
  263. beach_line_type beach_line;
  264. site_type site1(0, 0);
  265. site1.sorted_index(0);
  266. site_type site2(0, 2);
  267. site2.sorted_index(1);
  268. site_type site3(1, 0);
  269. site3.sorted_index(2);
  270. beach_line[key_type(site1, site2)] = 2;
  271. beach_line[key_type(site1, site3)] = 0;
  272. beach_line[key_type(site3, site1)] = 1;
  273. int cur_index = 0;
  274. for (bieach_line_iterator it = beach_line.begin();
  275. it != beach_line.end(); ++it, ++cur_index) {
  276. BOOST_TEST_EQ(it->second, cur_index);
  277. }
  278. }
  279. void node_comparison_test2()
  280. {
  281. beach_line_type beach_line;
  282. site_type site1(0, 1);
  283. site1.sorted_index(0);
  284. site_type site2(2, 0);
  285. site2.sorted_index(1);
  286. site_type site3(2, 4);
  287. site3.sorted_index(2);
  288. beach_line[key_type(site1, site2)] = 0;
  289. beach_line[key_type(site2, site1)] = 1;
  290. beach_line[key_type(site1, site3)] = 2;
  291. beach_line[key_type(site3, site1)] = 3;
  292. int cur_index = 0;
  293. for (bieach_line_iterator it = beach_line.begin();
  294. it != beach_line.end(); ++it, ++cur_index) {
  295. BOOST_TEST_EQ(it->second, cur_index);
  296. }
  297. }
  298. void node_comparison_test3()
  299. {
  300. key_type node(site_type(1, 0).sorted_index(1), site_type(0, 2).sorted_index(0));
  301. key_type nodes[] = {
  302. key_type(site_type(2, -10).sorted_index(2)),
  303. key_type(site_type(2, -1).sorted_index(2)),
  304. key_type(site_type(2, 0).sorted_index(2)),
  305. key_type(site_type(2, 1).sorted_index(2)),
  306. key_type(site_type(2, 2).sorted_index(2)),
  307. key_type(site_type(2, 3).sorted_index(2)),
  308. };
  309. bool res[] = {false, false, false, false, true, true};
  310. CHECK_NODE_COMPARISON(node, nodes, res, 6);
  311. }
  312. void node_comparison_test4()
  313. {
  314. key_type node(site_type(0, 1).sorted_index(0), site_type(1, 0).sorted_index(1));
  315. key_type nodes[] = {
  316. key_type(site_type(2, -3).sorted_index(2)),
  317. key_type(site_type(2, -2).sorted_index(2)),
  318. key_type(site_type(2, -1).sorted_index(2)),
  319. key_type(site_type(2, 0).sorted_index(2)),
  320. key_type(site_type(2, 1).sorted_index(2)),
  321. key_type(site_type(2, 3).sorted_index(2)),
  322. };
  323. bool res[] = {false, true, true, true, true, true};
  324. CHECK_NODE_COMPARISON(node, nodes, res, 6);
  325. }
  326. void node_comparison_test5()
  327. {
  328. key_type node(site_type(0, 0).sorted_index(0), site_type(1, 2).sorted_index(1));
  329. key_type nodes[] = {
  330. key_type(site_type(2, -10).sorted_index(2)),
  331. key_type(site_type(2, 0).sorted_index(2)),
  332. key_type(site_type(2, 1).sorted_index(2)),
  333. key_type(site_type(2, 2).sorted_index(2)),
  334. key_type(site_type(2, 5).sorted_index(2)),
  335. key_type(site_type(2, 20).sorted_index(2)),
  336. };
  337. bool res[] = {false, false, true, true, true, true};
  338. CHECK_NODE_COMPARISON(node, nodes, res, 6);
  339. }
  340. void node_comparison_test6()
  341. {
  342. key_type node(site_type(1, 1).sorted_index(1), site_type(0, 0).sorted_index(0));
  343. key_type nodes[] = {
  344. key_type(site_type(2, -3).sorted_index(2)),
  345. key_type(site_type(2, -2).sorted_index(2)),
  346. key_type(site_type(2, 0).sorted_index(2)),
  347. key_type(site_type(2, 1).sorted_index(2)),
  348. key_type(site_type(2, 2).sorted_index(2)),
  349. key_type(site_type(2, 3).sorted_index(2)),
  350. key_type(site_type(2, 5).sorted_index(2)),
  351. };
  352. bool res[] = {false, false, false, false, false, false, true};
  353. CHECK_NODE_COMPARISON(node, nodes, res, 7);
  354. }
  355. void node_comparison_test7()
  356. {
  357. key_type node(site_type(0, 0).sorted_index(0), site_type(0, 2).sorted_index(1));
  358. key_type nodes[] = {
  359. key_type(site_type(1, 0).sorted_index(2)),
  360. key_type(site_type(1, 1).sorted_index(2)),
  361. key_type(site_type(1, 2).sorted_index(2)),
  362. };
  363. bool res[] = {false, false, true};
  364. CHECK_NODE_COMPARISON(node, nodes, res, 3);
  365. }
  366. void node_comparison_test8()
  367. {
  368. key_type node(site_type(0, 0).sorted_index(0), site_type(1, 1).sorted_index(2));
  369. key_type nodes[] = {
  370. key_type(site_type(1, 0).sorted_index(1)),
  371. key_type(site_type(1, 1).sorted_index(2)),
  372. key_type(site_type(1, 2).sorted_index(3)),
  373. key_type(site_type(1, 1).sorted_index(2), site_type(0, 0).sorted_index(0)),
  374. };
  375. bool res[] = {false, true, true, true};
  376. CHECK_NODE_COMPARISON(node, nodes, res, 4);
  377. }
  378. void circle_formation_predicate_test1()
  379. {
  380. site_type site1(0, 0);
  381. site1.sorted_index(1);
  382. site_type site2(-8, 0);
  383. site2.sorted_index(0);
  384. site_type site3(0, 6);
  385. site3.sorted_index(2);
  386. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, -4.0, 3.0, 1.0);
  387. }
  388. void circle_formation_predicate_test2()
  389. {
  390. int min_int = (std::numeric_limits<int>::min)();
  391. int max_int = (std::numeric_limits<int>::max)();
  392. site_type site1(min_int, min_int);
  393. site1.sorted_index(0);
  394. site_type site2(min_int, max_int);
  395. site2.sorted_index(1);
  396. site_type site3(max_int-1, max_int-1);
  397. site3.sorted_index(2);
  398. site_type site4(max_int, max_int);
  399. site4.sorted_index(3);
  400. CHECK_CIRCLE_EXISTENCE(site1, site2, site4, true);
  401. CHECK_CIRCLE_EXISTENCE(site1, site3, site4, false);
  402. }
  403. void circle_formation_predicate_test3()
  404. {
  405. site_type site1(-4, 0);
  406. site1.sorted_index(0);
  407. site_type site2(0, 4);
  408. site2.sorted_index(4);
  409. site_type site3(site1.point0(), site2.point0());
  410. site3.sorted_index(1);
  411. CHECK_CIRCLE_EXISTENCE(site1, site3, site2, false);
  412. site_type site4(-2, 0);
  413. site4.sorted_index(2);
  414. site_type site5(0, 2);
  415. site5.sorted_index(3);
  416. CHECK_CIRCLE_EXISTENCE(site3, site4, site5, false);
  417. CHECK_CIRCLE_EXISTENCE(site4, site5, site3, false);
  418. }
  419. void circle_formation_predicate_test4()
  420. {
  421. site_type site1(-4, 0, -4, 20);
  422. site1.sorted_index(0);
  423. site_type site2(-2, 10);
  424. site2.sorted_index(1);
  425. site_type site3(4, 10);
  426. site3.sorted_index(2);
  427. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, 1.0, 6.0, 6.0);
  428. CHECK_CIRCLE_FORMATION_PREDICATE(site3, site2, site1, 1.0, 14.0, 6.0);
  429. }
  430. void circle_formation_predicate_test5()
  431. {
  432. site_type site1(1, 0, 7, 0);
  433. site1.sorted_index(2);
  434. site1.inverse();
  435. site_type site2(-2, 4, 10, 4);
  436. site2.sorted_index(0);
  437. site_type site3(6, 2);
  438. site3.sorted_index(3);
  439. site_type site4(1, 0);
  440. site4.sorted_index(1);
  441. CHECK_CIRCLE_FORMATION_PREDICATE(site3, site1, site2, 4.0, 2.0, 6.0);
  442. CHECK_CIRCLE_FORMATION_PREDICATE(site4, site2, site1, 1.0, 2.0, 3.0);
  443. }
  444. void circle_formation_predicate_test6()
  445. {
  446. site_type site1(-1, 2, 8, -10);
  447. site1.sorted_index(1);
  448. site1.inverse();
  449. site_type site2(-1, 0, 8, 12);
  450. site2.sorted_index(0);
  451. site_type site3(1, 1);
  452. site3.sorted_index(2);
  453. CHECK_CIRCLE_FORMATION_PREDICATE(site3, site2, site1, 6.0, 1.0, 11.0);
  454. }
  455. void circle_formation_predicate_test7()
  456. {
  457. site_type site1(1, 0, 6, 0);
  458. site1.sorted_index(2);
  459. site1.inverse();
  460. site_type site2(-6, 4, 0, 12);
  461. site2.sorted_index(0);
  462. site_type site3(1, 0);
  463. site3.sorted_index(1);
  464. CHECK_CIRCLE_FORMATION_PREDICATE(site3, site2, site1, 1.0, 5.0, 6.0);
  465. }
  466. void circle_formation_predicate_test8()
  467. {
  468. site_type site1(1, 0, 5, 0);
  469. site1.sorted_index(2);
  470. site1.inverse();
  471. site_type site2(0, 12, 8, 6);
  472. site2.sorted_index(0);
  473. site_type site3(1, 0);
  474. site3.sorted_index(1);
  475. CHECK_CIRCLE_FORMATION_PREDICATE(site3, site2, site1, 1.0, 5.0, 6.0);
  476. }
  477. void circle_formation_predicate_test9()
  478. {
  479. site_type site1(0, 0, 4, 0);
  480. site1.sorted_index(1);
  481. site_type site2(0, 0, 0, 4);
  482. site2.sorted_index(0);
  483. site_type site3(0, 4, 4, 4);
  484. site3.sorted_index(2);
  485. site1.inverse();
  486. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, 2.0, 2.0, 4.0);
  487. }
  488. void circle_formation_predicate_test10()
  489. {
  490. site_type site1(1, 0, 41, 30);
  491. site1.sorted_index(1);
  492. site_type site2(-39, 30, 1, 60);
  493. site2.sorted_index(0);
  494. site_type site3(1, 60, 41, 30);
  495. site3.sorted_index(2);
  496. site1.inverse();
  497. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, 1.0, 30.0, 25.0);
  498. }
  499. void circle_formation_predicate_test11()
  500. {
  501. site_type site1(0, 0, 0, 10);
  502. site1.sorted_index(2);
  503. site1.inverse();
  504. site_type site2(-8, 10);
  505. site2.sorted_index(0);
  506. site_type site3(-7, 14, -1, 14);
  507. site3.sorted_index(1);
  508. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, -4.0, 10.0, 0.0);
  509. }
  510. void circle_formation_predicate_test12()
  511. {
  512. site_type site1(0, 0, 0, 10);
  513. site1.sorted_index(2);
  514. site1.inverse();
  515. site_type site2(-8, 10);
  516. site2.sorted_index(0);
  517. site_type site3(-7, 15, -1, 15);
  518. site3.sorted_index(1);
  519. CHECK_CIRCLE_EXISTENCE(site1, site2, site3, false);
  520. }
  521. void circle_formation_predicate_test13()
  522. {
  523. site_type site1(0, 0, 0, 10);
  524. site1.sorted_index(2);
  525. site1.inverse();
  526. site_type site2(-7, -4, -1, -4);
  527. site2.sorted_index(1);
  528. site2.inverse();
  529. site_type site3(-8, 0);
  530. site3.sorted_index(0);
  531. CHECK_CIRCLE_FORMATION_PREDICATE(site1, site2, site3, -4.0, 0.0, 0.0);
  532. }
  533. void circle_formation_predicate_test14()
  534. {
  535. site_type site1(0, 0, 0, 10);
  536. site1.sorted_index(2);
  537. site1.inverse();
  538. site_type site2(-7, -5, -1, -5);
  539. site2.sorted_index(1);
  540. site2.inverse();
  541. site_type site3(-8, 0);
  542. site3.sorted_index(0);
  543. CHECK_CIRCLE_EXISTENCE(site1, site2, site3, false);
  544. }
  545. int main()
  546. {
  547. orientation_test();
  548. event_comparison_test1();
  549. event_comparison_test2();
  550. event_comparison_test3();
  551. event_comparison_test4();
  552. event_comparison_test5();
  553. distance_predicate_test1();
  554. distance_predicate_test2();
  555. distance_predicate_test3();
  556. distance_predicate_test4();
  557. distance_predicate_test5();
  558. distance_predicate_test6();
  559. distance_predicate_test7();
  560. distance_predicate_test8();
  561. node_comparison_test1();
  562. node_comparison_test2();
  563. node_comparison_test3();
  564. node_comparison_test4();
  565. node_comparison_test5();
  566. node_comparison_test6();
  567. node_comparison_test7();
  568. node_comparison_test8();
  569. circle_formation_predicate_test1();
  570. circle_formation_predicate_test2();
  571. circle_formation_predicate_test3();
  572. circle_formation_predicate_test4();
  573. circle_formation_predicate_test5();
  574. circle_formation_predicate_test6();
  575. circle_formation_predicate_test7();
  576. circle_formation_predicate_test8();
  577. circle_formation_predicate_test9();
  578. circle_formation_predicate_test10();
  579. circle_formation_predicate_test11();
  580. circle_formation_predicate_test12();
  581. circle_formation_predicate_test13();
  582. circle_formation_predicate_test14();
  583. return boost::report_errors();
  584. }