-
Notifications
You must be signed in to change notification settings - Fork 1
/
triangulate.h
126 lines (103 loc) · 2.76 KB
/
triangulate.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Copyright (c) 2011 Jesper Öqvist <jesper@llbit.se>
*
* This file is part of cTTF.
*
* cTTF is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* cTTF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with cTTF; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* Polygon triangulation.
*
* See triangulation.c for details and limitations
* for the algorithm used.
*/
#ifndef CTTF_TRIANGULATE_H
#define CTTF_TRIANGULATE_H
#include "shape.h"
#include "list.h"
#include "bstree.h"
typedef struct edge edge_t;
typedef struct vertex vertex_t;
typedef struct face face_t;
typedef struct edge_list edge_list_t;
typedef struct segment seg_t;
typedef struct segment_tree stree_t;
edge_list_t* triangulate(shape_t* shape);
void free_edgelist(edge_list_t** edge_list);
/* above-ness relation between vectors */
int vec_above(vector_t v1, vector_t v2);
edge_list_t* make_planar(shape_t* shape);
void connect_components(edge_list_t* edge_list);
void triangulate_face(edge_list_t* edge_list, face_t* face);
typedef enum vtype {
/* The highest vertex of a monotone polygon */
START_VERTEX,
/* The lowest vertex of a monotone polygon */
END_VERTEX,
/* A vertex where two monotone polygons separate */
SPLIT_VERTEX,
/* A vertex where two monotone polygons meet */
MERGE_VERTEX,
/* A regular vertex */
REGULAR_VERTEX,
/* Unclassified vertex */
UNCLASSIFIED_VERTEX
} vtype_t;
struct face {
list_t* inner_components;
edge_t* outer_component;
int is_inside;
};
struct edge {
vertex_t* origin;
face_t* left_face;
edge_t* twin;
edge_t* succ;
edge_t* pred;
vertex_t* helper;
int cycle;
};
struct vertex {
vtype_t vtype;/* vertex type */
vector_t vec;
edge_t* incident_edge;
/* flags for internal state of triangulation algorithm */
int flags;
/* for debugging */
int id;
};
struct edge_list {
int nvert;
vertex_t** vertices;
list_t* faces;
list_t* cycles;
bstree_t* etree;
/* for convenience - makes freeing memory easier */
list_t* edges;
};
/* Sweep line event points */
struct event {
vector_t vec;
list_t* in;/* segments entering (above) this point */
list_t* out;/* segments leaving (below) this point */
int id;
vertex_t* vertex;
};
struct segment {
struct event* origin;
struct event* end;
edge_t* edge;
};
#endif