File indexing completed on 2024-12-22 04:10:20
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_marker_painter_test.h" 0008 0009 #include <simpletest.h> 0010 0011 #include <KoColor.h> 0012 #include <KoColorSpace.h> 0013 #include <KoColorSpaceRegistry.h> 0014 0015 #include "kis_paint_device_debug_utils.h" 0016 #include "kis_paint_device.h" 0017 #include "kis_marker_painter.h" 0018 0019 #include "kis_algebra_2d.h" 0020 #include <testutil.h> 0021 0022 0023 void KisMarkerPainterTest::testFillHalfBrushDiff() 0024 { 0025 QRectF rc(10,10,10,10); 0026 KisAlgebra2D::RightHalfPlane p(QPointF(10,13), QPointF(20,17)); 0027 0028 QCOMPARE(cutOffRect(rc, p), QRectF(10,13,10,7)); 0029 0030 0031 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0032 KisPaintDeviceSP dev = new KisPaintDevice(cs); 0033 0034 QRect fullRect(0,0,20,20); 0035 0036 QPoint center(10,10); 0037 qreal radius = 5; 0038 QPointF p3(10,5); 0039 QPointF p2(12,10); 0040 QPointF p1(15,10); 0041 KoColor color(Qt::blue, cs); 0042 0043 KisMarkerPainter painter(dev, color); 0044 painter.fillHalfBrushDiff(p1, p2, p3, 0045 center, radius); 0046 0047 //KIS_DUMP_DEVICE_2(dev, fullRect, "fill_half_brush_raw_points", "dd"); 0048 QImage result = dev->convertToQImage(0, fullRect); 0049 QVERIFY(TestUtil::checkQImage(result, "marker_painter", "half_brush_fill", "")); 0050 } 0051 0052 void KisMarkerPainterTest::testFillFullCircle() 0053 { 0054 QRectF rc(10,10,10,10); 0055 KisAlgebra2D::RightHalfPlane p(QPointF(10,13), QPointF(20,17)); 0056 0057 QCOMPARE(cutOffRect(rc, p), QRectF(10,13,10,7)); 0058 0059 0060 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0061 KisPaintDeviceSP dev = new KisPaintDevice(cs); 0062 0063 QRect fullRect(0,0,20,20); 0064 0065 QPoint center(10,10); 0066 qreal radius = 5; 0067 KoColor color(Qt::blue, cs); 0068 0069 KisMarkerPainter painter(dev, color); 0070 painter.fillFullCircle(center, radius); 0071 0072 //KIS_DUMP_DEVICE_2(dev, fullRect, "fill_full_circle", "dd"); 0073 QImage result = dev->convertToQImage(0, fullRect); 0074 QVERIFY(TestUtil::checkQImage(result, "marker_painter", "fill_full_circle", "")); 0075 } 0076 0077 void KisMarkerPainterTest::testFillCirclesDiffSingle() 0078 { 0079 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0080 KisPaintDeviceSP dev = new KisPaintDevice(cs); 0081 0082 QRect fullRect(0,0,60,60); 0083 KoColor color(Qt::blue, cs); 0084 0085 0086 KisMarkerPainter painter(dev, color); 0087 painter.fillCirclesDiff(QPointF(10,30), 20, 0088 QPointF(30,30), 20); 0089 0090 //KIS_DUMP_DEVICE_2(dev, fullRect, "fill_single_diff", "dd"); 0091 QImage result = dev->convertToQImage(0, fullRect); 0092 QVERIFY(TestUtil::checkQImage(result, "marker_painter", "fill_single_diff", "")); 0093 } 0094 0095 void KisMarkerPainterTest::testFillCirclesDiff() 0096 { 0097 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); 0098 KisPaintDeviceSP dev = new KisPaintDevice(cs); 0099 0100 QRect fullRect(0,0,100,100); 0101 KoColor color(Qt::blue, cs); 0102 0103 const int x0 = 20; 0104 const int x1 = 80; 0105 const int y0 = 50; 0106 const int step = 2; 0107 0108 const qreal omega = 2 * M_PI / (x1 - x0); 0109 QPointF p0(x0, y0); 0110 0111 KisMarkerPainter painter(dev, color); 0112 painter.fillFullCircle(p0, 10); 0113 0114 for (int x = x0 + step; x < x1; x += step) { 0115 const qreal y = 20 * std::sin(omega * (x - x0)); 0116 0117 0118 0119 QPointF p1(x, y0 + y); 0120 painter.fillCirclesDiff(p0, 10, 0121 p1, 10); 0122 0123 p0 = p1; 0124 } 0125 0126 //KIS_DUMP_DEVICE_2(dev, fullRect, "fill_stroke", "dd"); 0127 QImage result = dev->convertToQImage(0, fullRect); 0128 QVERIFY(TestUtil::checkQImage(result, "marker_painter", "fill_stroke", "")); 0129 } 0130 0131 SIMPLE_TEST_MAIN(KisMarkerPainterTest)