From d118ccb2180cac3f8a18b9685f2abaff6d554d2a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 15 Nov 2015 20:49:16 +0200 Subject: [PATCH] Fix for calculating more accurate unclosed seam allowance. --HG-- branch : develop --- src/libs/vlayout/vabstractdetail.cpp | 51 ++++++++++++++++++++++++++-- src/libs/vlayout/vabstractdetail.h | 1 + 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/libs/vlayout/vabstractdetail.cpp b/src/libs/vlayout/vabstractdetail.cpp index 11845cf92..a3aad5ab1 100644 --- a/src/libs/vlayout/vabstractdetail.cpp +++ b/src/libs/vlayout/vabstractdetail.cpp @@ -203,7 +203,7 @@ QVector VAbstractDetail::Equidistant(const QVector &points, co } else if (i == 0 && eqv == EquidistantType::OpenEquidistant) {//first point, polyline doesn't closed - ekvPoints.append(SingleParallelPoint(QLineF(p.at(0), p.at(1)), 90, width)); + ekvPoints.append(UnclosedEkvPoint(QLineF(p.at(0), p.at(1)), QLineF(p.at(0), p.at(p.size()-1)), width)); continue; } if (i == p.size()-1 && eqv == EquidistantType::CloseEquidistant) @@ -213,8 +213,9 @@ QVector VAbstractDetail::Equidistant(const QVector &points, co } else if (i == p.size()-1 && eqv == EquidistantType::OpenEquidistant) {//last point, polyline doesn't closed - ekvPoints.append(SingleParallelPoint(QLineF(p.at(p.size()-1), p.at(p.size()-2)), -90, width)); - continue; + ekvPoints.append(UnclosedEkvPoint(QLineF(p.at(p.size()-2), p.at(p.size()-1)), + QLineF(p.at(0), p.at(p.size()-1)), width)); + continue; } //points in the middle of polyline ekvPoints< VAbstractDetail::EkvPoint(const QLineF &line1, const QLineF &li return points; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief UnclosedEkvPoint helps find point of an unclosed seam allowance. One side of two lines should be equal. + * + * In case of the first seam allowance point equal should be the first point of the two lines. In case the last point - + * the last point of the two lines. + * + * @param line line of a seam allowance + * @param helpLine help line of the main path that cut unclosed seam allowance + * @param width seam allowance width + * @return seam allowance point + */ +QPointF VAbstractDetail::UnclosedEkvPoint(const QLineF &line, const QLineF &helpLine, const qreal &width) +{ + if (width <= 0) + { + return QPointF(); + } + + if (not (line.p2() == helpLine.p2() || line.p1() == helpLine.p1())) + { + qDebug()<<"Two points of two lines must be equal."; + return QPointF(); + } + + QPointF CrosPoint; + const QLineF bigLine = ParallelLine(line, width ); + QLineF::IntersectType type = bigLine.intersect( helpLine, &CrosPoint ); + switch (type) + { + case (QLineF::BoundedIntersection): + case (QLineF::UnboundedIntersection): + return CrosPoint; + break; + case (QLineF::NoIntersection): + /*If we have correct lines this means lines lie on a line.*/ + return bigLine.p2(); + break; + default: + break; + } + return QPointF(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParallelLine create parallel line. diff --git a/src/libs/vlayout/vabstractdetail.h b/src/libs/vlayout/vabstractdetail.h index 339d931bf..94168f7c2 100644 --- a/src/libs/vlayout/vabstractdetail.h +++ b/src/libs/vlayout/vabstractdetail.h @@ -75,6 +75,7 @@ private: static QVector CorrectEquidistantPoints(const QVector &points); static QVector CheckLoops(const QVector &points); static QVector EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width); + static QPointF UnclosedEkvPoint(const QLineF &line, const QLineF &helpLine, const qreal &width); static QLineF ParallelLine(const QLineF &line, qreal width ); static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); };