4 * \brief poly_Boolean: a polygon clip library.
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
52 #define min(x, y) ((x) < (y) ? (x) : (y))
56 #define max(x, y) ((x) > (y) ? (x) : (y))
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
;
77 typedef struct CVCList CVCList
;
78 typedef struct VNODE VNODE
;
83 CVCList
*prev
, *next
, *head
;
88 VNODE
*next
, *prev
, *shared
;
90 unsigned int status
:3;
98 typedef struct PLINE PLINE
;
101 Coord xmin
, ymin
, xmax
, ymax
;
111 unsigned int status
:3;
112 unsigned int orient
:1;
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
;
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
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
{
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
,
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
);
193 #endif /* PCB_POLYAREA_H */