119 start_x_r, |
119 start_x_r, |
120 start_point.y as usize, |
120 start_point.y as usize, |
121 1, |
121 1, |
122 ); |
122 ); |
123 |
123 |
124 loop { |
124 while let Some(a) = stack.pop() { |
125 let a = stack.pop(); |
125 let (mut xl, mut xr, y, mut dir) = a; |
126 match a { |
126 |
127 None => return, |
127 while xl > 0 && self |
128 Some(a) => { |
128 .pixels |
129 let (mut xl, mut xr, y, mut dir) = a; |
129 .get(y, xl) |
130 |
130 .map_or(false, |v| *v != border_value && *v != fill_value) |
131 while xl > 0 && self |
131 { |
132 .pixels |
132 xl -= 1; |
133 .get(y, xl) |
133 } |
134 .map_or(false, |v| *v != border_value && *v != fill_value) |
134 |
135 { |
135 while xr < self.width() - 1 && self |
136 xl -= 1; |
136 .pixels |
137 } |
137 .get(y, xr) |
138 |
138 .map_or(false, |v| *v != border_value && *v != fill_value) |
139 while xr < self.width() - 1 && self |
139 { |
140 .pixels |
140 xr += 1; |
141 .get(y, xr) |
141 } |
142 .map_or(false, |v| *v != border_value && *v != fill_value) |
142 |
143 { |
143 while xl < xr { |
144 xr += 1; |
144 while xl <= xr |
145 } |
145 && (self.pixels[y][xl] == border_value || self.pixels[y][xl] == fill_value) |
146 |
146 { |
147 while xl < xr { |
147 xl += 1; |
148 while xl <= xr |
148 } |
149 && (self.pixels[y][xl] == border_value |
149 |
150 || self.pixels[y][xl] == fill_value) |
150 let mut x = xl; |
151 { |
151 |
152 xl += 1; |
152 while xl <= xr |
153 } |
153 && (self.pixels[y][xl] != border_value && self.pixels[y][xl] != fill_value) |
154 |
154 { |
155 let mut x = xl; |
155 self.pixels[y][xl] = fill_value; |
156 |
156 |
157 while xl <= xr |
157 xl += 1; |
158 && (self.pixels[y][xl] != border_value |
158 } |
159 && self.pixels[y][xl] != fill_value) |
159 |
160 { |
160 if x < xl { |
161 self.pixels[y][xl] = fill_value; |
161 push(self, &mut stack, x, xl - 1, y, dir); |
162 |
162 push(self, &mut stack, x, xl - 1, y, -dir); |
163 xl += 1; |
|
164 } |
|
165 |
|
166 if x < xl { |
|
167 push(self, &mut stack, x, xl - 1, y, dir); |
|
168 push(self, &mut stack, x, xl - 1, y, -dir); |
|
169 } |
|
170 } |
|
171 } |
163 } |
172 } |
164 } |
173 } |
165 } |
174 } |
166 } |
175 |
167 |