1 /*!
2  * \file src/polygon.h
3  *
4  * \brief Prototypes for polygon editing routines.
5  *
6  * <hr>
7  *
8  * <h1><b>Copyright.</b></h1>\n
9  *
10  * PCB, interactive printed circuit board design
11  *
12  * Copyright (C) 1994,1995,1996 Thomas Nau
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  *
28  * Contact addresses for paper mail and Email:
29  *
30  * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
31  *
32  * Thomas.Nau@rz.uni-ulm.de
33  */
34 
35 #ifndef	PCB_POLYGON_H
36 #define	PCB_POLYGON_H
37 
38 #include "global.h"
39 
40 /* Implementation constants */
41 
42 #define POLY_CIRC_SEGS 40
43 #define POLY_CIRC_SEGS_F ((float)POLY_CIRC_SEGS)
44 
45 /*!
46  * \brief Adjustment to make the segments outline the circle rather than
47  * connect points on the circle:
48  * \f$ 1 - cos ( \frac {\alpha} {2} ) < \frac { ( \frac {\alpha} {2} ) ^ 2 } {2} \f$
49  */
50 #define POLY_CIRC_RADIUS_ADJ (1.0 + M_PI / POLY_CIRC_SEGS_F * \
51                                     M_PI / POLY_CIRC_SEGS_F / 2.0)
52 
53 /*!
54  * \brief Polygon diverges from modelled arc no more than
55  * MAX_ARC_DEVIATION * thick.
56  */
57 #define POLY_ARC_MAX_DEVIATION 0.02
58 
59 /* Prototypes */
60 
61 void polygon_init (void);
62 Cardinal polygon_point_idx (PolygonType * polygon, PointType * point);
63 Cardinal polygon_point_contour (PolygonType * polygon, Cardinal point);
64 Cardinal prev_contour_point (PolygonType * polygon, Cardinal point);
65 Cardinal next_contour_point (PolygonType * polygon, Cardinal point);
66 Cardinal GetLowestDistancePolygonPoint (PolygonType *,
67 					Coord, Coord);
68 bool RemoveExcessPolygonPoints (LayerType *, PolygonType *);
69 void GoToPreviousPoint (void);
70 void ClosePolygon (void);
71 void CopyAttachedPolygonToLayer (void);
72 int PolygonHoles (PolygonType *ptr, const BoxType *range,
73 		  int (*callback) (PLINE *, void *user_data),
74                   void *user_data);
75 int PlowsPolygon (DataType *, int, void *, void *,
76                   int (*callback) (DataType *, LayerType *, PolygonType *, int, void *, void *, void *),
77                   void *userdata);
78 void ComputeNoHoles (PolygonType *poly);
79 POLYAREA * original_poly(PolygonType *);
80 POLYAREA * ContourToPoly (PLINE *);
81 POLYAREA * PolygonToPoly (PolygonType *);
82 POLYAREA * RectPoly (Coord x1, Coord x2, Coord y1, Coord y2);
83 POLYAREA * CirclePoly (Coord x, Coord y, Coord radius);
84 POLYAREA * OctagonPoly(Coord x, Coord y, Coord radius);
85 POLYAREA * LinePoly(LineType *l, Coord thick);
86 POLYAREA * ArcPoly(ArcType *l, Coord thick);
87 POLYAREA * PinPoly(PinType *l, Coord thick, Coord clear);
88 POLYAREA * BoxPolyBloated (BoxType *box, Coord radius);
89 void frac_circle (PLINE *, Coord, Coord, Vector, int);
90 int InitClip(DataType *d, LayerType *l, PolygonType *p);
91 void RestoreToPolygon(DataType *, int, void *, void *);
92 void ClearFromPolygon(DataType *, int, void *, void *);
93 
94 bool IsPointInPolygon (Coord, Coord, Coord, PolygonType *);
95 bool IsPointInPolygonIgnoreHoles (Coord, Coord, PolygonType *);
96 bool IsRectangleInPolygon (Coord, Coord, Coord, Coord, PolygonType *);
97 bool isects (POLYAREA *, PolygonType *, bool);
98 bool MorphPolygon (LayerType *, PolygonType *);
99 void NoHolesPolygonDicer (PolygonType *p, const BoxType *clip,
100                           void (*emit) (PLINE *, void *), void *user_data);
101 void PolyToPolygonsOnLayer (DataType *, LayerType *, POLYAREA *, FlagType);
102 
103 #endif
104