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

📄 qpolygon.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        else if (pd->y() > maxy)            maxy = pd->y();        ++pd;    }    return QRect(QPoint(minx,miny), QPoint(maxx,maxy));}#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug dbg, const QPolygon &a){#ifndef Q_BROKEN_DEBUG_STREAM    dbg.nospace() << "QPolygon(";    for (int i = 0; i < a.count(); ++i)        dbg.nospace() << a.at(i);    dbg.nospace() << ')';    return dbg.space();#else    qWarning("This compiler doesn't support streaming QPolygon to QDebug");    return dbg;    Q_UNUSED(a);#endif}#endif/*!    \class QPolygonF    \brief The QPolygonF class provides a vector of points using    floating point precision.    \reentrant    \ingroup multimedia    \ingroup shared    A QPolygonF is a QVector<QPointF>. The easiest way to add points    to a QPolygonF is to use its streaming operator, as illustrated    below:    \quotefromfile snippets/polygon/polygon.cpp    \skipto STREAMF    \skipto QPolygonF    \printuntil QPointF    In addition to the functions provided by QVector, QPolygonF    provides the boundingRect() and translate() functions for geometry    operations. Use the QMatrix::map() function for more general    transformations of QPolygonFs.    QPolygonF also provides the isClosed() function to determine    whether a polygon's start and end points are the same, and the    toPolygon() function returning an integer precision copy of this    polygon.    The QPolygonF class is \l {Implicit Data Sharing}{implicitly    shared}.    \sa QVector, QPolygon, QLineF*//*****************************************************************************  QPolygonF member functions *****************************************************************************//*!    \fn QPolygonF::QPolygonF()    Constructs a polygon with no points.    \sa QVector::isEmpty()*//*!    \fn QPolygonF::QPolygonF(int size)    Constructs a polygon of the given \a size. Creates an empty    polygon if \a size == 0.    \sa QVector::isEmpty()*//*!    \fn QPolygonF::QPolygonF(const QPolygonF &polygon)    Constructs a copy of the given \a polygon.*//*!    \fn QPolygonF::QPolygonF(const QVector<QPointF> &points)    Constructs a polygon containing the specified \a points.*//*!    \fn QPolygonF::QPolygonF(const QRectF &rectangle)    Constructs a closed polygon from the specified \a rectangle.    The polygon contains the four vertices of the rectangle in    clockwise order starting and ending with the top-left vertex.    \sa isClosed()*/QPolygonF::QPolygonF(const QRectF &r){    reserve(5);    append(QPointF(r.x(), r.y()));    append(QPointF(r.x() + r.width(), r.y()));    append(QPointF(r.x() + r.width(), r.y() + r.height()));    append(QPointF(r.x(), r.y() + r.height()));    append(QPointF(r.x(), r.y()));}/*!    \fn QPolygonF::QPolygonF(const QPolygon &polygon)    Constructs a float based polygon from the specified integer based    \a polygon.    \sa toPolygon()*/QPolygonF::QPolygonF(const QPolygon &a){    reserve(a.size());    for (int i=0; i<a.size(); ++i)        append(a.at(i));}/*!    \fn QPolygonF::~QPolygonF()    Destroys the polygon.*//*!    Translate all points in the polygon by the given \a offset.*/void QPolygonF::translate(const QPointF &offset){    register QPointF *p = data();    register int i = size();    while (i--) {        *p += offset;        ++p;    }}/*!    \fn void QPolygonF::translate(qreal dx, qreal dy)    \overload    Translates all points in the polygon by (\a{dx}, \a{dy}).*//*!    \fn bool QPolygonF::isClosed() const    Returns true if the polygon is closed; otherwise returns false.    A polygon is said to be closed if its start point and end point are equal.    \sa QVector::first(), QVector::last()*//*!    Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0)    if the polygon is empty.    \sa QVector::isEmpty()*/QRectF QPolygonF::boundingRect() const{    if (isEmpty())        return QRectF(0, 0, 0, 0);    register const QPointF *pd = constData();    qreal minx, maxx, miny, maxy;    minx = maxx = pd->x();    miny = maxy = pd->y();    ++pd;    for (int i = 1; i < size(); ++i) {        if (pd->x() < minx)            minx = pd->x();        else if (pd->x() > maxx)            maxx = pd->x();        if (pd->y() < miny)            miny = pd->y();        else if (pd->y() > maxy)            maxy = pd->y();        ++pd;    }    return QRectF(minx,miny, maxx - minx, maxy - miny);}/*!    Creates and returns a QPolygon by converting each QPointF to a    QPoint.    \sa QPointF::toPoint()*/QPolygon QPolygonF::toPolygon() const{    QPolygon a;    a.reserve(size());    for (int i=0; i<size(); ++i)        a.append(at(i).toPoint());    return a;}/*!   Returns the polygon as a QVariant*/QPolygon::operator QVariant() const{    return QVariant(QVariant::Polygon, this);}/*****************************************************************************  QPolygonF stream functions *****************************************************************************/#ifndef QT_NO_DATASTREAM/*!    \fn QDataStream &operator<<(QDataStream &stream, const QPolygonF &polygon)    \relates QPolygonF    Writes the given \a polygon to the given \a stream, and returns a    reference to the stream.    \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &s, const QPolygonF &a){    quint32 len = a.size();    uint i;    s << len;    for (i = 0; i < len; ++i)        s << a.at(i);    return s;}/*!    \fn QDataStream &operator>>(QDataStream &stream, QPolygonF &polygon)    \relates QPolygonF    Reads a polygon from the given \a stream into the given \a    polygon, and returns a reference to the stream.    \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &s, QPolygonF &a){    quint32 len;    uint i;    s >> len;    a.reserve(a.size() + (int)len);    QPointF p;    for (i = 0; i < len; ++i) {        s >> p;        a.insert(i, p);    }    return s;}#endif //QT_NO_DATASTREAM#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug dbg, const QPolygonF &a){#ifndef Q_BROKEN_DEBUG_STREAM    dbg.nospace() << "QPolygonF(";    for (int i = 0; i < a.count(); ++i)        dbg.nospace() << a.at(i);    dbg.nospace() << ')';    return dbg.space();#else    qWarning("This compiler doesn't support streaming QPolygonF to QDebug");    return dbg;    Q_UNUSED(a);#endif}#endif/*!    \since 4.3    \fn bool QPolygonF::containsPoint(const QPointF &point, Qt::FillRule fillRule) const    Returns true if the given \a point is inside the polygon according to    the specified \a fillRule; otherwise returns false.*/bool QPolygonF::containsPoint(const QPointF &pt, Qt::FillRule fillRule) const{    if (isEmpty())        return false;    int winding_number = 0;    QPointF last_pt = at(0);    QPointF last_start = at(0);    for (int i = 1; i < size(); ++i) {        const QPointF &e = at(i);        qt_polygon_isect_line(last_pt, e, pt, &winding_number);        last_pt = e;    }    // implicitly close last subpath    if (last_pt != last_start)        qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);    return (fillRule == Qt::WindingFill            ? (winding_number != 0)            : ((winding_number % 2) != 0));}/*!    \since 4.3    \fn bool QPolygon::containsPoint(const QPoint &point, Qt::FillRule fillRule) const    Returns true if the given \a point is inside the polygon according to    the specified \a fillRule; otherwise returns false.*/bool QPolygon::containsPoint(const QPoint &pt, Qt::FillRule fillRule) const{    if (isEmpty())        return false;    int winding_number = 0;    QPoint last_pt = at(0);    QPoint last_start = at(0);    for (int i = 1; i < size(); ++i) {        const QPoint &e = at(i);        qt_polygon_isect_line(last_pt, e, pt, &winding_number);        last_pt = e;    }    // implicitly close last subpath    if (last_pt != last_start)        qt_polygon_isect_line(last_pt, last_start, pt, &winding_number);    return (fillRule == Qt::WindingFill            ? (winding_number != 0)            : ((winding_number % 2) != 0));}/*!    \since 4.3    Returns a polygon which is the union of this polygon and \a r.    \sa intersected(), subtracted()*/QPolygon QPolygon::united(const QPolygon &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.united(clip).toFillPolygon().toPolygon();}/*!    \since 4.3    Returns a polygon which is the intersection of this polygon and \a r.*/QPolygon QPolygon::intersected(const QPolygon &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.intersected(clip).toFillPolygon().toPolygon();}/*!    \since 4.3    Returns a polygon which is \a r subtracted from this polygon.*/QPolygon QPolygon::subtracted(const QPolygon &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.subtracted(clip).toFillPolygon().toPolygon();}/*!    \since 4.3    Returns a polygon which is the union of this polygon and \a r.    \sa intersected(), subtracted()*/QPolygonF QPolygonF::united(const QPolygonF &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.united(clip).toFillPolygon();}/*!    \since 4.3    Returns a polygon which is the intersection of this polygon and \a r.*/QPolygonF QPolygonF::intersected(const QPolygonF &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.intersected(clip).toFillPolygon();}/*!    \since 4.3    Returns a polygon which is \a r subtracted from this polygon.*/QPolygonF QPolygonF::subtracted(const QPolygonF &r) const{    QPainterPath subject; subject.addPolygon(*this);    QPainterPath clip; clip.addPolygon(r);    return subject.subtracted(clip).toFillPolygon();}

⌨️ 快捷键说明

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