setops.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // Boost.Geometry
  2. // Copyright (c) 2019, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #include "common.hpp"
  7. #include <boost/geometry/algorithms/difference.hpp>
  8. #include <boost/geometry/algorithms/intersection.hpp>
  9. #include <boost/geometry/algorithms/sym_difference.hpp>
  10. #include <boost/geometry/algorithms/union.hpp>
  11. template <typename G1, typename G2, typename G3, typename S>
  12. inline void set_idsu(G1 const& g1, G2 const& g2, G3 & g3, S const& s)
  13. {
  14. bg::intersection(g1, g2, g3, s);
  15. bg::difference(g1, g2, g3, s);
  16. bg::sym_difference(g1, g2, g3, s);
  17. bg::union_(g1, g2, g3, s);
  18. }
  19. template <typename G1, typename G2, typename G3, typename S>
  20. inline void set_ids(G1 const& g1, G2 const& g2, G3 & g3, S const& s)
  21. {
  22. bg::intersection(g1, g2, g3, s);
  23. bg::difference(g1, g2, g3, s);
  24. bg::sym_difference(g1, g2, g3, s);
  25. }
  26. template <typename G1, typename G2, typename G3, typename S>
  27. inline void set_id(G1 const& g1, G2 const& g2, G3 & g3, S const& s)
  28. {
  29. bg::intersection(g1, g2, g3, s);
  30. bg::difference(g1, g2, g3, s);
  31. }
  32. template <typename G1, typename G2, typename G3, typename S>
  33. inline void set_i(G1 const& g1, G2 const& g2, G3 & g3, S const& s)
  34. {
  35. bg::intersection(g1, g2, g3, s);
  36. }
  37. template <typename G1, typename G2, typename G3, typename S>
  38. inline void set_d(G1 const& g1, G2 const& g2, G3 & g3, S const& s)
  39. {
  40. bg::difference(g1, g2, g3, s);
  41. }
  42. template <typename G1, typename G2, typename G3>
  43. inline void set_idsu_pp(G1 const& g1, G2 const& g2, G3 & g3)
  44. {
  45. ::set_idsu(g1, g2, g3, bg::strategy::within::cartesian_point_point());
  46. ::set_idsu(g1, g2, g3, bg::strategy::within::spherical_point_point());
  47. }
  48. template <typename G1, typename G2, typename G3>
  49. inline void set_idsu_ps(G1 const& g1, G2 const& g2, G3 & g3)
  50. {
  51. typedef typename bg::point_type<G1>::type point_type;
  52. ::set_idsu(g1, g2, g3, bg::strategy::within::cartesian_winding<point_type>());
  53. ::set_idsu(g1, g2, g3, bg::strategy::within::spherical_winding<point_type>());
  54. ::set_idsu(g1, g2, g3, bg::strategy::within::geographic_winding<point_type>());
  55. }
  56. template <typename G1, typename G2, typename G3>
  57. inline void set_idsu_ss(G1 const& g1, G2 const& g2, G3 & g3)
  58. {
  59. ::set_idsu(g1, g2, g3, bg::strategy::intersection::cartesian_segments<>());
  60. ::set_idsu(g1, g2, g3, bg::strategy::intersection::spherical_segments<>());
  61. ::set_idsu(g1, g2, g3, bg::strategy::intersection::geographic_segments<>());
  62. }
  63. template <typename G1, typename G2, typename G3>
  64. inline void set_ids_pp(G1 const& g1, G2 const& g2, G3 & g3)
  65. {
  66. ::set_ids(g1, g2, g3, bg::strategy::within::cartesian_point_point());
  67. ::set_ids(g1, g2, g3, bg::strategy::within::spherical_point_point());
  68. }
  69. template <typename G1, typename G2, typename G3>
  70. inline void set_ids_ps(G1 const& g1, G2 const& g2, G3 & g3)
  71. {
  72. typedef typename bg::point_type<G1>::type point_type;
  73. ::set_ids(g1, g2, g3, bg::strategy::within::cartesian_winding<point_type>());
  74. ::set_ids(g1, g2, g3, bg::strategy::within::spherical_winding<point_type>());
  75. ::set_ids(g1, g2, g3, bg::strategy::within::geographic_winding<point_type>());
  76. }
  77. template <typename G1, typename G2, typename G3>
  78. inline void set_ids_ss(G1 const& g1, G2 const& g2, G3 & g3)
  79. {
  80. ::set_ids(g1, g2, g3, bg::strategy::intersection::cartesian_segments<>());
  81. ::set_ids(g1, g2, g3, bg::strategy::intersection::spherical_segments<>());
  82. ::set_ids(g1, g2, g3, bg::strategy::intersection::geographic_segments<>());
  83. }
  84. template <typename G1, typename G2, typename G3>
  85. inline void set_id_pp(G1 const& g1, G2 const& g2, G3 & g3)
  86. {
  87. ::set_id(g1, g2, g3, bg::strategy::within::cartesian_point_point());
  88. ::set_id(g1, g2, g3, bg::strategy::within::spherical_point_point());
  89. }
  90. template <typename G1, typename G2, typename G3>
  91. inline void set_id_ps(G1 const& g1, G2 const& g2, G3 & g3)
  92. {
  93. typedef typename bg::point_type<G1>::type point_type;
  94. ::set_id(g1, g2, g3, bg::strategy::within::cartesian_winding<point_type>());
  95. ::set_id(g1, g2, g3, bg::strategy::within::spherical_winding<point_type>());
  96. ::set_id(g1, g2, g3, bg::strategy::within::geographic_winding<point_type>());
  97. }
  98. template <typename G1, typename G2, typename G3>
  99. inline void set_id_ss(G1 const& g1, G2 const& g2, G3 & g3)
  100. {
  101. ::set_id(g1, g2, g3, bg::strategy::intersection::cartesian_segments<>());
  102. ::set_id(g1, g2, g3, bg::strategy::intersection::spherical_segments<>());
  103. ::set_id(g1, g2, g3, bg::strategy::intersection::geographic_segments<>());
  104. }
  105. template <typename G1, typename G2, typename G3>
  106. inline void set_i_pp(G1 const& g1, G2 const& g2, G3 & g3)
  107. {
  108. ::set_i(g1, g2, g3, bg::strategy::within::cartesian_point_point());
  109. ::set_i(g1, g2, g3, bg::strategy::within::spherical_point_point());
  110. }
  111. template <typename G1, typename G2, typename G3>
  112. inline void set_i_ps(G1 const& g1, G2 const& g2, G3 & g3)
  113. {
  114. typedef typename bg::point_type<G1>::type point_type;
  115. ::set_i(g1, g2, g3, bg::strategy::within::cartesian_winding<point_type>());
  116. ::set_i(g1, g2, g3, bg::strategy::within::spherical_winding<point_type>());
  117. ::set_i(g1, g2, g3, bg::strategy::within::geographic_winding<point_type>());
  118. }
  119. template <typename G1, typename G2, typename G3>
  120. inline void set_i_ss(G1 const& g1, G2 const& g2, G3 & g3)
  121. {
  122. ::set_i(g1, g2, g3, bg::strategy::intersection::cartesian_segments<>());
  123. ::set_i(g1, g2, g3, bg::strategy::intersection::spherical_segments<>());
  124. ::set_i(g1, g2, g3, bg::strategy::intersection::geographic_segments<>());
  125. }
  126. template <typename G1, typename G2, typename G3>
  127. inline void set_d_pp(G1 const& g1, G2 const& g2, G3 & g3)
  128. {
  129. ::set_d(g1, g2, g3, bg::strategy::within::cartesian_point_point());
  130. ::set_d(g1, g2, g3, bg::strategy::within::spherical_point_point());
  131. }
  132. template <typename G1, typename G2, typename G3>
  133. inline void set_d_ps(G1 const& g1, G2 const& g2, G3 & g3)
  134. {
  135. typedef typename bg::point_type<G1>::type point_type;
  136. ::set_d(g1, g2, g3, bg::strategy::within::cartesian_winding<point_type>());
  137. ::set_d(g1, g2, g3, bg::strategy::within::spherical_winding<point_type>());
  138. ::set_d(g1, g2, g3, bg::strategy::within::geographic_winding<point_type>());
  139. }
  140. template <typename G1, typename G2, typename G3>
  141. inline void set_d_ss(G1 const& g1, G2 const& g2, G3 & g3)
  142. {
  143. ::set_d(g1, g2, g3, bg::strategy::intersection::cartesian_segments<>());
  144. ::set_d(g1, g2, g3, bg::strategy::intersection::spherical_segments<>());
  145. ::set_d(g1, g2, g3, bg::strategy::intersection::geographic_segments<>());
  146. }
  147. int test_main(int, char*[])
  148. {
  149. geom g;
  150. // P/P->P
  151. ::set_idsu_pp(g.pt, g.pt, g.mpt);
  152. ::set_idsu_pp(g.pt, g.mpt, g.mpt);
  153. ::set_idsu_pp(g.mpt, g.mpt, g.mpt);
  154. // P/L->P
  155. ::set_id_ps(g.pt, g.s, g.mpt);
  156. ::set_id_ps(g.pt, g.ls, g.mpt);
  157. ::set_id_ps(g.pt, g.mls, g.mpt);
  158. ::set_id_ps(g.mpt, g.s, g.mpt);
  159. ::set_id_ps(g.mpt, g.ls, g.mpt);
  160. ::set_id_ps(g.mpt, g.mls, g.mpt);
  161. // P/A->P
  162. // no intersection nor difference
  163. //::set_id_ps(g.pt, g.r, g.mpt);
  164. //::set_id_ps(g.pt, g.po, g.mpt);
  165. //::set_id_ps(g.pt, g.mpo, g.mpt);
  166. //::set_id_ps(g.mpt, g.r, g.mpt);
  167. //::set_id_ps(g.mpt, g.po, g.mpt);
  168. //::set_id_ps(g.mpt, g.mpo, g.mpt);
  169. // L/L->P
  170. ::set_ids_ss(g.s, g.s, g.mpt);
  171. //::set_i_ss(g.s, g.ls, g.mpt); // no intersection nor difference
  172. //::set_i_ss(g.s, g.mls, g.mpt); // no intersection nor difference
  173. //::set_i_ss(g.ls, g.s, g.mpt); // no intersection nor difference
  174. ::set_ids_ss(g.ls, g.ls, g.mpt);
  175. ::set_i_ss(g.ls, g.mls, g.mpt); // no difference nor sym_difference
  176. //::set_i_ss(g.mls, g.s, g.mpt); // no intersection nor difference
  177. ::set_i_ss(g.mls, g.ls, g.mpt); // no difference nor sym_difference
  178. ::set_ids_ss(g.mls, g.mls, g.mpt);
  179. // L/L->L
  180. //::set_ids_ss(g.s, g.s, g.mls); // union not implemented, missing specialization
  181. //::set_idsu_ss(g.s, g.ls, g.mls); // missing specialization
  182. //::set_idsu_ss(g.s, g.mls, g.mls); // missing specialization
  183. //::set_idsu_ss(g.ls, g.s, g.mls); // missing specialization
  184. ::set_idsu_ss(g.ls, g.ls, g.mls);
  185. ::set_idsu_ss(g.ls, g.mls, g.mls);
  186. //::set_idsu_ss(g.mls, g.s, g.mls); // missing specialization
  187. ::set_idsu_ss(g.mls, g.ls, g.mls);
  188. ::set_idsu_ss(g.mls, g.mls, g.mls);
  189. // S/B->L ?
  190. // L/B->L ?
  191. // L/A->P
  192. //::set_ids_ss(g.s, g.r, g.mpt); // no intersection
  193. //::set_ids_ss(g.s, g.po, g.mpt); // no intersection
  194. //::set_ids_ss(g.s, g.mpo, g.mpt); // no intersection
  195. ::set_ids_ss(g.ls, g.r, g.mpt);
  196. ::set_ids_ss(g.ls, g.po, g.mpt);
  197. ::set_ids_ss(g.ls, g.mpo, g.mpt);
  198. ::set_ids_ss(g.mls, g.r, g.mpt);
  199. ::set_ids_ss(g.mls, g.po, g.mpt);
  200. ::set_ids_ss(g.mls, g.mpo, g.mpt);
  201. // L/A->L
  202. //::set_id_ss(g.s, g.r, g.mls); // no intersection
  203. //::set_id_ss(g.s, g.po, g.mls); // no intersection
  204. //::set_id_ss(g.s, g.mpo, g.mls); // no intersection
  205. ::set_id_ss(g.ls, g.r, g.mls);
  206. ::set_id_ss(g.ls, g.po, g.mls);
  207. ::set_id_ss(g.ls, g.mpo, g.mls);
  208. ::set_id_ss(g.mls, g.r, g.mls);
  209. ::set_id_ss(g.mls, g.po, g.mls);
  210. ::set_id_ss(g.mls, g.mpo, g.mls);
  211. // A/A->P
  212. ::set_i_ss(g.r, g.r, g.mpt);
  213. ::set_i_ss(g.r, g.po, g.mpt);
  214. ::set_i_ss(g.r, g.mpo, g.mpt);
  215. ::set_i_ss(g.po, g.r, g.mpt);
  216. ::set_i_ss(g.po, g.po, g.mpt);
  217. ::set_i_ss(g.po, g.mpo, g.mpt);
  218. ::set_i_ss(g.mpo, g.r, g.mpt);
  219. ::set_i_ss(g.mpo, g.po, g.mpt);
  220. ::set_i_ss(g.mpo, g.mpo, g.mpt);
  221. // A/A->L
  222. ::set_i_ss(g.r, g.r, g.mls);
  223. ::set_i_ss(g.r, g.po, g.mls);
  224. ::set_i_ss(g.r, g.mpo, g.mls);
  225. ::set_i_ss(g.po, g.r, g.mls);
  226. ::set_i_ss(g.po, g.po, g.mls);
  227. ::set_i_ss(g.po, g.mpo, g.mls);
  228. ::set_i_ss(g.mpo, g.r, g.mls);
  229. ::set_i_ss(g.mpo, g.po, g.mls);
  230. ::set_i_ss(g.mpo, g.mpo, g.mls);
  231. // A/A->A
  232. ::set_idsu_ss(g.r, g.r, g.mpo);
  233. ::set_idsu_ss(g.r, g.po, g.mpo);
  234. ::set_idsu_ss(g.r, g.mpo, g.mpo);
  235. ::set_idsu_ss(g.po, g.r, g.mpo);
  236. ::set_idsu_ss(g.po, g.po, g.mpo);
  237. ::set_idsu_ss(g.po, g.mpo, g.mpo);
  238. ::set_idsu_ss(g.mpo, g.r, g.mpo);
  239. ::set_idsu_ss(g.mpo, g.po, g.mpo);
  240. ::set_idsu_ss(g.mpo, g.mpo, g.mpo);
  241. return 0;
  242. }