From c3ff1dbc0af72350acc364d3c6e3e3cdcda7a0d5 Mon Sep 17 00:00:00 2001 From: Mienek Date: Thu, 16 Jan 2020 12:36:19 +0100 Subject: [PATCH] =?UTF-8?q?kein=20bock=20mehr=20mach=20dein=20schei=C3=9F?= =?UTF-8?q?=20richtig=20das=20n=C3=A4chste=20mal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IntelliUnitTest.pro | 2 + src/Tool/IntelliToolPolygon.cpp | 15 +--- src/tst_unittest.cpp | 128 ++++++++++++++------------------ 3 files changed, 61 insertions(+), 84 deletions(-) diff --git a/src/IntelliUnitTest.pro b/src/IntelliUnitTest.pro index 6e41ba3..a285e28 100644 --- a/src/IntelliUnitTest.pro +++ b/src/IntelliUnitTest.pro @@ -10,6 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TEMPLATE = app SOURCES += tst_unittest.cpp \ + GUI/IntelliInputDialog.cpp \ GUI/IntelliPhotoGui.cpp \ Image/IntelliImage.cpp \ Image/IntelliRasterImage.cpp \ @@ -41,6 +42,7 @@ DISTFILES += \ icons/rectangle-tool.svg HEADERS += \ + GUI/IntelliInputDialog.h \ GUI/IntelliPhotoGui.h \ Image/IntelliImage.h \ Image/IntelliRasterImage.h \ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index d80c471..e860120 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -52,7 +52,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ this->Canvas->image->calculateVisiblity(); } } - else if(drawingOfPolygon && isNearStart(x,y,QPointList.front())) { + else if(drawingOfPolygon && QPointList.size() > 0 && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); @@ -90,7 +90,6 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { isInside = false; isPointNearStart = false; - isDrawing = false; if(!isSettingPolygon) { std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; @@ -139,17 +138,11 @@ void IntelliToolPolygon::onMouseMoved(int x, int y){ } bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ - bool isNear = false; int StartX = Startpoint.x(); int StartY = Startpoint.y(); int valueToNear = 5; - for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) { - for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) { - if((i == x) && (j == y)) { - isNear = true; - } - } - } - return isNear; + float euklid = sqrt(pow(static_cast(StartX-x),2.f)+pow(static_cast(StartY-y),2.f)); + + return static_cast(euklid)layerBundle[0].image->drawPlain(QColor(-1, -1, -1, -1)); - for(size_t i = 0; i<200; i++) { - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++) { - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } - - area->layerBundle[0].image->drawPlain(QColor(256, 256, 256, 256)); - for(size_t i = 0; i<200; i++) { - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++) { - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } - area->deleteLayer(0); } @@ -299,7 +281,7 @@ void UnitTest::test_moveActive(){ area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 255)); + area->layerBundle[1].image->drawPlain(QColor(0, 0, 0, 255)); QPoint point(0,0); area->moveActiveLayer(-1); @@ -1153,20 +1135,20 @@ void UnitTest::bench_moveActive(){ } void UnitTest::bench_setPolygon(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - std::vector polygon{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,10), - QPoint(00,10) - }; + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; - QBENCHMARK{ - area->layerBundle[1].image->setPolygon(polygon); - } + QBENCHMARK{ + area->layerBundle[0].image->setPolygon(polygon); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_setLayerUp(){ @@ -1578,65 +1560,65 @@ void UnitTest::bench_Plain_interruptedDraw(){ } void UnitTest::bench_Polygon_fullDraw(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseMoved(points[0].x(), points[0].y()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Polygon_interruptedDraw(){ - area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(100,000) - }; + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(100,000) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); - area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); }