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.
21 (C) 1997 Alexey Nikitin, Michael Leonov
22 (C) 1997 Klamer Schutte (minor patches)
25 #ifndef PCB_POLYAREA_H
26 #define PCB_POLYAREA_H
46 #define min(x, y) ((x) < (y) ? (x) : (y))
50 #define max(x, y) ((x) > (y) ? (x) : (y))
54 typedef Coord vertex
[2]; /* longing point representation of
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
;
72 typedef struct CVCList CVCList
;
73 typedef struct VNODE VNODE
;
78 CVCList
*prev
, *next
, *head
;
83 VNODE
*next
, *prev
, *shared
;
85 unsigned int status
:3;
93 typedef struct PLINE PLINE
;
96 Coord xmin
, ymin
, xmax
, ymax
;
106 unsigned int status
:3;
107 unsigned int orient
:1;
111 PLINE
*poly_NewContour(Vector v
);
113 void poly_IniContour(PLINE
* c
);
114 void poly_ClrContour(PLINE
* c
); /* clears list of vertices */
115 void poly_DelContour(PLINE
** c
);
117 BOOLp
poly_CopyContour(PLINE
** dst
, PLINE
* src
);
119 void poly_PreContour(PLINE
* c
, BOOLp optimize
); /* prepare contour */
120 void poly_InvContour(PLINE
* c
); /* invert contour */
122 VNODE
*poly_CreateNode(Vector v
);
124 void poly_InclVertex(VNODE
* after
, VNODE
* node
);
125 void poly_ExclVertex(VNODE
* node
);
127 /**********************************************************************/
129 typedef struct POLYAREA POLYAREA
;
134 rtree_t
*contour_tree
;
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
{
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
,
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
);
190 #endif /* PCB_POLYAREA_H */