]> Pileus Git - ~andy/gtk/blob - gdk/linux-fb/mipoly.h
545aa00e26747af5e74bec6722cfcc4842eac0a2
[~andy/gtk] / gdk / linux-fb / mipoly.h
1 /* $TOG: mipoly.h /main/6 1998/02/09 14:48:20 kaleb $ */
2 /*
3
4 Copyright 1987, 1998  The Open Group
5
6 All Rights Reserved.
7
8 The above copyright notice and this permission notice shall be included
9 in all copies or substantial portions of the Software.
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
15 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
16 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
17 OTHER DEALINGS IN THE SOFTWARE.
18
19 Except as contained in this notice, the name of The Open Group shall
20 not be used in advertising or otherwise to promote the sale, use or
21 other dealings in this Software without prior written authorization
22 from The Open Group.
23
24 */
25
26 #ifndef MIPOLY_H
27 #define MIPOLY_H
28
29 #include "miscanfill.h"
30
31 /*
32  *     fill.h
33  *
34  *     Created by Brian Kelleher; Oct 1985
35  *
36  *     Include file for filled polygon routines.
37  *
38  *     These are the data structures needed to scan
39  *     convert regions.  Two different scan conversion
40  *     methods are available -- the even-odd method, and
41  *     the winding number method.
42  *     The even-odd rule states that a point is inside
43  *     the polygon if a ray drawn from that point in any
44  *     direction will pass through an odd number of
45  *     path segments.
46  *     By the winding number rule, a point is decided
47  *     to be inside the polygon if a ray drawn from that
48  *     point in any direction passes through a different
49  *     number of clockwise and counter-clockwise path
50  *     segments.
51  *
52  *     These data structures are adapted somewhat from
53  *     the algorithm in (Foley/Van Dam) for scan converting
54  *     polygons.
55  *     The basic algorithm is to start at the top (smallest y)
56  *     of the polygon, stepping down to the bottom of
57  *     the polygon by incrementing the y coordinate.  We
58  *     keep a list of edges which the current scanline crosses,
59  *     sorted by x.  This list is called the Active Edge Table (AET)
60  *     As we change the y-coordinate, we update each entry in 
61  *     in the active edge table to reflect the edges new xcoord.
62  *     This list must be sorted at each scanline in case
63  *     two edges intersect.
64  *     We also keep a data structure known as the Edge Table (ET),
65  *     which keeps track of all the edges which the current
66  *     scanline has not yet reached.  The ET is basically a
67  *     list of ScanLineList structures containing a list of
68  *     edges which are entered at a given scanline.  There is one
69  *     ScanLineList per scanline at which an edge is entered.
70  *     When we enter a new edge, we move it from the ET to the AET.
71  *
72  *     From the AET, we can implement the even-odd rule as in
73  *     (Foley/Van Dam).
74  *     The winding number rule is a little trickier.  We also
75  *     keep the EdgeTableEntries in the AET linked by the
76  *     nextWETE (winding EdgeTableEntry) link.  This allows
77  *     the edges to be linked just as before for updating
78  *     purposes, but only uses the edges linked by the nextWETE
79  *     link as edges representing spans of the polygon to
80  *     drawn (as with the even-odd rule).
81  */
82
83 /*
84  * for the winding number rule
85  */
86 #define CLOCKWISE          1
87 #define COUNTERCLOCKWISE  -1 
88
89 typedef struct _EdgeTableEntry {
90      int ymax;             /* ycoord at which we exit this edge. */
91      BRESINFO bres;        /* Bresenham info to run the edge     */
92      struct _EdgeTableEntry *next;       /* next in the list     */
93      struct _EdgeTableEntry *back;       /* for insertion sort   */
94      struct _EdgeTableEntry *nextWETE;   /* for winding num rule */
95      int ClockWise;        /* flag for winding number rule       */
96 } EdgeTableEntry;
97
98
99 typedef struct _ScanLineList{
100      int scanline;              /* the scanline represented */
101      EdgeTableEntry *edgelist;  /* header node              */
102      struct _ScanLineList *next;  /* next in the list       */
103 } ScanLineList;
104
105
106 typedef struct {
107      int ymax;                 /* ymax for the polygon     */
108      int ymin;                 /* ymin for the polygon     */
109      ScanLineList scanlines;   /* header node              */
110 } EdgeTable;
111
112
113 /*
114  * Here is a struct to help with storage allocation
115  * so we can allocate a big chunk at a time, and then take
116  * pieces from this heap when we need to.
117  */
118 #define SLLSPERBLOCK 25
119
120 typedef struct _ScanLineListBlock {
121      ScanLineList SLLs[SLLSPERBLOCK];
122      struct _ScanLineListBlock *next;
123 } ScanLineListBlock;
124
125 /*
126  * number of points to buffer before sending them off
127  * to scanlines() :  Must be an even number
128  */
129 #define NUMPTSTOBUFFER 200
130
131 \f
132 /*
133  *
134  *     a few macros for the inner loops of the fill code where
135  *     performance considerations don't allow a procedure call.
136  *
137  *     Evaluate the given edge at the given scanline.
138  *     If the edge has expired, then we leave it and fix up
139  *     the active edge table; otherwise, we increment the
140  *     x value to be ready for the next scanline.
141  *     The winding number rule is in effect, so we must notify
142  *     the caller when the edge has been removed so he
143  *     can reorder the Winding Active Edge Table.
144  */
145 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
146    if (pAET->ymax == y) {          /* leaving this edge */ \
147       pPrevAET->next = pAET->next; \
148       pAET = pPrevAET->next; \
149       fixWAET = 1; \
150       if (pAET) \
151          pAET->back = pPrevAET; \
152    } \
153    else { \
154       BRESINCRPGONSTRUCT(pAET->bres); \
155       pPrevAET = pAET; \
156       pAET = pAET->next; \
157    } \
158 }
159
160
161 /*
162  *     Evaluate the given edge at the given scanline.
163  *     If the edge has expired, then we leave it and fix up
164  *     the active edge table; otherwise, we increment the
165  *     x value to be ready for the next scanline.
166  *     The even-odd rule is in effect.
167  */
168 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
169    if (pAET->ymax == y) {          /* leaving this edge */ \
170       pPrevAET->next = pAET->next; \
171       pAET = pPrevAET->next; \
172       if (pAET) \
173          pAET->back = pPrevAET; \
174    } \
175    else { \
176       BRESINCRPGONSTRUCT(pAET->bres); \
177       pPrevAET = pAET; \
178       pAET = pAET->next; \
179    } \
180 }
181
182 /* mipolyutil.c */
183
184 extern gboolean miInsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline,
185                                  ScanLineListBlock **SLLBlock, int *iSLLBlock);
186
187 extern gboolean miCreateETandAET(int count, GdkPoint* pts, EdgeTable *ET,
188                                  EdgeTableEntry *AET, EdgeTableEntry *pETEs,
189                                  ScanLineListBlock *pSLLBlock);
190
191 extern void miloadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs);
192
193 extern void micomputeWAET(EdgeTableEntry *AET);
194
195 extern int miInsertionSort(EdgeTableEntry *AET);
196
197 extern void miFreeStorage(ScanLineListBlock *pSLLBlock);
198
199 #endif