From 1a9af78befe6b54aeb52f3b1248f8adac9d2b364 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 13 Nov 2016 11:23:04 +0200 Subject: [PATCH] Fix seam allowance bug. Fix reverse dart case. --HG-- branch : feature --- src/libs/vlayout/vabstractpiece.cpp | 69 +++++++++++++++++++++++++---- src/libs/vlayout/vabstractpiece.h | 3 ++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 6907634f3..9661825ce 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -323,6 +323,31 @@ QVector VAbstractPiece::CheckLoops(const QVector &points) return ekvPoints; } +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR qreal VAbstractPiece::PointPosition(const QPointF &p, const QLineF &line) +{ + return (line.p2().x() - line.p1().x()) * (p.y() - line.p1().y()) - + (line.p2().y() - line.p1().y()) * (p.x() - line.p1().x()); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractPiece::MaxLocalSA(const VSAPoint &p, qreal width) +{ + qreal w1 = qApp->toPixel(p.GetSAAfter()); + if (w1 < 0) + { + w1 = width; + } + + qreal w2 = qApp->toPixel(p.GetSABefore()); + if (w2 < 0) + { + w2 = width; + } + + return qMax(w1, w2); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief EkvPoint return vector of points of equidistant two lines. Last point of two lines must be equal. @@ -356,17 +381,18 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin break; case (QLineF::UnboundedIntersection): { + const qreal localWidth = MaxLocalSA(p2Line1, width); QLineF line( p2Line1, CrosPoint ); const int angle1 = BisectorAngle(p1Line1, p2Line1, p1Line2); const int angle2 = BisectorAngle(bigLine1.p1(), CrosPoint, bigLine2.p2()); - if (qAbs(angle1 - angle2) < 180)// Go in a same direction + if (qAbs(angle1 - angle2) < 90)// Go in a same direction {//Regular equdistant case const qreal length = line.length(); - if (length > width*2.4) + if (length > localWidth*2.4) { // Cutting too long a cut angle - line.setLength(width); // Not sure about width value here + line.setLength(localWidth); // Not sure about width value here QLineF cutLine(line.p2(), CrosPoint); // Cut line is a perpendicular cutLine.setLength(length); // Decided take this length @@ -395,13 +421,30 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin } } else - {// Dart. Ignore if going outside of equdistant - const QLineF bigEdge = ParallelLine(p1Line1, p1Line2, width ); - QPointF px; - const QLineF::IntersectType type = bigEdge.intersect(line, &px); - if (type != QLineF::BoundedIntersection) + { + QLineF bisector(p2Line1, p1Line1); + bisector.setAngle(angle1); + + const qreal result1 = PointPosition(bisector.p2(), QLineF(p1Line1, p2Line1)); + const qreal result2 = PointPosition(bisector.p2(), QLineF(p2Line2, p1Line2)); + + if (result1 <=0 && result2 <= 0) { - points.append(CrosPoint); + // Dart. Ignore if going outside of equdistant + const QLineF bigEdge = ParallelLine(p1Line1, p1Line2, localWidth ); + QPointF px; + const QLineF::IntersectType type = bigEdge.intersect(line, &px); + if (type != QLineF::BoundedIntersection) + { + points.append(CrosPoint); + return points; + } + } + else + { + const QLineF bigEdge = ParallelLine(bigLine1.p2(), bigLine2.p1(), localWidth ); + points.append(bigEdge.p1()); + points.append(bigEdge.p2()); return points; } } @@ -438,6 +481,14 @@ QLineF VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qrea return paralel; } +//--------------------------------------------------------------------------------------------------------------------- +QLineF VAbstractPiece::ParallelLine(const QPointF &p1, const QPointF &p2, qreal width) +{ + const QLineF paralel = QLineF(SingleParallelPoint(p1, p2, 90, width), + SingleParallelPoint(p2, p1, -90, width)); + return paralel; +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VAbstractPiece::SingleParallelPoint(const QPointF &p1, const QPointF &p2, qreal angle, qreal width) { diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 579f46965..2433b8eac 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -141,9 +141,12 @@ protected: private: QSharedDataPointer d; + static Q_DECL_CONSTEXPR qreal PointPosition(const QPointF &p, const QLineF &line); + static qreal MaxLocalSA(const VSAPoint &p, qreal width); static QVector EkvPoint(const VSAPoint &p1Line1, const VSAPoint &p2Line1, const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width); static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width); + static QLineF ParallelLine(const QPointF &p1, const QPointF &p2, qreal width); static QPointF SingleParallelPoint(const QPointF &p1, const QPointF &p2, qreal angle, qreal width); static int BisectorAngle(const QPointF &p1, const QPointF &p2, const QPointF &p3); };