pcb 4.1.1
An interactive printed circuit board layout editor.

polyarea.h

Go to the documentation of this file.
00001 
00031 #ifndef PCB_POLYAREA_H
00032 #define PCB_POLYAREA_H
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00038 typedef int BOOLp;
00039 
00040 #ifndef FALSE
00041 enum {
00042         FALSE = 0,
00043         TRUE  = 1
00044 };
00045 #endif
00046 
00047 #define PLF_DIR 1
00048 #define PLF_INV 0
00049 #define PLF_MARK 1
00050 
00051 #ifndef min
00052 #define min(x, y) ((x) < (y) ? (x) : (y))
00053 #endif
00054 
00055 #ifndef max
00056 #define max(x, y) ((x) > (y) ? (x) : (y))
00057 #endif
00058 
00059 
00060 typedef Coord vertex[2]; 
00061 typedef vertex Vector;
00062 
00063 #define VertexEqu(a,b) (memcmp((a),(b),sizeof(Vector))==0)
00064 #define VertexCpy(a,b) memcpy((a),(b),sizeof(Vector))
00065 
00066 
00067 extern Vector vect_zero;
00068 
00069 enum
00070 {
00071     err_no_memory = 2,
00072     err_bad_parm = 3,
00073     err_ok = 0
00074 };
00075 
00076 
00077 typedef struct CVCList CVCList;
00078 typedef struct VNODE VNODE;
00079 struct CVCList
00080 {
00081     double angle;
00082     VNODE *parent;
00083     CVCList *prev, *next, *head;
00084     char poly, side;
00085 };
00086 struct VNODE
00087 {
00088     VNODE *next, *prev, *shared;
00089     struct {
00090       unsigned int status:3;
00091       unsigned int mark:1;
00092     } Flags;
00093     CVCList *cvc_prev;
00094     CVCList *cvc_next;
00095     Vector point;
00096 };
00097 
00098 typedef struct PLINE PLINE;
00099 struct PLINE
00100 {
00101     Coord xmin, ymin, xmax, ymax;
00102     PLINE *next;
00103     VNODE head;
00104     unsigned int Count;
00105     double area;
00106     rtree_t *tree;
00107     bool is_round;
00108     Coord cx, cy;
00109     Coord radius;
00110     struct {
00111       unsigned int status:3;
00112       unsigned int orient:1;
00113     } Flags;
00114 };
00115 
00116 PLINE *poly_NewContour(Vector v);
00117 
00118 void poly_IniContour(PLINE *  c);
00119 void poly_ClrContour(PLINE *  c);  /* clears list of vertices */
00120 void poly_DelContour(PLINE ** c);
00121 
00122 BOOLp poly_CopyContour(PLINE ** dst, PLINE * src);
00123 
00124 void poly_PreContour(PLINE * c, BOOLp optimize); /* prepare contour */
00125 void poly_InvContour(PLINE * c);  /* invert contour */
00126 
00127 VNODE *poly_CreateNode(Vector v);
00128 
00129 void poly_InclVertex(VNODE * after, VNODE * node);
00130 void poly_ExclVertex(VNODE * node);
00131 
00132 
00133 typedef struct POLYAREA POLYAREA;
00134 struct POLYAREA
00135 {
00136     POLYAREA *f, *b;
00137     PLINE *contours;
00138     rtree_t *contour_tree;
00139 };
00140 
00141 BOOLp poly_M_Copy0(POLYAREA ** dst, const POLYAREA * srcfst);
00142 void poly_M_Incl(POLYAREA **list, POLYAREA *a);
00143 
00144 BOOLp poly_Copy0(POLYAREA **dst, const POLYAREA *src);
00145 BOOLp poly_Copy1(POLYAREA  *dst, const POLYAREA *src);
00146 
00147 BOOLp poly_InclContour(POLYAREA * p, PLINE * c);
00148 BOOLp poly_ExclContour(POLYAREA * p, PLINE * c);
00149 
00150 
00151 BOOLp poly_ChkContour(PLINE * a);
00152 
00153 BOOLp poly_CheckInside(POLYAREA * c, Vector v0);
00154 BOOLp Touching(POLYAREA *p1, POLYAREA *p2);
00155 
00156 /* tools for clipping */
00157 
00162 int poly_InsideContour(PLINE *c, Vector v);
00163 int poly_ContourInContour(PLINE * poly, PLINE * inner);
00164 POLYAREA *poly_Create(void);
00165 
00166 void poly_Free(POLYAREA **p);
00167 void poly_Init(POLYAREA  *p);
00168 void poly_FreeContours(PLINE **pl);
00169 BOOLp poly_Valid(POLYAREA *p);
00170 
00171 enum PolygonBooleanOperation {
00172         PBO_UNITE,
00173         PBO_ISECT,
00174         PBO_SUB,
00175         PBO_XOR
00176 };
00177 
00178 double vect_dist2 (Vector v1, Vector v2);
00179 double vect_det2 (Vector v1, Vector v2);
00180 double vect_len2 (Vector v1);
00181 
00182 int vect_inters2 (Vector A, Vector B, Vector C, Vector D, Vector S1,
00183                   Vector S2);
00184 
00185 int poly_Boolean(const POLYAREA * a, const POLYAREA * b, POLYAREA ** res, int action);
00186 int poly_Boolean_free(POLYAREA * a, POLYAREA * b, POLYAREA ** res, int action);
00187 int poly_AndSubtract_free(POLYAREA * a, POLYAREA * b, POLYAREA ** aandb, POLYAREA ** aminusb);
00188 int SavePOLYAREA( POLYAREA *PA, char * fname);
00189 #ifdef __cplusplus
00190 }
00191 #endif
00192 
00193 #endif /* PCB_POLYAREA_H */