@@ -52,20 +52,39 @@ struct divide_interval<T, true>
52
52
{
53
53
static inline T apply (T const & mi, T const & ma)
54
54
{
55
- // avoid overflow
55
+ // Avoid overflow
56
56
return mi / 2 + ma / 2 + (mi % 2 + ma % 2 ) / 2 ;
57
57
}
58
58
};
59
59
60
- template <int Dimension, typename Box>
60
+ struct visit_no_policy
61
+ {
62
+ template <typename Box>
63
+ static inline void apply (Box const &, std::size_t )
64
+ {}
65
+ };
66
+
67
+ struct include_all_policy
68
+ {
69
+ template <typename Item>
70
+ static inline bool apply (Item const &)
71
+ {
72
+ return true ;
73
+ }
74
+ };
75
+
76
+
77
+ template <std::size_t Dimension, typename Box>
61
78
inline void divide_box (Box const & box, Box& lower_box, Box& upper_box)
62
79
{
63
- typedef typename coordinate_type<Box>::type ctype ;
80
+ using coor_t = typename coordinate_type<Box>::type;
64
81
65
- // Divide input box into two parts, e.g. left/right
66
- ctype mid = divide_interval<ctype>::apply (
67
- geometry::get<min_corner, Dimension>(box),
68
- geometry::get<max_corner, Dimension>(box));
82
+ // Divide input box into two halves
83
+ // either left/right (Dimension 0)
84
+ // or top/bottom (Dimension 1)
85
+ coor_t const mid
86
+ = divide_interval<coor_t >::apply (geometry::get<min_corner, Dimension>(box),
87
+ geometry::get<max_corner, Dimension>(box));
69
88
70
89
lower_box = box;
71
90
upper_box = box;
@@ -143,7 +162,7 @@ inline bool handle_one(IteratorVector const& input, VisitPolicy& visitor)
143
162
{
144
163
if (! visitor.apply (**it1, **it2))
145
164
{
146
- return false ; // interrupt
165
+ return false ; // Bail out if visitor returns false
147
166
}
148
167
}
149
168
}
@@ -174,7 +193,7 @@ inline bool handle_two(IteratorVector1 const& input1,
174
193
{
175
194
if (! visitor.apply (*it1, *it2))
176
195
{
177
- return false ; // interrupt
196
+ return false ; // Bail out if visitor returns false
178
197
}
179
198
}
180
199
}
@@ -215,11 +234,11 @@ inline bool recurse_ok(IteratorVector1 const& input1,
215
234
}
216
235
217
236
218
- template <int Dimension, typename Box>
237
+ template <std:: size_t Dimension, typename Box>
219
238
class partition_two_ranges ;
220
239
221
240
222
- template <int Dimension, typename Box>
241
+ template <std:: size_t Dimension, typename Box>
223
242
class partition_one_range
224
243
{
225
244
template <typename IteratorVector, typename ExpandPolicy>
@@ -328,10 +347,10 @@ public :
328
347
if (! boost::empty (exceeding))
329
348
{
330
349
// Get the box of exceeding-only
331
- Box exceeding_box = get_new_box (exceeding, expand_policy);
350
+ Box const exceeding_box = get_new_box (exceeding, expand_policy);
332
351
333
- // Recursively do exceeding elements only, in next dimension they
334
- // will probably be less exceeding within the new box
352
+ // Recursively do exceeding elements only, in next dimension they
353
+ // will probably be less exceeding within the new box
335
354
if (! (next_level (exceeding_box, exceeding, level, min_elements,
336
355
visitor, expand_policy, overlaps_policy, box_policy)
337
356
// Switch to two forward ranges, combine exceeding with
@@ -341,7 +360,7 @@ public :
341
360
&& next_level2 (exceeding_box, exceeding, upper, level, min_elements,
342
361
visitor, expand_policy, overlaps_policy, box_policy)) )
343
362
{
344
- return false ; // interrupt
363
+ return false ; // Bail out if visitor returns false
345
364
}
346
365
}
347
366
@@ -355,7 +374,7 @@ public :
355
374
356
375
template
357
376
<
358
- int Dimension,
377
+ std:: size_t Dimension,
359
378
typename Box
360
379
>
361
380
class partition_two_ranges
@@ -459,20 +478,20 @@ public :
459
478
460
479
if (recurse_ok (exceeding1, exceeding2, min_elements, level))
461
480
{
462
- Box exceeding_box = get_new_box (exceeding1, exceeding2,
463
- expand_policy1, expand_policy2);
481
+ Box const exceeding_box = get_new_box (exceeding1, exceeding2,
482
+ expand_policy1, expand_policy2);
464
483
if (! next_level (exceeding_box, exceeding1, exceeding2, level,
465
484
min_elements, visitor, expand_policy1, overlaps_policy1,
466
485
expand_policy2, overlaps_policy2, box_policy))
467
486
{
468
- return false ; // interrupt
487
+ return false ; // Bail out if visitor returns false
469
488
}
470
489
}
471
490
else
472
491
{
473
492
if (! handle_two (exceeding1, exceeding2, visitor))
474
493
{
475
- return false ; // interrupt
494
+ return false ; // Bail out if visitor returns false
476
495
}
477
496
}
478
497
@@ -482,23 +501,23 @@ public :
482
501
// the same combinations again and again)
483
502
if (recurse_ok (lower2, upper2, exceeding1, min_elements, level))
484
503
{
485
- Box exceeding_box = get_new_box (exceeding1, expand_policy1);
504
+ Box const exceeding_box = get_new_box (exceeding1, expand_policy1);
486
505
if (! (next_level (exceeding_box, exceeding1, lower2, level,
487
506
min_elements, visitor, expand_policy1, overlaps_policy1,
488
507
expand_policy2, overlaps_policy2, box_policy)
489
508
&& next_level (exceeding_box, exceeding1, upper2, level,
490
509
min_elements, visitor, expand_policy1, overlaps_policy1,
491
510
expand_policy2, overlaps_policy2, box_policy)) )
492
511
{
493
- return false ; // interrupt
512
+ return false ; // Bail out if visitor returns false
494
513
}
495
514
}
496
515
else
497
516
{
498
517
if (! (handle_two (exceeding1, lower2, visitor)
499
518
&& handle_two (exceeding1, upper2, visitor)) )
500
519
{
501
- return false ; // interrupt
520
+ return false ; // Bail out if visitor returns false
502
521
}
503
522
}
504
523
}
@@ -508,23 +527,23 @@ public :
508
527
// All exceeding from 2 with lower and upper of 1:
509
528
if (recurse_ok (lower1, upper1, exceeding2, min_elements, level))
510
529
{
511
- Box exceeding_box = get_new_box (exceeding2, expand_policy2);
530
+ Box const exceeding_box = get_new_box (exceeding2, expand_policy2);
512
531
if (! (next_level (exceeding_box, lower1, exceeding2, level,
513
532
min_elements, visitor, expand_policy1, overlaps_policy1,
514
533
expand_policy2, overlaps_policy2, box_policy)
515
534
&& next_level (exceeding_box, upper1, exceeding2, level,
516
535
min_elements, visitor, expand_policy1, overlaps_policy1,
517
536
expand_policy2, overlaps_policy2, box_policy)) )
518
537
{
519
- return false ; // interrupt
538
+ return false ; // Bail out if visitor returns false
520
539
}
521
540
}
522
541
else
523
542
{
524
543
if (! (handle_two (lower1, exceeding2, visitor)
525
544
&& handle_two (upper1, exceeding2, visitor)) )
526
545
{
527
- return false ; // interrupt
546
+ return false ; // Bail out if visitor returns false
528
547
}
529
548
}
530
549
}
@@ -535,14 +554,14 @@ public :
535
554
min_elements, visitor, expand_policy1, overlaps_policy1,
536
555
expand_policy2, overlaps_policy2, box_policy) )
537
556
{
538
- return false ; // interrupt
557
+ return false ; // Bail out if visitor returns false
539
558
}
540
559
}
541
560
else
542
561
{
543
562
if (! handle_two (lower1, lower2, visitor))
544
563
{
545
- return false ; // interrupt
564
+ return false ; // Bail out if visitor returns false
546
565
}
547
566
}
548
567
@@ -552,37 +571,21 @@ public :
552
571
min_elements, visitor, expand_policy1, overlaps_policy1,
553
572
expand_policy2, overlaps_policy2, box_policy) )
554
573
{
555
- return false ; // interrupt
574
+ return false ; // Bail out if visitor returns false
556
575
}
557
576
}
558
577
else
559
578
{
560
579
if (! handle_two (upper1, upper2, visitor))
561
580
{
562
- return false ; // interrupt
581
+ return false ; // Bail out if visitor returns false
563
582
}
564
583
}
565
584
566
585
return true ;
567
586
}
568
587
};
569
588
570
- struct visit_no_policy
571
- {
572
- template <typename Box>
573
- static inline void apply (Box const &, std::size_t )
574
- {}
575
- };
576
-
577
- struct include_all_policy
578
- {
579
- template <typename Item>
580
- static inline bool apply (Item const &)
581
- {
582
- return true ;
583
- }
584
- };
585
-
586
589
587
590
}} // namespace detail::partition
588
591
@@ -667,14 +670,14 @@ class partition
667
670
std::size_t min_elements,
668
671
VisitBoxPolicy box_visitor)
669
672
{
670
- typedef typename boost::range_iterator
673
+ using iterator_t = typename boost::range_iterator
671
674
<
672
675
ForwardRange const
673
- >::type iterator_type ;
676
+ >::type;
674
677
675
678
if (std::size_t (boost::size (forward_range)) > min_elements)
676
679
{
677
- std::vector<iterator_type > iterator_vector;
680
+ std::vector<iterator_t > iterator_vector;
678
681
Box total;
679
682
assign_inverse (total);
680
683
expand_to_range<IncludePolicy1>(forward_range, total,
@@ -688,16 +691,16 @@ class partition
688
691
}
689
692
else
690
693
{
691
- for (auto it1 = boost::begin (forward_range);
694
+ for (auto it1 = boost::begin (forward_range);
692
695
it1 != boost::end (forward_range);
693
696
++it1)
694
697
{
695
698
auto it2 = it1;
696
- for (++it2; it2 != boost::end (forward_range); ++it2)
699
+ for (++it2; it2 != boost::end (forward_range); ++it2)
697
700
{
698
701
if (! visitor.apply (*it1, *it2))
699
702
{
700
- return false ; // interrupt
703
+ return false ; // Bail out if visitor returns false
701
704
}
702
705
}
703
706
}
@@ -793,21 +796,21 @@ class partition
793
796
std::size_t min_elements,
794
797
VisitBoxPolicy box_visitor)
795
798
{
796
- typedef typename boost::range_iterator
799
+ using iterator1_t = typename boost::range_iterator
797
800
<
798
801
ForwardRange1 const
799
- >::type iterator_type1 ;
802
+ >::type;
800
803
801
- typedef typename boost::range_iterator
804
+ using iterator2_t = typename boost::range_iterator
802
805
<
803
806
ForwardRange2 const
804
- >::type iterator_type2 ;
807
+ >::type;
805
808
806
809
if (std::size_t (boost::size (forward_range1)) > min_elements
807
810
&& std::size_t (boost::size (forward_range2)) > min_elements)
808
811
{
809
- std::vector<iterator_type1 > iterator_vector1;
810
- std::vector<iterator_type2 > iterator_vector2;
812
+ std::vector<iterator1_t > iterator_vector1;
813
+ std::vector<iterator2_t > iterator_vector2;
811
814
Box total;
812
815
assign_inverse (total);
813
816
expand_to_range<IncludePolicy1>(forward_range1, total,
@@ -835,7 +838,7 @@ class partition
835
838
{
836
839
if (! visitor.apply (*it1, *it2))
837
840
{
838
- return false ; // interrupt
841
+ return false ; // Bail out if visitor returns false
839
842
}
840
843
}
841
844
}
0 commit comments