diff --git a/a.out b/a.out index 9683d80..e14bb78 100755 Binary files a/a.out and b/a.out differ diff --git a/a.out.dSYM/Contents/Resources/DWARF/a.out b/a.out.dSYM/Contents/Resources/DWARF/a.out index 307a6b6..8d48381 100644 Binary files a/a.out.dSYM/Contents/Resources/DWARF/a.out and b/a.out.dSYM/Contents/Resources/DWARF/a.out differ diff --git a/add_to_list.c b/add_to_list.c index 5a8dc83..037a2fc 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 16:41:09 by hulamy ### ########.fr */ +/* Updated: 2019/04/15 17:16:09 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ ** with the most little rectangle that fit the tetraminos */ -char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) +char **fill_tetraminos(char **square, int *tab) { char **result; int height; @@ -27,11 +27,11 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) int j; i = 0; - height = x2 - x1 + 1; - length = y2 - y1 + 1; - if (!(result = (char**)malloc(sizeof(*result) * (height + 1)))) + height = tab[2] - tab[0] + 1; + length = tab[3] - tab[1] + 1; + if (!(result = (char**)malloc(sizeof(*result) * (height)))) return (NULL); - while (i < 4) + while (i < height) { if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1)))) return (NULL); @@ -41,7 +41,7 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) i = -1; while (++i < height && (j = -1)) while (++j < length) - result[i][j] = square[x1 + i][y1 + j]; + result[i][j] = square[tab[0] + i][tab[1] + j]; return (result); } @@ -94,21 +94,13 @@ void find_start_and_end(char **square, int **x) int fill_list(char **square, t_fillist *list) { int *tab; - int x1; - int x2; - int y1; - int y2; tab = (int*)malloc(sizeof(int) * 4); find_start_and_end(square, &tab); - x1 = tab[0]; - y1 = tab[1]; - x2 = tab[2]; - y2 = tab[3]; - list->size[0] = y2 - y1 + 1; - list->size[1] = x2 - x1 + 1; + list->size[0] = tab[3] - tab[1] + 1; + list->size[1] = tab[2] - tab[0] + 1; list->area = list->size[0] * list->size[1]; - list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2); + list->tetraminos = fill_tetraminos(square, tab); return (1); } @@ -135,6 +127,7 @@ int add_to_list(char **square, t_fillist **list) return (1); } + int main(int ac, char **av) { static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure @@ -156,3 +149,4 @@ int main(int ac, char **av) return (0); } +