Flipping VSpline, VSplinePath, VEllipticalArc, VCubicBezierPath and
VCubicBezier. --HG-- branch : feature
This commit is contained in:
parent
800181e867
commit
fe56607d7d
|
@ -78,6 +78,18 @@ VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, con
|
|||
return curve;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const
|
||||
{
|
||||
const VPointF p1 = GetP1().Flip(axis);
|
||||
const VPointF p2 = GetP2().Flip(axis);
|
||||
const VPointF p3 = GetP3().Flip(axis);
|
||||
const VPointF p4 = GetP4().Flip(axis);
|
||||
VCubicBezier curve(p1, p2, p3, p4);
|
||||
curve.setName(name() + prefix);
|
||||
return curve;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VCubicBezier::~VCubicBezier()
|
||||
{
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
Draw mode = Draw::Calculation);
|
||||
VCubicBezier &operator=(const VCubicBezier &curve);
|
||||
VCubicBezier Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
|
||||
VCubicBezier Flip(const QLineF &axis, const QString &prefix = QString()) const;
|
||||
virtual ~VCubicBezier();
|
||||
|
||||
virtual VPointF GetP1() const Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -91,6 +91,19 @@ VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degr
|
|||
return curve;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefix) const
|
||||
{
|
||||
const QVector<VPointF> points = GetCubicPath();
|
||||
VCubicBezierPath curve;
|
||||
for(int i=0; i < points.size(); ++i)
|
||||
{
|
||||
curve.append(points.at(i).Flip(axis));
|
||||
}
|
||||
curve.setName(name() + prefix);
|
||||
return curve;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VCubicBezierPath::~VCubicBezierPath()
|
||||
{
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
VCubicBezierPath(const QVector<VPointF> &points, quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||
VCubicBezierPath &operator=(const VCubicBezierPath &curve);
|
||||
VCubicBezierPath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
|
||||
VCubicBezierPath Flip(const QLineF &axis, const QString &prefix = QString()) const;
|
||||
virtual ~VCubicBezierPath();
|
||||
|
||||
VPointF &operator[](int indx);
|
||||
|
|
|
@ -134,6 +134,20 @@ VEllipticalArc VEllipticalArc::Rotate(const QPointF &originPoint, qreal degrees,
|
|||
return elArc;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const
|
||||
{
|
||||
const VPointF center = GetCenter().Flip(axis);
|
||||
const QPointF p1 = VPointF::FlipPF(axis, GetP1());
|
||||
const QPointF p2 = VPointF::FlipPF(axis, GetP2());
|
||||
const qreal f1 = QLineF(center, p1).angle() - GetRotationAngle();
|
||||
const qreal f2 = QLineF(center, p2).angle() - GetRotationAngle();
|
||||
VEllipticalArc elArc(center, GetRadius1(), GetRadius2(), f1, f2, GetRotationAngle());
|
||||
elArc.setName(name() + prefix);
|
||||
elArc.SetFlipped(true);
|
||||
return elArc;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VEllipticalArc::~VEllipticalArc()
|
||||
{}
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
|
||||
VEllipticalArc& operator= (const VEllipticalArc &arc);
|
||||
VEllipticalArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
|
||||
VEllipticalArc Flip(const QLineF &axis, const QString &prefix = QString()) const;
|
||||
|
||||
virtual ~VEllipticalArc() Q_DECL_OVERRIDE;
|
||||
|
||||
|
@ -99,6 +100,7 @@ private:
|
|||
static int GetQuadransRad(qreal &rad);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(VEllipticalArc)
|
||||
Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE);
|
||||
|
||||
#endif // VELLIPTICALARC_H
|
||||
|
|
|
@ -126,6 +126,20 @@ VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString
|
|||
return spl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const
|
||||
{
|
||||
const VPointF p1 = GetP1().Flip(axis);
|
||||
const VPointF p4 = GetP4().Flip(axis);
|
||||
|
||||
const QPointF p2 = VPointF::FlipPF(axis, GetP2());
|
||||
const QPointF p3 = VPointF::FlipPF(axis, GetP3());
|
||||
|
||||
VSpline spl(p1, p2, p3, p4);
|
||||
spl.setName(name() + prefix);
|
||||
return spl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VSpline::~VSpline()
|
||||
{}
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length,
|
||||
const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||
VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
|
||||
VSpline Flip(const QLineF &axis, const QString &prefix = QString()) const;
|
||||
virtual ~VSpline();
|
||||
VSpline &operator=(const VSpline &spl);
|
||||
|
||||
|
|
|
@ -122,6 +122,28 @@ VSplinePath VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const
|
|||
return splPath;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VSplinePath VSplinePath::Flip(const QLineF &axis, const QString &prefix) const
|
||||
{
|
||||
QVector<VSplinePoint> newPoints(CountPoints());
|
||||
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
||||
{
|
||||
const VSpline spl = GetSpline(i).Flip(axis);
|
||||
|
||||
newPoints[i-1].SetP(spl.GetP1());
|
||||
newPoints[i-1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula());
|
||||
newPoints[i-1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
||||
|
||||
newPoints[i].SetP(spl.GetP4());
|
||||
newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula());
|
||||
newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
||||
}
|
||||
|
||||
VSplinePath splPath(newPoints);
|
||||
splPath.setName(name() + prefix);
|
||||
return splPath;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VSplinePath::~VSplinePath()
|
||||
{}
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
VSplinePath(const QVector<VSplinePoint> &points, quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||
VSplinePath(const VSplinePath& splPath);
|
||||
VSplinePath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
|
||||
VSplinePath Flip(const QLineF &axis, const QString &prefix = QString()) const;
|
||||
virtual ~VSplinePath() Q_DECL_OVERRIDE;
|
||||
|
||||
VSplinePath &operator=(const VSplinePath &path);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../vlayout/vabstractdetail.h"
|
||||
#include "../vmisc/logging.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QtTest>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -455,3 +456,43 @@ void TST_VEllipticalArc::TestRotation()
|
|||
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
|
||||
QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VEllipticalArc::TestFlip_data()
|
||||
{
|
||||
QTest::addColumn<VEllipticalArc>("elArc");
|
||||
QTest::addColumn<QLineF>("axis");
|
||||
QTest::addColumn<QString>("prefix");
|
||||
|
||||
const VEllipticalArc elArc(QPointF(), 10., 20.0, 1., 91., 0.);
|
||||
|
||||
QLineF axis(QPointF(600, 30), QPointF(600, 1800));
|
||||
|
||||
QTest::newRow("Vertical axis") << elArc << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(600, 30), QPointF(1200, 30));
|
||||
|
||||
QTest::newRow("Horizontal axis") << elArc << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(600, 30), QPointF(600, 1800));
|
||||
axis.setAngle(45);
|
||||
|
||||
QTest::newRow("Diagonal axis") << elArc << axis << "a2";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VEllipticalArc::TestFlip()
|
||||
{
|
||||
QFETCH(VEllipticalArc, elArc);
|
||||
QFETCH(QLineF, axis);
|
||||
QFETCH(QString, prefix);
|
||||
|
||||
const VEllipticalArc res = elArc.Flip(axis, prefix);
|
||||
|
||||
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
|
||||
QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg));
|
||||
|
||||
QCOMPARE(qRound(elArc.GetLength()*-1), qRound(res.GetLength()));
|
||||
QCOMPARE(elArc.GetRadius1(), res.GetRadius1());
|
||||
QCOMPARE(elArc.GetRadius2(), res.GetRadius2());
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ private slots:
|
|||
void TestGetPoints4();
|
||||
void TestRotation_data();
|
||||
void TestRotation();
|
||||
void TestFlip_data();
|
||||
void TestFlip();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TST_VEllipticalArc)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "tst_vspline.h"
|
||||
#include "../vgeometry/vspline.h"
|
||||
#include "../vmisc/logging.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
|
@ -388,6 +389,49 @@ void TST_VSpline::TestLengthByPoint()
|
|||
QVERIFY(qAbs(resLength - length) < ToPixel(0.5, Unit::Mm));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VSpline::TestFlip_data()
|
||||
{
|
||||
QTest::addColumn<VSpline>("spl");
|
||||
QTest::addColumn<QLineF>("axis");
|
||||
QTest::addColumn<QString>("prefix");
|
||||
|
||||
VPointF p1(1168.8582803149607, 39.999874015748034, "p1", 5.0000125984251973, 9.9999874015748045);
|
||||
VPointF p4(681.33729132409951, 1815.7969526662778, "p4", 5.0000125984251973, 9.9999874015748045);
|
||||
|
||||
VSpline spl(p1, p4, 229.381, 41.6325, 0.96294100000000005, 1.00054, 1);
|
||||
|
||||
QLineF axis(QPointF(600, 30), QPointF(600, 1800));
|
||||
|
||||
QTest::newRow("Vertical axis") << spl << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(600, 30), QPointF(1200, 30));
|
||||
|
||||
QTest::newRow("Horizontal axis") << spl << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(600, 30), QPointF(600, 1800));
|
||||
axis.setAngle(45);
|
||||
|
||||
QTest::newRow("Diagonal axis") << spl << axis << "a2";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VSpline::TestFlip()
|
||||
{
|
||||
QFETCH(VSpline, spl);
|
||||
QFETCH(QLineF, axis);
|
||||
QFETCH(QString, prefix);
|
||||
|
||||
const VSpline res = spl.Flip(axis, prefix);
|
||||
|
||||
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
|
||||
QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg));
|
||||
|
||||
QCOMPARE(spl.GetLength(), res.GetLength());
|
||||
QCOMPARE(spl.GetC1Length(), res.GetC1Length());
|
||||
QCOMPARE(spl.GetC2Length(), res.GetC2Length());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const
|
||||
{
|
||||
|
|
|
@ -51,6 +51,8 @@ private slots:
|
|||
void TestParametrT();
|
||||
void TestLengthByPoint_data();
|
||||
void TestLengthByPoint();
|
||||
void TestFlip_data();
|
||||
void TestFlip();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TST_VSpline)
|
||||
|
|
|
@ -135,3 +135,64 @@ void TST_VSplinePath::TestRotation()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VSplinePath::TestFlip_data()
|
||||
{
|
||||
QTest::addColumn<QVector<VSplinePoint>>("originPoints");
|
||||
QTest::addColumn<QLineF>("axis");
|
||||
QTest::addColumn<QString>("prefix");
|
||||
|
||||
QVector<VSplinePoint> originPoints;
|
||||
|
||||
{
|
||||
VPointF pSpline(30, 39.999874015748034, "X", 5.0000125984251973, 9.9999874015748045);
|
||||
VSplinePoint p(pSpline, 89.208600000000004, "89.2086", 269.20859999999999, "269.209", 0, "0",
|
||||
153.33618897637794, "4.05702");
|
||||
originPoints.append(p);
|
||||
}
|
||||
|
||||
{
|
||||
VPointF pSpline(198.77104389529981, 249.18158602595835, "X", 5.0000125984251973, 9.9999874015748045);
|
||||
VSplinePoint p(pSpline, 146.43199999999999, "146.432", 326.43200000000002, "326.432",
|
||||
36.387590551181106, "0.962755", 60.978897637795278, "1.6134");
|
||||
originPoints.append(p);
|
||||
}
|
||||
|
||||
{
|
||||
VPointF pSpline(820.42771653543309, 417.95262992125987, "X", 5.0000125984251973, 9.9999874015748045);
|
||||
VSplinePoint p(pSpline, 173.39500000000001, "173.395", 353.39499999999998, "353.395",
|
||||
381.23716535433073, "10.0869", 0, "0");
|
||||
originPoints.append(p);
|
||||
}
|
||||
|
||||
QLineF axis(QPointF(0, 0), QPointF(0, 10));
|
||||
|
||||
QTest::newRow("Vertical axis") << originPoints << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(0, 0), QPointF(10, 0));
|
||||
|
||||
QTest::newRow("Horizontal axis") << originPoints << axis << "a2";
|
||||
|
||||
axis = QLineF(QPointF(0, 0), QPointF(0, 10));
|
||||
axis.setAngle(45);
|
||||
|
||||
QTest::newRow("Diagonal axis") << originPoints << axis << "a2";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_VSplinePath::TestFlip()
|
||||
{
|
||||
QFETCH(QVector<VSplinePoint>, originPoints);
|
||||
QFETCH(QLineF, axis);
|
||||
QFETCH(QString, prefix);
|
||||
|
||||
const VSplinePath splPath(originPoints);
|
||||
const VSplinePath res = splPath.Flip(axis, prefix);
|
||||
|
||||
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
|
||||
QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg));
|
||||
|
||||
QCOMPARE(splPath.GetLength(), res.GetLength());
|
||||
QCOMPARE(splPath.CountPoints(), res.CountPoints());
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
private slots:
|
||||
void TestRotation_data();
|
||||
void TestRotation();
|
||||
void TestFlip_data();
|
||||
void TestFlip();
|
||||
private:
|
||||
Q_DISABLE_COPY(TST_VSplinePath)
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user