3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
33 * Created by Brian Kelleher; Oct 1985
35 * Include file for filled polygon routines.
37 * These are the data structures needed to scan
38 * convert regions. Two different scan conversion
39 * methods are available -- the even-odd method, and
40 * the winding number method.
41 * The even-odd rule states that a point is inside
42 * the polygon if a ray drawn from that point in any
43 * direction will pass through an odd number of
45 * By the winding number rule, a point is decided
46 * to be inside the polygon if a ray drawn from that
47 * point in any direction passes through a different
48 * number of clockwise and counter-clockwise path
51 * These data structures are adapted somewhat from
52 * the algorithm in (Foley/Van Dam) for scan converting
54 * The basic algorithm is to start at the top (smallest y)
55 * of the polygon, stepping down to the bottom of
56 * the polygon by incrementing the y coordinate. We
57 * keep a list of edges which the current scanline crosses,
58 * sorted by x. This list is called the Active Edge Table (AET)
59 * As we change the y-coordinate, we update each entry in
60 * in the active edge table to reflect the edges new xcoord.
61 * This list must be sorted at each scanline in case
62 * two edges intersect.
63 * We also keep a data structure known as the Edge Table (ET),
64 * which keeps track of all the edges which the current
65 * scanline has not yet reached. The ET is basically a
66 * list of ScanLineList structures containing a list of
67 * edges which are entered at a given scanline. There is one
68 * ScanLineList per scanline at which an edge is entered.
69 * When we enter a new edge, we move it from the ET to the AET.
71 * From the AET, we can implement the even-odd rule as in
73 * The winding number rule is a little trickier. We also
74 * keep the EdgeTableEntries in the AET linked by the
75 * nextWETE (winding EdgeTableEntry) link. This allows
76 * the edges to be linked just as before for updating
77 * purposes, but only uses the edges linked by the nextWETE
78 * link as edges representing spans of the polygon to
79 * drawn (as with the even-odd rule).
83 * for the winding number rule
86 #define COUNTERCLOCKWISE -1
88 typedef struct _EdgeTableEntry
{
89 int ymax
; /* ycoord at which we exit this edge. */
90 BRESINFO bres
; /* Bresenham info to run the edge */
91 struct _EdgeTableEntry
*next
; /* next in the list */
92 struct _EdgeTableEntry
*back
; /* for insertion sort */
93 struct _EdgeTableEntry
*nextWETE
; /* for winding num rule */
94 int ClockWise
; /* flag for winding number rule */
98 typedef struct _ScanLineList
{
99 int scanline
; /* the scanline represented */
100 EdgeTableEntry
*edgelist
; /* header node */
101 struct _ScanLineList
*next
; /* next in the list */
106 int ymax
; /* ymax for the polygon */
107 int ymin
; /* ymin for the polygon */
108 ScanLineList scanlines
; /* header node */
113 * Here is a struct to help with storage allocation
114 * so we can allocate a big chunk at a time, and then take
115 * pieces from this heap when we need to.
117 #define SLLSPERBLOCK 25
119 typedef struct _ScanLineListBlock
{
120 ScanLineList SLLs
[SLLSPERBLOCK
];
121 struct _ScanLineListBlock
*next
;
125 * number of points to buffer before sending them off
126 * to scanlines() : Must be an even number
128 #define NUMPTSTOBUFFER 200
133 * a few macros for the inner loops of the fill code where
134 * performance considerations don't allow a procedure call.
136 * Evaluate the given edge at the given scanline.
137 * If the edge has expired, then we leave it and fix up
138 * the active edge table; otherwise, we increment the
139 * x value to be ready for the next scanline.
140 * The winding number rule is in effect, so we must notify
141 * the caller when the edge has been removed so he
142 * can reorder the Winding Active Edge Table.
144 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
145 if (pAET->ymax == y) { /* leaving this edge */ \
146 pPrevAET->next = pAET->next; \
147 pAET = pPrevAET->next; \
150 pAET->back = pPrevAET; \
153 BRESINCRPGONSTRUCT(pAET->bres); \
161 * Evaluate the given edge at the given scanline.
162 * If the edge has expired, then we leave it and fix up
163 * the active edge table; otherwise, we increment the
164 * x value to be ready for the next scanline.
165 * The even-odd rule is in effect.
167 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
168 if (pAET->ymax == y) { /* leaving this edge */ \
169 pPrevAET->next = pAET->next; \
170 pAET = pPrevAET->next; \
172 pAET->back = pPrevAET; \
175 BRESINCRPGONSTRUCT(pAET->bres); \
183 extern Bool
miCreateETandAET(
187 EdgeTableEntry
* /*AET*/,
188 EdgeTableEntry
* /*pETEs*/,
189 ScanLineListBlock
* /*pSLLBlock*/
192 extern void miloadAET(
193 EdgeTableEntry
* /*AET*/,
194 EdgeTableEntry
* /*ETEs*/
197 extern void micomputeWAET(
198 EdgeTableEntry
* /*AET*/
201 extern int miInsertionSort(
202 EdgeTableEntry
* /*AET*/
205 extern void miFreeStorage(
206 ScanLineListBlock
* /*pSLLBlock*/