From 0efbe1745c92f6e6df5774cf21a9c502e13ff05c Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 12 Dec 2014 14:35:54 +0200 Subject: [PATCH] Fixed issue #198. --HG-- branch : develop --- src/app/geometry/vequidistant.cpp | 92 +++++++++++-------------------- src/app/geometry/vequidistant.h | 5 +- 2 files changed, 37 insertions(+), 60 deletions(-) diff --git a/src/app/geometry/vequidistant.cpp b/src/app/geometry/vequidistant.cpp index ec0bdcf90..a5547de35 100644 --- a/src/app/geometry/vequidistant.cpp +++ b/src/app/geometry/vequidistant.cpp @@ -35,6 +35,7 @@ #include #include #include "../container/vcontainer.h" +#include //--------------------------------------------------------------------------------------------------------------------- QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer *data) const @@ -63,73 +64,21 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer case (Tool::NodeArc): { const QSharedPointer arc = data->GeometricObject(detail.at(i).getId()); - qreal len1 = GetLengthContour(points, arc->GetPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(arc->GetPoints())); - if (len1 <= lenReverse) - { - points << arc->GetPoints(); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(arc->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); - } - } - else - { - points << GetReversePoint(arc->GetPoints()); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(GetReversePoint(arc->GetPoints()), detail.at(i).getMx(), - detail.at(i).getMy()); - } - } + // Detail points clockwise, but arc we draw counterclockwise. Main contour need reverse. + const QVector reversedPoints = GetReversePoint(arc->GetPoints()); + AddContour(reversedPoints, points, pointsEkv, detail, i); } break; case (Tool::NodeSpline): { const QSharedPointer spline = data->GeometricObject(detail.at(i).getId()); - qreal len1 = GetLengthContour(points, spline->GetPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(spline->GetPoints())); - if (len1 <= lenReverse) - { - points << spline->GetPoints(); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(spline->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); - } - } - else - { - points << GetReversePoint(spline->GetPoints()); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(GetReversePoint(spline->GetPoints()), detail.at(i).getMx(), - detail.at(i).getMy()); - } - } + AddContour(spline->GetPoints(), points, pointsEkv, detail, i); } break; case (Tool::NodeSplinePath): { const QSharedPointer splinePath = data->GeometricObject(detail.at(i).getId()); - qreal len1 = GetLengthContour(points, splinePath->GetPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPoints())); - if (len1 <= lenReverse) - { - points << splinePath->GetPoints(); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(splinePath->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); - } - } - else - { - points << GetReversePoint(splinePath->GetPoints()); - if (detail.getSeamAllowance() == true) - { - pointsEkv << biasPoints(GetReversePoint(splinePath->GetPoints()), detail.at(i).getMx(), - detail.at(i).getMy()); - } - } + AddContour(splinePath->GetPoints(), points, pointsEkv, detail, i); } break; default: @@ -167,7 +116,7 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer } //--------------------------------------------------------------------------------------------------------------------- -qreal VEquidistant::GetLengthContour(const QVector &contour, const QVector &newPoints) +int VEquidistant::GetLengthContour(const QVector &contour, const QVector &newPoints) { qreal length = 0; QVector points; @@ -177,7 +126,7 @@ qreal VEquidistant::GetLengthContour(const QVector &contour, const QVec QLineF line(points.at(i), points.at(i+1)); length += line.length(); } - return length; + return qFloor(length); } //--------------------------------------------------------------------------------------------------------------------- @@ -451,3 +400,28 @@ QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle pLine.setLength( width ); return pLine.p2(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VEquidistant::AddContour(const QVector &nodePoints, QVector &points, QVector &pointsEkv, + const VDetail &detail, int i) +{ + int len1 = GetLengthContour(points, nodePoints); + QVector reversedPoints = GetReversePoint(nodePoints); + int lenReverse = GetLengthContour(points, reversedPoints); + if (len1 <= lenReverse) + { + points << nodePoints; + if (detail.getSeamAllowance() == true) + { + pointsEkv << biasPoints(nodePoints, detail.at(i).getMx(), detail.at(i).getMy()); + } + } + else + { + points << reversedPoints; + if (detail.getSeamAllowance() == true) + { + pointsEkv << biasPoints(reversedPoints, detail.at(i).getMx(), detail.at(i).getMy()); + } + } +} diff --git a/src/app/geometry/vequidistant.h b/src/app/geometry/vequidistant.h index 940adca02..8d89bc678 100644 --- a/src/app/geometry/vequidistant.h +++ b/src/app/geometry/vequidistant.h @@ -56,7 +56,7 @@ private: * @param newPoints point whos we try to add to contour. * @return length length of contour. */ - static qreal GetLengthContour(const QVector &contour, const QVector &newPoints); + static int GetLengthContour(const QVector &contour, const QVector &newPoints); /** * @brief biasPoints bias point. * @param points vector of points. @@ -114,6 +114,9 @@ private: * @return point of parallel line. */ static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); + + static void AddContour(const QVector &nodePoints, QVector &points, + QVector &pointsEkv, const VDetail &detail, int i); }; #endif // VEQUIDISTANT_H