From c137c46e2d6c79b4cdcf180ff25fd342e93806f9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 2 Sep 2019 08:43:02 +0300 Subject: [PATCH] New test cover a rollback case. --HG-- branch : develop --- src/libs/vlayout/vabstractpiece.cpp | 70 ++- .../share/seamtest1_by_angle_2/input.json | 446 ++++++++++++++++++ .../share/seamtest1_by_angle_2/output.json | 214 +++++++++ src/test/ValentinaTest/share/test_data.qrc | 2 + src/test/ValentinaTest/tst_vabstractpiece.cpp | 6 + 5 files changed, 720 insertions(+), 18 deletions(-) create mode 100644 src/test/ValentinaTest/share/seamtest1_by_angle_2/input.json create mode 100644 src/test/ValentinaTest/share/seamtest1_by_angle_2/output.json diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index f4672f27f..5b051050a 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -788,23 +788,23 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid if (needRollback) { - auto Rollback = [&ekvPoints](const QLineF &edge) + auto Rollback = [](QVector &points, const QLineF &edge) { - if (not ekvPoints.isEmpty()) + bool success = false; + if (not points.isEmpty()) { - ekvPoints.removeLast(); + points.removeLast(); + points = RollbackSeamAllowance(points, edge, &success); - bool success = false; - ekvPoints = RollbackSeamAllowance(ekvPoints, edge, &success); - - if (not ekvPoints.isEmpty()) + if (not points.isEmpty()) { - if (ekvPoints.last().toPoint() != ekvPoints.first().toPoint()) + if (points.last().toPoint() != points.first().toPoint()) { - ekvPoints.append(ekvPoints.first());// Should be always closed + points.append(points.first());// Should be always closed } } } + return success; }; QT_WARNING_PUSH @@ -821,8 +821,15 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid case PieceNodeAngle::ByLengthCurve: { const QLineF bigLine1 = ParallelLine(points.at(points.size()-2), points.at(0), width); - ekvPoints.insert(ekvPoints.size()-1, bigLine1.p2()); - Rollback(ParallelLine(points.at(0), points.at(1), width)); + + QVector temp = ekvPoints; + temp.insert(ekvPoints.size()-1, bigLine1.p2()); + bool success = Rollback(temp, ParallelLine(points.at(0), points.at(1), width)); + + if (success) + { + ekvPoints = temp; + } break; } case PieceNodeAngle::ByFirstEdgeSymmetry: @@ -831,8 +838,15 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid const QLineF bigLine2 = ParallelLine(points.at(points.size()-1), points.at(1), width); QLineF sEdge(VPointF::FlipPF(axis, bigLine2.p1()), VPointF::FlipPF(axis, bigLine2.p2())); const QLineF bigLine1 = ParallelLine(points.at(points.size()-2), points.at(0), width); - ekvPoints.insert(ekvPoints.size()-1, bigLine1.p2()); - Rollback(sEdge); + + QVector temp = ekvPoints; + temp.insert(ekvPoints.size()-1, bigLine1.p2()); + bool success = Rollback(temp, sEdge); + + if (success) + { + ekvPoints = temp; + } break; } case PieceNodeAngle::BySecondEdgeSymmetry: @@ -840,18 +854,36 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid const QLineF axis = QLineF(points.at(points.size()-1), points.at(1)); const QLineF bigLine1 = ParallelLine(points.at(points.size()-2), points.at(0), width); QLineF sEdge(VPointF::FlipPF(axis, bigLine1.p1()), VPointF::FlipPF(axis, bigLine1.p2())); - ekvPoints.insert(ekvPoints.size()-1, bigLine1.p2()); - Rollback(sEdge); + + QVector temp = ekvPoints; + temp.insert(ekvPoints.size()-1, bigLine1.p2()); + bool success = Rollback(temp, sEdge); + + if (success) + { + ekvPoints = temp; + } break; } case PieceNodeAngle::ByPointsIntersection: - Rollback(QLineF(points.last(), points.at(1))); + { + const QLineF bigLine1 = ParallelLine(points.at(points.size()-2), points.at(0), width); + QVector temp = ekvPoints; + temp.insert(ekvPoints.size()-1, bigLine1.p2()); + bool success = Rollback(temp, QLineF(points.last(), points.at(1))); + + if (success) + { + ekvPoints = temp; + } + if (ekvPoints.size() > 2) { // Fix for the rule of main path ekvPoints.removeAt(ekvPoints.size()-1); ekvPoints.prepend(ekvPoints.at(ekvPoints.size()-1)); } break; + } case PieceNodeAngle::BySecondEdgeRightAngle: if (not ekvPoints.isEmpty()) { @@ -884,11 +916,13 @@ QVector VAbstractPiece::Equidistant(QVector points, qreal wid else { bool success = false; - ekvPoints.insert(ekvPoints.size()-1, bigLine1.p2()); - ekvPoints = RollbackSeamAllowance(ekvPoints, edge, &success); + QVector temp = ekvPoints; + temp.insert(ekvPoints.size()-1, bigLine1.p2()); + temp = VAbstractPiece::RollbackSeamAllowance(temp, edge, &success); if (success) { + ekvPoints = temp; px = ekvPoints.last(); } diff --git a/src/test/ValentinaTest/share/seamtest1_by_angle_2/input.json b/src/test/ValentinaTest/share/seamtest1_by_angle_2/input.json new file mode 100644 index 000000000..be283c9e5 --- /dev/null +++ b/src/test/ValentinaTest/share/seamtest1_by_angle_2/input.json @@ -0,0 +1,446 @@ +{ + "vector": [ + { + "saAfter": 0, + "type": "VSAPoint", + "x": 620.5290071875436, + "y": -5.506318761785565 + }, + { + "saAfter": 188.9763779527559, + "saBefore": 0, + "type": "VSAPoint", + "x": 944.294593326342, + "y": 136.63905516701556 + }, + { + "saAfter": 188.9763779527559, + "saBefore": 0, + "type": "VSAPoint", + "x": 944.294593326342, + "y": 136.63905516701556 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 930.9115139455133, + "y": 164.2021651072791 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 907.1077633892038, + "y": 216.20756088951924 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 886.6420235246574, + "y": 264.5706340127217 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 869.2733175133691, + "y": 309.4054580978941 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 854.760668516834, + "y": 350.82610676604384 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 842.8630996965472, + "y": 388.9466536381784 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 833.3396342140039, + "y": 423.88117233530534 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 825.9492952306991, + "y": 455.74373647843197 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 820.451105908128, + "y": 484.6484196885659 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 816.6040894077855, + "y": 510.7092955867147 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 814.1672688911669, + "y": 534.0404377938855 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 812.8996675197673, + "y": 554.7559199310863 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 812.5925673946043, + "y": 581.4656260538284 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 814.1809574610598, + "y": 608.5715133604979 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 815.1968503937007, + "y": 618.5825511811024 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 816.3634787672067, + "y": 628.380932746632 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 820.4053369940075, + "y": 649.1688436779486 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 826.5040284899703, + "y": 671.0654086429722 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 834.6667882477791, + "y": 693.7142683899226 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 844.9008512601183, + "y": 716.7590636670197 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 857.2134525196718, + "y": 739.8434352224829 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 871.6118270191237, + "y": 762.6110238045324 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 888.1032097511581, + "y": 784.7054701613878 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 906.6948357084594, + "y": 805.7704150412691 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 927.3939398837115, + "y": 825.4494991923958 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 950.2077572695983, + "y": 843.3863633629879 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 968.776733605274, + "y": 855.4073744953336 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 981.7764600118351, + "y": 862.7350547966848 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 995.3089344044396, + "y": 869.4267280237759 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1009.3750611571733, + "y": 875.4378492701345 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1023.9757446441214, + "y": 880.7238736292878 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1039.1118892393697, + "y": 885.2402561947638 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1054.784399317004, + "y": 888.9424520600894 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1070.994179251109, + "y": 891.7859163187926 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1087.7421334157707, + "y": 893.7261040644007 + }, + { + "angle": 6, + "saAfter": 188.9763779527559, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1105.0291661850742, + "y": 894.7184703904409 + }, + { + "saAfter": 0, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1113.8976377952758, + "y": 894.8030236220472 + }, + { + "saAfter": 0, + "saBefore": 188.9763779527559, + "type": "VSAPoint", + "x": 1113.8976377952758, + "y": 894.8030236220472 + }, + { + "saAfter": 0, + "saBefore": 75.59055118110237, + "type": "VSAPoint", + "x": 30, + "y": 894.8030236220472 + }, + { + "saBefore": 0, + "type": "VSAPoint", + "x": 30, + "y": 39.999874015748034 + }, + { + "saBefore": 0, + "type": "VSAPoint", + "x": 30, + "y": 39.999874015748034 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 47.53637144700478, + "y": 39.80977598775412 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 85.4092492068762, + "y": 37.36146293134895 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 125.57923134501877, + "y": 32.13056337758208 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 156.5108311435474, + "y": 26.074993549693005 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 177.21129897469388, + "y": 21.059222548891512 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 197.8216319874312, + "y": 15.159776113211533 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 218.19418331220902, + "y": 8.334870062533497 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 238.18130607947683, + "y": 0.5427202167378373 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 257.6353534196842, + "y": -8.258457604295018 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 276.4086784632808, + "y": -18.110447580684635 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 294.3536343407161, + "y": -29.055033892550586 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 311.32257418243984, + "y": -41.13400072001244 + }, + { + "angle": 6, + "type": "VSAPoint", + "x": 327.16785111890135, + "y": -54.389132243189756 + }, + { + "saAfter": 0.3779527559055119, + "type": "VSAPoint", + "x": 334.5669291338582, + "y": -61.522435695538036 + }, + { + "saAfter": 0.3779527559055119, + "type": "VSAPoint", + "x": 334.5669291338582, + "y": -61.522435695538036 + }, + { + "saBefore": 0.3779527559055119, + "type": "VSAPoint", + "x": 519.4465667350105, + "y": -36.01405338211433 + }, + { + "type": "VSAPoint", + "x": 460.3937007874016, + "y": 342.36207874015753 + } + ] +} diff --git a/src/test/ValentinaTest/share/seamtest1_by_angle_2/output.json b/src/test/ValentinaTest/share/seamtest1_by_angle_2/output.json new file mode 100644 index 000000000..1e757847a --- /dev/null +++ b/src/test/ValentinaTest/share/seamtest1_by_angle_2/output.json @@ -0,0 +1,214 @@ +{ + "vector": [ + { + "type": "QPointF", + "x": 1117.4559101159903, + "y": 212.6634418802967 + }, + { + "type": "QPointF", + "x": 1101.8482040478996, + "y": 244.8082798528157 + }, + { + "type": "QPointF", + "x": 1080.077560308019, + "y": 292.3718325563429 + }, + { + "type": "QPointF", + "x": 1061.8089025447719, + "y": 335.54292908714797 + }, + { + "type": "QPointF", + "x": 1046.6013689355652, + "y": 374.7989965048928 + }, + { + "type": "QPointF", + "x": 1034.1843603449322, + "y": 410.2384638595293 + }, + { + "type": "QPointF", + "x": 1024.2819001340656, + "y": 441.96655926454446 + }, + { + "type": "QPointF", + "x": 1016.6128103198596, + "y": 470.0987514791764 + }, + { + "type": "QPointF", + "x": 1010.891548127259, + "y": 494.7652903217379 + }, + { + "type": "QPointF", + "x": 1004.1409514475167, + "y": 534.3338730421456 + }, + { + "type": "QPointF", + "x": 1001.8096437359794, + "y": 561.6175009318105 + }, + { + "type": "QPointF", + "x": 1001.6561432953282, + "y": 574.9680381786756 + }, + { + "type": "QPointF", + "x": 1004.4715714217981, + "y": 605.7139974891637 + }, + { + "type": "QPointF", + "x": 1010.1411052399322, + "y": 623.2360341722922 + }, + { + "type": "QPointF", + "x": 1020.6660121283516, + "y": 644.7426504865729 + }, + { + "type": "QPointF", + "x": 1027.4243046890665, + "y": 655.4292751847524 + }, + { + "type": "QPointF", + "x": 1034.913026324476, + "y": 665.4623428264111 + }, + { + "type": "QPointF", + "x": 1042.9029269068749, + "y": 674.5151720813944 + }, + { + "type": "QPointF", + "x": 1051.171411576988, + "y": 682.3761985416603 + }, + { + "type": "QPointF", + "x": 1064.4550829934562, + "y": 692.2276518062896 + }, + { + "type": "QPointF", + "x": 1074.3372851140064, + "y": 697.4493100553057 + }, + { + "type": "QPointF", + "x": 1087.891993301369, + "y": 702.5858632116882 + }, + { + "type": "QPointF", + "x": 1102.5229793527785, + "y": 705.1981929082115 + }, + { + "type": "QPointF", + "x": 1290.6502488400083, + "y": 712.9440934612204 + }, + { + "type": "QPointF", + "x": 1302.4161318705776, + "y": 881.6558256043734 + }, + { + "type": "QPointF", + "x": 30, + "y": 970.3935748031496 + }, + { + "type": "QPointF", + "x": 30, + "y": 2.202377824282337 + }, + { + "type": "QPointF", + "x": 46.111397855976776, + "y": 2.027726815668483 + }, + { + "type": "QPointF", + "x": 81.74605442368645, + "y": -0.2758951981748612 + }, + { + "type": "QPointF", + "x": 119.50208828052781, + "y": -5.192452541281906 + }, + { + "type": "QPointF", + "x": 148.04367032633104, + "y": -10.78012159825089 + }, + { + "type": "QPointF", + "x": 186.97979694595927, + "y": -21.06789814835227 + }, + { + "type": "QPointF", + "x": 205.31950565747624, + "y": -27.21179180985321 + }, + { + "type": "QPointF", + "x": 223.51736443487215, + "y": -34.306381867523655 + }, + { + "type": "QPointF", + "x": 241.0503469884652, + "y": -42.23845350735769 + }, + { + "type": "QPointF", + "x": 257.76798751706616, + "y": -51.01164773556077 + }, + { + "type": "QPointF", + "x": 273.5285590176657, + "y": -60.62398316233916 + }, + { + "type": "QPointF", + "x": 284.94491218126115, + "y": -68.7504632158891 + }, + { + "type": "QPointF", + "x": 556.951317720607, + "y": -31.220946854728947 + }, + { + "type": "QPointF", + "x": 539.6101141051189, + "y": 79.89131577778124 + }, + { + "type": "QPointF", + "x": 585.9167315845333, + "y": -20.702420721823497 + }, + { + "type": "QPointF", + "x": 1117.4559101159903, + "y": 212.6634418802967 + } + ] +} diff --git a/src/test/ValentinaTest/share/test_data.qrc b/src/test/ValentinaTest/share/test_data.qrc index 51f63ec84..47470dc10 100644 --- a/src/test/ValentinaTest/share/test_data.qrc +++ b/src/test/ValentinaTest/share/test_data.qrc @@ -82,5 +82,7 @@ Issue_548/output.json Issue_642/input.json Issue_642/output.json + seamtest1_by_angle_2/input.json + seamtest1_by_angle_2/output.json diff --git a/src/test/ValentinaTest/tst_vabstractpiece.cpp b/src/test/ValentinaTest/tst_vabstractpiece.cpp index 41e5c1aed..c8d1e1c25 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.cpp +++ b/src/test/ValentinaTest/tst_vabstractpiece.cpp @@ -63,6 +63,12 @@ void TST_VAbstractPiece::EquidistantRemoveLoop_data() QStringLiteral("://seamtest1_by_angle/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); + // See file src/app/share/collection/test/seamtest1.val + ASSERT_TEST_CASE("Seam test 1. Piece. By angle 2.", + QStringLiteral("://seamtest1_by_angle_2/input.json"), + QStringLiteral("://seamtest1_by_angle_2/output.json"), + 37.795275590551185 /*seam allowance width (1.0 cm)*/); + // See file src/app/share/collection/test/seamtest1.val ASSERT_TEST_CASE("Seam test 1. Piece. By intersection.", QStringLiteral("://seamtest1_by_intersection/input.json"),