1 /***********************************************************
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 in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
46 #ifdef HAVE_DIX_CONFIG_H
47 #include <dix-config.h>
53 #include "windowstr.h"
54 #include "pixmapstr.h"
57 static int GetFPolyYBounds(SppPointPtr pts
, int n
, double yFtrans
,
61 * Written by Todd Newman; April. 1987.
63 * Fill a convex polygon. If the given polygon
64 * is not convex, then the result is undefined.
65 * The algorithm is to order the edges from smallest
66 * y to largest by partitioning the array into a left
67 * edge list and a right edge list. The algorithm used
68 * to traverse each edge is digital differencing analyzer
69 * line algorithm with y as the major axis. There's some funny linear
70 * interpolation involved because of the subpixel postioning.
73 miFillSppPoly(DrawablePtr dst
, GCPtr pgc
, int count
, /* number of points */
74 SppPointPtr ptsIn
, /* the points */
75 int xTrans
, int yTrans
, /* Translate each point by this */
76 double xFtrans
, double yFtrans
/* translate before conversion
77 by this amount. This provides
78 a mechanism to match rounding
79 errors with any shape that must
80 meet the polygon exactly.
84 double xl
= 0.0, xr
= 0.0, /* x vals of left and right edges */
85 ml
= 0.0, /* left edge slope */
86 mr
= 0.0, /* right edge slope */
89 int y
, /* current scanline */
90 j
, imin
, /* index of vertex with smallest y */
91 ymin
, /* y-extents of polygon */
92 ymax
, *width
, *FirstWidth
, /* output buffer */
93 *Marked
; /* set if this vertex has been used */
94 int left
, right
, /* indices to first endpoints */
95 nextleft
, nextright
; /* indices to second endpoints */
96 DDXPointPtr ptsOut
, FirstPoint
; /* output buffer */
98 if (pgc
->miTranslate
) {
103 imin
= GetFPolyYBounds(ptsIn
, count
, yFtrans
, &ymin
, &ymax
);
106 if ((count
< 3) || (y
<= 0))
108 ptsOut
= FirstPoint
= malloc(sizeof(DDXPointRec
) * y
);
109 width
= FirstWidth
= malloc(sizeof(int) * y
);
110 Marked
= malloc(sizeof(int) * count
);
112 if (!ptsOut
|| !width
|| !Marked
) {
119 for (j
= 0; j
< count
; j
++)
121 nextleft
= nextright
= imin
;
123 y
= ICEIL(ptsIn
[nextleft
].y
+ yFtrans
);
126 * loop through all edges of the polygon
129 /* add a left edge if we need to */
130 if ((y
> (ptsIn
[nextleft
].y
+ yFtrans
) ||
131 ISEQUAL(y
, ptsIn
[nextleft
].y
+ yFtrans
)) &&
132 Marked
[nextleft
] != 1) {
136 /* find the next edge, considering the end conditions */
137 if (nextleft
>= count
)
140 /* now compute the starting point and slope */
141 dy
= ptsIn
[nextleft
].y
- ptsIn
[left
].y
;
143 ml
= (ptsIn
[nextleft
].x
- ptsIn
[left
].x
) / dy
;
144 dy
= y
- (ptsIn
[left
].y
+ yFtrans
);
145 xl
= (ptsIn
[left
].x
+ xFtrans
) + ml
* max(dy
, 0);
149 /* add a right edge if we need to */
150 if ((y
> ptsIn
[nextright
].y
+ yFtrans
) ||
151 (ISEQUAL(y
, ptsIn
[nextright
].y
+ yFtrans
)
152 && Marked
[nextright
] != 1)) {
156 /* find the next edge, considering the end conditions */
158 nextright
= count
- 1;
160 /* now compute the starting point and slope */
161 dy
= ptsIn
[nextright
].y
- ptsIn
[right
].y
;
163 mr
= (ptsIn
[nextright
].x
- ptsIn
[right
].x
) / dy
;
164 dy
= y
- (ptsIn
[right
].y
+ yFtrans
);
165 xr
= (ptsIn
[right
].x
+ xFtrans
) + mr
* max(dy
, 0);
170 * generate scans to fill while we still have
171 * a right edge as well as a left edge.
173 i
= (min(ptsIn
[nextleft
].y
, ptsIn
[nextright
].y
) + yFtrans
) - y
;
176 if (Marked
[nextleft
] && Marked
[nextright
]) {
177 /* Arrgh, we're trapped! (no more points)
178 * Out, we've got to get out of here before this decadence saps
179 * our will completely! */
192 ptsOut
->y
= (y
) + yTrans
;
196 /* reverse the edges if necessary */
198 *(width
++) = cxr
- cxl
;
199 (ptsOut
++)->x
= cxl
+ xTrans
;
202 *(width
++) = cxl
- cxr
;
203 (ptsOut
++)->x
= cxr
+ xTrans
;
207 /* increment down the edges */
214 /* Finally, fill the spans we've collected */
215 (*pgc
->ops
->FillSpans
) (dst
, pgc
,
216 ptsOut
- FirstPoint
, FirstPoint
, FirstWidth
, 1);
222 /* Find the index of the point with the smallest y.also return the
223 * smallest and largest y */
226 GetFPolyYBounds(SppPointPtr pts
, int n
, double yFtrans
, int *by
, int *ty
)
230 SppPointPtr ptsStart
= pts
;
233 ymin
= ymax
= (pts
++)->y
;
246 *by
= ICEIL(ymin
+ yFtrans
);
247 *ty
= ICEIL(ymax
+ yFtrans
- 1);
248 return ptMin
- ptsStart
;