11 #ifndef hifi_FloodFill_h
12 #define hifi_FloodFill_h
39 template<
class Strategy,
typename Cursor >
40 void floodFill(Cursor
const& position,
41 Strategy
const& strategy = Strategy());
44 template<
class Strategy,
typename Cursor >
45 struct floodFill_impl : Strategy {
47 floodFill_impl(Strategy
const& s) : Strategy(s) { }
49 using Strategy::select;
50 using Strategy::process;
53 using Strategy::right;
57 using Strategy::defer;
58 using Strategy::deferred;
60 void go(Cursor position) {
62 if (! select(position)) {
66 Cursor higher, lower, h,l, i;
69 if (! process(position)) {
75 if (select(higher)) { defer(higher); }
79 if (select(lower)) { defer(lower); }
81 i = position, h = higher, l = lower;
84 right(i), right(h), right(l);
85 if (select(h)) { defer(h); }
86 if (select(l)) { defer(l); }
88 }
while (select(i) && process(i));
90 i = position, h = higher, l = lower;
92 left(i); left(h); left(l);
93 if (select(h)) { defer(h); }
94 if (select(l)) { defer(l); }
96 }
while (select(i) && process(i));
98 }
while (deferred(position));
102 template<
class Strategy,
typename Cursor >
103 void floodFill(Cursor
const& p, Strategy
const& s) {
105 floodFill_impl<Strategy,Cursor>(s).go(p);