-
Notifications
You must be signed in to change notification settings - Fork 0
/
flood_fill.c
30 lines (27 loc) · 1.43 KB
/
flood_fill.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flood_fill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: msoria-j <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 23:43:46 by msoria-j #+# #+# */
/* Updated: 2024/01/06 23:44:04 by msoria-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_cub_editor.h"
static void fill(char **tab, t_point size, t_point cur, char to_fill)
{
if (cur.y < 0 || cur.y >= size.y || cur.x < 0 || cur.x >= size.x
|| tab[cur.y][cur.x] != to_fill)
return;
tab[cur.y][cur.x] = '0';
fill(tab, size, (t_point){cur.x - 1, cur.y}, to_fill);
fill(tab, size, (t_point){cur.x + 1, cur.y}, to_fill);
fill(tab, size, (t_point){cur.x, cur.y - 1}, to_fill);
fill(tab, size, (t_point){cur.x, cur.y + 1}, to_fill);
}
void flood_fill(char **tab, t_point size, t_point begin)
{
fill(tab, size, begin, tab[begin.y][begin.x]);
}