From 2cf2dc5985967827a72e95ddb4cbfdf736e28f70 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Aug 2022 17:57:26 +0300 Subject: [PATCH] Fix segmenting a simple curve. --- ChangeLog.txt | 1 + src/libs/vgeometry/vabstractcubicbezier.cpp | 2 +- .../toolcut/vtoolcutspline.cpp | 3 +++ src/test/ValentinaTest/tst_vspline.cpp | 27 +++++++++++++++++++ src/test/ValentinaTest/tst_vspline.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d19d33a26..4cae7c2ee 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -17,6 +17,7 @@ - Unit type for increments. - Support for options Force Flipping and Forbid Flipping in Puzzle. - Remember selected dimension values. +- Fix segmenting a simple curve. # Valentina 0.7.51 April 18, 2022 - Z value change for a layout piece. diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index c7cbcb4b3..157cad51a 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -524,7 +524,7 @@ auto VAbstractCubicBezier::GetParmT(qreal length) const -> qreal length = base; } - Q_DECL_RELAXED_CONSTEXPR qreal eps = ToPixel(0.001, Unit::Mm); + Q_DECL_RELAXED_CONSTEXPR qreal eps = ToPixel(0.0001, Unit::Mm); qreal parT = 0.5; qreal step = parT; qreal splLength = 0; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index efa39d012..d58bb23d4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -152,6 +152,9 @@ VToolCutSpline* VToolCutSpline::Create(VToolCutInitData &initData) auto spline1 = QSharedPointer(new VSpline(spl->GetP1(), spl1p2, spl1p3, *p)); auto spline2 = QSharedPointer(new VSpline(*p, spl2p2, spl2p3, spl->GetP4())); + spline1->SetApproximationScale(spl->GetApproximationScale()); + spline2->SetApproximationScale(spl->GetApproximationScale()); + spline1->SetAliasSuffix(initData.aliasSuffix1); spline2->SetAliasSuffix(initData.aliasSuffix2); diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index d03471da9..f930ceafd 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -849,6 +849,33 @@ void TST_VSpline::TestFlip() QCOMPARE(spl.GetC2Length(), res.GetC2Length()); } +//--------------------------------------------------------------------------------------------------------------------- +// See file valentina_private_collection/bugs/men_jacket/issue_cut_spline.val (private collection) +void TST_VSpline::TestCutSpline() +{ + VPointF p1(187.31716535433043, 51.31464566929152, QStringLiteral("p1"), 140.42872440944885, -22.62372283464567); + VPointF p4(-991.8954330708666, 9.739842519685212, QStringLiteral("p4"), 9.999987401574804, 15.0); + + VSpline spl(p1, p4, 181.0, QStringLiteral("181"), 356.0, QStringLiteral("356"), 548.7874015748031, + QStringLiteral("Line_Г3_Г6*1.1"), 226.7716535433071, QStringLiteral("6")); + spl.SetApproximationScale(0.5); + + const QString name(QStringLiteral("з")); + const qreal result = 1.35; // Correct distance in cm. + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + QPointF point = spl.CutSpline(UnitConvertor(result, Unit::Cm, Unit::Px), spl1p2, spl1p3, spl2p2, spl2p3, name); + + VPointF p(point, name, -16.590651968503941, 37.574173228346453); + + VSpline spline1(spl.GetP1(), spl1p2, spl1p3, p); + spline1.SetApproximationScale(0.5); + + // Size 54 produces incorrect spline segment distance + + Q_DECL_RELAXED_CONSTEXPR qreal eps = ToPixel(0.0001, Unit::Mm); + QVERIFY(UnitConvertor(spline1.GetLength(), Unit::Px, Unit::Cm) - result < eps); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const { diff --git a/src/test/ValentinaTest/tst_vspline.h b/src/test/ValentinaTest/tst_vspline.h index ade7901ec..e62da0bf1 100644 --- a/src/test/ValentinaTest/tst_vspline.h +++ b/src/test/ValentinaTest/tst_vspline.h @@ -56,6 +56,7 @@ private slots: void TestLengthByPoint(); void TestFlip_data(); void TestFlip(); + void TestCutSpline(); private: // cppcheck-suppress unknownMacro