105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1988, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included
1205b261ecSmrgin all copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1505b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1605b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1705b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1805b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1905b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2005b261ecSmrgOTHER DEALINGS IN THE SOFTWARE.
2105b261ecSmrg
2205b261ecSmrgExcept as contained in this notice, the name of The Open Group shall
2305b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or
2405b261ecSmrgother dealings in this Software without prior written authorization
2505b261ecSmrgfrom The Open Group.
2605b261ecSmrg
2705b261ecSmrg*/
2805b261ecSmrg
2905b261ecSmrg/* Author:  Keith Packard, MIT X Consortium */
3005b261ecSmrg
3135c4bbdfSmrg#include "mifpoly.h"            /* for ICEIL */
3205b261ecSmrg
3305b261ecSmrg/*
3405b261ecSmrg * Polygon edge description for integer wide-line routines
3505b261ecSmrg */
3605b261ecSmrg
3705b261ecSmrgtypedef struct _PolyEdge {
3835c4bbdfSmrg    int height;                 /* number of scanlines to process */
3935c4bbdfSmrg    int x;                      /* starting x coordinate */
4035c4bbdfSmrg    int stepx;                  /* fixed integral dx */
4135c4bbdfSmrg    int signdx;                 /* variable dx sign */
4235c4bbdfSmrg    int e;                      /* initial error term */
4335c4bbdfSmrg    int dy;
4435c4bbdfSmrg    int dx;
4505b261ecSmrg} PolyEdgeRec, *PolyEdgePtr;
4605b261ecSmrg
4735c4bbdfSmrg#define SQSECANT 108.856472512142       /* 1/sin^2(11/2) - miter limit constant */
4805b261ecSmrg
4905b261ecSmrg/*
5005b261ecSmrg * types for general polygon routines
5105b261ecSmrg */
5205b261ecSmrg
5305b261ecSmrgtypedef struct _PolyVertex {
5435c4bbdfSmrg    double x, y;
5505b261ecSmrg} PolyVertexRec, *PolyVertexPtr;
5605b261ecSmrg
5705b261ecSmrgtypedef struct _PolySlope {
5835c4bbdfSmrg    int dx, dy;
5935c4bbdfSmrg    double k;                   /* x0 * dy - y0 * dx */
6005b261ecSmrg} PolySlopeRec, *PolySlopePtr;
6105b261ecSmrg
6205b261ecSmrg/*
6305b261ecSmrg * Line face description for caps/joins
6405b261ecSmrg */
6505b261ecSmrg
6605b261ecSmrgtypedef struct _LineFace {
6735c4bbdfSmrg    double xa, ya;
6835c4bbdfSmrg    int dx, dy;
6935c4bbdfSmrg    int x, y;
7035c4bbdfSmrg    double k;
7105b261ecSmrg} LineFaceRec, *LineFacePtr;
7205b261ecSmrg
7305b261ecSmrg/*
7405b261ecSmrg * macros for polygon fillers
7505b261ecSmrg */
7605b261ecSmrg
7705b261ecSmrg#define MILINESETPIXEL(pDrawable, pGC, pixel, oldPixel) { \
7805b261ecSmrg    oldPixel = pGC->fgPixel; \
7905b261ecSmrg    if (pixel != oldPixel) { \
806747b715Smrg	ChangeGCVal gcval; \
816747b715Smrg	gcval.val = pixel; \
826747b715Smrg	ChangeGC (NullClient, pGC, GCForeground, &gcval); \
8305b261ecSmrg	ValidateGC (pDrawable, pGC); \
8405b261ecSmrg    } \
8505b261ecSmrg}
8605b261ecSmrg#define MILINERESETPIXEL(pDrawable, pGC, pixel, oldPixel) { \
8705b261ecSmrg    if (pixel != oldPixel) { \
886747b715Smrg	ChangeGCVal gcval; \
896747b715Smrg	gcval.val = oldPixel; \
906747b715Smrg	ChangeGC (NullClient, pGC, GCForeground, &gcval); \
9105b261ecSmrg	ValidateGC (pDrawable, pGC); \
9205b261ecSmrg    } \
9305b261ecSmrg}
94