polygon_90_set_concept.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_POLYGON_90_SET_CONCEPT_HPP
  8. #define BOOST_POLYGON_POLYGON_90_SET_CONCEPT_HPP
  9. #include "polygon_90_set_data.hpp"
  10. #include "polygon_90_set_traits.hpp"
  11. namespace boost { namespace polygon{
  12. template <typename polygon_set_type>
  13. typename enable_if< typename is_polygon_90_set_type<polygon_set_type>::type,
  14. typename polygon_90_set_traits<polygon_set_type>::iterator_type>::type
  15. begin_90_set_data(const polygon_set_type& polygon_set) {
  16. return polygon_90_set_traits<polygon_set_type>::begin(polygon_set);
  17. }
  18. template <typename polygon_set_type>
  19. typename enable_if< typename is_polygon_90_set_type<polygon_set_type>::type,
  20. typename polygon_90_set_traits<polygon_set_type>::iterator_type>::type
  21. end_90_set_data(const polygon_set_type& polygon_set) {
  22. return polygon_90_set_traits<polygon_set_type>::end(polygon_set);
  23. }
  24. template <typename polygon_set_type>
  25. typename enable_if< typename is_polygon_90_set_type<polygon_set_type>::type,
  26. orientation_2d>::type
  27. scanline_orientation(const polygon_set_type& polygon_set) {
  28. return polygon_90_set_traits<polygon_set_type>::orient(polygon_set);
  29. }
  30. template <typename polygon_set_type>
  31. typename enable_if< typename is_polygon_90_set_type<polygon_set_type>::type,
  32. bool>::type
  33. clean(const polygon_set_type& polygon_set) {
  34. return polygon_90_set_traits<polygon_set_type>::clean(polygon_set);
  35. }
  36. //assign
  37. template <typename polygon_set_type_1, typename polygon_set_type_2>
  38. typename enable_if <
  39. typename gtl_and<
  40. typename is_mutable_polygon_90_set_type<polygon_set_type_1>::type,
  41. typename is_polygon_90_set_type<polygon_set_type_2>::type>::type,
  42. polygon_set_type_1>::type &
  43. assign(polygon_set_type_1& lvalue, const polygon_set_type_2& rvalue) {
  44. polygon_90_set_mutable_traits<polygon_set_type_1>::set(lvalue, begin_90_set_data(rvalue), end_90_set_data(rvalue),
  45. scanline_orientation(rvalue));
  46. return lvalue;
  47. }
  48. template <typename T1, typename T2>
  49. struct are_not_both_rectangle_concept { typedef gtl_yes type; };
  50. template <>
  51. struct are_not_both_rectangle_concept<rectangle_concept, rectangle_concept> { typedef gtl_no type; };
  52. //equivalence
  53. template <typename polygon_set_type_1, typename polygon_set_type_2>
  54. typename enable_if< typename gtl_and_3<
  55. typename is_polygon_90_set_type<polygon_set_type_1>::type,
  56. typename is_polygon_90_set_type<polygon_set_type_2>::type,
  57. typename are_not_both_rectangle_concept<typename geometry_concept<polygon_set_type_1>::type,
  58. typename geometry_concept<polygon_set_type_2>::type>::type>::type,
  59. bool>::type
  60. equivalence(const polygon_set_type_1& lvalue,
  61. const polygon_set_type_2& rvalue) {
  62. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type_1>::coordinate_type> ps1;
  63. assign(ps1, lvalue);
  64. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type_2>::coordinate_type> ps2;
  65. assign(ps2, rvalue);
  66. return ps1 == ps2;
  67. }
  68. //get rectangle tiles (slicing orientation is vertical)
  69. template <typename output_container_type, typename polygon_set_type>
  70. typename enable_if< typename gtl_if<typename is_polygon_90_set_type<polygon_set_type>::type>::type,
  71. void>::type
  72. get_rectangles(output_container_type& output, const polygon_set_type& polygon_set) {
  73. clean(polygon_set);
  74. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> ps(VERTICAL);
  75. assign(ps, polygon_set);
  76. ps.get_rectangles(output);
  77. }
  78. //get rectangle tiles
  79. template <typename output_container_type, typename polygon_set_type>
  80. typename enable_if< typename gtl_if<typename is_polygon_90_set_type<polygon_set_type>::type>::type,
  81. void>::type
  82. get_rectangles(output_container_type& output, const polygon_set_type& polygon_set, orientation_2d slicing_orientation) {
  83. clean(polygon_set);
  84. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> ps;
  85. assign(ps, polygon_set);
  86. ps.get_rectangles(output, slicing_orientation);
  87. }
  88. //get: min_rectangles max_rectangles
  89. template <typename output_container_type, typename polygon_set_type>
  90. typename enable_if <typename gtl_and<
  91. typename is_polygon_90_set_type<polygon_set_type>::type,
  92. typename gtl_same_type<rectangle_concept,
  93. typename geometry_concept
  94. <typename std::iterator_traits
  95. <typename output_container_type::iterator>::value_type>::type>::type>::type,
  96. void>::type
  97. get_max_rectangles(output_container_type& output, const polygon_set_type& polygon_set) {
  98. std::vector<rectangle_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> > rects;
  99. assign(rects, polygon_set);
  100. MaxCover<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::getMaxCover(output, rects, scanline_orientation(polygon_set));
  101. }
  102. //clear
  103. template <typename polygon_set_type>
  104. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  105. void>::type
  106. clear(polygon_set_type& polygon_set) {
  107. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> ps(scanline_orientation(polygon_set));
  108. assign(polygon_set, ps);
  109. }
  110. //empty
  111. template <typename polygon_set_type>
  112. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  113. bool>::type
  114. empty(const polygon_set_type& polygon_set) {
  115. if(clean(polygon_set)) return begin_90_set_data(polygon_set) == end_90_set_data(polygon_set);
  116. polygon_90_set_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> ps;
  117. assign(ps, polygon_set);
  118. ps.clean();
  119. return ps.empty();
  120. }
  121. //extents
  122. template <typename polygon_set_type, typename rectangle_type>
  123. typename enable_if <typename gtl_and< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  124. typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
  125. bool>::type
  126. extents(rectangle_type& extents_rectangle,
  127. const polygon_set_type& polygon_set) {
  128. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  129. polygon_90_set_data<Unit> ps;
  130. assign(ps, polygon_set);
  131. return ps.extents(extents_rectangle);
  132. }
  133. //area
  134. template <typename polygon_set_type>
  135. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  136. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::manhattan_area_type>::type
  137. area(const polygon_set_type& polygon_set) {
  138. typedef rectangle_data<typename polygon_90_set_traits<polygon_set_type>::coordinate_type> rectangle_type;
  139. typedef typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::manhattan_area_type area_type;
  140. std::vector<rectangle_type> rects;
  141. assign(rects, polygon_set);
  142. area_type retval = (area_type)0;
  143. for(std::size_t i = 0; i < rects.size(); ++i) {
  144. retval += (area_type)area(rects[i]);
  145. }
  146. return retval;
  147. }
  148. //interact
  149. template <typename polygon_set_type_1, typename polygon_set_type_2>
  150. typename enable_if <typename gtl_and< typename is_mutable_polygon_90_set_type<polygon_set_type_1>::type,
  151. typename is_mutable_polygon_90_set_type<polygon_set_type_2>::type>::type,
  152. polygon_set_type_1>::type&
  153. interact(polygon_set_type_1& polygon_set_1, const polygon_set_type_2& polygon_set_2) {
  154. typedef typename polygon_90_set_traits<polygon_set_type_1>::coordinate_type Unit;
  155. polygon_90_set_data<Unit> ps(scanline_orientation(polygon_set_2));
  156. polygon_90_set_data<Unit> ps2(ps);
  157. ps.insert(polygon_set_1);
  158. ps2.insert(polygon_set_2);
  159. ps.interact(ps2);
  160. assign(polygon_set_1, ps);
  161. return polygon_set_1;
  162. }
  163. //self_intersect
  164. template <typename polygon_set_type>
  165. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  166. polygon_set_type>::type &
  167. self_intersect(polygon_set_type& polygon_set) {
  168. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  169. polygon_90_set_data<Unit> ps;
  170. assign(ps, polygon_set);
  171. ps.self_intersect();
  172. assign(polygon_set, ps);
  173. return polygon_set;
  174. }
  175. //self_xor
  176. template <typename polygon_set_type>
  177. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  178. polygon_set_type>::type &
  179. self_xor(polygon_set_type& polygon_set) {
  180. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  181. polygon_90_set_data<Unit> ps;
  182. assign(ps, polygon_set);
  183. ps.self_xor();
  184. assign(polygon_set, ps);
  185. return polygon_set;
  186. }
  187. template <typename polygon_set_type>
  188. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  189. polygon_set_type>::type &
  190. bloat(polygon_set_type& polygon_set,
  191. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  192. return bloat(polygon_set, bloating, bloating, bloating, bloating);
  193. }
  194. template <typename polygon_set_type>
  195. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  196. polygon_set_type>::type &
  197. bloat(polygon_set_type& polygon_set, orientation_2d orient,
  198. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  199. if(orient == orientation_2d(HORIZONTAL))
  200. return bloat(polygon_set, bloating, bloating, 0, 0);
  201. return bloat(polygon_set, 0, 0, bloating, bloating);
  202. }
  203. template <typename polygon_set_type>
  204. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  205. polygon_set_type>::type &
  206. bloat(polygon_set_type& polygon_set, orientation_2d orient,
  207. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type low_bloating,
  208. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type high_bloating) {
  209. if(orient == orientation_2d(HORIZONTAL))
  210. return bloat(polygon_set, low_bloating, high_bloating, 0, 0);
  211. return bloat(polygon_set, 0, 0, low_bloating, high_bloating);
  212. }
  213. template <typename polygon_set_type>
  214. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  215. polygon_set_type>::type &
  216. bloat(polygon_set_type& polygon_set, direction_2d dir,
  217. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  218. if(dir == direction_2d(EAST))
  219. return bloat(polygon_set, 0, bloating, 0, 0);
  220. if(dir == direction_2d(WEST))
  221. return bloat(polygon_set, bloating, 0, 0, 0);
  222. if(dir == direction_2d(SOUTH))
  223. return bloat(polygon_set, 0, 0, bloating, 0);
  224. return bloat(polygon_set, 0, 0, 0, bloating);
  225. }
  226. template <typename polygon_set_type>
  227. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  228. polygon_set_type>::type &
  229. bloat(polygon_set_type& polygon_set,
  230. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type west_bloating,
  231. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type east_bloating,
  232. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type south_bloating,
  233. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type north_bloating) {
  234. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  235. polygon_90_set_data<Unit> ps;
  236. assign(ps, polygon_set);
  237. ps.bloat(west_bloating, east_bloating, south_bloating, north_bloating);
  238. ps.clean();
  239. assign(polygon_set, ps);
  240. return polygon_set;
  241. }
  242. template <typename polygon_set_type>
  243. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  244. polygon_set_type>::type &
  245. shrink(polygon_set_type& polygon_set,
  246. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type shrinking) {
  247. return shrink(polygon_set, shrinking, shrinking, shrinking, shrinking);
  248. }
  249. template <typename polygon_set_type>
  250. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  251. polygon_set_type>::type &
  252. shrink(polygon_set_type& polygon_set, orientation_2d orient,
  253. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type shrinking) {
  254. if(orient == orientation_2d(HORIZONTAL))
  255. return shrink(polygon_set, shrinking, shrinking, 0, 0);
  256. return shrink(polygon_set, 0, 0, shrinking, shrinking);
  257. }
  258. template <typename polygon_set_type>
  259. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  260. polygon_set_type>::type &
  261. shrink(polygon_set_type& polygon_set, orientation_2d orient,
  262. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type low_shrinking,
  263. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type high_shrinking) {
  264. if(orient == orientation_2d(HORIZONTAL))
  265. return shrink(polygon_set, low_shrinking, high_shrinking, 0, 0);
  266. return shrink(polygon_set, 0, 0, low_shrinking, high_shrinking);
  267. }
  268. template <typename polygon_set_type>
  269. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  270. polygon_set_type>::type &
  271. shrink(polygon_set_type& polygon_set, direction_2d dir,
  272. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type shrinking) {
  273. if(dir == direction_2d(EAST))
  274. return shrink(polygon_set, 0, shrinking, 0, 0);
  275. if(dir == direction_2d(WEST))
  276. return shrink(polygon_set, shrinking, 0, 0, 0);
  277. if(dir == direction_2d(SOUTH))
  278. return shrink(polygon_set, 0, 0, shrinking, 0);
  279. return shrink(polygon_set, 0, 0, 0, shrinking);
  280. }
  281. template <typename polygon_set_type>
  282. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  283. polygon_set_type>::type &
  284. shrink(polygon_set_type& polygon_set,
  285. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type west_shrinking,
  286. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type east_shrinking,
  287. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type south_shrinking,
  288. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type north_shrinking) {
  289. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  290. polygon_90_set_data<Unit> ps;
  291. assign(ps, polygon_set);
  292. ps.shrink(west_shrinking, east_shrinking, south_shrinking, north_shrinking);
  293. ps.clean();
  294. assign(polygon_set, ps);
  295. return polygon_set;
  296. }
  297. template <typename polygon_set_type, typename coord_type>
  298. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  299. polygon_set_type>::type &
  300. resize(polygon_set_type& polygon_set, coord_type resizing) {
  301. if(resizing > 0) {
  302. return bloat(polygon_set, resizing);
  303. }
  304. if(resizing < 0) {
  305. return shrink(polygon_set, -resizing);
  306. }
  307. return polygon_set;
  308. }
  309. //positive or negative values allow for any and all directions of sizing
  310. template <typename polygon_set_type, typename coord_type>
  311. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  312. polygon_set_type>::type &
  313. resize(polygon_set_type& polygon_set, coord_type west, coord_type east, coord_type south, coord_type north) {
  314. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  315. polygon_90_set_data<Unit> ps;
  316. assign(ps, polygon_set);
  317. ps.resize(west, east, south, north);
  318. assign(polygon_set, ps);
  319. return polygon_set;
  320. }
  321. template <typename polygon_set_type>
  322. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  323. polygon_set_type>::type &
  324. grow_and(polygon_set_type& polygon_set,
  325. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  326. return grow_and(polygon_set, bloating, bloating, bloating, bloating);
  327. }
  328. template <typename polygon_set_type>
  329. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  330. polygon_set_type>::type &
  331. grow_and(polygon_set_type& polygon_set, orientation_2d orient,
  332. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  333. if(orient == orientation_2d(HORIZONTAL))
  334. return grow_and(polygon_set, bloating, bloating, 0, 0);
  335. return grow_and(polygon_set, 0, 0, bloating, bloating);
  336. }
  337. template <typename polygon_set_type>
  338. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  339. polygon_set_type>::type &
  340. grow_and(polygon_set_type& polygon_set, orientation_2d orient,
  341. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type low_bloating,
  342. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type high_bloating) {
  343. if(orient == orientation_2d(HORIZONTAL))
  344. return grow_and(polygon_set, low_bloating, high_bloating, 0, 0);
  345. return grow_and(polygon_set, 0, 0, low_bloating, high_bloating);
  346. }
  347. template <typename polygon_set_type>
  348. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  349. polygon_set_type>::type &
  350. grow_and(polygon_set_type& polygon_set, direction_2d dir,
  351. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
  352. if(dir == direction_2d(EAST))
  353. return grow_and(polygon_set, 0, bloating, 0, 0);
  354. if(dir == direction_2d(WEST))
  355. return grow_and(polygon_set, bloating, 0, 0, 0);
  356. if(dir == direction_2d(SOUTH))
  357. return grow_and(polygon_set, 0, 0, bloating, 0);
  358. return grow_and(polygon_set, 0, 0, 0, bloating);
  359. }
  360. template <typename polygon_set_type>
  361. typename enable_if< typename gtl_if<typename is_mutable_polygon_90_set_type<polygon_set_type>::type>::type,
  362. polygon_set_type>::type &
  363. grow_and(polygon_set_type& polygon_set,
  364. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type west_bloating,
  365. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type east_bloating,
  366. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type south_bloating,
  367. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type north_bloating) {
  368. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  369. std::vector<polygon_90_data<Unit> > polys;
  370. assign(polys, polygon_set);
  371. clear(polygon_set);
  372. polygon_90_set_data<Unit> ps(scanline_orientation(polygon_set));
  373. for(std::size_t i = 0; i < polys.size(); ++i) {
  374. polygon_90_set_data<Unit> tmpPs(scanline_orientation(polygon_set));
  375. tmpPs.insert(polys[i]);
  376. bloat(tmpPs, west_bloating, east_bloating, south_bloating, north_bloating);
  377. tmpPs.clean(); //apply implicit OR on tmp polygon set
  378. ps.insert(tmpPs);
  379. }
  380. self_intersect(ps);
  381. assign(polygon_set, ps);
  382. return polygon_set;
  383. }
  384. template <typename polygon_set_type>
  385. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  386. polygon_set_type>::type &
  387. scale_up(polygon_set_type& polygon_set,
  388. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>
  389. ::unsigned_area_type factor) {
  390. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  391. polygon_90_set_data<Unit> ps;
  392. assign(ps, polygon_set);
  393. ps.scale_up(factor);
  394. assign(polygon_set, ps);
  395. return polygon_set;
  396. }
  397. template <typename polygon_set_type>
  398. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  399. polygon_set_type>::type &
  400. scale_down(polygon_set_type& polygon_set,
  401. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>
  402. ::unsigned_area_type factor) {
  403. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  404. polygon_90_set_data<Unit> ps;
  405. assign(ps, polygon_set);
  406. ps.scale_down(factor);
  407. assign(polygon_set, ps);
  408. return polygon_set;
  409. }
  410. template <typename polygon_set_type, typename scaling_type>
  411. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  412. polygon_set_type>::type &
  413. scale(polygon_set_type& polygon_set,
  414. const scaling_type& scaling) {
  415. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  416. polygon_90_set_data<Unit> ps;
  417. assign(ps, polygon_set);
  418. ps.scale(scaling);
  419. assign(polygon_set, ps);
  420. return polygon_set;
  421. }
  422. struct y_p_s_move : gtl_yes {};
  423. //move
  424. template <typename polygon_set_type>
  425. typename enable_if< typename gtl_and<y_p_s_move, typename gtl_if<typename is_mutable_polygon_90_set_type<polygon_set_type>::type>::type>::type,
  426. polygon_set_type>::type &
  427. move(polygon_set_type& polygon_set,
  428. orientation_2d orient, typename polygon_90_set_traits<polygon_set_type>::coordinate_type displacement) {
  429. if(orient == HORIZONTAL)
  430. return move(polygon_set, displacement, 0);
  431. else
  432. return move(polygon_set, 0, displacement);
  433. }
  434. struct y_p_s_move2 : gtl_yes {};
  435. template <typename polygon_set_type>
  436. typename enable_if< typename gtl_and<y_p_s_move2, typename gtl_if<typename is_mutable_polygon_90_set_type<polygon_set_type>::type>::type>::type,
  437. polygon_set_type>::type &
  438. move(polygon_set_type& polygon_set, typename polygon_90_set_traits<polygon_set_type>::coordinate_type x_displacement,
  439. typename polygon_90_set_traits<polygon_set_type>::coordinate_type y_displacement) {
  440. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  441. polygon_90_set_data<Unit> ps;
  442. assign(ps, polygon_set);
  443. ps.move(x_displacement, y_displacement);
  444. ps.clean();
  445. assign(polygon_set, ps);
  446. return polygon_set;
  447. }
  448. //transform
  449. template <typename polygon_set_type, typename transformation_type>
  450. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  451. polygon_set_type>::type &
  452. transform(polygon_set_type& polygon_set,
  453. const transformation_type& transformation) {
  454. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  455. polygon_90_set_data<Unit> ps;
  456. assign(ps, polygon_set);
  457. ps.transform(transformation);
  458. ps.clean();
  459. assign(polygon_set, ps);
  460. return polygon_set;
  461. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  462. }
  463. //keep
  464. template <typename polygon_set_type>
  465. typename enable_if< typename is_mutable_polygon_90_set_type<polygon_set_type>::type,
  466. polygon_set_type>::type &
  467. keep(polygon_set_type& polygon_set,
  468. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type min_area,
  469. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type max_area,
  470. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type min_width,
  471. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type max_width,
  472. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type min_height,
  473. typename coordinate_traits<typename polygon_90_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type max_height) {
  474. typedef typename polygon_90_set_traits<polygon_set_type>::coordinate_type Unit;
  475. typedef typename coordinate_traits<Unit>::unsigned_area_type uat;
  476. std::list<polygon_90_data<Unit> > polys;
  477. assign(polys, polygon_set);
  478. clear(polygon_set);
  479. typename std::list<polygon_90_data<Unit> >::iterator itr_nxt;
  480. for(typename std::list<polygon_90_data<Unit> >::iterator itr = polys.begin(); itr != polys.end(); itr = itr_nxt){
  481. itr_nxt = itr;
  482. ++itr_nxt;
  483. rectangle_data<Unit> bbox;
  484. extents(bbox, *itr);
  485. uat pwidth = delta(bbox, HORIZONTAL);
  486. if(pwidth > min_width && pwidth <= max_width){
  487. uat pheight = delta(bbox, VERTICAL);
  488. if(pheight > min_height && pheight <= max_height){
  489. uat parea = area(*itr);
  490. if(parea <= max_area && parea >= min_area) {
  491. continue;
  492. }
  493. }
  494. }
  495. polys.erase(itr);
  496. }
  497. assign(polygon_set, polys);
  498. return polygon_set;
  499. }
  500. }
  501. }
  502. #include "detail/polygon_90_set_view.hpp"
  503. #endif