Fix regression in VAbstractCurve::CurveIntersectLine.

This commit is contained in:
Roman Telezhynskyi 2020-10-13 12:12:52 +03:00
parent d5fd1380dc
commit 8c0bcfec37
7 changed files with 506 additions and 1 deletions

View File

@ -449,7 +449,8 @@ QVector<QPointF> VAbstractCurve::CurveIntersectLine(const QVector<QPointF> &poin
// QLineF::intersects not always accurate on edge cases // QLineF::intersects not always accurate on edge cases
if (type == QLineF::BoundedIntersection || 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); intersections.append(crosPoint);
} }

View File

@ -877,7 +877,12 @@ QVector<QLineF> VPassmark::SAPassmarkBaseLine(const QVector<QPointF> &seamAllowa
{ {
line.setLength(line.length()*100); // Hope 100 is enough line.setLength(line.length()*100); // Hope 100 is enough
// DumpVector(seamAllowance, QStringLiteral("points.json.XXXXXX")); // Uncomment for dumping test data
const QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(seamAllowance, line); const QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(seamAllowance, line);
// DumpVector(intersections, QStringLiteral("intersections.json.XXXXXX")); // Uncomment for dumping test data
if (not intersections.isEmpty()) if (not intersections.isEmpty())
{ {
if (intersections.last() != m_data.passmarkSAPoint) if (intersections.last() != m_data.passmarkSAPoint)

View File

@ -0,0 +1,9 @@
{
"vector": [
{
"type": "QPointF",
"x": 1200.4706839167343,
"y": 831.9991427263225
}
]
}

View File

@ -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
}
]
}

View File

@ -119,5 +119,7 @@
<file>smart_pattern_#36/output.json</file> <file>smart_pattern_#36/output.json</file>
<file>smart_pattern_#58/input.json</file> <file>smart_pattern_#58/input.json</file>
<file>smart_pattern_#58/output.json</file> <file>smart_pattern_#58/output.json</file>
<file>160-42_intersection/intersections.json</file>
<file>160-42_intersection/points.json</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -170,3 +170,40 @@ void TST_VAbstractCurve::IsPointOnCurve() const
bool result = VAbstractCurve::IsPointOnCurve(points, point); bool result = VAbstractCurve::IsPointOnCurve(points, point);
QCOMPARE(result, expectedResult); QCOMPARE(result, expectedResult);
} }
//---------------------------------------------------------------------------------------------------------------------
void TST_VAbstractCurve::CurveIntersectLine_data()
{
QTest::addColumn<QVector<QPointF>>("points");
QTest::addColumn<QVector<QPointF>>("intersections");
QTest::addColumn<QLineF>("line");
auto ASSERT_TEST_CASE = [this](const char *title, const QString &input, const QString &output, QLineF line)
{
QVector<QPointF> points;
AbstractTest::VectorFromJson(input, points);
QVector<QPointF> 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<QPointF>, points);
QFETCH(QVector<QPointF>, intersections);
QFETCH(QLineF, line);
const QVector<QPointF> result = VAbstractCurve::CurveIntersectLine(points, line);
QCOMPARE(result, intersections);
}

View File

@ -40,6 +40,8 @@ public:
private slots: private slots:
void IsPointOnCurve_data() const; void IsPointOnCurve_data() const;
void IsPointOnCurve() const; void IsPointOnCurve() const;
void CurveIntersectLine_data();
void CurveIntersectLine() const;
}; };
#endif // TST_VABSTRACTCURVE_H #endif // TST_VABSTRACTCURVE_H