From 8c0bcfec371c95557507ea937d74c486e8fdeb1a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Oct 2020 12:12:52 +0300 Subject: [PATCH] Fix regression in VAbstractCurve::CurveIntersectLine. --- src/libs/vgeometry/vabstractcurve.cpp | 3 +- src/libs/vpatterndb/vpassmark.cpp | 5 + .../160-42_intersection/intersections.json | 9 + .../share/160-42_intersection/points.json | 449 ++++++++++++++++++ src/test/ValentinaTest/share/test_data.qrc | 2 + src/test/ValentinaTest/tst_vabstractcurve.cpp | 37 ++ src/test/ValentinaTest/tst_vabstractcurve.h | 2 + 7 files changed, 506 insertions(+), 1 deletion(-) create mode 100644 src/test/ValentinaTest/share/160-42_intersection/intersections.json create mode 100644 src/test/ValentinaTest/share/160-42_intersection/points.json diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 15e6d466d..f46ba0409 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -449,7 +449,8 @@ QVector VAbstractCurve::CurveIntersectLine(const QVector &poin // QLineF::intersects not always accurate on edge cases if (type == QLineF::BoundedIntersection || - VGObject::IsPointOnLineSegment (crosPoint, points.at(i), points.at(i+1))) + (VGObject::IsPointOnLineSegment (crosPoint, points.at(i), points.at(i+1)) && + VGObject::IsPointOnLineSegment (crosPoint, line.p1(), line.p2()))) { intersections.append(crosPoint); } diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index 88a7597bc..2dd0998de 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -877,7 +877,12 @@ QVector VPassmark::SAPassmarkBaseLine(const QVector &seamAllowa { line.setLength(line.length()*100); // Hope 100 is enough +// DumpVector(seamAllowance, QStringLiteral("points.json.XXXXXX")); // Uncomment for dumping test data + const QVector intersections = VAbstractCurve::CurveIntersectLine(seamAllowance, line); + +// DumpVector(intersections, QStringLiteral("intersections.json.XXXXXX")); // Uncomment for dumping test data + if (not intersections.isEmpty()) { if (intersections.last() != m_data.passmarkSAPoint) diff --git a/src/test/ValentinaTest/share/160-42_intersection/intersections.json b/src/test/ValentinaTest/share/160-42_intersection/intersections.json new file mode 100644 index 000000000..b9e09adf4 --- /dev/null +++ b/src/test/ValentinaTest/share/160-42_intersection/intersections.json @@ -0,0 +1,9 @@ +{ + "vector": [ + { + "type": "QPointF", + "x": 1200.4706839167343, + "y": 831.9991427263225 + } + ] +} diff --git a/src/test/ValentinaTest/share/160-42_intersection/points.json b/src/test/ValentinaTest/share/160-42_intersection/points.json new file mode 100644 index 000000000..3ed53f617 --- /dev/null +++ b/src/test/ValentinaTest/share/160-42_intersection/points.json @@ -0,0 +1,449 @@ +{ + "vector": [ + { + "type": "QPointF", + "x": 1204.5220711597149, + "y": 794.4091052620581 + }, + { + "type": "QPointF", + "x": 1188.1004042688442, + "y": 946.7744647381325 + }, + { + "type": "QPointF", + "x": 1181.583283326743, + "y": 1016.3338758695331 + }, + { + "type": "QPointF", + "x": 1176.2564594430808, + "y": 1081.553134072023 + }, + { + "type": "QPointF", + "x": 1172.0563226160473, + "y": 1142.6584803882913 + }, + { + "type": "QPointF", + "x": 1168.913904096796, + "y": 1199.932358792221 + }, + { + "type": "QPointF", + "x": 1166.7601061639393, + "y": 1253.658516329682 + }, + { + "type": "QPointF", + "x": 1165.5258008146989, + "y": 1304.1223850685635 + }, + { + "type": "QPointF", + "x": 1165.1419820706442, + "y": 1351.6114697016624 + }, + { + "type": "QPointF", + "x": 1165.5394819446449, + "y": 1396.360385107551 + }, + { + "type": "QPointF", + "x": 1167.3771653444696, + "y": 1459.4229363236614 + }, + { + "type": "QPointF", + "x": 1172.05836916579, + "y": 1536.5257831224303 + }, + { + "type": "QPointF", + "x": 1178.6639664178686, + "y": 1608.1109200940812 + }, + { + "type": "QPointF", + "x": 1191.0406161269184, + "y": 1710.8249728759447 + }, + { + "type": "QPointF", + "x": 1204.9889686390782, + "y": 1814.2009018120025 + }, + { + "type": "QPointF", + "x": 1214.243723916857, + "y": 1888.1687697477428 + }, + { + "type": "QPointF", + "x": 1222.7133760513059, + "y": 1967.7079198970396 + }, + { + "type": "QPointF", + "x": 1229.8766626825727, + "y": 2055.233879467578 + }, + { + "type": "QPointF", + "x": 1235.6786803206705, + "y": 2153.1566255127655 + }, + { + "type": "QPointF", + "x": 1237.5499478831148, + "y": 2234.7630720635316 + }, + { + "type": "QPointF", + "x": 1238.310195961103, + "y": 2292.934308512474 + }, + { + "type": "QPointF", + "x": 1238.5369229425262, + "y": 2396.973894668973 + }, + { + "type": "QPointF", + "x": 1156.1450238709997, + "y": 2403.3321519997 + }, + { + "type": "QPointF", + "x": 1047.3721846473834, + "y": 2409.255364439901 + }, + { + "type": "QPointF", + "x": 930.6136213570926, + "y": 2413.4190816694104 + }, + { + "type": "QPointF", + "x": 809.9146854887778, + "y": 2416.139361869592 + }, + { + "type": "QPointF", + "x": 630.1769233305752, + "y": 2418.258606598836 + }, + { + "type": "QPointF", + "x": 417.2346175555265, + "y": 2418.6491652953964 + }, + { + "type": "QPointF", + "x": 333.9764409448819, + "y": 2418.582827377485 + }, + { + "type": "QPointF", + "x": 333.9764409448819, + "y": 849.2848996145437 + }, + { + "type": "QPointF", + "x": 358.14477039459007, + "y": 849.0768275341652 + }, + { + "type": "QPointF", + "x": 400.88789017502535, + "y": 847.9385215412262 + }, + { + "type": "QPointF", + "x": 437.73220035371065, + "y": 845.4683632737341 + }, + { + "type": "QPointF", + "x": 461.54775163099504, + "y": 842.4214776586695 + }, + { + "type": "QPointF", + "x": 475.64862913209305, + "y": 839.8596946800747 + }, + { + "type": "QPointF", + "x": 488.6235296235764, + "y": 836.7646858302943 + }, + { + "type": "QPointF", + "x": 500.4473695792253, + "y": 833.1393241038348 + }, + { + "type": "QPointF", + "x": 511.25610255550794, + "y": 828.9564637103209 + }, + { + "type": "QPointF", + "x": 521.2199818359429, + "y": 824.1677259012087 + }, + { + "type": "QPointF", + "x": 530.5333478284431, + "y": 818.6897215174541 + }, + { + "type": "QPointF", + "x": 539.3942168467836, + "y": 812.3978538920265 + }, + { + "type": "QPointF", + "x": 547.9804122560488, + "y": 805.1328153139191 + }, + { + "type": "QPointF", + "x": 556.4320979439857, + "y": 796.7182827828433 + }, + { + "type": "QPointF", + "x": 564.847029098972, + "y": 786.9819955396911 + }, + { + "type": "QPointF", + "x": 573.2875501240446, + "y": 775.7716678796102 + }, + { + "type": "QPointF", + "x": 581.7933904048705, + "y": 762.9617535709397 + }, + { + "type": "QPointF", + "x": 590.3311311346044, + "y": 748.5587050004192 + }, + { + "type": "QPointF", + "x": 603.5071434493324, + "y": 723.5671117044461 + }, + { + "type": "QPointF", + "x": 621.699421133646, + "y": 683.4029697788942 + }, + { + "type": "QPointF", + "x": 640.9113681857159, + "y": 635.4029741640036 + }, + { + "type": "QPointF", + "x": 661.6283092919746, + "y": 579.051363332499 + }, + { + "type": "QPointF", + "x": 696.4150307442666, + "y": 478.66256464696875 + }, + { + "type": "QPointF", + "x": 723.610250071157, + "y": 397.86133841324386 + }, + { + "type": "QPointF", + "x": 835.3891303952902, + "y": 76.20280724622233 + }, + { + "type": "QPointF", + "x": 1032.5567274287391, + "y": 144.72127770598863 + }, + { + "type": "QPointF", + "x": 1019.3469395724269, + "y": 180.14312704476697 + }, + { + "type": "QPointF", + "x": 1014.2139207707228, + "y": 196.05974413189915 + }, + { + "type": "QPointF", + "x": 1004.5112101094659, + "y": 228.96183060088478 + }, + { + "type": "QPointF", + "x": 996.0797580099623, + "y": 261.18141733279424 + }, + { + "type": "QPointF", + "x": 988.8671690071939, + "y": 292.7744596625039 + }, + { + "type": "QPointF", + "x": 982.8475180361602, + "y": 323.70595299221895 + }, + { + "type": "QPointF", + "x": 977.9945302240415, + "y": 353.9406652427878 + }, + { + "type": "QPointF", + "x": 974.2815097180072, + "y": 383.44313048382173 + }, + { + "type": "QPointF", + "x": 971.6812560696699, + "y": 412.17764919941646 + }, + { + "type": "QPointF", + "x": 970.1659664857561, + "y": 440.10829837829874 + }, + { + "type": "QPointF", + "x": 969.7071223553431, + "y": 467.1989558031546 + }, + { + "type": "QPointF", + "x": 970.2753588353071, + "y": 493.41334447055993 + }, + { + "type": "QPointF", + "x": 971.8403170977545, + "y": 518.7151050648946 + }, + { + "type": "QPointF", + "x": 974.3704803831488, + "y": 543.0679068913671 + }, + { + "type": "QPointF", + "x": 977.8329976443641, + "y": 566.4356106185173 + }, + { + "type": "QPointF", + "x": 982.1935028337135, + "y": 588.7824994397529 + }, + { + "type": "QPointF", + "x": 987.4159444456894, + "y": 610.0735984167809 + }, + { + "type": "QPointF", + "x": 993.4624495441881, + "y": 630.2751039559402 + }, + { + "type": "QPointF", + "x": 1000.2932598552349, + "y": 649.3549450208784 + }, + { + "type": "QPointF", + "x": 1007.8667948069833, + "y": 667.2834922505773 + }, + { + "type": "QPointF", + "x": 1016.1399166386087, + "y": 684.0344168537076 + }, + { + "type": "QPointF", + "x": 1025.0684924602422, + "y": 699.5856732092024 + }, + { + "type": "QPointF", + "x": 1034.6083600127965, + "y": 713.9205327678802 + }, + { + "type": "QPointF", + "x": 1044.716795077974, + "y": 727.0285301692011 + }, + { + "type": "QPointF", + "x": 1055.354531206257, + "y": 738.9061012141988 + }, + { + "type": "QPointF", + "x": 1066.4882784189501, + "y": 749.5566164708109 + }, + { + "type": "QPointF", + "x": 1078.093519634707, + "y": 758.9894825629082 + }, + { + "type": "QPointF", + "x": 1090.1571537187924, + "y": 767.2180483273171 + }, + { + "type": "QPointF", + "x": 1102.6793690739457, + "y": 774.2562591050652 + }, + { + "type": "QPointF", + "x": 1115.6740779771362, + "y": 780.1143446654222 + }, + { + "type": "QPointF", + "x": 1129.167420601831, + "y": 784.7942142271178 + }, + { + "type": "QPointF", + "x": 1143.1942778350115, + "y": 788.2854971762453 + }, + { + "type": "QPointF", + "x": 1158.0637701589192, + "y": 790.6053408374113 + }, + { + "type": "QPointF", + "x": 1204.5220711597149, + "y": 794.4091052620581 + } + ] +} diff --git a/src/test/ValentinaTest/share/test_data.qrc b/src/test/ValentinaTest/share/test_data.qrc index 458a709b4..d29022201 100644 --- a/src/test/ValentinaTest/share/test_data.qrc +++ b/src/test/ValentinaTest/share/test_data.qrc @@ -119,5 +119,7 @@ smart_pattern_#36/output.json smart_pattern_#58/input.json smart_pattern_#58/output.json + 160-42_intersection/intersections.json + 160-42_intersection/points.json diff --git a/src/test/ValentinaTest/tst_vabstractcurve.cpp b/src/test/ValentinaTest/tst_vabstractcurve.cpp index 6a930ab79..4b6660afd 100644 --- a/src/test/ValentinaTest/tst_vabstractcurve.cpp +++ b/src/test/ValentinaTest/tst_vabstractcurve.cpp @@ -170,3 +170,40 @@ void TST_VAbstractCurve::IsPointOnCurve() const bool result = VAbstractCurve::IsPointOnCurve(points, point); QCOMPARE(result, expectedResult); } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractCurve::CurveIntersectLine_data() +{ + QTest::addColumn>("points"); + QTest::addColumn>("intersections"); + QTest::addColumn("line"); + + auto ASSERT_TEST_CASE = [this](const char *title, const QString &input, const QString &output, QLineF line) + { + QVector points; + AbstractTest::VectorFromJson(input, points); + + QVector intersections; + AbstractTest::VectorFromJson(output, intersections); + + QTest::newRow(title) << points << intersections << line; + }; + + // See file src/app/share/collection/bugs/160-42.val (private collection) + ASSERT_TEST_CASE("Notch angle by intersection (right side)", + QStringLiteral("://160-42_intersection/points.json"), + QStringLiteral("://160-42_intersection/intersections.json"), + QLineF(QPointF(1153.6026868898712, 828.1618345186405), + QPointF(2072.237934910698, 903.3749180877085))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractCurve::CurveIntersectLine() const +{ + QFETCH(QVector, points); + QFETCH(QVector, intersections); + QFETCH(QLineF, line); + + const QVector result = VAbstractCurve::CurveIntersectLine(points, line); + QCOMPARE(result, intersections); +} diff --git a/src/test/ValentinaTest/tst_vabstractcurve.h b/src/test/ValentinaTest/tst_vabstractcurve.h index 25e694bef..85ff865b8 100644 --- a/src/test/ValentinaTest/tst_vabstractcurve.h +++ b/src/test/ValentinaTest/tst_vabstractcurve.h @@ -40,6 +40,8 @@ public: private slots: void IsPointOnCurve_data() const; void IsPointOnCurve() const; + void CurveIntersectLine_data(); + void CurveIntersectLine() const; }; #endif // TST_VABSTRACTCURVE_H