Fix regression in angle type "By second edge right angle".

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-09-06 11:12:01 +03:00
parent aa6a75298c
commit 880aa4de0c
2 changed files with 76 additions and 43 deletions

View file

@ -132,7 +132,7 @@ QVector<QPointF> AngleByLength(QVector<QPointF> points, QPointF p1, QPointF p2,
QLineF edge2(p2, p3); QLineF edge2(p2, p3);
const qreal angle = edge1.angleTo(edge2); const qreal angle = edge1.angleTo(edge2);
if (angle > 225) if (angle > 268)
{ {
QLineF loop(sp2, bigLine1.p1()); QLineF loop(sp2, bigLine1.p1());
loop.setLength(accuracyPointOnLine*2.); loop.setLength(accuracyPointOnLine*2.);
@ -442,7 +442,7 @@ QVector<QPointF> AngleByFirstRightAngle(const QVector<QPointF> &points, QPointF
QLineF edge2(p2, p3); QLineF edge2(p2, p3);
const qreal angle = edge1.angleTo(edge2); const qreal angle = edge1.angleTo(edge2);
if (angle > 180) if (angle > 270)
{ {
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
} }
@ -463,27 +463,39 @@ QVector<QPointF> AngleByFirstRightAngle(const QVector<QPointF> &points, QPointF
seam.setAngle(seam.angle()-90); seam.setAngle(seam.angle()-90);
seam.setLength(p.GetSABefore(width)); seam.setLength(p.GetSABefore(width));
pointsRA.append(seam.p2()); if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), seam.p1()) && IsSameDirection(p1, p2, px))
if (IsOutsidePoint(bigLine2.p2(), bigLine2.p1(), seam.p1()))
{ {
if (QLineF(p2, px).length() > localWidth*maxL) if (QLineF(p2, px).length() > localWidth*maxL)
{ {
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
} }
pointsRA.append(seam.p2());
pointsRA.append(seam.p1()); pointsRA.append(seam.p1());
} }
else else
{ {
QLineF loopLine(px, sp2); QLineF edge1(p2, p1);
const qreal length = loopLine.length()*0.98; QLineF edge2(p2, p3);
loopLine.setLength(length); const qreal angle = edge1.angleTo(edge2);
QLineF tmp(seam.p2(), seam.p1()); if (angle > 180)
tmp.setLength(tmp.length()+length); {
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
}
else
{
pointsRA.append(seam.p2());
pointsRA.append(tmp.p2()); QLineF loopLine(px, sp2);
pointsRA.append(loopLine.p2()); 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; return pointsRA;
@ -499,7 +511,7 @@ QVector<QPointF> AngleBySecondRightAngle(QVector<QPointF> points, QPointF p1, QP
QLineF edge2(p2, p3); QLineF edge2(p2, p3);
const qreal angle = edge1.angleTo(edge2); const qreal angle = edge1.angleTo(edge2);
if (angle > 180) if (angle > 270)
{ {
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
} }
@ -520,7 +532,7 @@ QVector<QPointF> AngleBySecondRightAngle(QVector<QPointF> points, QPointF p1, QP
return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback); 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) if (QLineF(p2, px).length() > localWidth*maxL)
{ {
@ -540,35 +552,46 @@ QVector<QPointF> AngleBySecondRightAngle(QVector<QPointF> points, QPointF p1, QP
} }
else else
{ {
// Because artificial loop can lead to wrong clipping we must rollback current seam allowance points QLineF edge1(p2, p1);
bool success = false; QLineF edge2(p2, p3);
const int countBefore = points.size(); const qreal angle = edge1.angleTo(edge2);
QVector<QPointF> temp = points;
temp.append(bigLine1.p2());
temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success);
if (success) if (angle > 180)
{ {
points = temp; return AngleByLength(points, p1, p2, p3, bigLine1, sp2, bigLine2, p, width, needRollback);
}
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 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<QPointF> 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<QPointF> VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal wid
return QVector<QPointF>(); return QVector<QPointF>();
} }
// DumpVector(points); // Uncomment for dumping test data // DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data
points = CorrectEquidistantPoints(points); points = CorrectEquidistantPoints(points);
if ( points.size() < 3 ) if ( points.size() < 3 )
@ -1051,7 +1074,7 @@ QVector<QPointF> VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal wid
ekvPoints = CheckLoops(RemoveDublicates(ekvPoints, removeFirstAndLast));//Result path can contain loops ekvPoints = CheckLoops(RemoveDublicates(ekvPoints, removeFirstAndLast));//Result path can contain loops
ekvPoints = CorrectEquidistantPoints(ekvPoints, removeFirstAndLast); ekvPoints = CorrectEquidistantPoints(ekvPoints, removeFirstAndLast);
ekvPoints = CorrectPathDistortion(ekvPoints); ekvPoints = CorrectPathDistortion(ekvPoints);
// DumpVector(ekvPoints); // Uncomment for dumping test data // DumpVector(ekvPoints, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data
return ekvPoints; return ekvPoints;
} }

View file

@ -3,12 +3,22 @@
{ {
"type": "QPointF", "type": "QPointF",
"x": 1984.9598604245455, "x": 1984.9598604245455,
"y": 3105.0906012087407 "y": 3107.491870978859
}, },
{ {
"type": "QPointF", "type": "QPointF",
"x": 1964.1829732503948, "x": 2022.7551360150967,
"y": 3102.4512091620227 "y": 3107.491870978859
},
{
"type": "QPointF",
"x": 1995.0755134542264,
"y": 3106.375643281218
},
{
"type": "QPointF",
"x": 1964.1900563650538,
"y": 3102.4221905864492
}, },
{ {
"type": "QPointF", "type": "QPointF",
@ -348,7 +358,7 @@
{ {
"type": "QPointF", "type": "QPointF",
"x": 1984.9598604245455, "x": 1984.9598604245455,
"y": 3105.0906012087407 "y": 3107.491870978859
} }
] ]
} }