1/****************************************************************************
2**
3** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include <Qt3DCore/private/vector4d_sse_p.h>
31#include <Qt3DCore/qt3dcore-config.h>
32
33using namespace Qt3DCore;
34
35class tst_Vector4D_SSE: public QObject
36{
37 Q_OBJECT
38private Q_SLOTS:
39 void defaultConstruction()
40 {
41 // GIVEN
42 Vector4D_SSE vec4;
43
44 // THEN
45 QCOMPARE(vec4.x(), 0.0f);
46 QCOMPARE(vec4.y(), 0.0f);
47 QCOMPARE(vec4.z(), 0.0f);
48 QCOMPARE(vec4.w(), 0.0f);
49 }
50
51 void checkExplicitConstruction()
52 {
53 // GIVEN
54 Vector4D_SSE vec4(427.0f, 454.0f, 383.0f, 350.0f);
55
56 // THEN
57 QCOMPARE(vec4.x(), 427.0f);
58 QCOMPARE(vec4.y(), 454.0f);
59 QCOMPARE(vec4.z(), 383.0f);
60 QCOMPARE(vec4.w(), 350.0f);
61 }
62
63 void checkSetters()
64 {
65 // GIVEN
66 Vector4D_SSE vec4;
67
68 // WHEN
69 vec4.setX(427.0f);
70
71 // THEN
72 QCOMPARE(vec4.x(), 427.0f);
73 QCOMPARE(vec4.y(), 0.0f);
74 QCOMPARE(vec4.z(), 0.0f);
75 QCOMPARE(vec4.w(), 0.0f);
76
77 // WHEN
78 vec4.setY(454.0f);
79
80 // THEN
81 QCOMPARE(vec4.x(), 427.0f);
82 QCOMPARE(vec4.y(), 454.0f);
83 QCOMPARE(vec4.z(), 0.0f);
84 QCOMPARE(vec4.w(), 0.0f);
85
86 // WHEN
87 vec4.setZ(383.0f);
88
89 // THEN
90 QCOMPARE(vec4.x(), 427.0f);
91 QCOMPARE(vec4.y(), 454.0f);
92 QCOMPARE(vec4.z(), 383.0f);
93 QCOMPARE(vec4.w(), 0.0f);
94
95 // WHEN
96 vec4.setW(350.0f);
97
98 // THEN
99 QCOMPARE(vec4.x(), 427.0f);
100 QCOMPARE(vec4.y(), 454.0f);
101 QCOMPARE(vec4.z(), 383.0f);
102 QCOMPARE(vec4.w(), 350.0f);
103 }
104
105 void checkSelfAddition_data()
106 {
107 QTest::addColumn<float>(name: "xO");
108 QTest::addColumn<float>(name: "yO");
109 QTest::addColumn<float>(name: "zO");
110 QTest::addColumn<float>(name: "wO");
111
112 QTest::addColumn<float>(name: "xA");
113 QTest::addColumn<float>(name: "yA");
114 QTest::addColumn<float>(name: "zA");
115 QTest::addColumn<float>(name: "wA");
116
117 QTest::addColumn<float>(name: "xR");
118 QTest::addColumn<float>(name: "yR");
119 QTest::addColumn<float>(name: "zR");
120 QTest::addColumn<float>(name: "wR");
121
122 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 0.0f << 0.0f
123 << 1.0f << 5.0f << 8.0f << -5.0f
124 << 1.0f << 5.0f << 8.0f << -5.0f;
125
126 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << -4.0f << 6.0f
127 << 5.0f << -8.0f << 4.0f << -6.0f
128 << 0.0f << 0.0f << 0.0f << 0.0f;
129 }
130
131 void checkSelfAddition()
132 {
133 QFETCH(float, xO);
134 QFETCH(float, yO);
135 QFETCH(float, zO);
136 QFETCH(float, wO);
137
138 QFETCH(float, xA);
139 QFETCH(float, yA);
140 QFETCH(float, zA);
141 QFETCH(float, wA);
142
143 QFETCH(float, xR);
144 QFETCH(float, yR);
145 QFETCH(float, zR);
146 QFETCH(float, wR);
147
148 // GIVEN
149 Vector4D_SSE vo(xO, yO, zO, wO);
150
151 // WHEN
152 vo += Vector4D_SSE(xA, yA, zA, wA);
153
154 // THEN
155 QCOMPARE(vo.x(), xR);
156 QCOMPARE(vo.y(), yR);
157 QCOMPARE(vo.z(), zR);
158 QCOMPARE(vo.w(), wR);
159 }
160
161 void checkSelfSubstraction_data()
162 {
163 QTest::addColumn<float>(name: "xO");
164 QTest::addColumn<float>(name: "yO");
165 QTest::addColumn<float>(name: "zO");
166 QTest::addColumn<float>(name: "wO");
167
168 QTest::addColumn<float>(name: "xA");
169 QTest::addColumn<float>(name: "yA");
170 QTest::addColumn<float>(name: "zA");
171 QTest::addColumn<float>(name: "wA");
172
173 QTest::addColumn<float>(name: "xR");
174 QTest::addColumn<float>(name: "yR");
175 QTest::addColumn<float>(name: "zR");
176 QTest::addColumn<float>(name: "wR");
177
178 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 0.0f << 0.0f
179 << 1.0f << 5.0f << 8.0f << -5.0f
180 << -1.0f << -5.0f << -8.0f << 5.0f;
181
182 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << -4.0f << 6.0f
183 << 5.0f << -8.0f << 4.0f << -6.0f
184 << -10.0f << 16.0f << -8.0f << 12.0f;
185 }
186
187 void checkSelfSubstraction()
188 {
189 QFETCH(float, xO);
190 QFETCH(float, yO);
191 QFETCH(float, zO);
192 QFETCH(float, wO);
193
194 QFETCH(float, xA);
195 QFETCH(float, yA);
196 QFETCH(float, zA);
197 QFETCH(float, wA);
198
199 QFETCH(float, xR);
200 QFETCH(float, yR);
201 QFETCH(float, zR);
202 QFETCH(float, wR);
203
204 // GIVEN
205 Vector4D_SSE vo(xO, yO, zO, wO);
206
207 // WHEN
208 vo -= Vector4D_SSE(xA, yA, zA, wA);
209
210 // THEN
211 QCOMPARE(vo.x(), xR);
212 QCOMPARE(vo.y(), yR);
213 QCOMPARE(vo.z(), zR);
214 QCOMPARE(vo.w(), wR);
215 }
216
217 void checkSelfMultiplication_data()
218 {
219 QTest::addColumn<float>(name: "xO");
220 QTest::addColumn<float>(name: "yO");
221 QTest::addColumn<float>(name: "zO");
222 QTest::addColumn<float>(name: "wO");
223
224 QTest::addColumn<float>(name: "xA");
225 QTest::addColumn<float>(name: "yA");
226 QTest::addColumn<float>(name: "zA");
227 QTest::addColumn<float>(name: "wA");
228
229 QTest::addColumn<float>(name: "xR");
230 QTest::addColumn<float>(name: "yR");
231 QTest::addColumn<float>(name: "zR");
232 QTest::addColumn<float>(name: "wR");
233
234 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
235 << 1.0f << 5.0f << 8.0f << -5.0f
236 << 0.0f << 0.0f << 16.0f << -5.0f;
237
238 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << 4.0f << 6.0f
239 << 5.0f << -8.0f << 4.0f << 6.0f
240 << -25.0f << -64.0f << 16.0f << 36.0f;
241 }
242
243 void checkSelfMultiplication()
244 {
245 QFETCH(float, xO);
246 QFETCH(float, yO);
247 QFETCH(float, zO);
248 QFETCH(float, wO);
249
250 QFETCH(float, xA);
251 QFETCH(float, yA);
252 QFETCH(float, zA);
253 QFETCH(float, wA);
254
255 QFETCH(float, xR);
256 QFETCH(float, yR);
257 QFETCH(float, zR);
258 QFETCH(float, wR);
259
260 // GIVEN
261 Vector4D_SSE vo(xO, yO, zO, wO);
262
263 // WHEN
264 vo *= Vector4D_SSE(xA, yA, zA, wA);
265
266 // THEN
267 QCOMPARE(vo.x(), xR);
268 QCOMPARE(vo.y(), yR);
269 QCOMPARE(vo.z(), zR);
270 QCOMPARE(vo.w(), wR);
271 }
272
273 void checkSelfDivision_data()
274 {
275 QTest::addColumn<float>(name: "xO");
276 QTest::addColumn<float>(name: "yO");
277 QTest::addColumn<float>(name: "zO");
278 QTest::addColumn<float>(name: "wO");
279
280 QTest::addColumn<float>(name: "xA");
281 QTest::addColumn<float>(name: "yA");
282 QTest::addColumn<float>(name: "zA");
283 QTest::addColumn<float>(name: "wA");
284
285 QTest::addColumn<float>(name: "xR");
286 QTest::addColumn<float>(name: "yR");
287 QTest::addColumn<float>(name: "zR");
288 QTest::addColumn<float>(name: "wR");
289
290 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
291 << 1.0f << 5.0f << 8.0f << -5.0f
292 << 0.0f << 0.0f << 0.25f << -0.20f;
293
294 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << 4.0f << 6.0f
295 << 5.0f << -8.0f << 4.0f << 6.0f
296 << -1.0f << -1.0f << 1.0f << 1.0f;
297 }
298
299 void checkSelfDivision()
300 {
301 QFETCH(float, xO);
302 QFETCH(float, yO);
303 QFETCH(float, zO);
304 QFETCH(float, wO);
305
306 QFETCH(float, xA);
307 QFETCH(float, yA);
308 QFETCH(float, zA);
309 QFETCH(float, wA);
310
311 QFETCH(float, xR);
312 QFETCH(float, yR);
313 QFETCH(float, zR);
314 QFETCH(float, wR);
315
316 // GIVEN
317 Vector4D_SSE vo(xO, yO, zO, wO);
318
319 // WHEN
320 vo /= Vector4D_SSE(xA, yA, zA, wA);
321
322 // THEN
323 QCOMPARE(vo.x(), xR);
324 QCOMPARE(vo.y(), yR);
325 QCOMPARE(vo.z(), zR);
326 QCOMPARE(vo.w(), wR);
327 }
328
329 void checkSelfDivisionFactor_data()
330 {
331 QTest::addColumn<float>(name: "xO");
332 QTest::addColumn<float>(name: "yO");
333 QTest::addColumn<float>(name: "zO");
334 QTest::addColumn<float>(name: "wO");
335
336 QTest::addColumn<float>(name: "factor");
337
338 QTest::addColumn<float>(name: "xR");
339 QTest::addColumn<float>(name: "yR");
340 QTest::addColumn<float>(name: "zR");
341 QTest::addColumn<float>(name: "wR");
342
343 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
344 << 1.0f
345 << 0.0f << 0.0f << 2.0f << 1.0f;
346
347 QTest::newRow(dataTag: "sample_2") << -5.0f << 20.0f << -25.0f << 10.0f
348 << 5.0f
349 << -1.0f << 4.0f << -5.0f << 2.0f;
350 }
351
352 void checkSelfDivisionFactor()
353 {
354 QFETCH(float, xO);
355 QFETCH(float, yO);
356 QFETCH(float, zO);
357 QFETCH(float, wO);
358
359 QFETCH(float, factor);
360
361 QFETCH(float, xR);
362 QFETCH(float, yR);
363 QFETCH(float, zR);
364 QFETCH(float, wR);
365
366 // GIVEN
367 Vector4D_SSE vo(xO, yO, zO, wO);
368
369 // WHEN
370 vo /= factor;
371
372 // THEN
373 QCOMPARE(vo.x(), xR);
374 QCOMPARE(vo.y(), yR);
375 QCOMPARE(vo.z(), zR);
376 QCOMPARE(vo.w(), wR);
377 }
378
379 void checkSelfMultiplicationFactor_data()
380 {
381 QTest::addColumn<float>(name: "xO");
382 QTest::addColumn<float>(name: "yO");
383 QTest::addColumn<float>(name: "zO");
384 QTest::addColumn<float>(name: "wO");
385
386 QTest::addColumn<float>(name: "factor");
387
388 QTest::addColumn<float>(name: "xR");
389 QTest::addColumn<float>(name: "yR");
390 QTest::addColumn<float>(name: "zR");
391 QTest::addColumn<float>(name: "wR");
392
393 QTest::newRow(dataTag: "sample_1") << 0.0f << -3.0f << 2.0f << 1.0f
394 << 1.0f
395 << 0.0f << -3.0f << 2.0f << 1.0f;
396
397 QTest::newRow(dataTag: "sample_2") << -5.0f << 20.0f << -25.0f << 10.0f
398 << 5.0f
399 << -25.0f << 100.0f << -125.0f << 50.0f;
400 }
401
402 void checkSelfMultiplicationFactor()
403 {
404 QFETCH(float, xO);
405 QFETCH(float, yO);
406 QFETCH(float, zO);
407 QFETCH(float, wO);
408
409 QFETCH(float, factor);
410
411 QFETCH(float, xR);
412 QFETCH(float, yR);
413 QFETCH(float, zR);
414 QFETCH(float, wR);
415
416 // GIVEN
417 Vector4D_SSE vo(xO, yO, zO, wO);
418
419 // WHEN
420 vo *= factor;
421
422 // THEN
423 QCOMPARE(vo.x(), xR);
424 QCOMPARE(vo.y(), yR);
425 QCOMPARE(vo.z(), zR);
426 QCOMPARE(vo.w(), wR);
427 }
428
429 void checkAddition_data()
430 {
431 QTest::addColumn<float>(name: "xO");
432 QTest::addColumn<float>(name: "yO");
433 QTest::addColumn<float>(name: "zO");
434 QTest::addColumn<float>(name: "wO");
435
436 QTest::addColumn<float>(name: "xA");
437 QTest::addColumn<float>(name: "yA");
438 QTest::addColumn<float>(name: "zA");
439 QTest::addColumn<float>(name: "wA");
440
441 QTest::addColumn<float>(name: "xR");
442 QTest::addColumn<float>(name: "yR");
443 QTest::addColumn<float>(name: "zR");
444 QTest::addColumn<float>(name: "wR");
445
446 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 0.0f << 0.0f
447 << 1.0f << 5.0f << 8.0f << -5.0f
448 << 1.0f << 5.0f << 8.0f << -5.0f;
449
450 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << -4.0f << 6.0f
451 << 5.0f << -8.0f << 4.0f << -6.0f
452 << 0.0f << 0.0f << 0.0f << 0.0f;
453 }
454
455 void checkAddition()
456 {
457 QFETCH(float, xO);
458 QFETCH(float, yO);
459 QFETCH(float, zO);
460 QFETCH(float, wO);
461
462 QFETCH(float, xA);
463 QFETCH(float, yA);
464 QFETCH(float, zA);
465 QFETCH(float, wA);
466
467 QFETCH(float, xR);
468 QFETCH(float, yR);
469 QFETCH(float, zR);
470 QFETCH(float, wR);
471
472 // GIVEN
473 Vector4D_SSE v0(xO, yO, zO, wO);
474 Vector4D_SSE v1(xA, yA, zA, wA);
475
476 // WHEN
477 Vector4D_SSE v2 = v0 + v1;
478
479 // THEN
480 QCOMPARE(v2.x(), xR);
481 QCOMPARE(v2.y(), yR);
482 QCOMPARE(v2.z(), zR);
483 QCOMPARE(v2.w(), wR);
484 }
485
486 void checkSubstraction_data()
487 {
488 QTest::addColumn<float>(name: "xO");
489 QTest::addColumn<float>(name: "yO");
490 QTest::addColumn<float>(name: "zO");
491 QTest::addColumn<float>(name: "wO");
492
493 QTest::addColumn<float>(name: "xA");
494 QTest::addColumn<float>(name: "yA");
495 QTest::addColumn<float>(name: "zA");
496 QTest::addColumn<float>(name: "wA");
497
498 QTest::addColumn<float>(name: "xR");
499 QTest::addColumn<float>(name: "yR");
500 QTest::addColumn<float>(name: "zR");
501 QTest::addColumn<float>(name: "wR");
502
503 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 0.0f << 0.0f
504 << 1.0f << 5.0f << 8.0f << -5.0f
505 << -1.0f << -5.0f << -8.0f << 5.0f;
506
507 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << -4.0f << 6.0f
508 << 5.0f << -8.0f << 4.0f << -6.0f
509 << -10.0f << 16.0f << -8.0f << 12.0f;
510 }
511
512 void checkSubstraction()
513 {
514 QFETCH(float, xO);
515 QFETCH(float, yO);
516 QFETCH(float, zO);
517 QFETCH(float, wO);
518
519 QFETCH(float, xA);
520 QFETCH(float, yA);
521 QFETCH(float, zA);
522 QFETCH(float, wA);
523
524 QFETCH(float, xR);
525 QFETCH(float, yR);
526 QFETCH(float, zR);
527 QFETCH(float, wR);
528
529 // GIVEN
530 Vector4D_SSE v0(xO, yO, zO, wO);
531 Vector4D_SSE v1(xA, yA, zA, wA);
532
533 // WHEN
534 Vector4D_SSE v2 = v0 - v1;
535
536 // THEN
537 QCOMPARE(v2.x(), xR);
538 QCOMPARE(v2.y(), yR);
539 QCOMPARE(v2.z(), zR);
540 QCOMPARE(v2.w(), wR);
541 }
542
543 void checkMultiplication_data()
544 {
545 QTest::addColumn<float>(name: "xO");
546 QTest::addColumn<float>(name: "yO");
547 QTest::addColumn<float>(name: "zO");
548 QTest::addColumn<float>(name: "wO");
549
550 QTest::addColumn<float>(name: "xA");
551 QTest::addColumn<float>(name: "yA");
552 QTest::addColumn<float>(name: "zA");
553 QTest::addColumn<float>(name: "wA");
554
555 QTest::addColumn<float>(name: "xR");
556 QTest::addColumn<float>(name: "yR");
557 QTest::addColumn<float>(name: "zR");
558 QTest::addColumn<float>(name: "wR");
559
560 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
561 << 1.0f << 5.0f << 8.0f << -5.0f
562 << 0.0f << 0.0f << 16.0f << -5.0f;
563
564 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << 4.0f << 6.0f
565 << 5.0f << -8.0f << 4.0f << 6.0f
566 << -25.0f << -64.0f << 16.0f << 36.0f;
567 }
568
569 void checkMultiplication()
570 {
571 QFETCH(float, xO);
572 QFETCH(float, yO);
573 QFETCH(float, zO);
574 QFETCH(float, wO);
575
576 QFETCH(float, xA);
577 QFETCH(float, yA);
578 QFETCH(float, zA);
579 QFETCH(float, wA);
580
581 QFETCH(float, xR);
582 QFETCH(float, yR);
583 QFETCH(float, zR);
584 QFETCH(float, wR);
585
586 // GIVEN
587 Vector4D_SSE v0(xO, yO, zO, wO);
588 Vector4D_SSE v1(xA, yA, zA, wA);
589
590 // WHEN
591 Vector4D_SSE v2 = v0 * v1;
592
593 // THEN
594 QCOMPARE(v2.x(), xR);
595 QCOMPARE(v2.y(), yR);
596 QCOMPARE(v2.z(), zR);
597 QCOMPARE(v2.w(), wR);
598 }
599
600 void checkDivision_data()
601 {
602 QTest::addColumn<float>(name: "xO");
603 QTest::addColumn<float>(name: "yO");
604 QTest::addColumn<float>(name: "zO");
605 QTest::addColumn<float>(name: "wO");
606
607 QTest::addColumn<float>(name: "xA");
608 QTest::addColumn<float>(name: "yA");
609 QTest::addColumn<float>(name: "zA");
610 QTest::addColumn<float>(name: "wA");
611
612 QTest::addColumn<float>(name: "xR");
613 QTest::addColumn<float>(name: "yR");
614 QTest::addColumn<float>(name: "zR");
615 QTest::addColumn<float>(name: "wR");
616
617 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
618 << 1.0f << 5.0f << 8.0f << -5.0f
619 << 0.0f << 0.0f << 0.25f << -0.20f;
620
621 QTest::newRow(dataTag: "sample_2") << -5.0f << 8.0f << 4.0f << 6.0f
622 << 5.0f << -8.0f << 4.0f << 6.0f
623 << -1.0f << -1.0f << 1.0f << 1.0f;
624 }
625
626 void checkDivision()
627 {
628 QFETCH(float, xO);
629 QFETCH(float, yO);
630 QFETCH(float, zO);
631 QFETCH(float, wO);
632
633 QFETCH(float, xA);
634 QFETCH(float, yA);
635 QFETCH(float, zA);
636 QFETCH(float, wA);
637
638 QFETCH(float, xR);
639 QFETCH(float, yR);
640 QFETCH(float, zR);
641 QFETCH(float, wR);
642
643 // GIVEN
644 Vector4D_SSE v0(xO, yO, zO, wO);
645 Vector4D_SSE v1(xA, yA, zA, wA);
646
647 // WHEN
648 Vector4D_SSE v2 = v0 / v1;
649
650 // THEN
651 QCOMPARE(v2.x(), xR);
652 QCOMPARE(v2.y(), yR);
653 QCOMPARE(v2.z(), zR);
654 QCOMPARE(v2.w(), wR);
655 }
656
657 void checkDivisionFactor_data()
658 {
659 QTest::addColumn<float>(name: "xO");
660 QTest::addColumn<float>(name: "yO");
661 QTest::addColumn<float>(name: "zO");
662 QTest::addColumn<float>(name: "wO");
663
664 QTest::addColumn<float>(name: "factor");
665
666 QTest::addColumn<float>(name: "xR");
667 QTest::addColumn<float>(name: "yR");
668 QTest::addColumn<float>(name: "zR");
669 QTest::addColumn<float>(name: "wR");
670
671 QTest::newRow(dataTag: "sample_1") << 0.0f << 0.0f << 2.0f << 1.0f
672 << 1.0f
673 << 0.0f << 0.0f << 2.0f << 1.0f;
674
675 QTest::newRow(dataTag: "sample_2") << -5.0f << 20.0f << -25.0f << 10.0f
676 << 5.0f
677 << -1.0f << 4.0f << -5.0f << 2.0f;
678 }
679
680 void checkDivisionFactor()
681 {
682 QFETCH(float, xO);
683 QFETCH(float, yO);
684 QFETCH(float, zO);
685 QFETCH(float, wO);
686
687 QFETCH(float, factor);
688
689 QFETCH(float, xR);
690 QFETCH(float, yR);
691 QFETCH(float, zR);
692 QFETCH(float, wR);
693
694 // GIVEN
695 Vector4D_SSE v0(xO, yO, zO, wO);
696
697 // WHEN
698 Vector4D_SSE v2 = v0 / factor;
699
700 // THEN
701 QCOMPARE(v2.x(), xR);
702 QCOMPARE(v2.y(), yR);
703 QCOMPARE(v2.z(), zR);
704 QCOMPARE(v2.w(), wR);
705 }
706
707 void checkMultiplicationFactor_data()
708 {
709 QTest::addColumn<float>(name: "xO");
710 QTest::addColumn<float>(name: "yO");
711 QTest::addColumn<float>(name: "zO");
712 QTest::addColumn<float>(name: "wO");
713
714 QTest::addColumn<float>(name: "factor");
715
716 QTest::addColumn<float>(name: "xR");
717 QTest::addColumn<float>(name: "yR");
718 QTest::addColumn<float>(name: "zR");
719 QTest::addColumn<float>(name: "wR");
720
721 QTest::newRow(dataTag: "sample_1") << 0.0f << -3.0f << 2.0f << 1.0f
722 << 1.0f
723 << 0.0f << -3.0f << 2.0f << 1.0f;
724
725 QTest::newRow(dataTag: "sample_2") << -5.0f << 20.0f << -25.0f << 10.0f
726 << 5.0f
727 << -25.0f << 100.0f << -125.0f << 50.0f;
728 }
729
730 void checkMultiplicationFactor()
731 {
732 QFETCH(float, xO);
733 QFETCH(float, yO);
734 QFETCH(float, zO);
735 QFETCH(float, wO);
736
737 QFETCH(float, factor);
738
739 QFETCH(float, xR);
740 QFETCH(float, yR);
741 QFETCH(float, zR);
742 QFETCH(float, wR);
743
744 // GIVEN
745 Vector4D_SSE v0(xO, yO, zO, wO);
746
747 // WHEN
748 Vector4D_SSE v2 = v0 * factor;
749
750 // THEN
751 QCOMPARE(v2.x(), xR);
752 QCOMPARE(v2.y(), yR);
753 QCOMPARE(v2.z(), zR);
754 QCOMPARE(v2.w(), wR);
755 }
756
757 void checkEquality()
758 {
759 {
760 // GIVEN
761 Vector4D_SSE v0;
762 Vector4D_SSE v1;
763
764 // THEN
765 QVERIFY(v0 == v1);
766 }
767 {
768 // GIVEN
769 Vector4D_SSE v0(1.0f, 2.0f, -5.0f, 10.0f);
770 Vector4D_SSE v1(1.0f, 2.0f, -5.0f, 10.0f);
771
772 // THEN
773 QVERIFY(v0 == v1);
774 }
775 }
776
777 void checkInequality()
778 {
779 {
780 // GIVEN
781 Vector4D_SSE v0;
782 Vector4D_SSE v1;
783
784 // THEN
785 QVERIFY(!(v0 != v1));
786 }
787 {
788 // GIVEN
789 Vector4D_SSE v0(1.0f, 2.0f, -5.0f, 10.0f);
790 Vector4D_SSE v1(1.0f, 5.0f, -5.0f, 10.0f);
791
792 // THEN
793 QVERIFY(v0 != v1);
794 }
795 }
796
797 void checkToQVector4D_SSE()
798 {
799 {
800 // GIVEN
801 Vector4D_SSE v0;
802
803 // WHEN
804 QVector4D v1 = v0.toQVector4D();
805
806 // THEN
807 QCOMPARE(v0.x(), v1.x());
808 QCOMPARE(v0.y(), v1.y());
809 QCOMPARE(v0.z(), v1.z());
810 QCOMPARE(v0.w(), v1.w());
811 }
812 {
813 // GIVEN
814 Vector4D_SSE v0(1.0f, 2.0f, -5.0f, 10.0f);
815
816 // WHEN
817 QVector4D v1 = v0.toQVector4D();
818
819 // THEN
820 QCOMPARE(v0.x(), v1.x());
821 QCOMPARE(v0.y(), v1.y());
822 QCOMPARE(v0.z(), v1.z());
823 QCOMPARE(v0.w(), v1.w());
824 }
825 }
826
827 void checkLengthSquared()
828 {
829 {
830 // GIVEN
831 Vector4D_SSE v0(10.0f, 10.0f, 10.0f, 10.0f);
832
833 // THEN
834 QCOMPARE(v0.lengthSquared(), 400.0f);
835 }
836 {
837 // GIVEN
838 Vector4D_SSE v0(3.0f, 1.0f, 2.0f, 4.0f);
839
840 // THEN
841 QCOMPARE(v0.lengthSquared(), 30.0f);
842 }
843 }
844
845 void checkLength()
846 {
847 {
848 // GIVEN
849 Vector4D_SSE v0(3.0f, 0.0f, 0.0f, 0.0f);
850
851 // THEN
852 QCOMPARE(v0.length(), 3.0f);
853 }
854 {
855 // GIVEN
856 Vector4D_SSE v0(0.0f, 10.0f, 0.0f, 0.0f);
857
858 // THEN
859 QCOMPARE(v0.length(), 10.0f);
860 }
861 {
862 // GIVEN
863 Vector4D_SSE v0(0.0f, 0.0f, 9.0f, 0.0f);
864
865 // THEN
866 QCOMPARE(v0.length(), 9.0f);
867 }
868 {
869 // GIVEN
870 Vector4D_SSE v0(0.0f, 0.0f, 0.0f, 8.0f);
871
872 // THEN
873 QCOMPARE(v0.length(), 8.0f);
874 }
875 }
876
877 void checkNormalize()
878 {
879 {
880 // GIVEN
881 Vector4D_SSE v0(10.0f, 0.0f, 0.0f, 0.0f);
882
883 // WHEN
884 v0.normalize();
885
886 // THEN
887 QCOMPARE(v0, Vector4D_SSE(1.0f, 0.0f, 0.0f, 0.0f));
888 }
889 {
890 // GIVEN
891 Vector4D_SSE v0(0.0f, 0.0f, 3.0f, 0.0f);
892
893 // WHEN
894 v0.normalize();
895
896 // THEN
897 QCOMPARE(v0, Vector4D_SSE(0.0, 0.0f, 1.0f, 0.0f));
898 }
899 }
900
901 void checkIsNull()
902 {
903 {
904 // GIVEN
905 Vector4D_SSE v0;
906
907 // THEN
908 QVERIFY(v0.isNull());
909 }
910 {
911 // GIVEN
912 Vector4D_SSE v0(1.0f, 1.0f, 1.0f, 1.0f);
913
914 // THEN
915 QVERIFY(!v0.isNull());
916 }
917 }
918};
919
920QTEST_APPLESS_MAIN(tst_Vector4D_SSE)
921
922#include "tst_vector4d_sse.moc"
923

source code of qt3d/tests/auto/core/vector4d_sse/tst_vector4d_sse.cpp