Fixed disappearing curve in detail if path counterclockwise.

--HG--
branch : feature
This commit is contained in:
dismine 2014-12-16 15:33:00 +02:00
parent ad96323e29
commit 8fac8f87ae
6 changed files with 63 additions and 33 deletions

View File

@ -52,9 +52,14 @@ VAbstractCurve &VAbstractCurve::operator=(const VAbstractCurve &curve)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end) const QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end,
const QVector<QPointF> &contourPoints) const
{ {
QVector<QPointF> points = GetPoints(); QVector<QPointF> points = GetPoints();
if (contourPoints.isEmpty() == false)
{
points = CorrectAnticlockwise(points, contourPoints);
}
points = FromBegin(points, begin); points = FromBegin(points, begin);
points = ToEnd(points, end); points = ToEnd(points, end);
return points; return points;
@ -117,6 +122,23 @@ QVector<QPointF> VAbstractCurve::ToEnd(const QVector<QPointF> &points, const QPo
return GetReversePoints(reversed); return GetReversePoints(reversed);
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VAbstractCurve::CorrectAnticlockwise(const QVector<QPointF> &points,
const QVector<QPointF> &contourPoints) const
{
const int len1 = GetLengthContour(contourPoints, points);
const QVector<QPointF> reversedPoints = GetReversePoints(points);
const int lenReverse = GetLengthContour(contourPoints, reversedPoints);
if (len1 <= lenReverse)
{
return points;
}
else
{
return reversedPoints;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPainterPath VAbstractCurve::GetPath(PathDirection direction) const QPainterPath VAbstractCurve::GetPath(PathDirection direction) const
{ {

View File

@ -45,7 +45,8 @@ public:
VAbstractCurve& operator= (const VAbstractCurve &curve); VAbstractCurve& operator= (const VAbstractCurve &curve);
virtual QVector<QPointF> GetPoints() const =0; virtual QVector<QPointF> GetPoints() const =0;
QVector<QPointF> GetSegmentPoints(const QPointF &begin, const QPointF &end) const; QVector<QPointF> GetSegmentPoints(const QPointF &begin, const QPointF &end,
const QVector<QPointF> &contourPoints = QVector<QPointF>()) const;
virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const;
virtual qreal GetLength() const =0; virtual qreal GetLength() const =0;
@ -55,6 +56,8 @@ protected:
private: private:
QVector<QPointF> FromBegin(const QVector<QPointF> &points, const QPointF &begin) const; QVector<QPointF> FromBegin(const QVector<QPointF> &points, const QPointF &begin) const;
QVector<QPointF> ToEnd(const QVector<QPointF> &points, const QPointF &end) const; QVector<QPointF> ToEnd(const QVector<QPointF> &points, const QPointF &end) const;
QVector<QPointF> CorrectAnticlockwise(const QVector<QPointF> &points,
const QVector<QPointF> &contourPoints) const;
}; };
#endif // VABSTRACTCURVE_H #endif // VABSTRACTCURVE_H

View File

@ -77,7 +77,7 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail) const
const QPointF begin = StartSegment(detail, i); const QPointF begin = StartSegment(detail, i);
const QPointF end = EndSegment(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; break;
default: default:
@ -162,20 +162,6 @@ QPointF VEquidistant::EndSegment(const VDetail &detail, const int &i) const
return end; return end;
} }
//---------------------------------------------------------------------------------------------------------------------
int VEquidistant::GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints)
{
qreal length = 0;
QVector<QPointF> 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<QPointF> VEquidistant::biasPoints(const QVector<QPointF> &points, const qreal &mx, const qreal &my) QVector<QPointF> VEquidistant::biasPoints(const QVector<QPointF> &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<QPointF> &nodePoints, QVector<QPointF> &points, QVector<QPointF> &pointsEkv, void VEquidistant::AddContourPoints(const QVector<QPointF> &nodePoints, QVector<QPointF> &points,
const VDetail &detail, int i) QVector<QPointF> &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<QPointF> reversedPoints = VGObject::GetReversePoints(nodePoints); QVector<QPointF> reversedPoints = VGObject::GetReversePoints(nodePoints);
int lenReverse = GetLengthContour(points, reversedPoints); int lenReverse = VGObject::GetLengthContour(points, reversedPoints);
if (len1 <= lenReverse) if (len1 <= lenReverse)
{ {
points << nodePoints; points << nodePoints;

View File

@ -54,13 +54,6 @@ public:
private: private:
Q_DISABLE_COPY(VEquidistant) Q_DISABLE_COPY(VEquidistant)
const VContainer *data; 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<QPointF> &contour, const QVector<QPointF> &newPoints);
/** /**
* @brief biasPoints bias point. * @brief biasPoints bias point.
* @param points vector of points. * @param points vector of points.

View File

@ -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<QPointF> VGObject::GetReversePoints(const QVector<QPointF> &points) QVector<QPointF> VGObject::GetReversePoints(const QVector<QPointF> &points)
{ {
if (points.isEmpty()) if (points.isEmpty())
@ -392,3 +397,23 @@ QVector<QPointF> VGObject::GetReversePoints(const QVector<QPointF> &points)
} }
return reversePoints; 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<QPointF> &contour, const QVector<QPointF> &newPoints)
{
qreal length = 0;
QVector<QPointF> 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);
}

View File

@ -79,12 +79,9 @@ public:
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); 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 PointInSegment (const QPointF &t, const QPointF &p1, const QPointF &p2);
static bool PointInBox (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<QPointF> GetReversePoints(const QVector<QPointF> &points); static QVector<QPointF> GetReversePoints(const QVector<QPointF> &points);
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
private: private:
QSharedDataPointer<VGObjectData> d; QSharedDataPointer<VGObjectData> d;
}; };