⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qregion_unix.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                 * reset left fence to edge of new minuend.                 */                ++r1;                if (r1 != r1End)                    x1 = r1->left();            } else {                // Subtrahend now used up since it doesn't extend beyond minuend                ++r2;            }        } else if (r2->left() <= r1->right()) {            /*             * Left part of subtrahend covers part of minuend: add uncovered             * part of minuend to region and skip to next subtrahend.             */            Q_ASSERT(x1 < r2->left());            MEMCHECK(dest, pNextRect, dest.rects)            pNextRect->setCoords(x1, y1, r2->left() - 1, y2);            ++dest.numRects;            ++pNextRect;            x1 = r2->right() + 1;            if (x1 > r1->right()) {                /*                 * Minuend used up: advance to new...                 */                ++r1;                if (r1 != r1End)                    x1 = r1->left();            } else {                // Subtrahend used up                ++r2;            }        } else {            /*             * Minuend used up: add any remaining piece before advancing.             */            if (r1->right() >= x1) {                MEMCHECK(dest, pNextRect, dest.rects)                pNextRect->setCoords(x1, y1, r1->right(), y2);                ++dest.numRects;                ++pNextRect;            }            ++r1;            if (r1 != r1End)                x1 = r1->left();        }    }    /*     * Add remaining minuend rectangles to region.     */    while (r1 != r1End) {        Q_ASSERT(x1 <= r1->right());        MEMCHECK(dest, pNextRect, dest.rects)        pNextRect->setCoords(x1, y1, r1->right(), y2);        ++dest.numRects;        ++pNextRect;        ++r1;        if (r1 != r1End)            x1 = r1->left();    }}/*- *----------------------------------------------------------------------- * miSubtract -- *      Subtract regS from regM and leave the result in regD. *      S stands for subtrahend, M for minuend and D for difference. * * Side Effects: *      regD is overwritten. * *----------------------------------------------------------------------- */static void SubtractRegion(QRegionPrivate *regM, QRegionPrivate *regS,                           register QRegionPrivate &dest){    Q_ASSERT(!isEmpty(regM));    Q_ASSERT(!isEmpty(regS));    Q_ASSERT(EXTENTCHECK(&regM->extents, &regS->extents));    Q_ASSERT(!regS->contains(*regM));    Q_ASSERT(!EqualRegion(regM, regS));    miRegionOp(dest, regM, regS, miSubtractO, miSubtractNonO1, 0);    /*     * Can't alter dest's extents before we call miRegionOp because     * it might be one of the source regions and miRegionOp depends     * on the extents of those regions being the unaltered. Besides, this     * way there's no checking against rectangles that will be nuked     * due to coalescing, so we have to examine fewer rectangles.     */    miSetExtents(dest);}static void XorRegion(QRegionPrivate *sra, QRegionPrivate *srb, QRegionPrivate &dest){    Q_ASSERT(!isEmpty(sra) && !isEmpty(srb));    Q_ASSERT(EXTENTCHECK(&sra->extents, &srb->extents));    Q_ASSERT(!EqualRegion(sra, srb));    QRegionPrivate tra, trb;    if (!srb->contains(*sra))        SubtractRegion(sra, srb, tra);    if (!sra->contains(*srb))        SubtractRegion(srb, sra, trb);    Q_ASSERT(isEmpty(&trb) || !tra.contains(trb));    Q_ASSERT(isEmpty(&tra) || !trb.contains(tra));    if (isEmpty(&tra)) {        dest = trb;    } else if (isEmpty(&trb)) {        dest = tra;    } else if (tra.canAppend(&trb)) {        dest = tra;        dest.append(&trb);    } else if (trb.canAppend(&tra)) {        dest = trb;        dest.append(&tra);    } else {        UnionRegion(&tra, &trb, dest);    }}/* *      Check to see if two regions are equal */static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2){    if (r1->numRects != r2->numRects) {        return false;    } else if (r1->numRects == 0) {        return true;    } else if (r1->extents != r2->extents) {        return false;    } else {        const QRect *rr1 = r1->rects.constData();        const QRect *rr2 = r2->rects.constData();        for (int i = 0; i < r1->numRects; ++i, ++rr1, ++rr2) {            if (*rr1 != *rr2)                return false;        }    }    return true;}static bool PointInRegion(QRegionPrivate *pRegion, int x, int y){    int i;    if (isEmpty(pRegion))        return false;    if (!pRegion->extents.contains(x, y))        return false;    if (pRegion->innerRect.contains(x, y))        return true;    for (i = 0; i < pRegion->numRects; ++i) {        if (pRegion->rects[i].contains(x, y))            return true;    }    return false;}static bool RectInRegion(register QRegionPrivate *region, int rx, int ry, uint rwidth, uint rheight){    register const QRect *pbox;    register const QRect *pboxEnd;    QRect rect(rx, ry, rwidth, rheight);    register QRect *prect = &rect;    int partIn, partOut;    if (!region || region->numRects == 0 || !EXTENTCHECK(&region->extents, prect))        return RectangleOut;    partOut = false;    partIn = false;    /* can stop when both partOut and partIn are true, or we reach prect->y2 */    for (pbox = region->rects.constData(), pboxEnd = pbox + region->numRects;         pbox < pboxEnd; ++pbox) {        if (pbox->bottom() < ry)           continue;        if (pbox->top() > ry) {           partOut = true;           if (partIn || pbox->top() > prect->bottom())              break;           ry = pbox->top();        }        if (pbox->right() < rx)           continue;            /* not far enough over yet */        if (pbox->left() > rx) {           partOut = true;      /* missed part of rectangle to left */           if (partIn)              break;        }        if (pbox->left() <= prect->right()) {            partIn = true;      /* definitely overlap */            if (partOut)               break;        }        if (pbox->right() >= prect->right()) {           ry = pbox->bottom() + 1;     /* finished with this band */           if (ry > prect->bottom())              break;           rx = prect->left();  /* reset x out to left again */        } else {            /*             * Because boxes in a band are maximal width, if the first box             * to overlap the rectangle doesn't completely cover it in that             * band, the rectangle must be partially out, since some of it             * will be uncovered in that band. partIn will have been set true             * by now...             */            break;        }    }    return partIn ? ((ry <= prect->bottom()) ? RectanglePart : RectangleIn) : RectangleOut;}// END OF Region.c extract// START OF poly.h extract/* $XConsortium: poly.h,v 1.4 94/04/17 20:22:19 rws Exp $ *//************************************************************************Copyright (c) 1987  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.                        All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.************************************************************************//* *     This file contains a few macros to help track *     the edge of a filled object.  The object is assumed *     to be filled in scanline order, and thus the *     algorithm used is an extension of Bresenham's line *     drawing algorithm which assumes that y is always the *     major axis. *     Since these pieces of code are the same for any filled shape, *     it is more convenient to gather the library in one *     place, but since these pieces of code are also in *     the inner loops of output primitives, procedure call *     overhead is out of the question. *     See the author for a derivation if needed. *//* *  In scan converting polygons, we want to choose those pixels *  which are inside the polygon.  Thus, we add .5 to the starting *  x coordinate for both left and right edges.  Now we choose the *  first pixel which is inside the pgon for the left edge and the *  first pixel which is outside the pgon for the right edge. *  Draw the left pixel, but not the right. * *  How to add .5 to the starting x coordinate: *      If the edge is moving to the right, then subtract dy from the *  error term from the general form of the algorithm. *      If the edge is moving to the left, then add dy to the error term. * *  The reason for the difference between edges moving to the left *  and edges moving to the right is simple:  If an edge is moving *  to the right, then we want the algorithm to flip immediately. *  If it is moving to the left, then we don't want it to flip until *  we traverse an entire pixel. */#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \    int dx;      /* local storage */ \\    /* \     *  if the edge is horizontal, then it is ignored \     *  and assumed not to be processed.  Otherwise, do this stuff. \     */ \    if ((dy) != 0) { \        xStart = (x1); \        dx = (x2) - xStart; \        if (dx < 0) { \            m = dx / (dy); \            m1 = m - 1; \            incr1 = -2 * dx + 2 * (dy) * m1; \            incr2 = -2 * dx + 2 * (dy) * m; \            d = 2 * m * (dy) - 2 * dx - 2 * (dy); \        } else { \            m = dx / (dy); \            m1 = m + 1; \            incr1 = 2 * dx - 2 * (dy) * m1; \            incr2 = 2 * dx - 2 * (dy) * m; \            d = -2 * m * (dy) + 2 * dx; \        } \    } \}#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \    if (m1 > 0) { \        if (d > 0) { \            minval += m1; \            d += incr1; \        } \        else { \            minval += m; \            d += incr2; \        } \    } else {\        if (d >= 0) { \            minval += m1; \            d += incr1; \        } \        else { \            minval += m; \            d += incr2; \        } \    } \}/* *     This structure contains all of the information needed *     to run the bresenham algorithm. *     The variables may be hardcoded into the declarations *     instead of using this structure to make use of *     register declarations. */typedef struct {    int minor_axis;     /* minor axis        */    int d;              /* decision variable */    int m, m1;          /* slope and slope+1 */    int incr1, incr2;   /* error increments */} BRESINFO;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -