-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetriminos_normalize.c
75 lines (66 loc) · 1.87 KB
/
tetriminos_normalize.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tetriminos_normalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: juazouz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/02 00:57:20 by juazouz #+# #+# */
/* Updated: 2018/11/26 13:29:17 by juazouz ### ########.fr */
/* */
/* ************************************************************************** */
#include <limits.h>
#include "fillit.h"
static int get_min(t_point *point, int (f)(t_point*))
{
int min;
int i;
min = f(&point[0]);
i = 1;
while (i < TETRIMINOS_SIZE)
{
if (f(&point[i]) < min)
min = f(&point[i]);
i++;
}
return (min);
}
static int get_max(t_point *point, int (f)(t_point*))
{
int max;
int i;
max = f(&point[0]);
i = 1;
while (i < TETRIMINOS_SIZE)
{
if (f(&point[i]) > max)
max = f(&point[i]);
i++;
}
return (max);
}
static int get_x(t_point *point)
{
return (point->x);
}
static int get_y(t_point *point)
{
return (point->y);
}
void tetriminos_normalize(t_tetriminos *tetriminos)
{
int i;
int min_x;
int min_y;
min_x = get_min(tetriminos->points, get_x);
min_y = get_min(tetriminos->points, get_y);
i = 0;
while (i < TETRIMINOS_SIZE)
{
tetriminos->points[i].x -= min_x;
tetriminos->points[i].y -= min_y;
i++;
}
tetriminos->width = get_max(tetriminos->points, get_x) + 1;
tetriminos->height = get_max(tetriminos->points, get_y) + 1;
}