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

📄 qmatrix.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    The rectangle's coordinates are transformed using the following    formulas:    \code        x' = m11*x + m21*y + dx        y' = m22*y + m12*x + dy    \endcode    If rotation or shearing has been specified, this function returns    the \e bounding rectangle. To retrieve the exact region the given    \a rectangle maps to, use the mapToPolygon() function instead.    \sa mapToPolygon(), {QMatrix#Basic Matrix Operations}{Basic Matrix    Operations}*/QRectF QMatrix::mapRect(const QRectF &rect) const{    QRectF result;    if (_m12 == 0.0F && _m21 == 0.0F) {        qreal x = _m11*rect.x() + _dx;        qreal y = _m22*rect.y() + _dy;        qreal w = _m11*rect.width();        qreal h = _m22*rect.height();        if (w < 0) {            w = -w;            x -= w;        }        if (h < 0) {            h = -h;            y -= h;        }        result = QRectF(x, y, w, h);    } else {        qreal x0, y0;        qreal x, y;        MAPDOUBLE(rect.x(), rect.y(), x0, y0);        qreal xmin = x0;        qreal ymin = y0;        qreal xmax = x0;        qreal ymax = y0;        MAPDOUBLE(rect.x() + rect.width(), rect.y(), x, y);        xmin = qMin(xmin, x);        ymin = qMin(ymin, y);        xmax = qMax(xmax, x);        ymax = qMax(ymax, y);        MAPDOUBLE(rect.x() + rect.width(), rect.y() + rect.height(), x, y);        xmin = qMin(xmin, x);        ymin = qMin(ymin, y);        xmax = qMax(xmax, x);        ymax = qMax(ymax, y);        MAPDOUBLE(rect.x(), rect.y() + rect.height(), x, y);        xmin = qMin(xmin, x);        ymin = qMin(ymin, y);        xmax = qMax(xmax, x);        ymax = qMax(ymax, y);        result = QRectF(xmin, ymin, xmax-xmin, ymax - ymin);    }    return result;}/*!    \fn QRect QMatrix::mapRect(const QRect &rectangle) const    \overload    Creates and returns a QRect object that is a copy of the given \a    rectangle, mapped into the coordinate system defined by this    matrix. Note that the transformed coordinates are rounded to the    nearest integer.*//*!    \fn QPoint operator*(const QPoint &point, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{point}).    \sa QMatrix::map()*/QPoint QMatrix::map(const QPoint &p) const{    qreal fx = p.x();    qreal fy = p.y();    return QPoint(qRound(_m11*fx + _m21*fy + _dx),                   qRound(_m12*fx + _m22*fy + _dy));}/*!    \fn QPointF operator*(const QPointF &point, const QMatrix &matrix)    \relates QMatrix    Same as \a{matrix}.map(\a{point}).    \sa QMatrix::map()*//*!    \overload    Creates and returns a QPointF object that is a copy of the given    \a point, mapped into the coordinate system defined by this    matrix.*/QPointF QMatrix::map(const QPointF &point) const{    qreal fx = point.x();    qreal fy = point.y();    return QPointF(_m11*fx + _m21*fy + _dx, _m12*fx + _m22*fy + _dy);}/*!    \fn QPoint QMatrix::map(const QPoint &point) const    \overload    Creates and returns a QPoint object that is a copy of the given \a    point, mapped into the coordinate system defined by this    matrix. Note that the transformed coordinates are rounded to the    nearest integer.*//*!    \fn QLineF operator*(const QLineF &line, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{line}).    \sa QMatrix::map()*//*!    \fn QLine operator*(const QLine &line, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{line}).    \sa QMatrix::map()*//*!    \overload    Creates and returns a QLineF object that is a copy of the given \a    line, mapped into the coordinate system defined by this matrix.*/QLineF QMatrix::map(const QLineF &line) const{    return QLineF(map(line.p1()), map(line.p2()));}/*!    \overload    Creates and returns a QLine object that is a copy of the given \a    line, mapped into the coordinate system defined by this matrix.    Note that the transformed coordinates are rounded to the nearest    integer.*/QLine QMatrix::map(const QLine &line) const{    return QLine(map(line.p1()), map(line.p2()));}/*!    \fn QPolygonF operator *(const QPolygonF &polygon, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{polygon}).    \sa QMatrix::map()*//*!    \fn QPolygon operator*(const QPolygon &polygon, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{polygon}).    \sa QMatrix::map()*/QPolygon QMatrix::map(const QPolygon &a) const{    int size = a.size();    int i;    QPolygonF p(size);    const QPoint *da = a.constData();    QPointF *dp = p.data();    qreal xmin = qreal(INT_MAX);    qreal ymin = xmin;    qreal xmax = qreal(INT_MIN);    qreal ymax = xmax;    int xminp = 0;    int yminp = 0;    for(i = 0; i < size; i++) {        dp[i].xp = da[i].x();        dp[i].yp = da[i].y();        if (dp[i].xp < xmin) {            xmin = dp[i].xp;            xminp = i;        }        if (dp[i].yp < ymin) {            ymin = dp[i].yp;            yminp = i;        }        xmax = qMax(xmax, dp[i].xp);        ymax = qMax(ymax, dp[i].yp);    }    qreal w = qMax<qreal>(xmax - xmin, 1.);    qreal h = qMax<qreal>(ymax - ymin, 1.);    for(i = 0; i < size; i++) {        dp[i].xp += (dp[i].xp - xmin)/w;        dp[i].yp += (dp[i].yp - ymin)/h;        MAPDOUBLE(dp[i].xp, dp[i].yp, dp[i].xp, dp[i].yp);    }    // now apply correction back for transformed values...    xmin = qreal(INT_MAX/256);    ymin = xmin;    xmax = qreal(INT_MIN/256);    ymax = xmax;    for(i = 0; i < size; i++) {        xmin = qMin<qreal>(xmin, dp[i].xp);        ymin = qMin<qreal>(ymin, dp[i].yp);        xmax = qMax<qreal>(xmax, dp[i].xp);        ymax = qMax<qreal>(ymax, dp[i].yp);    }    w = qMax<qreal>(xmax - xmin, 1.);    h = qMax<qreal>(ymax - ymin, 1.);    QPolygon result(size);    QPoint *dr = result.data();    for(i = 0; i < size; i++) {        dr[i].setX(qRound(dp[i].xp - (dp[i].xp - dp[xminp].xp)/w));        dr[i].setY(qRound(dp[i].yp - (dp[i].yp - dp[yminp].yp)/h));    }    return result;}/*!    \fn QPolygonF QMatrix::map(const QPolygonF &polygon) const    \overload    Creates and returns a QPolygonF object that is a copy of the given    \a polygon, mapped into the coordinate system defined by this    matrix.*/QPolygonF QMatrix::map(const QPolygonF &a) const{    int size = a.size();    int i;    QPolygonF p(size);    const QPointF *da = a.constData();    QPointF *dp = p.data();    for(i = 0; i < size; i++) {        MAPDOUBLE(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp);    }    return p;}/*!    \fn QPolygon QMatrix::map(const QPolygon &polygon) const    \overload    Creates and returns a QPolygon object that is a copy of the given    \a polygon, mapped into the coordinate system defined by this    matrix. Note that the transformed coordinates are rounded to the    nearest integer.*//*!    \fn QRegion operator*(const QRegion &region, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{region}).    \sa QMatrix::map()*//*!    \fn QRegion QMatrix::map(const QRegion &region) const    \overload    Creates and returns a QRegion object that is a copy of the given    \a region, mapped into the coordinate system defined by this matrix.    Calling this method can be rather expensive if rotations or    shearing are used.*/QRegion QMatrix::map(const QRegion &r) const{    if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // translate or identity        if (_dx == 0.0 && _dy == 0.0) // Identity            return r;        QRegion copy(r);        copy.translate(qRound(_dx), qRound(_dy));        return copy;    }    QPainterPath p;    p.addRegion(r);    p = map(p);    return p.toFillPolygon().toPolygon();}/*!    \fn QPainterPath operator *(const QPainterPath &path, const QMatrix &matrix)    \relates QMatrix    This is the same as \a{matrix}.map(\a{path}).    \sa QMatrix::map()*//*!    \overload    Creates and returns a QPainterPath object that is a copy of the    given \a path, mapped into the coordinate system defined by this    matrix.*/QPainterPath QMatrix::map(const QPainterPath &path) const{    if (path.isEmpty())        return QPainterPath();    QPainterPath copy = path;    // Translate or identity    if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) {        // Translate        if (_dx != 0.0 || _dy != 0.0) {            copy.detach();            for (int i=0; i<path.elementCount(); ++i) {                QPainterPath::Element &e = copy.d_ptr->elements[i];                e.x += _dx;                e.y += _dy;            }        }    // Full xform    } else {        copy.detach();        for (int i=0; i<path.elementCount(); ++i) {            QPainterPath::Element &e = copy.d_ptr->elements[i];            qreal fx = e.x, fy = e.y;            e.x = _m11*fx + _m21*fy + _dx;            e.y =  _m12*fx + _m22*fy + _dy;        }    }    return copy;}/*!    \fn QRegion QMatrix::mapToRegion(const QRect &rectangle) const    Returns the transformed rectangle \a rectangle as a QRegion    object. A rectangle which has been rotated or sheared may result    in a non-rectangular region being returned.    Use the mapToPolygon() or map() function instead.*/#ifdef QT3_SUPPORTQRegion QMatrix::mapToRegion(const QRect &rect) const{    QRegion result;    if (isIdentity()) {        result = rect;    } else if (m12() == 0.0F && m21() == 0.0F) {        int x = qRound(m11()*rect.x() + dx());        int y = qRound(m22()*rect.y() + dy());        int w = qRound(m11()*rect.width());        int h = qRound(m22()*rect.height());        if (w < 0) {            w = -w;            x -= w - 1;        }        if (h < 0) {            h = -h;            y -= h - 1;        }        result = QRect(x, y, w, h);    } else {        result = QRegion(mapToPolygon(rect));    }    return result;}#endif/*!    \fn QPolygon QMatrix::mapToPolygon(const QRect &rectangle) const    Creates and returns a QPolygon representation of the given \a    rectangle, mapped into the coordinate system defined by this    matrix.    The rectangle's coordinates are transformed using the following    formulas:    \code        x' = m11*x + m21*y + dx        y' = m22*y + m12*x + dy    \endcode    Polygons and rectangles behave slightly differently when    transformed (due to integer rounding), so    \c{matrix.map(QPolygon(rectangle))} is not always the same as    \c{matrix.mapToPolygon(rectangle)}.    \sa mapRect(), {QMatrix#Basic Matrix Operations}{Basic Matrix    Operations}

⌨️ 快捷键说明

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