annotate DEPENDENCIES/generic/include/boost/polygon/polygon_90_set_concept.hpp @ 125:34e428693f5d vext

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