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; QVector<QPointF> segment = points;
if (reverse) if (reverse)
{ {
segment = GetReversePoints(segment); segment = Reverse(segment);
} }
QPointF start = begin; 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> 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); reversed = FromBegin(reversed, end, ok);
return GetReversePoints(reversed); return Reverse(reversed);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -33,6 +33,7 @@
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
#include "../vmisc/compatibility.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "vabstractcurve.h" #include "vabstractcurve.h"
#include "varc_p.h" #include "varc_p.h"
@ -307,7 +308,7 @@ QVector<QPointF> VArc::GetPoints() const
points << splPoints; points << splPoints;
pStart = lineP4P3.p1(); 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 QPointF CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2);
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2, static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2,
qreal accuracy = accuracyPointOnLine); 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); static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
protected: protected:
static QTransform FlippingMatrix(const QLineF &axis); static QTransform FlippingMatrix(const QLineF &axis);
@ -115,29 +112,6 @@ private:
static int PointInCircle (const QPointF &p, const QPointF &center, qreal radius); 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); Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE);
#endif // VGOBJECT_H #endif // VGOBJECT_H

View file

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

View file

@ -39,26 +39,6 @@ extern "C" {
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "compatibility.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. /* 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 * 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(); return QString();
} }
appSub = ReverseList(appSub); appSub = Reverse(appSub);
defaultSub = ReverseList(defaultSub); defaultSub = Reverse(defaultSub);
for (int i = 0; i < defaultSub.size(); ++i) 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()); QStringList rootSub = appSub.mid(defaultSub.size());
rootSub = ReverseList(rootSub); rootSub = Reverse(rootSub);
return '/' + rootSub.join('/'); return '/' + rootSub.join('/');
} }

View file

@ -181,6 +181,25 @@ inline void Move(T &vector, int from, int to)
QT_WARNING_POP 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> template <typename Cont, typename Input>
inline void AppendTo(Cont &container, const Input &input) inline void AppendTo(Cont &container, const Input &input)

View file

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

View file

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

View file

@ -45,29 +45,12 @@
namespace 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) QStringList SelectNumber(QStringList path, int number)
{ {
path = ReverseList(path); path = Reverse(path);
QStringList subPath = path.mid(0, number); QStringList subPath = path.mid(0, number);
return ReverseList(subPath); return Reverse(subPath);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------