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)); }
void onDrawContent(SkCanvas* canvas) override { const float SCALE = 1; canvas->translate(30, 40); canvas->scale(SCALE, SCALE); SkPoint p1 = SkPoint::Make(50, 50); SkPoint p2 = SkPoint::Make(80, 50); SkPath path; switch (fPathType) { case 0: path = quadPath(p1, p2); break; case 1: path = linSemicirclePath(p1, p2); break; case 2: path = rectPath(p1); break; default: path = quadPath(p1, p2); break; } if (fClosePath) { path.close(); } SkPaint p; p.setColor(SK_ColorRED); p.setAntiAlias(true); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(fStroke); canvas->drawPath(path, p); if (fDrawFillPath) { SkPath fillpath; p.getFillPath(path, &fillpath); SkPaint fillp; fillp.setColor(SK_ColorBLACK); fillp.setAntiAlias(true); fillp.setStyle(SkPaint::kStroke_Style); canvas->drawPath(fillpath, fillp); } }
void tst_QPainterPath::testSimplified_data() { QTest::addColumn<QPainterPath>("path"); QTest::addColumn<int>("elements"); QTest::newRow("rect") << rectPath(0, 0, 10, 10) << 5; QPainterPath twoRects = rectPath(0, 0, 10, 10); twoRects.addPath(rectPath(5, 0, 10, 10)); QTest::newRow("two rects (odd)") << twoRects << 10; twoRects.setFillRule(Qt::WindingFill); QTest::newRow("two rects (winding)") << twoRects << 5; QPainterPath threeSteps = rectPath(0, 0, 10, 10); threeSteps.addPath(rectPath(0, 10, 20, 10)); threeSteps.addPath(rectPath(0, 20, 30, 10)); QTest::newRow("three rects (steps)") << threeSteps << 9; }
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; }
void onDrawContent(SkCanvas* canvas) override { const float SCALE = 1; canvas->translate(30, 40); canvas->scale(SCALE, SCALE); SkPoint p1 = SkPoint::Make(50, 50); SkPoint p2 = SkPoint::Make(80, 50); SkPath path; switch (fPathType) { case 0: path = quadPath(p1, p2); break; case 1: path = cubicPath(p1, p2); break; case 2: path = rectPath(p1); break; case 3: path = linSemicirclePath(p1, p2); break; default: path = quadPath(p1, p2); break; } if (fClosePath) { path.close(); } SkPaint p; p.setColor(SK_ColorRED); p.setAntiAlias(true); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(fStroke); canvas->drawPath(path, p); if (fDumpHex) { std::cerr << "path dumpHex" << std::endl; path.dumpHex(); } SkPaint hairp; hairp.setColor(SK_ColorBLACK); hairp.setAntiAlias(true); hairp.setStyle(SkPaint::kStroke_Style); if (fDrawFillPath) { SkPath fillpath; p.getFillPath(path, &fillpath); canvas->drawPath(fillpath, hairp); if (fDumpHex) { std::cerr << "fillpath dumpHex" << std::endl; fillpath.dumpHex(); } } if (fDumpHex) { std::cerr << std::endl; fDumpHex = false; } // draw original path with green hairline hairp.setColor(SK_ColorGREEN); canvas->drawPath(path, hairp); }