-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilsgraph.c
62 lines (55 loc) · 1.93 KB
/
utilsgraph.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilsgraph.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dcelsa <dcelsa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/04 02:42:45 by dcelsa #+# #+# */
/* Updated: 2022/03/04 02:42:45 by dcelsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_bool pxlinbounds(t_res *res, t_cart *dot)
{
if (round(dot->x) < 0 || round(dot->x) > res->x - 0.5)
return (FALSE);
if (round(dot->y) < 0 || round(dot->y) > res->y - 0.5)
return (FALSE);
return (TRUE);
}
t_ui *pxl(int x, int y, t_img *img)
{
char *pixel;
pixel = img->addr + y * img->line + x * (img->bpp / 8);
return ((t_ui *)pixel);
}
void cartcopy(t_cart **ref, t_cart **cpy, int rows, int cols)
{
int i;
int j;
i = -1;
while (++i < rows)
{
j = -1;
while (++j < cols)
{
cpy[i][j].x = ref[i][j].x;
cpy[i][j].y = ref[i][j].y;
cpy[i][j].z = ref[i][j].z;
cpy[i][j].color.t = ref[i][j].color.t;
cpy[i][j].color.r = ref[i][j].color.r;
cpy[i][j].color.g = ref[i][j].color.g;
cpy[i][j].color.b = ref[i][j].color.b;
}
}
}
void dotalloc(t_dot *dots, char *prog, int i)
{
dots->ref[i - 1] = perrhndlr(prog,
malloc(sizeof(**dots->ref) * dots->cols));
dots->dots[i - 1] = perrhndlr(prog,
malloc(sizeof(**dots->dots) * dots->cols));
dots->pos[i - 1] = perrhndlr(prog,
malloc(sizeof(**dots->pos) * dots->cols));
}