-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyhedron.c
51 lines (42 loc) · 1.27 KB
/
polyhedron.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
#include <stdlib.h>
#include <string.h>
#include "polyhedron.h"
void
PH_free_polyhedron(Polyhedron **polyhedron)
{
free((*polyhedron)->vertex);
(*polyhedron)->vertex = NULL;
(*polyhedron)->vertices = 0;
free(*polyhedron);
*polyhedron = NULL;
}
Polyhedron *
PH_clone_polyhedron(Polyhedron *polyhedron)
{
Polyhedron *clone = malloc(sizeof(struct Polyhedron));
size_t size = sizeof(struct Matrix_1x3) * polyhedron->vertices;
C3 *vertex = malloc(size);
clone->vertices = polyhedron->vertices;
clone->vertex = memcpy(vertex, polyhedron->vertex, size);
return clone;
}
Polyhedron *
PH_construct_cube(const double side_length)
{
float h_len = side_length / 2;
float h_neg = h_len * -1;
C3 *vertex = malloc(sizeof(struct Matrix_1x3) * 8);
C3 *v_inc = vertex;
*v_inc++ = GP_new_C3(h_len, h_len, h_neg);
*v_inc++ = GP_new_C3(h_len, h_neg, h_neg);
*v_inc++ = GP_new_C3(h_neg, h_neg, h_neg);
*v_inc++ = GP_new_C3(h_neg, h_len, h_neg);
*v_inc++ = GP_new_C3(h_len, h_len, h_len);
*v_inc++ = GP_new_C3(h_len, h_neg, h_len);
*v_inc++ = GP_new_C3(h_neg, h_neg, h_len);
*v_inc++ = GP_new_C3(h_neg, h_len, h_len);
Polyhedron *polyhedron = malloc(sizeof(struct Polyhedron));
polyhedron->vertex = vertex;
polyhedron->vertices = 8;
return polyhedron;
}