Refactoring. Redesign a container reversing method.

This commit is contained in:
Roman Telezhynskyi 2020-07-13 16:28:13 +03:00
parent acac092ff3
commit 9389cb546c
9 changed files with 35 additions and 77 deletions

View File

@ -87,7 +87,7 @@ QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QVector<QPointF> &points
QVector<QPointF> segment = points;
if (reverse)
{
segment = GetReversePoints(segment);
segment = Reverse(segment);
}
QPointF start = begin;
@ -217,9 +217,9 @@ QVector<QPointF> VAbstractCurve::FromBegin(const QVector<QPointF> &points, const
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VAbstractCurve::ToEnd(const QVector<QPointF> &points, const QPointF &end, bool *ok)
{
QVector<QPointF> reversed = GetReversePoints(points);
QVector<QPointF> reversed = Reverse(points);
reversed = FromBegin(reversed, end, ok);
return GetReversePoints(reversed);
return Reverse(reversed);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -33,6 +33,7 @@
#include "../vmisc/def.h"
#include "../vmisc/vmath.h"
#include "../vmisc/compatibility.h"
#include "../ifc/ifcdef.h"
#include "vabstractcurve.h"
#include "varc_p.h"
@ -307,7 +308,7 @@ QVector<QPointF> VArc::GetPoints() const
points << splPoints;
pStart = lineP4P3.p1();
}
return IsFlipped() ? VGObject::GetReversePoints(points) : points;
return IsFlipped() ? Reverse(points) : points;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -103,9 +103,6 @@ public:
static QPointF CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2);
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2,
qreal accuracy = accuracyPointOnLine);
template <typename T>
static QVector<T> GetReversePoints(const QVector<T> &points);
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
protected:
static QTransform FlippingMatrix(const QLineF &axis);
@ -115,29 +112,6 @@ private:
static int PointInCircle (const QPointF &p, const QPointF &center, qreal radius);
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetReversePoint return revers container of points.
* @param points container with points.
* @return reverced points.
*/
template <typename T>
QVector<T> VGObject::GetReversePoints(const QVector<T> &points)
{
if (points.isEmpty())
{
return points;
}
QVector<T> reversePoints(points.size());
qint32 j = 0;
for (qint32 i = points.size() - 1; i >= 0; --i)
{
reversePoints.replace(j, points.at(i));
++j;
}
return reversePoints;
}
Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE);
#endif // VGOBJECT_H

View File

@ -1755,7 +1755,7 @@ QVector<VRawSAPoint> VAbstractPiece::RollbackSeamAllowance(QVector<VRawSAPoint>
{
clipped.append(points.at(j));
}
points = VGObject::GetReversePoints(clipped);
points = Reverse(clipped);
*success = true;
break;
}

View File

@ -39,26 +39,6 @@ extern "C" {
#include "../vmisc/def.h"
#include "compatibility.h"
namespace
{
//---------------------------------------------------------------------------------------------------------------------
QStringList ReverseList(const QStringList &list)
{
if (list.isEmpty())
{
return list;
}
QVector<QString> reversedList(list.size());
qint32 j = 0;
for (qint32 i = list.size() - 1; i >= 0; --i)
{
reversedList.replace(j, list.at(i));
++j;
}
return ConvertToList(reversedList);
}
}
//---------------------------------------------------------------------------------------------------------------------
/* When deploying with AppImage based on OpenSuse, the ICU library has a hardcoded path to the icudt*.dat file.
* This prevents the library from using shared in memory data. There are few ways to resolve this issue. According
@ -112,8 +92,8 @@ QString AppImageRoot(const QString &applicationDir, const QString &defaultAppDir
return QString();
}
appSub = ReverseList(appSub);
defaultSub = ReverseList(defaultSub);
appSub = Reverse(appSub);
defaultSub = Reverse(defaultSub);
for (int i = 0; i < defaultSub.size(); ++i)
{
@ -124,7 +104,7 @@ QString AppImageRoot(const QString &applicationDir, const QString &defaultAppDir
}
QStringList rootSub = appSub.mid(defaultSub.size());
rootSub = ReverseList(rootSub);
rootSub = Reverse(rootSub);
return '/' + rootSub.join('/');
}

View File

@ -181,6 +181,25 @@ inline void Move(T &vector, int from, int to)
QT_WARNING_POP
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
T Reverse(const T &container)
{
if (container.isEmpty())
{
return container;
}
T reversed;
reversed.reserve(container.size());
qint32 j = 0;
for (qint32 i = container.size() - 1; i >= 0; --i)
{
reversed.replace(j, container.at(i));
++j;
}
return reversed;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename Cont, typename Input>
inline void AppendTo(Cont &container, const Input &input)

View File

@ -35,6 +35,7 @@
#include "../vgeometry/varc.h"
#include "vcontainer.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include "../ifc/exception/vexceptioninvalidnotch.h"
#include "../vlayout/testpath.h"
@ -780,7 +781,7 @@ QVector<VPieceNode> VPiece::GetUnitedPath(const VContainer *data) const
QVector<VPieceNode> customNodes = data->GetPiecePath(records.at(i).path).GetNodes();
if (records.at(i).reverse)
{
customNodes = VGObject::GetReversePoints(customNodes);
customNodes = Reverse(customNodes);
}
for (int j = 0; j < customNodes.size(); ++j)

View File

@ -33,6 +33,7 @@
#include "../vlayout/vabstractpiece.h"
#include "calculator.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include <qnumeric.h>
@ -391,8 +392,7 @@ QVector<QPointF> VPiecePath::PathPoints(const VContainer *data, const QVector<QP
if (IsLastToCuttingCountour())
{
QPointF lastConnection;
if (IntersectionWithCuttingCountour(cuttingPath, VGObject::GetReversePoints(points),
&lastConnection))
if (IntersectionWithCuttingCountour(cuttingPath, Reverse(points), &lastConnection))
{
extended.append(lastConnection);
}
@ -509,7 +509,7 @@ QVector<VSAPoint> VPiecePath::SeamAllowancePoints(const VContainer *data, qreal
if (reverse)
{
pointsEkv = VGObject::GetReversePoints(pointsEkv);
pointsEkv = Reverse(pointsEkv);
}
return pointsEkv;

View File

@ -45,29 +45,12 @@
namespace
{
//---------------------------------------------------------------------------------------------------------------------
QStringList ReverseList(const QStringList &list)
{
if (list.isEmpty())
{
return list;
}
QVector<QString> reversedList(list.size());
qint32 j = 0;
for (qint32 i = list.size() - 1; i >= 0; --i)
{
reversedList.replace(j, list.at(i));
++j;
}
return ConvertToList(reversedList);
}
//---------------------------------------------------------------------------------------------------------------------
QStringList SelectNumber(QStringList path, int number)
{
path = ReverseList(path);
path = Reverse(path);
QStringList subPath = path.mid(0, number);
return ReverseList(subPath);
return Reverse(subPath);
}
//---------------------------------------------------------------------------------------------------------------------