Move internationalization macros to one header
[geda-pcb/gde.git] / src / polyarea.h
blob958498b41b2db09f0faec0a10e28c61f04febb22
1 /*
2 poly_Boolean: a polygon clip library
3 Copyright (C) 1997 Alexey Nikitin, Michael Leonov
4 leonov@propro.iis.nsk.su
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the Free
18 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 polyarea.h
21 (C) 1997 Alexey Nikitin, Michael Leonov
22 (C) 1997 Klamer Schutte (minor patches)
25 #ifndef _POLYBOOL_H
26 #define _POLYBOOL_H
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 typedef int BOOLp;
34 #ifndef FALSE
35 enum {
36 FALSE = 0,
37 TRUE = 1
39 #endif
41 #define PLF_DIR 1
42 #define PLF_INV 0
43 #define PLF_MARK 1
45 #ifndef min
46 #define min(x, y) ((x) < (y) ? (x) : (y))
47 #endif
49 #ifndef max
50 #define max(x, y) ((x) > (y) ? (x) : (y))
51 #endif
54 typedef int vertex[2]; /* longing point representation of
55 coordinates */
56 typedef vertex Vector;
58 #define VertexEqu(a,b) (memcmp((a),(b),sizeof(Vector))==0)
59 #define VertexCpy(a,b) memcpy((a),(b),sizeof(Vector))
62 extern Vector vect_zero;
64 enum
66 err_no_memory = 2,
67 err_bad_parm = 3,
68 err_ok = 0
72 typedef struct CVCList CVCList;
73 typedef struct VNODE VNODE;
74 struct CVCList
76 double angle;
77 VNODE *parent;
78 CVCList *prev, *next, *head;
79 char poly, side;
81 struct VNODE
83 VNODE *next, *prev, *shared;
84 struct {
85 unsigned int status:3;
86 unsigned int mark:1;
87 } Flags;
88 CVCList *cvc_prev;
89 CVCList *cvc_next;
90 Vector point;
93 typedef struct PLINE PLINE;
94 struct PLINE
96 int xmin, ymin, xmax, ymax;
97 PLINE *next;
98 VNODE head;
99 unsigned int Count;
100 double area;
101 rtree_t *tree;
102 int is_round;
103 int cx;
104 int cy;
105 int radius;
106 struct {
107 unsigned int status:3;
108 unsigned int orient:1;
109 } Flags;
112 PLINE *poly_NewContour(Vector v);
114 void poly_IniContour(PLINE * c);
115 void poly_ClrContour(PLINE * c); /* clears list of vertices */
116 void poly_DelContour(PLINE ** c);
118 BOOLp poly_CopyContour(PLINE ** dst, PLINE * src);
120 void poly_PreContour(PLINE * c, BOOLp optimize); /* prepare contour */
121 void poly_InvContour(PLINE * c); /* invert contour */
123 VNODE *poly_CreateNode(Vector v);
125 void poly_InclVertex(VNODE * after, VNODE * node);
126 void poly_ExclVertex(VNODE * node);
128 /**********************************************************************/
130 typedef struct POLYAREA POLYAREA;
131 struct POLYAREA
133 POLYAREA *f, *b;
134 PLINE *contours;
137 BOOLp poly_M_Copy0(POLYAREA ** dst, const POLYAREA * srcfst);
138 void poly_M_Incl(POLYAREA **list, POLYAREA *a);
140 BOOLp poly_Copy0(POLYAREA **dst, const POLYAREA *src);
141 BOOLp poly_Copy1(POLYAREA *dst, const POLYAREA *src);
143 BOOLp poly_InclContour(POLYAREA * p, PLINE * c);
144 BOOLp poly_ExclContour(POLYAREA * p, PLINE * c);
147 BOOLp poly_ChkContour(PLINE * a);
149 BOOLp poly_CheckInside(POLYAREA * c, Vector v0);
150 BOOLp Touching(POLYAREA *p1, POLYAREA *p2);
152 /**********************************************************************/
154 /* tools for clipping */
156 /* checks whether point lies within contour
157 independently of its orientation */
159 int poly_InsideContour(PLINE *c, Vector v);
160 int poly_ContourInContour(PLINE * poly, PLINE * inner);
161 POLYAREA *poly_Create(void);
163 void poly_Free(POLYAREA **p);
164 void poly_Init(POLYAREA *p);
165 void poly_FreeContours(PLINE **pl);
166 BOOLp poly_Valid(POLYAREA *p);
168 enum PolygonBooleanOperation {
169 PBO_UNITE,
170 PBO_ISECT,
171 PBO_SUB,
172 PBO_XOR
175 double vect_dist2 (Vector v1, Vector v2);
176 double vect_det2 (Vector v1, Vector v2);
177 double vect_len2 (Vector v1);
179 int vect_inters2 (Vector A, Vector B, Vector C, Vector D, Vector S1,
180 Vector S2);
182 int poly_Boolean(const POLYAREA * a, const POLYAREA * b, POLYAREA ** res, int action);
183 int poly_Boolean_free(POLYAREA * a, POLYAREA * b, POLYAREA ** res, int action);
184 int poly_AndSubtract_free(POLYAREA * a, POLYAREA * b, POLYAREA ** aandb, POLYAREA ** aminusb);
185 int SavePOLYAREA( POLYAREA *PA, char * fname);
186 #ifdef __cplusplus
188 #endif
190 #endif /* POLY_H */