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();
if (contourPoints.isEmpty() == false)
{
points = CorrectAnticlockwise(points, contourPoints);
}
points = FromBegin(points, begin);
points = ToEnd(points, end);
return points;
@ -117,6 +122,23 @@ QVector<QPointF> VAbstractCurve::ToEnd(const QVector<QPointF> &points, const QPo
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
{

View File

@ -45,7 +45,8 @@ public:
VAbstractCurve& operator= (const VAbstractCurve &curve);
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 qreal GetLength() const =0;
@ -55,6 +56,8 @@ protected:
private:
QVector<QPointF> FromBegin(const QVector<QPointF> &points, const QPointF &begin) 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

View File

@ -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<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)
{
@ -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,
const VDetail &detail, int i)
void VEquidistant::AddContourPoints(const QVector<QPointF> &nodePoints, QVector<QPointF> &points,
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);
int lenReverse = GetLengthContour(points, reversedPoints);
int lenReverse = VGObject::GetLengthContour(points, reversedPoints);
if (len1 <= lenReverse)
{
points << nodePoints;

View File

@ -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<QPointF> &contour, const QVector<QPointF> &newPoints);
/**
* @brief biasPoints bias point.
* @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)
{
if (points.isEmpty())
@ -392,3 +397,23 @@ QVector<QPointF> VGObject::GetReversePoints(const QVector<QPointF> &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<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 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<QPointF> GetReversePoints(const QVector<QPointF> &points);
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
private:
QSharedDataPointer<VGObjectData> d;
};