1 /* $XConsortium: mipoly.h,v 1.5 94/04/17 20:27:42 dpw Exp $ */
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of the X Consortium shall
26 not be used in advertising or otherwise to promote the sale, use or
27 other dealings in this Software without prior written authorization
28 from the X Consortium.
36 * Created by Brian Kelleher; Oct 1985
38 * Include file for filled polygon routines.
40 * These are the data structures needed to scan
41 * convert regions. Two different scan conversion
42 * methods are available -- the even-odd method, and
43 * the winding number method.
44 * The even-odd rule states that a point is inside
45 * the polygon if a ray drawn from that point in any
46 * direction will pass through an odd number of
48 * By the winding number rule, a point is decided
49 * to be inside the polygon if a ray drawn from that
50 * point in any direction passes through a different
51 * number of clockwise and counter-clockwise path
54 * These data structures are adapted somewhat from
55 * the algorithm in (Foley/Van Dam) for scan converting
57 * The basic algorithm is to start at the top (smallest y)
58 * of the polygon, stepping down to the bottom of
59 * the polygon by incrementing the y coordinate. We
60 * keep a list of edges which the current scanline crosses,
61 * sorted by x. This list is called the Active Edge Table (AET)
62 * As we change the y-coordinate, we update each entry in
63 * in the active edge table to reflect the edges new xcoord.
64 * This list must be sorted at each scanline in case
65 * two edges intersect.
66 * We also keep a data structure known as the Edge Table (ET),
67 * which keeps track of all the edges which the current
68 * scanline has not yet reached. The ET is basically a
69 * list of ScanLineList structures containing a list of
70 * edges which are entered at a given scanline. There is one
71 * ScanLineList per scanline at which an edge is entered.
72 * When we enter a new edge, we move it from the ET to the AET.
74 * From the AET, we can implement the even-odd rule as in
76 * The winding number rule is a little trickier. We also
77 * keep the EdgeTableEntries in the AET linked by the
78 * nextWETE (winding EdgeTableEntry) link. This allows
79 * the edges to be linked just as before for updating
80 * purposes, but only uses the edges linked by the nextWETE
81 * link as edges representing spans of the polygon to
82 * drawn (as with the even-odd rule).
86 * for the winding number rule
89 #define COUNTERCLOCKWISE -1
91 typedef struct _EdgeTableEntry {
92 int ymax; /* ycoord at which we exit this edge. */
93 BRESINFO bres; /* Bresenham info to run the edge */
94 struct _EdgeTableEntry *next; /* next in the list */
95 struct _EdgeTableEntry *back; /* for insertion sort */
96 struct _EdgeTableEntry *nextWETE; /* for winding num rule */
97 int ClockWise; /* flag for winding number rule */
101 typedef struct _ScanLineList{
102 int scanline; /* the scanline represented */
103 EdgeTableEntry *edgelist; /* header node */
104 struct _ScanLineList *next; /* next in the list */
109 int ymax; /* ymax for the polygon */
110 int ymin; /* ymin for the polygon */
111 ScanLineList scanlines; /* header node */
116 * Here is a struct to help with storage allocation
117 * so we can allocate a big chunk at a time, and then take
118 * pieces from this heap when we need to.
120 #define SLLSPERBLOCK 25
122 typedef struct _ScanLineListBlock {
123 ScanLineList SLLs[SLLSPERBLOCK];
124 struct _ScanLineListBlock *next;
128 * number of points to buffer before sending them off
129 * to scanlines() : Must be an even number
131 #define NUMPTSTOBUFFER 200
136 * a few macros for the inner loops of the fill code where
137 * performance considerations don't allow a procedure call.
139 * Evaluate the given edge at the given scanline.
140 * If the edge has expired, then we leave it and fix up
141 * the active edge table; otherwise, we increment the
142 * x value to be ready for the next scanline.
143 * The winding number rule is in effect, so we must notify
144 * the caller when the edge has been removed so he
145 * can reorder the Winding Active Edge Table.
147 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
148 if (pAET->ymax == y) { /* leaving this edge */ \
149 pPrevAET->next = pAET->next; \
150 pAET = pPrevAET->next; \
153 pAET->back = pPrevAET; \
156 BRESINCRPGONSTRUCT(pAET->bres); \
164 * Evaluate the given edge at the given scanline.
165 * If the edge has expired, then we leave it and fix up
166 * the active edge table; otherwise, we increment the
167 * x value to be ready for the next scanline.
168 * The even-odd rule is in effect.
170 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
171 if (pAET->ymax == y) { /* leaving this edge */ \
172 pPrevAET->next = pAET->next; \
173 pAET = pPrevAET->next; \
175 pAET->back = pPrevAET; \
178 BRESINCRPGONSTRUCT(pAET->bres); \
186 extern Bool miInsertEdgeInET(
187 #if NeedFunctionPrototypes
189 EdgeTableEntry * /*ETE*/,
191 ScanLineListBlock ** /*SLLBlock*/,
196 extern Bool miCreateETandAET(
197 #if NeedFunctionPrototypes
201 EdgeTableEntry * /*AET*/,
202 EdgeTableEntry * /*pETEs*/,
203 ScanLineListBlock * /*pSLLBlock*/
207 extern void miloadAET(
208 #if NeedFunctionPrototypes
209 EdgeTableEntry * /*AET*/,
210 EdgeTableEntry * /*ETEs*/
214 extern void micomputeWAET(
215 #if NeedFunctionPrototypes
216 EdgeTableEntry * /*AET*/
220 extern int miInsertionSort(
221 #if NeedFunctionPrototypes
222 EdgeTableEntry * /*AET*/
226 extern void miFreeStorage(
227 #if NeedFunctionPrototypes
228 ScanLineListBlock * /*pSLLBlock*/