Flipping VArc.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-09-10 18:18:11 +03:00
parent 4c47c33c5e
commit 800181e867
6 changed files with 97 additions and 2 deletions

View File

@ -131,6 +131,20 @@ VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &pref
return arc; return arc;
} }
//---------------------------------------------------------------------------------------------------------------------
VArc VArc::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());
VArc arc(center, GetRadius(), QLineF(center, p1).angle(), QLineF(center, p2).angle());
arc.setName(name() + prefix);
arc.SetFlipped(true);
return arc;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VArc::~VArc() VArc::~VArc()
{} {}

View File

@ -63,6 +63,7 @@ public:
VArc(const VArc &arc); VArc(const VArc &arc);
VArc& operator= (const VArc &arc); VArc& operator= (const VArc &arc);
VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
VArc Flip(const QLineF &axis, const QString &prefix = QString()) const;
virtual ~VArc() Q_DECL_OVERRIDE; virtual ~VArc() Q_DECL_OVERRIDE;
QString GetFormulaRadius () const; QString GetFormulaRadius () const;

View File

@ -117,8 +117,7 @@ VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const
{ {
const QTransform matrix = FlippingMatrix(axis); const QPointF p = FlipPF(axis, toQPointF());
const QPointF p = matrix.map(toQPointF());
return VPointF(p, name() + prefix, mx(), my()); return VPointF(p, name() + prefix, mx(), my());
} }
@ -215,3 +214,10 @@ QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qrea
axis.setAngle(axis.angle() + degrees); axis.setAngle(axis.angle() + degrees);
return axis.p2(); return axis.p2();
} }
//---------------------------------------------------------------------------------------------------------------------
QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point)
{
const QTransform matrix = FlippingMatrix(axis);
return matrix.map(point);
}

View File

@ -77,6 +77,7 @@ public:
void setY(const qreal &value); void setY(const qreal &value);
static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees);
static QPointF FlipPF(const QLineF &axis, const QPointF &point);
private: private:
QSharedDataPointer<VPointFData> d; QSharedDataPointer<VPointFData> d;
}; };

View File

@ -246,3 +246,74 @@ void TST_VArc::TestRotation()
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg));
} }
//---------------------------------------------------------------------------------------------------------------------
void TST_VArc::TestFlip_data()
{
QTest::addColumn<QPointF>("center");
QTest::addColumn<qreal>("radius");
QTest::addColumn<qreal>("startAngle");
QTest::addColumn<qreal>("endAngle");
QTest::addColumn<QLineF>("axis");
QTest::addColumn<QString>("prefix");
const qreal radius = 5;
QPointF center(10, 5);
QPointF p1(10, 0);
QPointF p2(5, 5);
QLineF axis(QPointF(4, 6), QPointF(12, 6));
QTest::newRow("Vertical axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle()
<< axis << "a2";
p1 = QPointF(15, 5);
p2 = QPointF(10, 0);
axis = QLineF(QPointF(9, -1), QPointF(9, 6));
QTest::newRow("Horizontal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle()
<< axis << "a2";
QLineF l(center.x(), center.y(), center.x() + radius, center.y());
l.setAngle(45);
p2 = l.p2();
l.setAngle(225);
p1 = l.p2();
l.setAngle(45+90);
l.setLength(5);
const QPointF p1Axis = l.p2();
axis = QLineF(p1Axis.x(), p1Axis.y(), p1Axis.x() + radius, p1Axis.y());
axis.setAngle(45);
QTest::newRow("Diagonal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle()
<< axis << "a2";
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VArc::TestFlip()
{
QFETCH(QPointF, center);
QFETCH(qreal, radius);
QFETCH(qreal, startAngle);
QFETCH(qreal, endAngle);
QFETCH(QLineF, axis);
QFETCH(QString, prefix);
VArc originArc(center, radius, startAngle, endAngle);
const VArc res = originArc.Flip(axis, prefix);
const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix);
QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg));
QVERIFY2(res.IsFlipped(), qUtf8Printable("The arc is not flipped"));
QCOMPARE(originArc.GetLength()*-1, res.GetLength());
QCOMPARE(originArc.GetRadius(), res.GetRadius());
QCOMPARE(originArc.AngleArc(), res.AngleArc());
}

View File

@ -44,6 +44,8 @@ private slots:
void TestGetPoints(); void TestGetPoints();
void TestRotation_data(); void TestRotation_data();
void TestRotation(); void TestRotation();
void TestFlip_data();
void TestFlip();
}; };
#endif // TST_VARC_H #endif // TST_VARC_H