From 8fac8f87ae2e0d033fc39cead6cea9aaf161aca0 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 16 Dec 2014 15:33:00 +0200 Subject: [PATCH] Fixed disappearing curve in detail if path counterclockwise. --HG-- branch : feature --- src/app/geometry/vabstractcurve.cpp | 24 +++++++++++++++++++++++- src/app/geometry/vabstractcurve.h | 5 ++++- src/app/geometry/vequidistant.cpp | 28 +++++++++------------------- src/app/geometry/vequidistant.h | 7 ------- src/app/geometry/vgobject.cpp | 25 +++++++++++++++++++++++++ src/app/geometry/vgobject.h | 7 ++----- 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/app/geometry/vabstractcurve.cpp b/src/app/geometry/vabstractcurve.cpp index 2f863d21f..e483e430e 100644 --- a/src/app/geometry/vabstractcurve.cpp +++ b/src/app/geometry/vabstractcurve.cpp @@ -52,9 +52,14 @@ VAbstractCurve &VAbstractCurve::operator=(const VAbstractCurve &curve) } //--------------------------------------------------------------------------------------------------------------------- -QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end) const +QVector VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end, + const QVector &contourPoints) const { QVector points = GetPoints(); + if (contourPoints.isEmpty() == false) + { + points = CorrectAnticlockwise(points, contourPoints); + } points = FromBegin(points, begin); points = ToEnd(points, end); return points; @@ -117,6 +122,23 @@ QVector VAbstractCurve::ToEnd(const QVector &points, const QPo return GetReversePoints(reversed); } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractCurve::CorrectAnticlockwise(const QVector &points, + const QVector &contourPoints) const +{ + const int len1 = GetLengthContour(contourPoints, points); + const QVector reversedPoints = GetReversePoints(points); + const int lenReverse = GetLengthContour(contourPoints, reversedPoints); + if (len1 <= lenReverse) + { + return points; + } + else + { + return reversedPoints; + } +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VAbstractCurve::GetPath(PathDirection direction) const { diff --git a/src/app/geometry/vabstractcurve.h b/src/app/geometry/vabstractcurve.h index b0bc65cce..9a6fcaefb 100644 --- a/src/app/geometry/vabstractcurve.h +++ b/src/app/geometry/vabstractcurve.h @@ -45,7 +45,8 @@ public: VAbstractCurve& operator= (const VAbstractCurve &curve); virtual QVector GetPoints() const =0; - QVector GetSegmentPoints(const QPointF &begin, const QPointF &end) const; + QVector GetSegmentPoints(const QPointF &begin, const QPointF &end, + const QVector &contourPoints = QVector()) const; virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; virtual qreal GetLength() const =0; @@ -55,6 +56,8 @@ protected: private: QVector FromBegin(const QVector &points, const QPointF &begin) const; QVector ToEnd(const QVector &points, const QPointF &end) const; + QVector CorrectAnticlockwise(const QVector &points, + const QVector &contourPoints) const; }; #endif // VABSTRACTCURVE_H diff --git a/src/app/geometry/vequidistant.cpp b/src/app/geometry/vequidistant.cpp index f57bba431..edc001ecd 100644 --- a/src/app/geometry/vequidistant.cpp +++ b/src/app/geometry/vequidistant.cpp @@ -77,7 +77,7 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail) const const QPointF begin = StartSegment(detail, i); const QPointF end = EndSegment(detail, i); - AddContourPoints(curve->GetSegmentPoints(begin, end), points, pointsEkv, detail, i); + AddContourPoints(curve->GetSegmentPoints(begin, end, points), points, pointsEkv, detail, i); } break; default: @@ -162,20 +162,6 @@ QPointF VEquidistant::EndSegment(const VDetail &detail, const int &i) const return end; } -//--------------------------------------------------------------------------------------------------------------------- -int VEquidistant::GetLengthContour(const QVector &contour, const QVector &newPoints) -{ - qreal length = 0; - QVector points; - points << contour << newPoints; - for (qint32 i = 0; i < points.size()-1; ++i) - { - QLineF line(points.at(i), points.at(i+1)); - length += line.length(); - } - return qFloor(length); -} - //--------------------------------------------------------------------------------------------------------------------- QVector VEquidistant::biasPoints(const QVector &points, const qreal &mx, const qreal &my) { @@ -437,12 +423,16 @@ QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle } //--------------------------------------------------------------------------------------------------------------------- -void VEquidistant::AddContourPoints(const QVector &nodePoints, QVector &points, QVector &pointsEkv, - const VDetail &detail, int i) +void VEquidistant::AddContourPoints(const QVector &nodePoints, QVector &points, + QVector &pointsEkv, const VDetail &detail, int i) { - int len1 = GetLengthContour(points, nodePoints); + /* + * Even if we made correction anticlockwise in method VAbstractCurve::GetSegmentPoints i decided left this check + * also here. I think it will make code more bullet proof. If it will slowdown creation contour delete correction. + */ + int len1 = VGObject::GetLengthContour(points, nodePoints); QVector reversedPoints = VGObject::GetReversePoints(nodePoints); - int lenReverse = GetLengthContour(points, reversedPoints); + int lenReverse = VGObject::GetLengthContour(points, reversedPoints); if (len1 <= lenReverse) { points << nodePoints; diff --git a/src/app/geometry/vequidistant.h b/src/app/geometry/vequidistant.h index a6eda3376..4af0ef7ed 100644 --- a/src/app/geometry/vequidistant.h +++ b/src/app/geometry/vequidistant.h @@ -54,13 +54,6 @@ public: private: Q_DISABLE_COPY(VEquidistant) const VContainer *data; - /** - * @brief GetLengthContour return length of contour. - * @param contour container with points of contour. - * @param newPoints point whos we try to add to contour. - * @return length length of contour. - */ - static int GetLengthContour(const QVector &contour, const QVector &newPoints); /** * @brief biasPoints bias point. * @param points vector of points. diff --git a/src/app/geometry/vgobject.cpp b/src/app/geometry/vgobject.cpp index 143b08e97..a191354c3 100644 --- a/src/app/geometry/vgobject.cpp +++ b/src/app/geometry/vgobject.cpp @@ -379,6 +379,11 @@ bool VGObject::PointInBox(const QPointF &t, const QPointF &p1, const QPointF &p2 } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetReversePoint return revers container of points. + * @param points container with points. + * @return reverced points. + */ QVector VGObject::GetReversePoints(const QVector &points) { if (points.isEmpty()) @@ -392,3 +397,23 @@ QVector VGObject::GetReversePoints(const QVector &points) } return reversePoints; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetLengthContour return length of contour. + * @param contour container with points of contour. + * @param newPoints point whos we try to add to contour. + * @return length length of contour. + */ +int VGObject::GetLengthContour(const QVector &contour, const QVector &newPoints) +{ + qreal length = 0; + QVector points; + points << contour << newPoints; + for (qint32 i = 0; i < points.size()-1; ++i) + { + QLineF line(points.at(i), points.at(i+1)); + length += line.length(); + } + return qFloor(length); +} diff --git a/src/app/geometry/vgobject.h b/src/app/geometry/vgobject.h index 15af49cd9..8c91fd54f 100644 --- a/src/app/geometry/vgobject.h +++ b/src/app/geometry/vgobject.h @@ -79,12 +79,9 @@ public: static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); static bool PointInSegment (const QPointF &t, const QPointF &p1, const QPointF &p2); static bool PointInBox (const QPointF &t, const QPointF &p1, const QPointF &p2); - /** - * @brief GetReversePoint return revers container of points. - * @param points container with points. - * @return reverced points. - */ + static QVector GetReversePoints(const QVector &points); + static int GetLengthContour(const QVector &contour, const QVector &newPoints); private: QSharedDataPointer d; };