From 325a95bfbc0caf4f6ff4edbc7777646647fb0ac9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 11 May 2023 18:21:19 +0300 Subject: [PATCH] Redesign the notch angle. --- src/libs/vpatterndb/vpassmark.cpp | 127 +++++++++++++++--------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index c93f6c0ae..43e174ab8 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -73,66 +73,6 @@ auto GetSeamPassmarkSAPoint(const VPiecePassmarkData &passmarkData, const QVecto return needRollback ? PassmarkStatus::Rollback : PassmarkStatus::Common; } -//--------------------------------------------------------------------------------------------------------------------- -auto FixNotchPoint(const QVector &seamAllowance, const QPointF ¬chBase, QPointF *notch) -> bool -{ - bool fixed = true; - if (not VAbstractCurve::IsPointOnCurve(seamAllowance, *notch)) - { - fixed = false; - QLineF axis = QLineF(notchBase, *notch); - axis.setLength(ToPixel(50, Unit::Cm)); - const QVector points = VAbstractCurve::CurveIntersectLine(seamAllowance, axis); - - if (!points.empty()) - { - if (points.size() == 1) - { - *notch = points.at(0); - fixed = true; - } - else - { - QMap forward; - - for ( qint32 i = 0; i < points.size(); ++i ) - { - if (points.at(i) == notchBase) - { // Always seek unique intersection - continue; - } - - const QLineF length(notchBase, points.at(i)); - if (qAbs(length.angle() - axis.angle()) < 0.1) - { - forward.insert(length.length(), i); - } - } - - - // Closest point is not always want we need. First return point in forward direction if exists. - if (not forward.isEmpty()) - { - *notch = points.at(forward.first()); - fixed = true; - } - } - } - } - else - { // Fixing distortion - QLineF axis = QLineF(notchBase, *notch); - axis.setLength(axis.length() + accuracyPointOnLine * 10); - const QVector points = VAbstractCurve::CurveIntersectLine(seamAllowance, axis); - if (points.size() == 1) - { - *notch = ConstFirst(points); - } - } - - return fixed; -} - //--------------------------------------------------------------------------------------------------------------------- auto PointsToSegments(const QVector &points) -> QVector { @@ -240,6 +180,69 @@ auto PassmarkWidth(const VPiecePassmarkData &passmarkData, qreal width) -> qreal return passmarkData.passmarkSAPoint.GetPasskmarkWidth(); } +//--------------------------------------------------------------------------------------------------------------------- +auto FixNotchPoint(const QVector &seamAllowance, const VPiecePassmarkData &data, QPointF *notch) -> bool +{ + QLineF axis = QLineF(data.passmarkSAPoint, *notch); + + if (data.passmarkAngleType == PassmarkAngleType::Straightforward) + { + axis.setAngle(PassmarkAngle(data, axis.angle())); + } + + // Point is on seam allowance + if (VAbstractCurve::IsPointOnCurve(seamAllowance, *notch)) + { // Fixing distortion + axis.setLength(axis.length() + accuracyPointOnLine * 10); + const QVector points = VAbstractCurve::CurveIntersectLine(seamAllowance, axis); + if (points.size() == 1) + { + *notch = ConstFirst(points); + } + return true; + } + + // Point is not on seam allowance + axis.setLength(ToPixel(500, Unit::Cm)); + const QVector points = VAbstractCurve::CurveIntersectLine(seamAllowance, axis); + + if (points.empty()) + { + return false; + } + + if (points.size() == 1) + { + *notch = points.at(0); + return true; + } + + QMap forward; + + for (qint32 i = 0; i < points.size(); ++i) + { + if (points.at(i) == data.passmarkSAPoint) + { // Always seek unique intersection + continue; + } + + const QLineF length(data.passmarkSAPoint, points.at(i)); + if (qAbs(length.angle() - axis.angle()) < 0.1) + { + forward.insert(length.length(), i); + } + } + + // Closest point is not always want we need. First return point in forward direction if exists. + if (not forward.isEmpty()) + { + *notch = points.at(forward.first()); + return true; + } + + return false; +} + //--------------------------------------------------------------------------------------------------------------------- auto CreateOnePassmarkLines(const VPiecePassmarkData &passmarkData, const QLineF &line) -> QVector { @@ -781,7 +784,6 @@ auto VPassmark::PassmarkStraightforwardBaseLine(const QPointF &seamPassmarkSAPoi QLineF line = QLineF(seamPassmarkSAPoint, m_data.passmarkSAPoint); line.setLength(length); - line.setAngle(PassmarkAngle(m_data, line.angle())); return {line}; } @@ -952,7 +954,6 @@ auto VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const -> QVector< edge1.setAngle(edge1.angle() + edge1.angleTo(edge2)/2.); edge1.setLength(length); - edge1.setAngle(PassmarkAngle(m_data, edge1.angle())); return {edge1}; } @@ -1016,7 +1017,7 @@ auto VPassmark::SAPassmarkBaseLine(const QVector &seamAllowance, const ? rotatedSeamAllowance : seamAllowance; - if (not FixNotchPoint(path, m_data.passmarkSAPoint, &seamPassmarkSAPoint)) + if (not FixNotchPoint(path, m_data, &seamPassmarkSAPoint)) { const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Unable to fix a " "notch position.")