37 void testIntersection();
38 void testIntersection_data();
41 void testLength_data();
44 void testCenter_data();
47 void testCenterF_data();
49 void testNormalVector();
50 void testNormalVector_data();
53 void testAngle2_data();
58 void testAngleTo_data();
65 void tst_QLine::testSet()
83 l.setLine(9, 10, 11, 12);
106 l.setLine(9.0, 10.0, 11.0, 12.0);
115 void tst_QLine::testIntersection_data()
117 QTest::addColumn<double>(
"xa1");
118 QTest::addColumn<double>(
"ya1");
119 QTest::addColumn<double>(
"xa2");
120 QTest::addColumn<double>(
"ya2");
121 QTest::addColumn<double>(
"xb1");
122 QTest::addColumn<double>(
"yb1");
123 QTest::addColumn<double>(
"xb2");
124 QTest::addColumn<double>(
"yb2");
125 QTest::addColumn<int>(
"type");
126 QTest::addColumn<double>(
"ix");
127 QTest::addColumn<double>(
"iy");
130 << 5.0 << 6.0 << 7.0 << 9.0
133 << 0.0 << 4.0 << 3.0 << 4.0
136 << 0.0 << 4.0 << 5.0 << 4.0
139 QTest::newRow(
"almost vertical") << 0.0 << 10.0 << 20.0000000000001 << 10.0
140 << 10.0 << 0.0 << 10.0 << 20.0
143 QTest::newRow(
"almost horizontal") << 0.0 << 10.0 << 20.0 << 10.0
144 << 10.0000000000001 << 0.0 << 10.0 << 20.0
151 << 10.0 << 50.0 << 190.0 << 50.0
156 for (
int i = 0;
i < 1000; ++
i) {
164 a =
a.translated(1, 1);
165 b =
b.translated(1, 1);
168 << (double)
a.x1() << (double)
a.y1() << (double)
a.x2() << (double)
a.y2()
169 << (double)
b.x1() << (double)
b.y1() << (double)
b.x2() << (double)
b.y2()
176 void tst_QLine::testIntersection()
204 void tst_QLine::testLength_data()
206 QTest::addColumn<double>(
"x1");
207 QTest::addColumn<double>(
"y1");
208 QTest::addColumn<double>(
"x2");
209 QTest::addColumn<double>(
"y2");
210 QTest::addColumn<double>(
"length");
211 QTest::addColumn<double>(
"lengthToSet");
212 QTest::addColumn<double>(
"vx");
213 QTest::addColumn<double>(
"vy");
217 QTest::newRow(
"[1,0]->|2|") << 0.0 << 0.0 << 1.0 << 0.0 << 1.0 << 2.0 << 2.0 << 0.0;
218 QTest::newRow(
"[0,1]->|2|") << 0.0 << 0.0 << 0.0 << 1.0 << 1.0 << 2.0 << 0.0 << 2.0;
219 QTest::newRow(
"[-1,0]->|2|") << 0.0 << 0.0 << -1.0 << 0.0 << 1.0 << 2.0 << -2.0 << 0.0;
220 QTest::newRow(
"[0,-1]->|2|") << 0.0 << 0.0 << 0.0 << -1.0 << 1.0 << 2.0 << 0.0 << -2.0;
229 QTest::newRow(
"[1,0]->|2| (2,2)") << 2.0 << 2.0 << 3.0 << 2.0 << 1.0 << 2.0 << 2.0 << 0.0;
230 QTest::newRow(
"[0,1]->|2| (2,2)") << 2.0 << 2.0 << 2.0 << 3.0 << 1.0 << 2.0 << 0.0 << 2.0;
231 QTest::newRow(
"[-1,0]->|2| (2,2)") << 2.0 << 2.0 << 1.0 << 2.0 << 1.0 << 2.0 << -2.0 << 0.0;
232 QTest::newRow(
"[0,-1]->|2| (2,2)") << 2.0 << 2.0 << 2.0 << 1.0 << 1.0 << 2.0 << 0.0 << -2.0;
233 QTest::newRow(
"[1,1]->|1| (2,2)") << 2.0 << 2.0 << 3.0 << 3.0
235 QTest::newRow(
"[-1,1]->|1| (2,2)") << 2.0 << 2.0 << 1.0 << 3.0
237 QTest::newRow(
"[1,-1]->|1| (2,2)") << 2.0 << 2.0 << 3.0 << 1.0
239 QTest::newRow(
"[-1,-1]->|1| (2,2)") << 2.0 << 2.0 << 1.0 << 1.0
241 const double small =
qSqrt(std::numeric_limits<qreal>::denorm_min()) / 8;
243 << -(small * .5) << -(small * .5) << (small * .5) << (small * .5)
245 const double tiny = std::numeric_limits<qreal>::min() / 2;
247 << -(tiny * .5) << -(tiny * .5) << (tiny * .5) << (tiny * .5)
250 << 1.0 << 1.0 << (1 + 3
e-13) << (1 + 4
e-13)
251 << 5
e-13 << 1895.0 << 1137.0 << 1516.0;
253 << 0.0 << 0.0 << 4
e-323 << 5
e-324
254 << 4
e-323 << 1892.0 << 4
e-323 << 5
e-324;
257 void tst_QLine::testLength()
264 QFETCH(
double, lengthToSet);
271 l.setLength(lengthToSet);
273 if constexpr (std::numeric_limits<double>::has_denorm != std::denorm_present) {
276 QSKIP(
"Skipping 'denorm' as this type lacks denormals on this system");
281 QVERIFY(
l.length() > lengthToSet / 2 &&
l.length() < lengthToSet * 2);
289 void tst_QLine::testCenter()
303 void tst_QLine::testCenter_data()
305 QTest::addColumn<int>(
"x1");
306 QTest::addColumn<int>(
"y1");
307 QTest::addColumn<int>(
"x2");
308 QTest::addColumn<int>(
"y2");
309 QTest::addColumn<int>(
"centerX");
310 QTest::addColumn<int>(
"centerY");
321 const int max = std::numeric_limits<int>::max();
322 const int min = std::numeric_limits<int>::min();
323 QTest::newRow(
"max") << max << max << max << max << max << max;
324 QTest::newRow(
"min") << min << min << min << min << min << min;
325 QTest::newRow(
"minmax") << min << min << max << max << 0 << 0;
328 void tst_QLine::testCenterF()
342 void tst_QLine::testCenterF_data()
344 QTest::addColumn<double>(
"x1");
345 QTest::addColumn<double>(
"y1");
346 QTest::addColumn<double>(
"x2");
347 QTest::addColumn<double>(
"y2");
348 QTest::addColumn<double>(
"centerX");
349 QTest::addColumn<double>(
"centerY");
351 QTest::newRow(
"[0, 0]") << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0;
352 QTest::newRow(
"top") << 0.0 << 0.0 << 1.0 << 0.0 << 0.5 << 0.0;
353 QTest::newRow(
"right") << 0.0 << 0.0 << 0.0 << 1.0 << 0.0 << 0.5;
354 QTest::newRow(
"bottom") << 0.0 << 0.0 << -1.0 << 0.0 << -0.5 << 0.0;
355 QTest::newRow(
"left") << 0.0 << 0.0 << 0.0 << -1.0 << 0.0 << -0.5;
357 const double max = std::numeric_limits<qreal>::max();
358 QTest::newRow(
"max") << max << max << max << max << max << max;
361 void tst_QLine::testNormalVector_data()
363 QTest::addColumn<double>(
"x1");
364 QTest::addColumn<double>(
"y1");
365 QTest::addColumn<double>(
"x2");
366 QTest::addColumn<double>(
"y2");
367 QTest::addColumn<double>(
"nvx");
368 QTest::addColumn<double>(
"nvy");
370 QTest::newRow(
"[1, 0]") << 0.0 << 0.0 << 1.0 << 0.0 << 0.0 << -1.0;
371 QTest::newRow(
"[-1, 0]") << 0.0 << 0.0 << -1.0 << 0.0 << 0.0 << 1.0;
372 QTest::newRow(
"[0, 1]") << 0.0 << 0.0 << 0.0 << 1.0 << 1.0 << 0.0;
373 QTest::newRow(
"[0, -1]") << 0.0 << 0.0 << 0.0 << -1.0 << -1.0 << 0.0;
374 QTest::newRow(
"[2, 3]") << 2.0 << 3.0 << 4.0 << 6.0 << 3.0 << -2.0;
377 void tst_QLine::testNormalVector()
396 void tst_QLine::testAngle2_data()
398 QTest::addColumn<qreal>(
"x1");
399 QTest::addColumn<qreal>(
"y1");
400 QTest::addColumn<qreal>(
"x2");
401 QTest::addColumn<qreal>(
"y2");
402 QTest::addColumn<qreal>(
"angle");
415 void tst_QLine::testAngle2()
434 void tst_QLine::testAngle3()
436 for (
int i = -720;
i <= 720; ++
i) {
439 const int expected = (
i + 720) % 360;
449 void tst_QLine::testAngleTo()
464 const qreal resultAngle =
a.angleTo(
b);
467 a.translate(
b.p1() -
a.p1());
468 a.setAngle(
a.angle() + resultAngle);
469 a.setLength(
b.length());
474 void tst_QLine::testAngleTo_data()
476 QTest::addColumn<qreal>(
"xa1");
477 QTest::addColumn<qreal>(
"ya1");
478 QTest::addColumn<qreal>(
"xa2");
479 QTest::addColumn<qreal>(
"ya2");
480 QTest::addColumn<qreal>(
"xb1");
481 QTest::addColumn<qreal>(
"yb1");
482 QTest::addColumn<qreal>(
"xb2");
483 QTest::addColumn<qreal>(
"yb2");
484 QTest::addColumn<qreal>(
"angle");
496 for (
int i = 0;
i < 360; ++
i) {
506 #include "tst_qline.moc"
small capitals from c petite p scientific i
[1]
static QByteArray number(int, int base=10)
The QLineF class provides a two-dimensional vector using floating point precision.
constexpr qreal x1() const
constexpr qreal y2() const
constexpr QPointF center() const
constexpr qreal x2() const
static QLineF fromPolar(qreal length, qreal angle)
constexpr qreal y1() const
The QLine class provides a two-dimensional vector using integer precision.
constexpr QPoint center() const
The QObject class is the base class of all Qt objects.
The QPointF class defines a point in the plane using floating point precision.
constexpr qreal x() const noexcept
constexpr qreal y() const noexcept
The QPoint class defines a point in the plane using integer precision.
static QString fromLatin1(QByteArrayView ba)
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Q_TESTLIB_EXPORT const char * currentDataTag()
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
bool qFuzzyIsNull(qfloat16 f) noexcept
QT_END_INCLUDE_NAMESPACE typedef double qreal
GLenum GLuint GLenum GLsizei length
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLfixed GLfixed GLfixed y2
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QFETCH(Type, name)
#define QVERIFY(statement)
#define QVERIFY2(statement, description)