void tst_QPainterPath::intersects_QRectF_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QRectF>("rect");
    QTest::addColumn<bool>("intersects");

    QPainterPath path;
    path.addRect(0, 0, 100, 100);

    QTest::newRow("same rect") << path << QRectF(0.1, 0.1, 99, 99) << true; // ###
    QTest::newRow("outside") << path << QRectF(-1, -1, 100, 100) << true;
    QTest::newRow("covers") << path << QRectF(-1, -1, 102, 102) << true;
    QTest::newRow("left") << path << QRectF(-10, 50, 5, 5) << false;
    QTest::newRow("top") << path << QRectF(50, -10, 5, 5) << false;
    QTest::newRow("right") << path << QRectF(110, 50, 5, 5) << false;
    QTest::newRow("bottom") << path << QRectF(50, 110, 5, 5) << false;

    path.addRect(50, 50, 100, 100);

    QTest::newRow("r1 top") << path << QRectF(0.1, 0.1, 99, 49) << true;
    QTest::newRow("r1 left") << path << QRectF(0.1, 0.1, 49, 99) << true;
    QTest::newRow("r2 right") << path << QRectF(100.01, 50.1, 49, 99) << true;
    QTest::newRow("r2 bottom") << path << QRectF(50.1, 100.1, 99, 49) << true;
    QTest::newRow("inside 2 rects") << path << QRectF(51, 51, 48, 48) << false;

    path.setFillRule(Qt::WindingFill);
    QTest::newRow("inside 2 rects (winding)") << path << QRectF(51, 51, 48, 48) << true;

    path.addEllipse(0, 0, 150, 150);
    QTest::newRow("topRight 2 rects") << path << QRectF(100, 25, 24, 24) << true;
    QTest::newRow("bottomLeft 2 rects") << path << QRectF(25, 100, 24, 24) << true;

    QTest::newRow("horizontal line") << linePath(0, 0, 10, 0) << QRectF(1, -1, 2, 2) << true;
    QTest::newRow("vertical line") << linePath(0, 0, 0, 10) << QRectF(-1, 1, 2, 2) << true;
}
void tst_QPainterPath::testStroker_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QPen>("pen");
    QTest::addColumn<QPainterPath>("stroke");

    QTest::newRow("line 1") << linePath(2, 2, 10, 2) << QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap) << rectPath(2, 1, 8, 2);
    QTest::newRow("line 2") << linePath(2, 2, 10, 2) << QPen(Qt::black, 2, Qt::SolidLine, Qt::SquareCap) << rectPath(1, 1, 10, 2);

    QTest::newRow("rect") << rectPath(1, 1, 8, 8) << QPen(Qt::black, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin) << rectPath(0, 0, 10, 10).subtracted(rectPath(2, 2, 6, 6));

    QTest::newRow("dotted line") << linePath(0, 0, 10, 0) << QPen(Qt::black, 2, Qt::DotLine) << rectPath(-1, -1, 4, 2).united(rectPath(5, -1, 4, 2));
}
示例#3
0
Line::Line(QPointF p1, QPointF p2)
{
    // set values of start point and end point of line
    startP = p1;
    endP = p2;

    linePath();
}
示例#4
0
Line::Line(int i, QPointF p1, QPointF p2)
{
    // assigns id
    id = i;

    // set values of start point and end point of line
    startP = p1;
    endP = p2;

    linePath();
}
void tst_QPainterPath::testContainsAndIntersects_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QPainterPath>("candidate");
    QTest::addColumn<bool>("contained");
    QTest::addColumn<bool>("intersects");

    QTest::newRow("rect vs small ellipse (upper left)") << rectPath(0, 0, 100, 100) << ellipsePath(0, 0, 50, 50) << false << true;
    QTest::newRow("rect vs small ellipse (upper right)") << rectPath(0, 0, 100, 100) << ellipsePath(50, 0, 50, 50) << false << true;
    QTest::newRow("rect vs small ellipse (lower right)") << rectPath(0, 0, 100, 100) << ellipsePath(50, 50, 50, 50) << false << true;
    QTest::newRow("rect vs small ellipse (lower left)") << rectPath(0, 0, 100, 100) << ellipsePath(0, 50, 50, 50) << false << true;
    QTest::newRow("rect vs small ellipse (centered)") << rectPath(0, 0, 100, 100) << ellipsePath(25, 25, 50, 50) << true << true;
    QTest::newRow("rect vs equal ellipse") << rectPath(0, 0, 100, 100) << ellipsePath(0, 0, 100, 100) << false << true;
    QTest::newRow("rect vs big ellipse") << rectPath(0, 0, 100, 100) << ellipsePath(-10, -10, 120, 120) << false << true;

    QPainterPath twoEllipses = ellipsePath(0, 0, 100, 100).united(ellipsePath(200, 0, 100, 100));

    QTest::newRow("rect vs two small ellipses") << rectPath(0, 0, 100, 100) << ellipsePath(25, 25, 50, 50).united(ellipsePath(225, 25, 50, 50)) << false << true;
    QTest::newRow("rect vs two equal ellipses") << rectPath(0, 0, 100, 100) << twoEllipses << false << true;

    QTest::newRow("rect vs self") << rectPath(0, 0, 100, 100) << rectPath(0, 0, 100, 100) << false << true;
    QTest::newRow("ellipse vs self") << ellipsePath(0, 0, 100, 100) << ellipsePath(0, 0, 100, 100) << false << true;

    QPainterPath twoRects = rectPath(0, 0, 100, 100).united(rectPath(200, 0, 100, 100));
    QTest::newRow("two rects vs small ellipse (upper left)") << twoRects << ellipsePath(0, 0, 50, 50) << false << true;
    QTest::newRow("two rects vs small ellipse (upper right)") << twoRects << ellipsePath(50, 0, 50, 50) << false << true;
    QTest::newRow("two rects vs small ellipse (lower right)") << twoRects << ellipsePath(50, 50, 50, 50) << false << true;
    QTest::newRow("two rects vs small ellipse (lower left)") << twoRects << ellipsePath(0, 50, 50, 50) << false << true;
    QTest::newRow("two rects vs small ellipse (centered)") << twoRects << ellipsePath(25, 25, 50, 50) << true << true;
    QTest::newRow("two rects vs equal ellipse") << twoRects << ellipsePath(0, 0, 100, 100) << false << true;
    QTest::newRow("two rects vs big ellipse") << twoRects << ellipsePath(-10, -10, 120, 120) << false << true;

    QTest::newRow("two rects vs two small ellipses") << twoRects << ellipsePath(25, 25, 50, 50).united(ellipsePath(225, 25, 50, 50)) << true << true;
    QTest::newRow("two rects vs two equal ellipses") << twoRects << ellipsePath(0, 0, 100, 100).united(ellipsePath(200, 0, 100, 100)) << false << true;

    QTest::newRow("two rects vs self") << twoRects << twoRects << false << true;
    QTest::newRow("two ellipses vs self") << twoEllipses << twoEllipses << false << true;

    QPainterPath windingRect = rectPath(0, 0, 100, 100);
    windingRect.addRect(25, 25, 100, 50);
    windingRect.setFillRule(Qt::WindingFill);

    QTest::newRow("rect with winding rule vs tall rect") << windingRect << rectPath(40, 20, 20, 60) << true << true;
    QTest::newRow("rect with winding rule vs self") << windingRect << windingRect << false << true;

    QPainterPath thickFrame = rectPath(0, 0, 100, 100).subtracted(rectPath(25, 25, 50, 50));
    QPainterPath thinFrame = rectPath(10, 10, 80, 80).subtracted(rectPath(15, 15, 70, 70));

    QTest::newRow("thin frame in thick frame") << thickFrame << thinFrame << true << true;
    QTest::newRow("rect in thick frame") << thickFrame << rectPath(40, 40, 20, 20) << false << false;
    QTest::newRow("rect in thin frame") << thinFrame << rectPath(40, 40, 20, 20) << false << false;

    QPainterPath ellipses;
    ellipses.addEllipse(0, 0, 10, 10);
    ellipses.addEllipse(4, 4, 2, 2);
    ellipses.setFillRule(Qt::WindingFill);

    // the definition of QPainterPath::intersects() and contains() is fill-area based,
    QTest::newRow("line in rect") << rectPath(0, 0, 100, 100) << linePath(10, 10, 90, 90) << true << true;
    QTest::newRow("horizontal line in rect") << rectPath(0, 0, 100, 100) << linePath(10, 50, 90, 50) << true << true;
    QTest::newRow("vertical line in rect") << rectPath(0, 0, 100, 100) << linePath(50, 10, 50, 90) << true << true;

    QTest::newRow("line through rect") << rectPath(0, 0, 100, 100) << linePath(-10, -10, 110, 110) << false << true;
    QTest::newRow("line through rect 2") << rectPath(0, 0, 100, 100) << linePath(-10, 0, 110, 100) << false << true;
    QTest::newRow("line through rect 3") << rectPath(0, 0, 100, 100) << linePath(5, 10, 110, 100) << false << true;
    QTest::newRow("line through rect 4") << rectPath(0, 0, 100, 100) << linePath(-10, 0, 90, 90) << false << true;

    QTest::newRow("horizontal line through rect") << rectPath(0, 0, 100, 100) << linePath(-10, 50, 110, 50) << false << true;
    QTest::newRow("vertical line through rect") << rectPath(0, 0, 100, 100) << linePath(50, -10, 50, 110) << false << true;

    QTest::newRow("line vs line") << linePath(0, 0, 10, 10) << linePath(10, 0, 0, 10) << false << true;

    QTest::newRow("line in rect with hole") << rectPath(0, 0, 10, 10).subtracted(rectPath(2, 2, 6, 6)) << linePath(4, 4, 6, 6) << false << false;
    QTest::newRow("line in ellipse") << ellipses << linePath(3, 5, 7, 5) << false << true;
    QTest::newRow("line in ellipse 2") << ellipses << linePath(4.5, 5, 5.5, 5) << true << true;

    QTest::newRow("winding ellipse") << ellipses << ellipsePath(4, 4, 2, 2) << false << true;
    QTest::newRow("winding ellipse 2") << ellipses << ellipsePath(4.5, 4.5, 1, 1) << true << true;
    ellipses.setFillRule(Qt::OddEvenFill);
    QTest::newRow("odd even ellipse") << ellipses << ellipsePath(4, 4, 2, 2) << false << true;
    QTest::newRow("odd even ellipse 2") << ellipses << ellipsePath(4.5, 4.5, 1, 1) << false << false;
}