-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_matrix.c
48 lines (43 loc) · 1.59 KB
/
create_matrix.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_matrix.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoumni <mmoumni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/21 22:37:54 by mmoumni #+# #+# */
/* Updated: 2022/01/05 21:33:29 by mmoumni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void fill_data(t_matrix *matrix, t_stack **stack, t_fdf *fdf)
{
int width;
width = fdf->width;
while (width--)
{
matrix[width].z.altitude = (*stack)->z->altitude;
matrix[width].z.color = (*stack)->z->color;
(*stack) = (*stack)->next;
}
}
t_matrix **create_matrix(t_fdf *fdf, t_stack *stack)
{
t_matrix **matrix;
int height;
int width;
height = fdf->height;
width = fdf->width;
matrix = (t_matrix **)malloc(sizeof(t_matrix *) * (height + 1));
if (!matrix)
return (NULL);
while (height-- > 0)
{
matrix[height] = (t_matrix *)malloc(sizeof(t_matrix) * (width));
if (!matrix[height])
return (NULL);
fill_data(matrix[height], &stack, fdf);
}
matrix[height] = NULL;
return (matrix);
}