From 880aa4de0c2004c2b6b2e1734ccfce6a6ce6ec6a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 6 Sep 2019 11:12:01 +0300 Subject: [PATCH] Fix regression in angle type "By second edge right angle". --HG-- branch : develop --- src/libs/vlayout/vabstractpiece.cpp | 101 +++++++++++------- .../output.json | 18 +++- 2 files changed, 76 insertions(+), 43 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 8430fa131..6a3170698 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -132,7 +132,7 @@ QVector AngleByLength(QVector points, QPointF p1, QPointF p2, QLineF edge2(p2, p3); const qreal angle = edge1.angleTo(edge2); - if (angle > 225) + if (angle > 268) { QLineF loop(sp2, bigLine1.p1()); loop.setLength(accuracyPointOnLine*2.); @@ -442,7 +442,7 @@ QVector AngleByFirstRightAngle(const QVector &points, QPointF QLineF edge2(p2, p3); const qreal angle = edge1.angleTo(edge2); - if (angle > 180) + if (angle > 270) { return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); } @@ -463,27 +463,39 @@ QVector AngleByFirstRightAngle(const QVector &points, QPointF seam.setAngle(seam.angle()-90); seam.setLength(p.GetSABefore(width)); - pointsRA.append(seam.p2()); - - if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), seam.p1())) + if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), seam.p1()) && IsSameDirection(p1, p2, px)) { if (QLineF(p2, px).length() > localWidth*maxL) { return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); } + pointsRA.append(seam.p2()); pointsRA.append(seam.p1()); } else { - QLineF loopLine(px, sp2); - const qreal length = loopLine.length()*0.98; - loopLine.setLength(length); + QLineF edge1(p2, p1); + QLineF edge2(p2, p3); + const qreal angle = edge1.angleTo(edge2); - QLineF tmp(seam.p2(), seam.p1()); - tmp.setLength(tmp.length()+length); + if (angle > 180) + { + return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); + } + else + { + pointsRA.append(seam.p2()); - pointsRA.append(tmp.p2()); - pointsRA.append(loopLine.p2()); + QLineF loopLine(px, sp2); + const qreal length = loopLine.length()*0.98; + loopLine.setLength(length); + + QLineF tmp(seam.p2(), seam.p1()); + tmp.setLength(tmp.length()+length); + + pointsRA.append(tmp.p2()); + pointsRA.append(loopLine.p2()); + } } return pointsRA; @@ -499,7 +511,7 @@ QVector AngleBySecondRightAngle(QVector points, QPointF p1, QP QLineF edge2(p2, p3); const qreal angle = edge1.angleTo(edge2); - if (angle > 180) + if (angle > 270) { return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); } @@ -520,7 +532,7 @@ QVector AngleBySecondRightAngle(QVector points, QPointF p1, QP return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); } - if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px)) + if (IsOutsidePoint(bigLine1.p1(), bigLine1.p2(), px) && IsSameDirection(p3, p2, px)) { if (QLineF(p2, px).length() > localWidth*maxL) { @@ -540,35 +552,46 @@ QVector AngleBySecondRightAngle(QVector points, QPointF p1, QP } else { - // Because artificial loop can lead to wrong clipping we must rollback current seam allowance points - bool success = false; - const int countBefore = points.size(); - QVector temp = points; - temp.append(bigLine1.p2()); - temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success); + QLineF edge1(p2, p1); + QLineF edge2(p2, p3); + const qreal angle = edge1.angleTo(edge2); - if (success) + if (angle > 180) { - points = temp; - } - - if (success) - { - px = points.last(); - } - - if (countBefore > 0) - { - QLineF seam(px, p3); - seam.setAngle(seam.angle()+90); - seam.setLength(p.GetSAAfter(width)); - points.append(seam.p2()); + return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); } else { - if (needRollback != nullptr) + // Because artificial loop can lead to wrong clipping we must rollback current seam allowance points + bool success = false; + const int countBefore = points.size(); + QVector temp = points; + temp.append(bigLine1.p2()); + temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success); + + if (success) { - *needRollback = not success; + points = temp; + } + + if (success) + { + px = points.last(); + } + + if (countBefore > 0) + { + QLineF seam(px, p3); + seam.setAngle(seam.angle()+90); + seam.setLength(p.GetSAAfter(width)); + points.append(seam.p2()); + } + else + { + if (needRollback != nullptr) + { + *needRollback = not success; + } } } } @@ -974,7 +997,7 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid return QVector(); } -// DumpVector(points); // Uncomment for dumping test data +// DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data points = CorrectEquidistantPoints(points); if ( points.size() < 3 ) @@ -1051,7 +1074,7 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid ekvPoints = CheckLoops(RemoveDublicates(ekvPoints, removeFirstAndLast));//Result path can contain loops ekvPoints = CorrectEquidistantPoints(ekvPoints, removeFirstAndLast); ekvPoints = CorrectPathDistortion(ekvPoints); -// DumpVector(ekvPoints); // Uncomment for dumping test data +// DumpVector(ekvPoints, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data return ekvPoints; } diff --git a/src/test/ValentinaTest/share/DP_6_hem_by_first_edge_right_angle/output.json b/src/test/ValentinaTest/share/DP_6_hem_by_first_edge_right_angle/output.json index eecd7a793..04a51318d 100644 --- a/src/test/ValentinaTest/share/DP_6_hem_by_first_edge_right_angle/output.json +++ b/src/test/ValentinaTest/share/DP_6_hem_by_first_edge_right_angle/output.json @@ -3,12 +3,22 @@ { "type": "QPointF", "x": 1984.9598604245455, - "y": 3105.0906012087407 + "y": 3107.491870978859 }, { "type": "QPointF", - "x": 1964.1829732503948, - "y": 3102.4512091620227 + "x": 2022.7551360150967, + "y": 3107.491870978859 + }, + { + "type": "QPointF", + "x": 1995.0755134542264, + "y": 3106.375643281218 + }, + { + "type": "QPointF", + "x": 1964.1900563650538, + "y": 3102.4221905864492 }, { "type": "QPointF", @@ -348,7 +358,7 @@ { "type": "QPointF", "x": 1984.9598604245455, - "y": 3105.0906012087407 + "y": 3107.491870978859 } ] }