Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Clean up Knife Tool code
Agata Cackoe510a98c06b7
diff --git a/libs/global/kis_algebra_2d.cpp b/libs/global/kis_algebra_2d.cppindex e84a5ce25b..39b7549de1 100644--- a/libs/global/kis_algebra_2d.cpp+++ b/libs/global/kis_algebra_2d.cpp@@ -1460,6 +1460,7 @@ QPolygonF calculateConvexHull(const QPolygonF &polygon)QList<QLineF> intersectLineConcavePolygon(const QPolygonF polygon, const QLineF& line, bool extendFirst, bool extendSecond) {+ // should use kis_convex_hull instead, that one uses boostQPolygonF convexHull = calculateConvexHull(polygon);if (convexHull.count() == polygon.count()) {QLineF resultLine = line;@@ -1474,6 +1475,8 @@ QList<QLineF> intersectLineConcavePolygon(const QPolygonF polygon, const QLineF&// it was a concave polygon// intersectLines+ // should be as easy as cutting every line, then sorting the points and creating the lines, except gotta take care of exceptions+KIS_ASSERT(false && "Not implemented yet");return QList<QLineF>();@@ -1577,46 +1580,25 @@ QList<QLineF> getParallelLines(const QLineF& line, const qreal distance) {QPainterPath getOnePathFromRectangleCutThrough(const QList<QPointF> &points, const QLineF &line, bool left) {- qCritical() << "~~~ ONE PATH at a time ~~~" << left;- qCritical() << "line: " << line << ", left: " << left << ", points:" << points[0] << points[1] << points[2] << points[3];-auto onTheLine = [](QPointF first, QPointF second) {- //qCritical() << "Fuzzy compating " << first << " and " << second << "more precisely: " << first.y() << second.y();- //qCritical() << "X: " << qFuzzyCompare(first.x(), second.x()) << " Y: " << qFuzzyCompare(first.y(), second.y());- qCritical() << "(inside) on the line? " << first << second << ":" << qAbs(first.x() - second.x()) << qAbs(first.y() - second.y());- //return qFuzzyCompare(first.x(), second.x()) || qFuzzyCompare(first.y(), second.y());- //return KisAlgebra2D::fuzzyPointCompare(first, second, 0.5f);float delta = 0.1f;- qCritical() << (qAbs(first.x() - second.x()) < delta || qAbs(first.y() - second.y()) < delta);return qAbs(first.x() - second.x()) < delta || qAbs(first.y() - second.y()) < delta;};-bool started = false;QPainterPath path;path.moveTo(line.p1());path.lineTo(line.p2());- qCritical() << "path after initialization: " << path;------ qCritical() << "Number of points is: " << points.length();-QList<QPointF> availablePoints;int maxRectPointsNumber = 4; // in case the list has five points to count the first one twicefor(int i = 0; i < maxRectPointsNumber; i++) {qreal whichSide = KisAlgebra2D::crossProduct(line.p2() - line.p1(), line.p2() - points[i]);- qCritical() << "Point " << points[i] << " has which side: " << whichSide;if (whichSide*(left ? 1 : -1) >= 0) {availablePoints << points[i];- qCritical() << "Available point:" << points[i];}}- qCritical() << "That's the end of the available points.";int startValue, increment;if (!left) {@@ -1637,84 +1619,37 @@ QPainterPath getOnePathFromRectangleCutThrough(const QList<QPointF> &points, confor (int i = startValue; !stopFor(i, 2*availablePoints.length(), left); i += increment) {int index = KisAlgebra2D::wrapValue(i, 0, availablePoints.length());- qCritical() << "Index is: " << index << "started: " << started << "on the line: " << onTheLine(availablePoints[index], path.currentPosition());- qCritical() << "...And previous position was: " << path.currentPosition() << "while the point at index is: " << availablePoints[index];if (onTheLine(availablePoints[index], path.currentPosition())) {- qCritical() << "It is on the line with the previous point.";if (!started) {- qCritical() << "It starts now, at" << availablePoints[index];started = true;// TODO: if it's not the same point?path.lineTo(availablePoints[index]);if (onTheLine(availablePoints[index], line.p1())) {- qCritical() << "Despite already starting, we're on the line with p1, so ending the path: " << path;break;}} else {// usually would add, unless it's the ending- qCritical() << "It started already, we're at" << availablePoints[index] << "now checking whether the currently checked point from points it's on the line with the end";if (onTheLine(availablePoints[index], line.p1())) {path.lineTo(availablePoints[index]);- qCritical() << "We're on the line with p1, so ending the path: " << path;//path.lineTo();break;}- qCritical() << "It wasn't on the line with the end, we're adding the current point: " << availablePoints[index];path.lineTo(availablePoints[index]);- qCritical() << "Path after adding a new point with a line:" << path;}}}- qCritical() << "Adding the p1 point to the line at the end of the function, path before that: " << path;path.lineTo(line.p1());- qCritical() << "Adding the p1 point to the line at the end of the function, now path: " << path;--- return path;-- for (int i = startValue; !stopFor(i, 2*points.length(), left); i += increment) {- int index = KisAlgebra2D::wrapValue(i, 0, points.length());- qCritical() << "Index is: " << index << "started: " << started << "on the line: " << onTheLine(points[index], path.currentPosition());- qCritical() << "...And current position is: " << path.currentPosition() << "while the point at index is: " << points[index];- qreal whichSide = KisAlgebra2D::dotProduct(line.p2() - line.p1(), line.p2() - points[index]);- if (whichSide*(left ? 1 : -1) >= 0) {- continue;- }-- if (onTheLine(points[index], path.currentPosition())) {- qCritical() << "it is on the line";- if (!started) {- qCritical() << "it Starts now, at" << points[index] << "but without it";- started = true;-- // TODO: if it's not the same point?- path.lineTo(points[index]);-- } else {- // usually would add, unless it's the ending- qCritical() << "it started already, we're at" << points[index];- if (onTheLine(points[index], line.p1())) {- qCritical() << "We're on the line with p1, so ending the path: " << path;- break;- }- path.lineTo(points[index]);- qCritical() << "Path after adding a new point with a line:" << path;- }- }- }- qCritical() << "~~~ ONE PATH ^^^ ~~~" << left;return path;}QList<QPainterPath> getPathsFromRectangleCutThrough(const QRectF &rect, const QLineF &leftLine, const QLineF &rightLine) {- qCritical() << "~~~ BOTH PATHS ~~~";QPainterPath left;QPainterPath right;@@ -1734,7 +1669,6 @@ QList<QPainterPath> getPathsFromRectangleCutThrough(const QRectF &rect, const QLQList<QPainterPath> paths;paths << left << right;- qCritical() << "~~~ BOTH PATHS ^^^ ~~~";return paths;}@@ -1813,35 +1747,21 @@ QPainterPath removeGutterOneEndSmart(const QPainterPath &shape1, int index1, conQLineF line1 = reverseIfNeeded(getLineFromElements(shape1, index1), reverseFirstPoly);QLineF line2 = reverseIfNeeded(getLineFromElements(shape2, index2), reverseSecondPoly);- qCritical() << ppVar(line1) << ppVar(line2) << ppVar(reverseFirstPoly) << ppVar(reverseSecondPoly) << ppVar(index1) << ppVar(index2);-QLineF leftLine;QLineF rightLine;int indexMultiplierFirst = reverseFirstPoly ? -1 : 1;int indexMultiplierSecond = reverseSecondPoly ? -1 : 1;- auto fixIndex = [] (int index, const QPainterPath& shape) {- //if (index == shape.)- };--leftLine = reverseIfNeeded(getLineFromElements(shape1, index1 - indexMultiplierFirst*1), reverseFirstPoly);rightLine = reverseIfNeeded(getLineFromElements(shape2, index2 + indexMultiplierSecond*1), reverseSecondPoly);- qCritical() << "Lines from the polygons next to the points to figure out correct behaviour: ";- qCritical() << ppVar(leftLine);- qCritical() << ppVar(rightLine);-qreal leftPointDistanceFromMiddle;qreal rightPointDistanceFromMiddle;QPointF leftPoint = line1.p1();QPointF rightPoint = line2.p2();- qCritical() << ppVar(leftPoint) << ppVar(rightPoint);--leftPointDistanceFromMiddle = kisDistanceToLine(leftPoint, middleLine);rightPointDistanceFromMiddle = kisDistanceToLine(rightPoint, middleLine);@@ -1860,12 +1780,9 @@ QPainterPath removeGutterOneEndSmart(const QPainterPath &shape1, int index1, conQPointF intersectionPoint;QLineF::IntersectionType intersectionType = leftLine.intersects(rightLine, &intersectionPoint);- qCritical() << "Checking intersection between lines: leftLine & rightLine, shown above, result: " << ppVar(intersectionType) << ppVar(intersectionPoint);-qreal distanceToMiddle = 0;if (intersectionType != QLineF::NoIntersection) {distanceToMiddle = kisDistanceToLine(intersectionPoint, middleLine);- qCritical() << "Distances: " << ppVar(distanceToMiddle) << ppVar(leftPointDistanceFromMiddle) << ppVar(rightPointDistanceFromMiddle);}@@ -1875,11 +1792,6 @@ QPainterPath removeGutterOneEndSmart(const QPainterPath &shape1, int index1, conboost::optional<QPointF> leftIntersection = intersectLines(line2, leftLine);boost::optional<QPointF> rightIntersection = intersectLines(line1, rightLine);- qCritical() << "We're in the if. Checking two cases: ";- qCritical() << "Intersection between bounded: " << ppVar(line2) << "and unbounded: " << ppVar(leftLine) << "result: " << ppVar(leftIntersection.get_value_or(QPointF()));- qCritical() << "Intersection between bounded: " << ppVar(line1) << "and unbounded: " << ppVar(rightLine) << "result:" << ppVar(rightIntersection.get_value_or(QPointF()));--if (leftIntersection.has_value()) {return makeTrianglePath(leftIntersection.value());} else if (rightIntersection.has_value()) {@@ -1890,121 +1802,24 @@ QPainterPath removeGutterOneEndSmart(const QPainterPath &shape1, int index1, con}- //qreal distanceToMiddle = kisDistanceToLine(intersectionPoint, middleLine);- //if (distanceToMiddle > qMax(leftPointDistanceFromMiddle, rightPointDistanceFromMiddle)) {- // return simpleResult;- //}-QPainterPath betterResult = makeTrianglePath(intersectionPoint);return betterResult;}-// local-QPainterPath removeGutterOneEndOld(const QPainterPath &shape1, int index1, const QPainterPath &shape2, int index2, QPointF middleLineVector, bool whichEnd, bool reverseSecondPoly)-{- auto reverseIfNeeded = [] (const QLineF &line, bool reverse) {- if (reverse) {- return reverseDirection(line);- }- return line;- };-- QLineF line1 = getLineFromElements(shape1, index1);- QLineF line2 = reverseIfNeeded(getLineFromElements(shape1, index1), reverseSecondPoly);-- QLineF leftLine;- QLineF rightLine;-- int indexMultiplier = reverseSecondPoly ? -1 : 1;-- if (whichEnd) {- leftLine = getLineFromElements(shape1, index1 - 1);- rightLine = reverseIfNeeded(getLineFromElements(shape1, index2 + indexMultiplier*1), reverseSecondPoly);- } else {- leftLine = getLineFromElements(shape1, index1 + 1);- rightLine = reverseIfNeeded(getLineFromElements(shape1, index2 - indexMultiplier*1), reverseSecondPoly);- }-- qreal leftPointDistanceFromMiddle;- qreal rightPointDistanceFromMiddle;-- QLineF middleLine = QLineF(QPointF(), middleLineVector);-- if (whichEnd) {- leftPointDistanceFromMiddle = kisDistanceToLine(line1.p1(), middleLine);- rightPointDistanceFromMiddle = kisDistanceToLine(line2.p2(), middleLine);- } else {- leftPointDistanceFromMiddle = kisDistanceToLine(line1.p2(), middleLine);- rightPointDistanceFromMiddle = kisDistanceToLine(line2.p1(), middleLine);- }-- QPainterPath simpleResult;- if (whichEnd) {- simpleResult.moveTo(line1.p1());- simpleResult.lineTo(line2.p2());- } else {- simpleResult.moveTo(line1.p2());- simpleResult.lineTo(line2.p1());- }-- QPointF intersectionPoint;- QLineF::IntersectionType intersectionType = leftLine.intersects(rightLine, &intersectionPoint);- if (intersectionType == QLineF::NoIntersection) {- return simpleResult;- }- qreal distanceToMiddle = kisDistanceToLine(intersectionPoint, middleLine);- if (distanceToMiddle > leftPointDistanceFromMiddle + rightPointDistanceFromMiddle) {- return simpleResult;- }---- return QPainterPath();-}-QPainterPath simplifyShape(const QPainterPath& path) {VectorPath vector(path);return vector.trulySimplified().asPainterPath();}--// TODO: obsolete, to remove-VectorPath combineShapes(VectorPath shape1, int index1, VectorPath shape2, int index2, VectorPath end1, VectorPath end2)-{- using VPoint = VectorPath::VectorPathPoint;- QList<VPoint> result;-- // s1(0..index1), end1, s2(index2, ..., index2 wrapped)-- for(int i = 0; i < index1; i++) {- result << shape1.pointAt(i);- }- for (int i = 0; i < end1.pointsCount(); i++) {- result << end1.pointAt(i);- }- for (int i = index2; i < index2 + shape2.pointsCount(); i++) {- result << shape2.pointAt(wrapValue(i, 0, shape2.pointsCount()));- }-- return VectorPath(QList<VPoint>());---}--VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& shape2, const VectorPath& oneEnd, const VectorPath& otherEnd, int index1, int index2, bool reverseSecondPoly, bool isSameShape){using VPoint = VectorPath::VectorPathPoint;QList<VPoint> result;-- ENTER_FUNCTION();-result.append(shape1.pointAt(0));- qCritical() << "Added point from shape1: " << shape1.pointAt(0).endPoint;auto appendFrom = [] (QList<VPoint>& res, int start, int end, const VectorPath& shape) {for (int i = start; i < end; i++) {@@ -2018,26 +1833,9 @@ VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& shaint reversedIndex2 = reverseSecondPoly ? (shape2.segmentsCount() - index2 - 1) : index2;if (isSameShape) {-- qCritical() << "Same shape = true, is reversedIndex?" << reverseSecondPoly;int minIndex = qMin(index1, index2);int maxIndex = qMax(index1, index2);-- qCritical() << "Indexes are: " << index1 << index2 << "therefore: " << minIndex << maxIndex;- /*- qCritical() << "Append from shape1, indexes: (" << 0 << ", " << minIndex << ")";- appendFrom(0, minIndex, shape1);- qCritical() << "Append from oneEnd, indexes: (" << 0 << ", " << oneEnd.segmentsCount() << ")";- appendFrom(0, oneEnd.segmentsCount(), oneEnd);- qCritical() << "Append from shape1, indexes: (" << minIndex + 1 << ", " << maxIndex << ")";- appendFrom(minIndex + 1, maxIndex, shape1);- qCritical() << "Append from otherEnd, indexes: (" << 0 << ", " << otherEnd.segmentsCount() << ")";- appendFrom(0, otherEnd.segmentsCount(), otherEnd);- qCritical() << "Append from shape1, indexes: (" << maxIndex + 1 << ", " << shape1.segmentsCount() << ")";- appendFrom(maxIndex + 1, shape1.segmentsCount(), shape1);- */-// the indexes define a way to cut the shape into two shapes// and one of them is kind of more outer than the other// (they could intersect but... that's the user problem at that point, they can fix it point by point)@@ -2046,8 +1844,6 @@ VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& sha// and if they're inside a shape, we're assuming that's the resulting shape (and the other is discarded)// no islands in comic panels on my watch!--QList<VPoint> result1;// min index to max indexresult1 << VPoint::moveTo(shape1.segmentAt(minIndex)[1].endPoint);@@ -2058,67 +1854,16 @@ VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& shaappendFrom(result2, maxIndex + 1, shape1.segmentsCount(), shape1);appendFrom(result2, 0, minIndex, shape1);- qCritical() << "result 1 initialized with: " << shape1.segmentAt(minIndex)[1].endPoint;- qCritical() << "result 2 initialized with: " << shape1.segmentAt(maxIndex)[1].endPoint;-- qCritical() << "Result 1 got indexes: (" << ppVar(minIndex + 1) << ", " << ppVar(maxIndex) << ")";- qCritical() << "Result 2 got indexes: (" << ppVar(maxIndex + 1) << ", " << ppVar(shape1.segmentsCount()) << ")";- qCritical() << "And: (" << ppVar(0) << ", " << ppVar(minIndex) << ")";---- // TODO: include gutter shapes!!!!!- // minEnd and maxEnd- // and combine with results!---- qCritical() << "Result 1 before appending = " << ppVar(VectorPath(result1).asPainterPath()) << ppVar(VectorPath(result1).segmentsCount());- qCritical() << "Result 2 before appending = " << ppVar(VectorPath(result2).asPainterPath()) << ppVar(VectorPath(result2).segmentsCount());- qCritical() << "Original had: " << ppVar(shape1.segmentsCount());---VectorPath minEnd = index1 > index2 ? oneEnd : otherEnd;VectorPath maxEnd = index1 > index2 ? otherEnd : oneEnd;-- qCritical() << "Indexes were: " << index1 << index2 << "therefore NOT swapping: " << (index1 < index2);- qCritical() << ppVar(oneEnd.asPainterPath()) << ppVar(otherEnd.asPainterPath()) << ppVar(minEnd.asPainterPath()) << ppVar(maxEnd.asPainterPath());--appendFrom(result1, 0, minEnd.segmentsCount(), minEnd);appendFrom(result2, 0, maxEnd.segmentsCount(), maxEnd);-----VectorPath result1Vec(result1);VectorPath result2Vec(result2);-- qCritical() << "Result 1 = " << ppVar(VectorPath(result1).asPainterPath()) << ppVar(VectorPath(result1).segmentsCount());- qCritical() << "Result 2 = " << ppVar(VectorPath(result2).asPainterPath()) << ppVar(VectorPath(result2).segmentsCount());- qCritical() << "Original had: " << ppVar(shape1.segmentsCount());---------------- //QPolygonF result1Poly = result1Vec.asPainterPath().toFillPolygon();QPolygonF result2Poly = result2Vec.asPainterPath().toFillPolygon();// TODO: assumes winding fill@@ -2128,16 +1873,6 @@ VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& sha}return result1Vec;---- //return VectorPath(result1);------} else {appendFrom(result, 0, index1, shape1);appendFrom(result, 0, oneEnd.segmentsCount(), oneEnd);@@ -2149,46 +1884,18 @@ VectorPath mergeShapesWithGutter(const VectorPath& shape1, const VectorPath& shareturn VectorPath(result);--- /*-- for (int i = 0; i < index1; i++) {- QList<VPoint> segment = shape1.segmentAt(i);- KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(segment.length() > 1, shape1);- result.append(segment[1]);- }-- for (int i = 0; i < oneEnd.segmentsCount(); i++) {- QList<VPoint> segment = oneEnd.segmentAt(i);- KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(segment.length() > 1, shape1);- result.append(segment[1]);- }---- */---}QPainterPath removeGutterSmart(const QPainterPath &shape1, int index1, const QPainterPath &shape2, int index2, bool isSameShape){- qCritical() << ppVar(index1) << ppVar(shape1.elementCount()) << ppVar(index2) << ppVar(shape2.elementCount());if (index1 + 1 >= shape1.elementCount() || index2 + 1 >= shape2.elementCount()) {return QPainterPath();}- // shape1.elementAt(index1)QLineF line1 = getLineFromElements(shape1, index1);QLineF line2 = getLineFromElements(shape2, index2);- //QPointF middleLineVector = QPointF((line1.dx() + line2.dx())/2, (line1.dy() + line2.dy())/2);--- QPainterPath gutterShape = QPainterPath();QVector<QPointF> poly1 = QVector<QPointF>() << line1.p1() << line1.p2() << line2.p1();QVector<QPointF> poly2 = QVector<QPointF>() << line1.p2() << line2.p1() << line2.p2();bool reverseSecondPoly = false;@@ -2198,16 +1905,11 @@ QPainterPath removeGutterSmart(const QPainterPath &shape1, int index1, const QPa}QLineF middleLine = QLineF((line1.p1() + line2.p2())/2, (line1.p2() + line2.p1())/2);- QPointF middleLineVector = middleLine.p2() - middleLine.p1();// more difficult version:QPainterPath oneEnd = removeGutterOneEndSmart(shape1, index1, shape2, index2, middleLine, false, reverseSecondPoly);- int secondShapeIndexInOtherEnd = reverseSecondPoly ? -index2 + 1 : -index2 + 1;- //QPainterPath otherEnd = removeGutterOneEndSmart(shape2, secondShapeIndexInOtherEnd, shape1, -index1 + 2, middleLineVector, reverseSecondPoly);- //QPainterPath otherEnd = removeGutterOneEndSmart(shape2, index2, shape1, index1, middleLineVector, true, !reverseSecondPoly);QPainterPath otherEnd = removeGutterOneEndSmart(shape2, index2, shape1, index1, middleLine, reverseSecondPoly, false);-VectorPath vectorShape1 = VectorPath(shape1);VectorPath vectorShape2 = VectorPath(shape2);VectorPath vectorOneEnd = VectorPath(oneEnd);@@ -2218,186 +1920,17 @@ QPainterPath removeGutterSmart(const QPainterPath &shape1, int index1, const QPa- /// ------- gutterShape.moveTo(oneEnd.elementAt(0));- gutterShape.connectPath(oneEnd);- gutterShape.connectPath(otherEnd);- gutterShape.closeSubpath();-- gutterShape = gutterShape.toReversed();--- QPainterPath roundedShape1 = shape1;- QPainterPath roundedShape2 = shape2;--- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "GUTTER SHAPE BEFORE ROUNDING:" ppVar(gutterShape);--- // NOW THE DANGEROUS PART:- for (int i = 0; i < gutterShape.elementCount(); i++) {- QPainterPath::Element el = gutterShape.elementAt(i);- gutterShape.setElementPositionAt(i, qRound(el.x), qRound(el.y));- }-- for (int i = 0; i < roundedShape1.elementCount(); i++) {- QPainterPath::Element el = roundedShape1.elementAt(i);- roundedShape1.setElementPositionAt(i, qRound(el.x), qRound(el.y));- }-- for (int i = 0; i < roundedShape2.elementCount(); i++) {- QPainterPath::Element el = roundedShape2.elementAt(i);- roundedShape2.setElementPositionAt(i, qRound(el.x), qRound(el.y));- }------- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << ppVar(gutterShape);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << ppVar(oneEnd);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << ppVar(otherEnd);-- qreal eps = 1e-05;- /*- for (int i = 0; i < gutterShape.elementCount(); i++) {- QPainterPath::Element gutterEl = gutterShape.elementAt(i);- qCritical() << "Gutter element: " << gutterEl.x << gutterEl.y << gutterEl.type;- for (int j = 0; j < shape1.elementCount(); j++) {- QPainterPath::Element shapeEl = shape1.elementAt(j);- if (qAbs(gutterEl.x - shapeEl.x) < eps && qAbs(gutterEl.y - shapeEl.y) < eps) {- gutterShape.setElementPositionAt(i, shapeEl.x, shapeEl.y);- break;- }- }- for (int j = 0; j < shape2.elementCount(); j++) {- QPainterPath::Element shapeEl = shape2.elementAt(j);- if (qAbs(gutterEl.x - shapeEl.x) < eps && qAbs(gutterEl.y - shapeEl.y) < eps) {- gutterShape.setElementPositionAt(i, shapeEl.x, shapeEl.y);- break;- }- }- }- */-- for (int i = 0; i < shape1.elementCount(); i++) {- QPainterPath::Element shapeEl = shape1.elementAt(i);- qCritical() << "Shape1 element: " << shapeEl.x << shapeEl.y << shapeEl.type;- }-- for (int i = 0; i < shape2.elementCount(); i++) {- QPainterPath::Element shapeEl = shape2.elementAt(i);- qCritical() << "Shape2 element: " << shapeEl.x << shapeEl.y << shapeEl.type;- }--- QPainterPath windingShape1 = shape1;- QPainterPath windingShape2 = shape2;- gutterShape.setFillRule(Qt::WindingFill);- windingShape1.setFillRule(Qt::WindingFill);- windingShape2.setFillRule(Qt::WindingFill);--- QPainterPath result = (windingShape1 | windingShape2 | gutterShape);---- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Result of everything, after adding the gutter, is: " << result;- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Partial results: " << ppVar(shape1 | shape2) << ppVar(shape2 | gutterShape) << ppVar(shape1 | gutterShape) << ppVar(shape1 | shape2 | gutterShape) << ppVar((shape1 | shape2) | gutterShape) << ppVar((shape1 | gutterShape) | shape2);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Shapes to unite were also: " << ppVar(shape1) << ppVar(shape2) << ppVar(gutterShape);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Shapes to unite were also (2): " << ppVar(shape1.toFillPolygon()) << ppVar(shape2.toFillPolygon()) << ppVar(gutterShape.toFillPolygon());- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Fill rules:" << ppVar(shape1.fillRule()) << ppVar(shape2.fillRule()) << ppVar(gutterShape.fillRule());--- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Result of everything, after adding the gutter, is: " << result;- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Partial results: " << ppVar(windingShape1 | windingShape2) << ppVar(windingShape2 | gutterShape) << ppVar(windingShape1 | gutterShape) << ppVar(windingShape1 | windingShape2 | gutterShape)- << ppVar((windingShape1 | windingShape2) | gutterShape) << ppVar((windingShape1 | gutterShape) | windingShape2);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Shapes to unite were also: " << ppVar(windingShape1) << ppVar(windingShape2);- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Shapes to unite were also (2): " << ppVar(windingShape1.toFillPolygon()) << ppVar(windingShape2.toFillPolygon()) << ppVar(gutterShape.toFillPolygon());- qCritical() << Qt::fixed << qSetRealNumberPrecision(10) << "#* Fill rules:" << ppVar(windingShape1.fillRule()) << ppVar(windingShape2.fillRule()) << ppVar(gutterShape.fillRule());--- return VectorPath(result).trulySimplified(1e-02).asPainterPath();- /// --------- QPainterPath closedShape1 = shape1;- QPainterPath closedShape2 = shape2;-- closedShape1.closeSubpath();- closedShape2.closeSubpath();- gutterShape.closeSubpath();-- closedShape1.setFillRule(Qt::WindingFill);- closedShape2.setFillRule(Qt::WindingFill);- gutterShape.setFillRule(Qt::WindingFill);--- QPainterPath partialResult = (closedShape1 | gutterShape);- partialResult.closeSubpath();- partialResult.setFillRule(Qt::WindingFill);- result = (partialResult | closedShape2);- result.closeSubpath();- result = result.simplified();- //result = (shape1 | gutterShape) | shape2;--- qCritical() << "# Result of everything, after adding the gutter, is: " << result;- qCritical() << "# Partial results: " << ppVar(shape1 | shape2) << ppVar(shape2 | gutterShape) << ppVar(shape1 | gutterShape) << ppVar(shape1 | shape2 | gutterShape) << ppVar((shape1 | shape2) | gutterShape) << ppVar((shape1 | gutterShape) | shape2);- qCritical() << "# Shapes to unite were also: " << ppVar(shape1) << ppVar(shape2);- qCritical() << "# Shapes to unite were also (2): " << ppVar(shape1.toFillPolygon()) << ppVar(shape2.toFillPolygon()) << ppVar(gutterShape.toFillPolygon());--- // TEMPORARY:- VectorPath shape1Vector(shape1);- VectorPath shape2Vector(shape2);- VectorPath gutterVector(gutterShape);-- QPolygonF shape1Polygon = shape1Vector.trulySimplified().asPainterPath().toFillPolygon();- QPolygonF shape2Polygon = shape2Vector.trulySimplified().asPainterPath().toFillPolygon();- QPolygonF gutterPolygon = gutterVector.trulySimplified().asPainterPath().toFillPolygon();-- QPolygonF resultPolygon = shape1Polygon.united(gutterPolygon);- resultPolygon = resultPolygon.united(shape2Polygon);---- QPainterPath newResult;- newResult.addPolygon(resultPolygon);- newResult.closeSubpath();-- newResult = VectorPath(newResult).trulySimplified().asPainterPath();-- return newResult;- //return QPainterPath.addPolygon();------ VectorPath vectorResult(result);- qCritical() << ppVar(vectorResult.asPainterPath()) << ppVar(vectorResult.trulySimplified().asPainterPath());- qCritical() << "^ that's what we're gonna return.";-- return vectorResult.trulySimplified().asPainterPath();--}-// isAlgebra2D::getLineSegmentCrossingLineIndexes(QLineF const&, QPainterPath const&)QList<int> getLineSegmentCrossingLineIndexes(const QLineF &line, const QPainterPath &shape){QList<int> indexes;- qCritical() << "Searching for line: " << line;for (int i = 0; i < shape.elementCount() - 1; i++) { // last element would wrap around to be the first segment againQLineF lineSegment = getLineFromElements(shape, i);QPointF intersection;QLineF::IntersectionType type = lineSegment.intersects(line, &intersection);- qCritical() << ppVar(i) << ppVar(lineSegment);if (type == QLineF::IntersectionType::BoundedIntersection) {- qCritical() << "Found an intersection: " << ppVar(line) << ppVar(lineSegment) << ppVar(intersection) << "At: " << ppVar(i);indexes << i;}}@@ -2407,7 +1940,6 @@ QList<int> getLineSegmentCrossingLineIndexes(const QLineF &line, const QPainterPVectorPath::VectorPath(const QPainterPath &path){using VPoint = VectorPath::VectorPathPoint;- qCritical() << "Start, for the path that has elements: " << path.elementCount();m_points = QList<VectorPath::VectorPathPoint>();for (int i = 0; i < path.elementCount(); i++) {@@ -2420,7 +1952,6 @@ VectorPath::VectorPath(const QPainterPath &path)m_points.append(VPoint(VPoint::LineTo, el));break;case QPainterPath::CurveToElement:- //m_points.append(VPoint(VPoint::CuTo, el));KIS_SAFE_ASSERT_RECOVER(i + 2 < path.elementCount()) { continue; }KIS_SAFE_ASSERT_RECOVER(path.elementAt(i + 1).type == QPainterPath::CurveToDataElement) { continue; }KIS_SAFE_ASSERT_RECOVER(path.elementAt(i + 2).type == QPainterPath::CurveToDataElement) { continue; }@@ -2429,9 +1960,7 @@ VectorPath::VectorPath(const QPainterPath &path)i += 2; // skip next two pointsbreak;}- qCritical() << "Added point: " << m_points[m_points.length() - 1].endPoint;}- qCritical() << "End.";}VectorPath::VectorPath(const QList<VectorPathPoint> path)@@ -2480,7 +2009,6 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) constusing VPoint = VectorPath::VectorPathPoint;- qCritical() << "Start simplifying path that has segments: " << segmentsCount();if (m_points.length() < 1) {return VectorPath(QList<VectorPath::VectorPathPoint>());}@@ -2492,20 +2020,13 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) const//qreal eps = 1e-05;auto onTheLine = [eps] (QPointF start, QPointF middle, QPointF end) {- //QPointF vector1 = end - start;- //QPointF vector2 = end - start;QLineF line1(start, end);QLineF line2(start, middle);- qCritical() << "abs after dividing:" << qAbs(crossProduct(end - start, middle - start)/line1.length()/line2.length());- qCritical() << "meaning degrees: " << kisRadiansToDegrees(qAbs(crossProduct(end - start, middle - start)/line1.length()/line2.length()));--return (qAbs(crossProduct(end - start, middle - start)/line1.length()/line2.length()) < eps);};for (int i = 1; i < m_points.length(); i++) {- qCritical() << "Point is: " << m_points[i].endPoint << m_points[i].type;if (m_points[i].type == VPoint::MoveTo) {if (previousPoint.type == VPoint::MoveTo) {previousPoint = m_points[i]; // let's skip the previous point since they're both just moving@@ -2518,18 +2039,9 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) const} else if (m_points[i].type == VPoint::LineTo) {if (previousPoint.type == VPoint::LineTo) {// check whether they're parallel- qCritical() << "Check whether they're parallel: to " << ppVar(m_points[i].endPoint) << " from " << ppVar(lineBeginPoint.endPoint) << " and to " << ppVar(previousPoint.endPoint) << " from " << ppVar(lineBeginPoint.endPoint);-- qCritical() << "Are they parallel?: (two vectors) " << m_points[i].endPoint - lineBeginPoint.endPoint << previousPoint.endPoint - lineBeginPoint.endPoint- << "cross product = " << crossProduct(m_points[i].endPoint - lineBeginPoint.endPoint, previousPoint.endPoint - lineBeginPoint.endPoint)- << "abs(cross product) = " << qAbs(crossProduct(m_points[i].endPoint - lineBeginPoint.endPoint, previousPoint.endPoint - lineBeginPoint.endPoint))- << ppVar(eps);if (!onTheLine(lineBeginPoint.endPoint, previousPoint.endPoint, m_points[i].endPoint)) {- qCritical() << "Not parallel";response << previousPoint;lineBeginPoint = previousPoint;- } else {- qCritical() << "Parallel!";}previousPoint = m_points[i]; // let's skip the previous point since they're parallelcontinue;@@ -2546,7 +2058,6 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) const}}response << previousPoint;- qCritical() << "After simplification, we've got points: " << response.length();// now eliminate additional point at the beginning of the shape if it's in the middle of a line// and wasn't simplified only because it's at the beginning@@ -2558,21 +2069,13 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) constVPoint start = response[0];VPoint second = response[1];- qCritical() << "In the middle, the amount of points is: " << response.length();- for(int i = 0; i < response.length(); i++) {- qCritical() << ppVar(response[i].type) << response[i].endPoint;- }--if (start.type == VPoint::MoveTo) {if (fuzzyPointCompare(previousPoint.endPoint, start.endPoint)) {// they are the same point, now whether they're on the lineif (second.type == VPoint::LineTo && onTheLine(response[response.length()-2].endPoint, start.endPoint, second.endPoint)) {- qCritical() << "Checked: " << "fuzzy compare point: " << ppVar(response[response.length()-2].endPoint) << ppVar(start.endPoint) << ", on the line: " << ppVar(previousPoint.endPoint) << ppVar(start.endPoint) << ppVar(second.endPoint);response.pop_front();response[0].type = VPoint::MoveTo;response[response.length() - 1].endPoint = second.endPoint;- qCritical() << "We're in this case: simplify first MoveTo";}}@@ -2580,6 +2083,7 @@ VectorPath VectorPath::trulySimplified(qreal epsDegrees) constif (qFuzzyIsNull(previousPoint.endPoint.x()) && qFuzzyIsNull(previousPoint.endPoint.y())) {// they are the same point, now whether they're on the lineif (second.type == VPoint::LineTo && onTheLine(previousPoint.endPoint, QPointF(0, 0), start.endPoint)) {+ // note: leaving this debug for future referenceqCritical() << "We're in this case";//response.pop_front();//response[0].type = VPoint::MoveTo;@@ -2602,9 +2106,7 @@ VectorPath VectorPath::reversed() constfor (int i = m_points.length() - 1; i > 0; i--) {// to reverse a segment, we take the end VPoint and change the .endPoint to the start VPoint coordsVPoint point = m_points[i];- //qCritical() << "Copying point" << point;point.endPoint = m_points[i - 1].endPoint;- //qCritical() << "Changed end point to: " << point;response.append(point);}return VectorPath(response);diff --git a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp b/plugins/tools/tool_knife/CutThroughShapeStrategy.cppindex 91b6a143b9..774e50947d 100644--- a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp+++ b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp@@ -32,12 +32,8 @@ CutThroughShapeStrategy::CutThroughShapeStrategy(KoToolBase *tool, KoSelection *, m_endPoint(startPoint), m_width(width){- qCritical() << "Creating a strategy";-m_selectedShapes = selection->selectedEditableShapes();- qCritical() << "Amount of selected shapes: " << m_selectedShapes.length();m_allShapes = shapes;- qCritical() << "Amount of all shapes: " << m_allShapes.length();}CutThroughShapeStrategy::~CutThroughShapeStrategy()@@ -76,25 +72,13 @@ QPointF snapEndPoint(const QPointF &startPoint, const QPointF &mouseLocation, Qtvoid CutThroughShapeStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers){m_endPoint = snapEndPoint(m_startPoint, mouseLocation, modifiers);- //qCritical() << "Now supposedly drawing a line between " << m_d->startPoint << " to " << m_d->endPoint;QRectF dirtyRect;KisAlgebra2D::accumulateBounds(m_startPoint, &dirtyRect);KisAlgebra2D::accumulateBounds(m_endPoint, &dirtyRect);dirtyRect = kisGrowRect(dirtyRect, gutterWidthInDocumentCoordinates(calculateLineAngle(m_startPoint, m_endPoint))); // twice as much as it should need to account for lines showing the effect- KisCanvas2* kisCanvas = dynamic_cast<KisCanvas2*>(tool()->canvas());- //dirtyRect = kisCanvas->viewManager()->- //dirtyRect = canvas()->viewConverter()->viewToDocument(dirtyRect);- //qCritical() << "And the dirty rect is: " << dirtyRect;-QRectF accumulatedWithPrevious = m_previousLineDirtyRect | dirtyRect;- //KisAlgebra2D::accumulateBounds(dirtyRect, &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.topLeft(), &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.bottomRight(), &accumulatedWithPrevious);-- //QRectF rect = dirtyRect + m_d->previousLineDirtyRect;-tool()->canvas()->updateCanvas(accumulatedWithPrevious);m_previousLineDirtyRect = dirtyRect;@@ -129,8 +113,7 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)}if (outlineRect.isEmpty()) {-- qCritical() << "The outline rect is empty";+ //qCritical() << "The outline rect is empty";return;}@@ -143,20 +126,10 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)return;}- qCritical() << "line angle = " << calculateLineAngle(m_startPoint, m_endPoint);qreal gutterWidth = gutterWidthInDocumentCoordinates(calculateLineAngle(m_startPoint, m_endPoint));-QList<QLineF> gapLines = KisAlgebra2D::getParallelLines(gapLine, gutterWidth/2);- qCritical() << "############ Are those lines correct? " << KisAlgebra2D::pointToLineDistSquared(gapLines[0].p1(), gapLines[1])- << KisAlgebra2D::pointToLineDistSquared(gapLines[1].p1(), gapLines[0]) << KisAlgebra2D::pointToLineDistSquared(gapLines[0].p1(), gapLine);- //qCritical() << "Should be: " << pow2(gapWidth/2) << "or" << pow2(gapWidth);---- //KIS_ASSERT(qFuzzyCompare(KisAlgebra2D::pointToLineDistSquared(gapLines[0].p1(), gapLines[1]), pow2(m_width)) && "Distance doesn't match");-gapLine = booleanWorkaroundTransform.map(gapLine);gapLines[0] = booleanWorkaroundTransform.map(gapLines[0]);gapLines[1] = booleanWorkaroundTransform.map(gapLines[1]);@@ -179,9 +152,6 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)if (leftLine.length() == 0 || rightLine.length() == 0) {- qCritical() << "No cutting at all, because one of the lines has length 0. Line is: " << leftLine << rightLine << " and the outline rect is: " << outlineRect << ppVar(outlineRectBigger);- qCritical() << "^ No cutting at all... line was: " << gapLine << "and the other were: " << gapLines[0] << gapLines[1];-KIS_SAFE_ASSERT_RECOVER_RETURN(gapLine.length() != 0 && gapLines[0].length() != 0 && gapLines[1].length() != 0 && "Original gap lines shouldn't be empty at this point");// looks like *all* shapes need to be cut out@@ -199,11 +169,6 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)QPainterPath leftOpposite = pathsOpposite[0];QPainterPath rightOpposite = pathsOpposite[1];--- //QPainterPath dstOutline;- //QList<QPainterPath> dstOutlines;-QList<KoShape*> newSelectedShapes;QList<KoShape*> shapesToRemove;@@ -246,8 +211,8 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)bool crossesGapLine = KisAlgebra2D::getLineSegmentCrossingLineIndexes(leftLine, srcOutlines[i]).count() > 0|| KisAlgebra2D::getLineSegmentCrossingLineIndexes(rightLine, srcOutlines[i]).count() > 0;if (!containsGapLinePoint && !crossesGapLine) {- //- qCritical() << "it doesn't cross the line!";++ //qCritical() << "it doesn't cross the line!";if (wasSelected) {newSelectedShapes << referenceShape;}@@ -374,11 +339,6 @@ void CutThroughShapeStrategy::paint(QPainter &painter, const KoViewConverter &copainter.setPen(pen);- //QLineF gutterLineExtended1 = gutterLine1;- //QLineF gutterLineExtended2 = gutterLine2;- //KisAlgebra2D::cropLineToRect(gutterLineExtended1, painter.viewport(), true, true);- //KisAlgebra2D::cropLineToRect(gutterLineExtended2, painter.viewport(), true, true);-painter.drawLine(gutterCenterLine);painter.restore();diff --git a/plugins/tools/tool_knife/GutterWidthsConfig.cpp b/plugins/tools/tool_knife/GutterWidthsConfig.cppindex f5ca677386..e456585c75 100644--- a/plugins/tools/tool_knife/GutterWidthsConfig.cpp+++ b/plugins/tools/tool_knife/GutterWidthsConfig.cpp@@ -34,8 +34,6 @@ bool inRangeWrapped(qreal value, qreal min, qreal max, qreal rangeMax) {min = KisAlgebra2D::wrapValue(min, 0.0, rangeMax);max = KisAlgebra2D::wrapValue(max, 0.0, rangeMax);- qCritical() << "in range wrapped: " << ppVar(value) << ppVar(min) << ppVar(max) << ppVar(rangeMax);-if (min > max) {return value > min || value < max; // range is on the edges instead of in the middle} else {@@ -55,23 +53,16 @@ qreal convertToPixels(KoUnit baseUnit, qreal resolution, qreal length)qreal GutterWidthsConfig::widthForAngleInPixels(qreal lineAngleDegrees){qreal angleMax = 360;- qCritical() << "~~~ Searching for line angle: " << lineAngleDegrees;- qCritical() << "~~~ Values for gutters are: " << horizontal << vertical << diagonal << "with angle diff = " << angleDegrees;if (inRangeWrapped(lineAngleDegrees, -angleDegrees, angleDegrees, angleMax)) {- qCritical() << "horizontal 1";return convertToPixels(baseUnit, resolution, horizontal);} else if (inRangeWrapped(lineAngleDegrees, 180-angleDegrees, 180+angleDegrees, angleMax)) {- qCritical() << "horizontal 2";return convertToPixels(baseUnit, resolution, horizontal);} else if (inRangeWrapped(lineAngleDegrees, 90-angleDegrees, 90+angleDegrees, angleMax)) {- qCritical() << "vertical 1";return convertToPixels(baseUnit, resolution, vertical);} else if (inRangeWrapped(lineAngleDegrees, 270-angleDegrees, 270+angleDegrees, angleMax)) {- qCritical() << "vertical 2";return convertToPixels(baseUnit, resolution, vertical);} else {- qCritical() << "diagonal";return convertToPixels(baseUnit, resolution, diagonal);}}diff --git a/plugins/tools/tool_knife/KisToolKnife.cpp b/plugins/tools/tool_knife/KisToolKnife.cppindex b8ece5f237..5e07029953 100644--- a/plugins/tools/tool_knife/KisToolKnife.cpp+++ b/plugins/tools/tool_knife/KisToolKnife.cpp@@ -50,10 +50,7 @@ struct KisToolKnife::Private {KisToolKnifeOptionsWidget *optionsWidget = nullptr;QPointF startPoint = QPointF(0, 0);QPointF endPoint = QPointF(0, 0);- //QPointF mousePoint = QPointF(0, 0);QRectF previousLineDirtyRect = QRectF();- //QRectF previousMouseDirtyRect = QRectF();-};@@ -62,7 +59,6 @@ KisToolKnife::KisToolKnife(KoCanvasBase * canvas)m_d(new Private){setObjectName("tool_knife");- //useCursor(KisCursor::arrowCursor());useCursor(Qt::ArrowCursor);repaintDecorations();}@@ -72,38 +68,6 @@ KisToolKnife::~KisToolKnife()m_d->optionsWidget = nullptr;}-void drawCoordsStartFrom(QPainter &painter, QTransform transform, QColor color)-{- painter.save();- QPen pen = QPen(QBrush(color), 5, Qt::SolidLine);- painter.setPen(pen);- painter.setTransform(transform * painter.transform());- painter.drawLine(QPointF(0, 0), QPointF(100, 0));- painter.drawLine(QPointF(0, 0), QPointF(0, 100));- painter.drawLine(QPointF(0, 100), QPointF(5, 100));- painter.drawLine(QPointF(100, 0), QPointF(100, 5));-- painter.drawArc(QRect(-50, -50, 100, 100), 0, -16*90);-- painter.restore();-}---void drawCoordsStart(QPainter &painter, const KoViewConverter &converter)-{- //painter.drawLine(QPointF(0, 0), QPointF(100, 0));- //painter.drawLine(QPointF(0, 0), QPointF(0, 100));- //painter.drawArc(QRect(-50, -50, 100, 100), 0, -16*90);-- drawCoordsStartFrom(painter, QTransform(), Qt::red);- drawCoordsStartFrom(painter, converter.documentToView(), Qt::blue); // < ten ma sens w painterze- drawCoordsStartFrom(painter, converter.viewToDocument(), Qt::green);----}--void paintSelectedEdge(QPainter &painter, const KoViewConverter &converter, const QLineF &lineSegment){QLineF lineInView = converter.documentToView().map(lineSegment);@@ -188,7 +152,8 @@ void KisToolKnife::paint(QPainter &painter, const KoViewConverter &converter)KoInteractionTool::paint(painter, converter);- bool paintSelection = false;+#ifdef KNIFE_DEBUG+ bool paintSelection = true;if (paintSelection) {KIS_SAFE_ASSERT_RECOVER_RETURN(canvas());@@ -214,55 +179,14 @@ void KisToolKnife::paint(QPainter &painter, const KoViewConverter &converter)}}-+#endif}void KisToolKnife::activate(const QSet<KoShape *> &shapes){- // Questions to Dmitry or Wolthera:- // + 1. Which tool base should it be based on?- // + 2. Which functions should I reimplement: mouse events, or beingPrimaryAction, or a strategy?- // - 3. How to get shapes from the layer? I assume that it might happen that no shape is selected, in which case- // it should use all shapes on the layer as potential input- // - 4. How to get points from that shape? I noticed I have KoPathShape* sometimes, and that has (protected) subpaths,- // but I can access segments I think? And outline() is useful for now for debug. But how to do it properly?- // 5. How to get all shapes from the layer, not just selected ones? Or how to select all shapes?- // 6. Can I make three files out of kis_algebra_2d? also what about kis_global? -> it's a mess and it's difficult to find things- // 7. How to get a cursor? I knew how to in a different tool class, but not here...-- //canvas()->selectedShapesProxy();- //this->set---KoInteractionTool::activate(shapes);- Q_FOREACH(KoShape* shape, shapes) {- if (shape) {- qCritical() << "We've got a shape!";- KoPathShape* pathShape = dynamic_cast<KoPathShape *>(shape);- qCritical() << "Is it a path shape? " << pathShape;- if (pathShape) {- qCritical() << "Let's see the points:";- //qCritical() << pathShape->isClosedSubpath(0);- //pathShape->subpaths();- // ok, subpaths are protected...-- //temporary:- QPainterPath pp = pathShape->outline();- //qCritical() << pp.;- //Q_FOREACH(QPainterPath::Element element, pp.elem)- for (int i = 0; i < pp.elementCount(); i++) {- qCritical() << "Point at: " << pp.elementAt(i).x << pp.elementAt(i).y;- }-- //Q_FOREACH(QPointF& p, pathShape.)- }-- }- }-useCursor(KisCursor::arrowCursor());}@@ -272,12 +196,6 @@ void KisToolKnife::deactivate()KoInteractionTool::deactivate();}-void KisToolKnife::mousePressEventBackup(KoPointerEvent *event)-{- m_d->startPoint = event->point;//canvas()->viewConverter()->viewToDocument(event->pos());- m_d->endPoint = event->point;//canvas()->viewConverter()->viewToDocument(event->pos());-}-void KisToolKnife::mousePressEvent(KoPointerEvent *event){// this tool only works on a vector layer right now, so give a warning if another layer type is trying to use it@@ -296,42 +214,21 @@ void KisToolKnife::mouseMoveEvent(KoPointerEvent *event){KoInteractionTool::mouseMoveEvent(event);- //qCritical() << "mouse move event button flags: " << event->buttons() << ", " << event->button();if (event->buttons().testFlag(Qt::MouseButton::LeftButton)) {- //m_d->endPoint = canvas()->viewConverter()->viewToDocument(event->pos());m_d->endPoint = event->point;- //qCritical() << "Now supposedly drawing a line between " << m_d->startPoint << " to " << m_d->endPoint;QRectF dirtyRect;KisAlgebra2D::accumulateBounds(m_d->startPoint, &dirtyRect);KisAlgebra2D::accumulateBounds(m_d->endPoint, &dirtyRect);- //dirtyRect = canvas()->viewConverter()->viewToDocument(dirtyRect);- //qCritical() << "And the dirty rect is: " << dirtyRect;QRectF accumulatedWithPrevious = m_d->previousLineDirtyRect;accumulatedWithPrevious |= dirtyRect;- //KisAlgebra2D::accumulateBounds(dirtyRect, &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.topLeft(), &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.bottomRight(), &accumulatedWithPrevious);-- //QRectF rect = dirtyRect + m_d->previousLineDirtyRect;canvas()->updateCanvas(accumulatedWithPrevious);m_d->previousLineDirtyRect = dirtyRect;- } else {- //m_d->mousePoint = event->point;- //QRectF dirtyRect;- //KisAlgebra2D::accumulateBounds(m_d->mousePoint + QPointF(-2, -2), &dirtyRect);- //KisAlgebra2D::accumulateBounds(m_d->mousePoint + QPointF(2, 2), &dirtyRect);-- //canvas()->updateCanvas(dirtyRect);- //dirtyRect = canvas()->viewConverter()->viewToD(dirtyRect);-- //canvas()->updateCanvas(dirtyRect);-- //qCritical() << "Changing mouse point to " << event->point << " as opposed to " << event->pos();}+repaintDecorations();}@@ -341,28 +238,18 @@ void KisToolKnife::mouseReleaseEvent(KoPointerEvent *event)m_d->endPoint = event->point;- //qCritical() << "Now, AFTER release, supposedly drawing a line between " << m_d->startPoint.x() << ", " << m_d->startPoint.y() << " to " << m_d->endPoint.x() << "," << m_d->endPoint.y();QRectF dirtyRect;KisAlgebra2D::accumulateBounds(m_d->startPoint, &dirtyRect);KisAlgebra2D::accumulateBounds(m_d->endPoint, &dirtyRect);QRectF accumulatedWithPrevious = m_d->previousLineDirtyRect | dirtyRect;- //KisAlgebra2D::accumulateBounds(dirtyRect.topLeft(), &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.bottomRight(), &accumulatedWithPrevious);-- //KisAlgebra2D::accumulateBounds(dirtyRect, &accumulatedWithPrevious);canvas()->updateCanvas(accumulatedWithPrevious);m_d->previousLineDirtyRect = dirtyRect;- //dirtyRect = canvas()->viewConverter()->viewToDocument(dirtyRect);-- //canvas()->updateCanvas(dirtyRect);}KoInteractionStrategy *KisToolKnife::createStrategy(KoPointerEvent *event){- qCritical() << "Creating a strategy for " << event->point << event->buttons();- //KoSelection *selection = canvas()->selectedShapesProxy()->selection();QList<KoShape*> shapes = canvas()->shapeManager()->shapes();if (m_d->optionsWidget->getToolMode() == KisToolKnifeOptionsWidget::ToolMode::AddGutter) {diff --git a/plugins/tools/tool_knife/KisToolKnife.h b/plugins/tools/tool_knife/KisToolKnife.hindex e12781b42a..bea70bacd2 100644--- a/plugins/tools/tool_knife/KisToolKnife.h+++ b/plugins/tools/tool_knife/KisToolKnife.h@@ -45,7 +45,6 @@ protected Q_SLOTS:public Q_SLOTS:void activate(const QSet<KoShape*> &shapes) override;void deactivate() override;- void mousePressEventBackup(KoPointerEvent *event);void mousePressEvent(KoPointerEvent *event);void mouseMoveEvent(KoPointerEvent *event) override;void mouseReleaseEvent(KoPointerEvent *event) override;diff --git a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cppindex 56753b8b0f..9503e686a4 100644--- a/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp+++ b/plugins/tools/tool_knife/KisToolKnifeOptionsWidget.cpp@@ -39,7 +39,6 @@ struct KisToolKnifeOptionsWidget::Private {qreal resolution {1.0};QString toolId {""};- //KoGroupButton* m_buttonModeAddGutter {nullptr};@@ -362,7 +361,6 @@ void KisToolKnifeOptionsWidget::unitForWidthChanged(int index)void KisToolKnifeOptionsWidget::currentNodeChanged(const KisNodeSP node){- ENTER_FUNCTION();const KisShapeLayer *shapeLayer = qobject_cast<const KisShapeLayer*>(node.data());if (!shapeLayer) {m_d->ui->gapOptionsWidget->setVisible(false);@@ -391,8 +389,6 @@ void KisToolKnifeOptionsWidget::modeChanged()void KisToolKnifeOptionsWidget::currentWidthSystemChanged(){- ENTER_FUNCTION();-GapWidthType gapConfig = m_d->getCurrentWidthType();switch(gapConfig) {case Thin:diff --git a/plugins/tools/tool_knife/RemoveGutterStrategy.cpp b/plugins/tools/tool_knife/RemoveGutterStrategy.cppindex 46ef8a5292..9d04cbfef0 100644--- a/plugins/tools/tool_knife/RemoveGutterStrategy.cpp+++ b/plugins/tools/tool_knife/RemoveGutterStrategy.cpp@@ -57,24 +57,13 @@ void RemoveGutterStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::Keyl = tool()->canvas()->viewConverter()->viewToDocument().map(l);dirtyRect = kisGrowRect(dirtyRect, l.length()); // twice as much as it should need to account for lines showing the effect- KisCanvas2* kisCanvas = dynamic_cast<KisCanvas2*>(tool()->canvas());- //dirtyRect = kisCanvas->viewManager()->- //dirtyRect = canvas()->viewConverter()->viewToDocument(dirtyRect);- //qCritical() << "And the dirty rect is: " << dirtyRect;-QRectF accumulatedWithPrevious = m_previousLineDirtyRect | dirtyRect;- //KisAlgebra2D::accumulateBounds(dirtyRect, &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.topLeft(), &accumulatedWithPrevious);- //KisAlgebra2D::accumulateBounds(dirtyRect.bottomRight(), &accumulatedWithPrevious);-- //QRectF rect = dirtyRect + m_d->previousLineDirtyRect;-tool()->canvas()->updateCanvas(accumulatedWithPrevious);m_previousLineDirtyRect = dirtyRect;}-+#ifdef KNIFE_DEBUGvoid convertShapeToDebugArray(const QPainterPath& shape) {// useful to use with Geogebra// TODO: to remove later@@ -103,26 +92,10 @@ void convertShapeToDebugArray(const QLineF& line) {qCritical() << line.p2().x() << "\t" << line.p2().y();}+#endifvoid RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers){-- // so, first find all the shapes whose bounding rect is nonempty when intersected with the line bounding rect- // then for every one of them find a path that's crossing the mouse line- // save info for later- // ensure you have only two paths belonging to two different shapes- // WAIT- // what about the situation o T- // There are three (four?) cases. Gotta look a the picture to understand it!- // write it down later, after implementing--- // also: when moving the gutter or gutter end, remember about keeping the gutter of the same--- qCritical() << "vvvvvvvvvvvvvvvvvvvvvvvvv REMOVING A GUTTER vvvvvvvvvvvvvvvvvvvvvvvvv";--tool()->canvas()->updateCanvas(m_previousLineDirtyRect);@@ -133,8 +106,6 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)QList<QPainterPath> srcOutlines;QList<QPainterPath> srcOutlinesOutside;- //QRectF outlineRect;-if (m_allShapes.length() == 0) {qCritical() << "No shapes on the layer";return;@@ -149,17 +120,13 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)QLineF mouseLine = QLineF(m_startPoint, m_endPoint);QRectF lineRect = KisAlgebra2D::createRectFromCorners(m_startPoint, m_endPoint);- qCritical() << "Line and line rect before boolean trans: " << mouseLine << lineRect;mouseLine = booleanWorkaroundTransform.map(mouseLine);- lineRect = KisAlgebra2D::createRectFromCorners(mouseLine.p1(), mouseLine.p2());-+ lineRect = KisAlgebra2D::createRectFromCorners(mouseLine);- qCritical() << "Line and line rect after boolean trans: " << mouseLine << lineRect;- qCritical() << "Line:";+#ifdef KNIFE_DEBUGconvertShapeToDebugArray(mouseLine);- qCritical() << "Rect:";convertShapeToDebugArray(lineRect);- qCritical() << "end.";+#endifQList<int> indexes;@@ -171,10 +138,9 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)booleanWorkaroundTransform.map(shape->absoluteTransformation().map(shape->outline()));-- qCritical() << "> Selected path (in boolean): ";+#ifdef KNIFE_DEBUGconvertShapeToDebugArray(outlineHere);-+#endifif (outlineHere.boundingRect().intersects(lineRect)) {srcOutlines << outlineHere;indexes << i;@@ -186,7 +152,6 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)}if (srcOutlines.isEmpty()) {- qCritical() << "The list of possible shapes is empty";return;}@@ -213,7 +178,7 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)}if (shapeNewIndexes.length() != 2) {-+#ifdef KNIFE_DEBUGqCritical() << "Shape indexes count isn't correct: " << ppVar(shapeNewIndexes.length()) << ppVar(lineSegmentIndexes.length());qCritical() << "Mouse line in used coordinates: " << mouseLine;qCritical() << "Number of shapes even considered: " << srcOutlines.length();@@ -235,9 +200,6 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)qCritical() << "Line index: " << lineSegmentIndexes[i] << " meaning it's: " << srcOutlines[index].elementAt(KisAlgebra2D::wrapValue(lineSegmentIndexes[i], 0, srcOutlines[index].elementCount()))<< srcOutlines[index].elementAt(KisAlgebra2D::wrapValue(lineSegmentIndexes[i] + 1, 0, srcOutlines[index].elementCount()));}-- qCritical() << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF REMOVING A GUTTER, UNSUCCESSFUL";-// TODO: this if should end here; code below adds a debug line showing the mouse lineQPainterPath newLineShape = QPainterPath();@@ -257,11 +219,13 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)tool()->canvas()->shapeController()->addShapeDirect(newLineShapeToAdd, m_allShapes[0]->parent(), cmd);tool()->canvas()->addCommand(cmd);+#endif+return;}- // KisAlgebra2D::getLineSegmentCrossingLineIndexes(QLineF const&, QPainterPath const&)+#ifdef KNIFE_DEBUGqCritical() << "Found two shapes.";qCritical() << "Shape 1:";convertShapeToDebugArray(srcOutlines[shapeNewIndexes[0]]);@@ -270,28 +234,21 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)qCritical() << "Shape 2:";convertShapeToDebugArray(srcOutlines[shapeNewIndexes[1]]);qCritical() << ppVar(srcOutlines[shapeNewIndexes[1]].toFillPolygon());-+#endifQPainterPath result = KisAlgebra2D::removeGutterSmart(srcOutlines[shapeNewIndexes[0]], lineSegmentIndexes[0], srcOutlines[shapeNewIndexes[1]], lineSegmentIndexes[1], shapeNewIndexes[0]==shapeNewIndexes[1]);+#ifdef KNIFE_DEBUGqCritical() << "Finally got a result:";convertShapeToDebugArray(result);qCritical() << ppVar(result.toFillPolygon());+#endifQList<KoShape*> resultSelectedShapes;- qCritical() << "Indexes that are supposed to be left:";- Q_FOREACH(int index, indexesOutside) {- qCritical() << index;- }- qCritical() << "End.";- qCritical() << "Indexes that compose the result shape: " << shapeOrigIndexes[0] << shapeOrigIndexes[1];- qCritical() << "All indexes are up to: " << m_allShapes.length();--Q_FOREACH(int index, indexesOutside) {if (isSelected[index]) {resultSelectedShapes << m_allShapes[index];@@ -340,22 +297,11 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)}--tool()->canvas()->shapeController()->removeShapes(shapesToRemove, cmd);-new KoKeepShapesSelectedCommand({}, resultSelectedShapes, tool()->canvas()->selectedShapesProxy(), true, cmd);--tool()->canvas()->addCommand(cmd);-- qCritical() << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF REMOVING A GUTTER, it did happen, whether successful or not... ";----}void RemoveGutterStrategy::paint(QPainter &painter, const KoViewConverter &converter)