1 /*
2  * Phlipple
3  * Copyright (C) Remigiusz Dybka 2011 <remigiusz.dybka@gmail.com>
4  *
5  Phlipple is free software: you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Phlipple is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <stdlib.h>
20 
21 #include "vertex.h"
22 
vertex_isLinked(Vertex * v1,Vertex * v2)23 int vertex_isLinked(Vertex *v1, Vertex *v2)
24 {
25 	if (v1->nHardLinked == 0)
26 		return 0;
27 
28 	for (int f = 0; f < v1->nHardLinked; f++)
29 	{
30 		if (v1->hardLinked[f] == v2)
31 			return 1;
32 	}
33 
34 	return 0;
35 }
36 
vertex_link(Vertex * v1,Vertex * v2)37 void vertex_link(Vertex *v1, Vertex *v2)
38 {
39 	if (!vertex_isLinked(v1, v2))
40 		v1->hardLinked[v1->nHardLinked++] = v2;
41 
42 	if (!vertex_isLinked(v2, v1))
43 		v2->hardLinked[v2->nHardLinked++] = v1;
44 }
45 
vertex_create(int x,int y,int z)46 Vertex *vertex_create(int x, int y, int z)
47 {
48 	Vertex *vert = malloc(sizeof(Vertex));
49 	vert->x = x;
50 	vert->y = y;
51 	vert->z = z;
52 
53 	vert->nHardLinked = 0;
54 	vert->nLinkedQuads = 0;
55 
56 	for (int f = 0; f < MAX_HARDLINKED_VERTS; f++)
57 	{
58 		vert->hardLinked[f] = NULL;
59 	}
60 
61 	for (int f = 0; f < MAX_QUADS; f++)
62 	{
63 		vert->quads[f] = NULL;
64 	}
65 
66 
67 	return vert;
68 }
69 
vertex_isEqualVertex(Vertex * v1,Vertex * v2)70 int vertex_isEqualVertex(Vertex *v1, Vertex *v2)
71 {
72 	if (v2->x != v1->x)
73 		return 0;
74 
75 	if (v2->y != v1->y)
76 		return 0;
77 
78 	if (v2->z != v1->z)
79 		return 0;
80 
81 	return 1;
82 }
83 
vertex_isEqualInt(Vertex * v1,int * v2)84 int vertex_isEqualInt(Vertex *v1, int *v2)
85 {
86 	if (v1->x != v2[0])
87 		return 0;
88 
89 	if (v1->y != v2[1])
90 		return 0;
91 
92 	if (v1->z != v2[2])
93 		return 0;
94 
95 	return 1;
96 }
97 
vertex_destroy(Vertex * vert)98 void vertex_destroy(Vertex *vert)
99 {
100 	if (vert == NULL)
101 		return;
102 
103 	free(vert);
104 }
105