Fix bug with expanding text.
[geda-pcb/pcjc2.git] / src / polyarea.h
blob2979012568817e980773851ed0d39f85f11f6137
1 /*!
2 * \file src/polyarea.h
4 * \brief poly_Boolean: a polygon clip library.
6 * <hr>
8 * <h1><b>Copyright.</b></h1>\n
10 * Copyright (C) 1997 Alexey Nikitin, Michael Leonov
12 * leonov@propro.iis.nsk.su
14 * Copyright (C) 1997 Klamer Schutte (minor patches)
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Library General Public
18 * License as published by the Free Software Foundation; either
19 * version 2 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Library General Public License for more details.
26 * You should have received a copy of the GNU Library General Public
27 * License along with this library; if not, write to the Free
28 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #ifndef PCB_POLYAREA_H
32 #define PCB_POLYAREA_H
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 typedef int BOOLp;
40 #ifndef FALSE
41 enum {
42 FALSE = 0,
43 TRUE = 1
45 #endif
47 #define PLF_DIR 1
48 #define PLF_INV 0
49 #define PLF_MARK 1
51 #ifndef min
52 #define min(x, y) ((x) < (y) ? (x) : (y))
53 #endif
55 #ifndef max
56 #define max(x, y) ((x) > (y) ? (x) : (y))
57 #endif
60 typedef Coord vertex[2]; /*!< longing point representation of coordinates. */
61 typedef vertex Vector;
63 #define VertexEqu(a,b) (memcmp((a),(b),sizeof(Vector))==0)
64 #define VertexCpy(a,b) memcpy((a),(b),sizeof(Vector))
67 extern Vector vect_zero;
69 enum
71 err_no_memory = 2,
72 err_bad_parm = 3,
73 err_ok = 0
77 typedef struct CVCList CVCList;
78 typedef struct VNODE VNODE;
79 struct CVCList
81 double angle;
82 VNODE *parent;
83 CVCList *prev, *next, *head;
84 char poly, side;
86 struct VNODE
88 VNODE *next, *prev, *shared;
89 struct {
90 unsigned int status:3;
91 unsigned int mark:1;
92 } Flags;
93 CVCList *cvc_prev;
94 CVCList *cvc_next;
95 Vector point;
98 typedef struct PLINE PLINE;
99 struct PLINE
101 Coord xmin, ymin, xmax, ymax;
102 PLINE *next;
103 VNODE head;
104 unsigned int Count;
105 double area;
106 rtree_t *tree;
107 bool is_round;
108 Coord cx, cy;
109 Coord radius;
110 struct {
111 unsigned int status:3;
112 unsigned int orient:1;
113 } Flags;
116 PLINE *poly_NewContour(Vector v);
118 void poly_IniContour(PLINE * c);
119 void poly_ClrContour(PLINE * c); /* clears list of vertices */
120 void poly_DelContour(PLINE ** c);
122 BOOLp poly_CopyContour(PLINE ** dst, PLINE * src);
124 void poly_PreContour(PLINE * c, BOOLp optimize); /* prepare contour */
125 void poly_InvContour(PLINE * c); /* invert contour */
127 VNODE *poly_CreateNode(Vector v);
129 void poly_InclVertex(VNODE * after, VNODE * node);
130 void poly_ExclVertex(VNODE * node);
133 typedef struct POLYAREA POLYAREA;
134 struct POLYAREA
136 POLYAREA *f, *b;
137 PLINE *contours;
138 rtree_t *contour_tree;
141 BOOLp poly_M_Copy0(POLYAREA ** dst, const POLYAREA * srcfst);
142 void poly_M_Incl(POLYAREA **list, POLYAREA *a);
144 BOOLp poly_Copy0(POLYAREA **dst, const POLYAREA *src);
145 BOOLp poly_Copy1(POLYAREA *dst, const POLYAREA *src);
147 BOOLp poly_InclContour(POLYAREA * p, PLINE * c);
148 BOOLp poly_ExclContour(POLYAREA * p, PLINE * c);
151 BOOLp poly_ChkContour(PLINE * a);
153 BOOLp poly_CheckInside(POLYAREA * c, Vector v0);
154 BOOLp Touching(POLYAREA *p1, POLYAREA *p2);
156 /* tools for clipping */
159 * \brief Checks whether point lies within contour independently of its
160 * orientation.
162 int poly_InsideContour(PLINE *c, Vector v);
163 int poly_ContourInContour(PLINE * poly, PLINE * inner);
164 POLYAREA *poly_Create(void);
166 void poly_Free(POLYAREA **p);
167 void poly_Init(POLYAREA *p);
168 void poly_FreeContours(PLINE **pl);
169 BOOLp poly_Valid(POLYAREA *p);
171 enum PolygonBooleanOperation {
172 PBO_UNITE,
173 PBO_ISECT,
174 PBO_SUB,
175 PBO_XOR
178 double vect_dist2 (Vector v1, Vector v2);
179 double vect_det2 (Vector v1, Vector v2);
180 double vect_len2 (Vector v1);
182 int vect_inters2 (Vector A, Vector B, Vector C, Vector D, Vector S1,
183 Vector S2);
185 int poly_Boolean(const POLYAREA * a, const POLYAREA * b, POLYAREA ** res, int action);
186 int poly_Boolean_free(POLYAREA * a, POLYAREA * b, POLYAREA ** res, int action);
187 int poly_AndSubtract_free(POLYAREA * a, POLYAREA * b, POLYAREA ** aandb, POLYAREA ** aminusb);
188 int SavePOLYAREA( POLYAREA *PA, char * fname);
189 #ifdef __cplusplus
191 #endif
193 #endif /* PCB_POLYAREA_H */