New test. Testing arc points.
--HG-- branch : develop
This commit is contained in:
parent
0e60b20ace
commit
75701f8cad
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "tst_varc.h"
|
||||
#include "../vgeometry/varc.h"
|
||||
#include "../vlayout/vabstractdetail.h"
|
||||
#include "../vmisc/logging.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
|
@ -73,3 +75,150 @@ void TST_VArc::NegativeArc()
|
|||
QCOMPARE(arc.GetLength(), -length);
|
||||
QCOMPARE(arc.GetEndAngle(), f2);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// cppcheck-suppress unusedFunction
|
||||
void TST_VArc::TestGetPoints_data()
|
||||
{
|
||||
QTest::addColumn<qreal>("radius");
|
||||
QTest::addColumn<qreal>("startAngle");
|
||||
QTest::addColumn<qreal>("endAngle");
|
||||
|
||||
QTest::newRow("Full circle: radius 10") << 10.0 << 0.0 << 360.0;
|
||||
QTest::newRow("Full circle: radius 150") << 150.0 << 0.0 << 360.0;
|
||||
QTest::newRow("Full circle: radius 1500") << 1500.0 << 0.0 << 360.0;
|
||||
QTest::newRow("Full circle: radius 50000") << 50000.0 << 0.0 << 360.0;
|
||||
QTest::newRow("Full circle: radius 90000") << 90000.0 << 0.0 << 360.0;
|
||||
QTest::newRow("Full circle: radius 900000") << 900000.0 << 0.0 << 360.0;
|
||||
|
||||
QTest::newRow("Arc less than 45 degree, radius 100") << 100.0 << 0.0 << 10.5;
|
||||
QTest::newRow("Arc less than 45 degree, radius 150") << 150.0 << 0.0 << 10.5;
|
||||
QTest::newRow("Arc less than 45 degree, radius 1500") << 1500.0 << 0.0 << 10.5;
|
||||
QTest::newRow("Arc less than 45 degree, radius 50000") << 50000.0 << 0.0 << 10.5;
|
||||
QTest::newRow("Arc less than 45 degree, radius 90000") << 90000.0 << 0.0 << 10.5;
|
||||
QTest::newRow("Arc less than 45 degree, radius 900000") << 900000.0 << 0.0 << 10.5;
|
||||
|
||||
QTest::newRow("Arc 45 degree, radius 100") << 100.0 << 0.0 << 45.0;
|
||||
QTest::newRow("Arc 45 degree, radius 150") << 150.0 << 0.0 << 45.0;
|
||||
QTest::newRow("Arc 45 degree, radius 1500") << 1500.0 << 0.0 << 45.0;
|
||||
QTest::newRow("Arc 45 degree, radius 50000") << 50000.0 << 0.0 << 45.0;
|
||||
QTest::newRow("Arc 45 degree, radius 90000") << 90000.0 << 0.0 << 45.0;
|
||||
QTest::newRow("Arc 45 degree, radius 900000") << 900000.0 << 0.0 << 45.0;
|
||||
|
||||
QTest::newRow("Arc less than 90 degree, radius 100") << 100.0 << 0.0 << 75.0;
|
||||
QTest::newRow("Arc less than 90 degree, radius 150") << 150.0 << 0.0 << 75.0;
|
||||
QTest::newRow("Arc less than 90 degree, radius 1500") << 1500.0 << 0.0 << 75.0;
|
||||
QTest::newRow("Arc less than 90 degree, radius 50000") << 50000.0 << 0.0 << 75.0;
|
||||
QTest::newRow("Arc less than 90 degree, radius 90000") << 90000.0 << 0.0 << 75.0;
|
||||
QTest::newRow("Arc less than 90 degree, radius 900000") << 900000.0 << 0.0 << 75.0;
|
||||
|
||||
QTest::newRow("Arc 90 degree, radius 100") << 100.0 << 0.0 << 90.0;
|
||||
QTest::newRow("Arc 90 degree, radius 150") << 150.0 << 0.0 << 90.0;
|
||||
QTest::newRow("Arc 90 degree, radius 1500") << 1500.0 << 0.0 << 90.0;
|
||||
QTest::newRow("Arc 90 degree, radius 50000") << 50000.0 << 0.0 << 90.0;
|
||||
QTest::newRow("Arc 90 degree, radius 90000") << 90000.0 << 0.0 << 90.0;
|
||||
QTest::newRow("Arc 90 degree, radius 900000") << 900000.0 << 0.0 << 90.0;
|
||||
|
||||
QTest::newRow("Arc less than 135 degree, radius 100") << 100.0 << 0.0 << 110.6;
|
||||
QTest::newRow("Arc less than 135 degree, radius 150") << 150.0 << 0.0 << 110.6;
|
||||
QTest::newRow("Arc less than 135 degree, radius 1500") << 1500.0 << 0.0 << 110.6;
|
||||
QTest::newRow("Arc less than 135 degree, radius 50000") << 50000.0 << 0.0 << 110.6;
|
||||
QTest::newRow("Arc less than 135 degree, radius 90000") << 90000.0 << 0.0 << 110.6;
|
||||
QTest::newRow("Arc less than 135 degree, radius 900000") << 900000.0 << 0.0 << 110.6;
|
||||
|
||||
QTest::newRow("Arc 135 degree, radius 100") << 100.0 << 0.0 << 135.0;
|
||||
QTest::newRow("Arc 135 degree, radius 150") << 150.0 << 0.0 << 135.0;
|
||||
QTest::newRow("Arc 135 degree, radius 1500") << 1500.0 << 0.0 << 135.0;
|
||||
QTest::newRow("Arc 135 degree, radius 50000") << 50000.0 << 0.0 << 135.0;
|
||||
QTest::newRow("Arc 135 degree, radius 90000") << 90000.0 << 0.0 << 135.0;
|
||||
QTest::newRow("Arc 135 degree, radius 900000") << 900000.0 << 0.0 << 135.0;
|
||||
|
||||
QTest::newRow("Arc less than 180 degree, radius 100") << 100.0 << 0.0 << 160.7;
|
||||
QTest::newRow("Arc less than 180 degree, radius 150") << 150.0 << 0.0 << 160.7;
|
||||
QTest::newRow("Arc less than 180 degree, radius 1500") << 1500.0 << 0.0 << 160.7;
|
||||
QTest::newRow("Arc less than 180 degree, radius 50000") << 50000.0 << 0.0 << 160.7;
|
||||
QTest::newRow("Arc less than 180 degree, radius 90000") << 90000.0 << 0.0 << 160.7;
|
||||
QTest::newRow("Arc less than 180 degree, radius 900000") << 900000.0 << 0.0 << 160.7;
|
||||
|
||||
QTest::newRow("Arc 180 degree, radius 100") << 100.0 << 0.0 << 180.0;
|
||||
QTest::newRow("Arc 180 degree, radius 150") << 150.0 << 0.0 << 180.0;
|
||||
QTest::newRow("Arc 180 degree, radius 1500") << 1500.0 << 0.0 << 180.0;
|
||||
QTest::newRow("Arc 180 degree, radius 50000") << 50000.0 << 0.0 << 180.0;
|
||||
QTest::newRow("Arc 180 degree, radius 90000") << 90000.0 << 0.0 << 180.0;
|
||||
QTest::newRow("Arc 180 degree, radius 900000") << 900000.0 << 0.0 << 180.0;
|
||||
|
||||
QTest::newRow("Arc less than 270 degree, radius 100") << 100.0 << 0.0 << 150.3;
|
||||
QTest::newRow("Arc less than 270 degree, radius 150") << 150.0 << 0.0 << 150.3;
|
||||
QTest::newRow("Arc less than 270 degree, radius 1500") << 1500.0 << 0.0 << 150.3;
|
||||
QTest::newRow("Arc less than 270 degree, radius 50000") << 50000.0 << 0.0 << 150.3;
|
||||
QTest::newRow("Arc less than 270 degree, radius 90000") << 90000.0 << 0.0 << 150.3;
|
||||
QTest::newRow("Arc less than 270 degree, radius 900000") << 900000.0 << 0.0 << 150.3;
|
||||
|
||||
QTest::newRow("Arc 270 degree, radius 100") << 100.0 << 0.0 << 270.0;
|
||||
QTest::newRow("Arc 270 degree, radius 150") << 150.0 << 0.0 << 270.0;
|
||||
QTest::newRow("Arc 270 degree, radius 1500") << 1500.0 << 0.0 << 270.0;
|
||||
QTest::newRow("Arc 270 degree, radius 50000") << 50000.0 << 0.0 << 270.0;
|
||||
QTest::newRow("Arc 270 degree, radius 90000") << 90000.0 << 0.0 << 270.0;
|
||||
QTest::newRow("Arc 270 degree, radius 900000") << 900000.0 << 0.0 << 270.0;
|
||||
|
||||
QTest::newRow("Arc less than 360 degree, radius 100") << 100.0 << 0.0 << 340.0;
|
||||
QTest::newRow("Arc less than 360 degree, radius 150") << 150.0 << 0.0 << 340.0;
|
||||
QTest::newRow("Arc less than 360 degree, radius 1500") << 1500.0 << 0.0 << 340.0;
|
||||
QTest::newRow("Arc less than 360 degree, radius 50000") << 50000.0 << 0.0 << 340.0;
|
||||
QTest::newRow("Arc less than 360 degree, radius 90000") << 90000.0 << 0.0 << 340.0;
|
||||
QTest::newRow("Arc less than 360 degree, radius 900000") << 900000.0 << 0.0 << 340.0;
|
||||
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 100") << 100.0 << 90.0 << 135.0;
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 150") << 150.0 << 90.0 << 135.0;
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 1500") << 1500.0 << 90.0 << 135.0;
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 50000") << 50000.0 << 90.0 << 135.0;
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 90000") << 90000.0 << 90.0 << 135.0;
|
||||
QTest::newRow("Arc start 90 degree, angle 45 degree, radius 900000") << 900000.0 << 90.0 << 135.0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// cppcheck-suppress unusedFunction
|
||||
void TST_VArc::TestGetPoints()
|
||||
{
|
||||
QFETCH(qreal, radius);
|
||||
QFETCH(qreal, startAngle);
|
||||
QFETCH(qreal, endAngle);
|
||||
|
||||
const VPointF center;
|
||||
VArc arc(center, radius, startAngle, endAngle);
|
||||
|
||||
QVector<QPointF> points = arc.GetPoints();
|
||||
|
||||
{
|
||||
const qreal epsRadius = 1.0; // computing error
|
||||
|
||||
for (int i=0; i < points.size(); ++i)
|
||||
{
|
||||
QLineF rLine(center.toQPointF(), points.at(i));
|
||||
QVERIFY2(qAbs(rLine.length() - radius) <= epsRadius,
|
||||
"Broken the first rule. All points should be on the same distance from the center.");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qreal gSquere = 0.0;// geometry squere
|
||||
|
||||
if (qFuzzyCompare(arc.AngleArc(), 360.0))
|
||||
{// circle squere
|
||||
gSquere = M_PI * radius * radius;
|
||||
}
|
||||
else
|
||||
{// sector squere
|
||||
gSquere = (M_PI * radius * radius) / 360.0 * arc.AngleArc();
|
||||
points.append(center.toQPointF());
|
||||
}
|
||||
|
||||
// calculated squere
|
||||
qreal cSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0);
|
||||
const qreal value = qAbs(gSquere - cSquare);
|
||||
const QString errorMsg =
|
||||
QString("Broken the second rule. Interpolation has too big computing error. Error ='%1'.").arg(value);
|
||||
const qreal epsSquere = 1.0; // computing error
|
||||
QVERIFY2(value <= epsSquere, qUtf8Printable(errorMsg));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
private slots:
|
||||
void CompareTwoWays();
|
||||
void NegativeArc();
|
||||
void TestGetPoints_data();
|
||||
void TestGetPoints();
|
||||
};
|
||||
|
||||
#endif // TST_VARC_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user