File indexing completed on 2024-05-19 15:26:49
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "bezier_test.hpp" 0008 0009 #include "model/document.hpp" 0010 #include "model/shapes/trim.hpp" 0011 0012 0013 using namespace glaxnimate; 0014 0015 /* 0016 * Note: 0017 * This test class defines a lot of machinery to ensure we can properly compare 0018 * bezier curves (using fuzzy float comparison) and to produce nice readable output. 0019 * 0020 * The process() function creates a model::Trim object, initializes its properties 0021 * as per arguments and returns the processed bezier. 0022 * 0023 * To compare beziers in a test, use COMPARE_MULTIBEZIER. 0024 * 0025 * Most test case have comments that shows a visual representation of the input 0026 * and output because the number of tests is kinda overwhelming. 0027 */ 0028 class TestTrimPath: public QObject, public BezierTestBase 0029 { 0030 Q_OBJECT 0031 0032 private: 0033 math::bezier::MultiBezier process(float start, float end, float offset, const math::bezier::MultiBezier& input) 0034 { 0035 model::Document doc("foo"); 0036 model::Trim trim(&doc); 0037 trim.start.set(start); 0038 trim.end.set(end); 0039 trim.offset.set(offset); 0040 return trim.process(0, input); 0041 } 0042 0043 private Q_SLOTS: 0044 0045 void test_process_empty() 0046 { 0047 math::bezier::MultiBezier input; 0048 math::bezier::MultiBezier output = process(0, 0.5, 0, input); 0049 QVERIFY(output.empty()); 0050 } 0051 0052 // Line 0053 0054 /* 0055 * ====================== 0056 * ^--------------------^ 0057 */ 0058 void test_process_line_full() 0059 { 0060 math::bezier::MultiBezier input; 0061 input.move_to(QPointF(0, 0)); 0062 input.line_to(QPointF(100, 0)); 0063 math::bezier::MultiBezier output = process(0, 1, 0, input); 0064 math::bezier::MultiBezier expected; 0065 expected.move_to(QPointF(0, 0)); 0066 expected.line_to(QPointF(100, 0)); 0067 COMPARE_MULTIBEZIER(output, expected); 0068 } 0069 0070 /* 0071 * ====================== 0072 * ^----------^ 0073 */ 0074 void test_process_line_start() 0075 { 0076 math::bezier::MultiBezier input; 0077 input.move_to(QPointF(0, 0)); 0078 input.line_to(QPointF(100, 0)); 0079 math::bezier::MultiBezier output = process(0, 0.5, 0, input); 0080 math::bezier::MultiBezier expected; 0081 expected.move_to(QPointF(0, 0)); 0082 expected.line_to(QPointF(50, 0)); 0083 COMPARE_MULTIBEZIER(output, expected); 0084 } 0085 0086 /* 0087 * ====================== 0088 * ^----------^ 0089 */ 0090 void test_process_line_mid() 0091 { 0092 math::bezier::MultiBezier input; 0093 input.move_to(QPointF(0, 0)); 0094 input.line_to(QPointF(100, 0)); 0095 math::bezier::MultiBezier output = process(0, 0.5, 0.2, input); 0096 math::bezier::MultiBezier expected; 0097 expected.move_to(QPointF(20, 0)); 0098 expected.line_to(QPointF(70, 0)); 0099 COMPARE_MULTIBEZIER(output, expected); 0100 } 0101 0102 /* 0103 * ====================== 0104 * ^----------^ 0105 */ 0106 void test_process_line_end() 0107 { 0108 math::bezier::MultiBezier input; 0109 input.move_to(QPointF(0, 0)); 0110 input.line_to(QPointF(100, 0)); 0111 math::bezier::MultiBezier output = process(0, 0.5, 0.5, input); 0112 math::bezier::MultiBezier expected; 0113 expected.move_to(QPointF(50, 0)); 0114 expected.line_to(QPointF(100, 0)); 0115 COMPARE_MULTIBEZIER(output, expected); 0116 } 0117 0118 /* 0119 * ====================== 0120 * -----^ ^----- 0121 */ 0122 void test_process_line_wrap() 0123 { 0124 math::bezier::MultiBezier input; 0125 input.move_to(QPointF(0, 0)); 0126 input.line_to(QPointF(100, 0)); 0127 math::bezier::MultiBezier output = process(0, 0.5, 0.7, input); 0128 math::bezier::MultiBezier expected; 0129 expected.move_to(QPointF(70, 0)); 0130 expected.line_to(QPointF(100, 0)); 0131 expected.move_to(QPointF(0, 0)); 0132 expected.line_to(QPointF(20, 0)); 0133 COMPARE_MULTIBEZIER(output, expected); 0134 } 0135 0136 // Square 0137 0138 /* ____ 0139 * | | 0140 * |____| 0141 * ____ 0142 * | | 0143 * |____| 0144 */ 0145 void test_process_square_full() 0146 { 0147 math::bezier::MultiBezier input; 0148 input.move_to(QPointF(0, 0)); 0149 input.line_to(QPointF(100, 0)); 0150 input.line_to(QPointF(100, 100)); 0151 input.line_to(QPointF(0, 100)); 0152 input.close(); 0153 math::bezier::MultiBezier output = process(0, 1, 0, input); 0154 COMPARE_MULTIBEZIER(output, input); 0155 } 0156 0157 /* ____ 0158 * | | 0159 * |____| 0160 * ____ 0161 * | 0162 * | 0163 */ 0164 void test_process_square_start_corner() 0165 { 0166 math::bezier::MultiBezier input; 0167 input.move_to(QPointF(0, 0)); 0168 input.line_to(QPointF(100, 0)); 0169 input.line_to(QPointF(100, 100)); 0170 input.line_to(QPointF(0, 100)); 0171 input.close(); 0172 math::bezier::MultiBezier output = process(0, 0.5, 0, input); 0173 math::bezier::MultiBezier expected; 0174 expected.move_to(QPointF(0, 0)); 0175 expected.line_to(QPointF(100, 0)); 0176 expected.line_to(QPointF(100, 100)); 0177 COMPARE_MULTIBEZIER(output, expected); 0178 } 0179 0180 /* ____ 0181 * | | 0182 * |____| 0183 * ____ 0184 * | 0185 * 0186 */ 0187 void test_process_square_start_edge() 0188 { 0189 math::bezier::MultiBezier input; 0190 input.move_to(QPointF(0, 0)); 0191 input.line_to(QPointF(100, 0)); 0192 input.line_to(QPointF(100, 100)); 0193 input.line_to(QPointF(0, 100)); 0194 input.close(); 0195 math::bezier::MultiBezier output = process(0, 0.375, 0, input); 0196 math::bezier::MultiBezier expected; 0197 expected.move_to(QPointF(0, 0)); 0198 expected.line_to(QPointF(100, 0)); 0199 expected.line_to(QPointF(100, 50)); 0200 COMPARE_MULTIBEZIER(output, expected); 0201 } 0202 0203 /* ____ 0204 * | | 0205 * |____| 0206 * 0207 * | 0208 * ____| 0209 */ 0210 void test_process_square_mid_corner() 0211 { 0212 math::bezier::MultiBezier input; 0213 input.move_to(QPointF(0, 0)); 0214 input.line_to(QPointF(100, 0)); 0215 input.line_to(QPointF(100, 100)); 0216 input.line_to(QPointF(0, 100)); 0217 input.close(); 0218 math::bezier::MultiBezier output = process(0, 0.5, 0.25, input); 0219 math::bezier::MultiBezier expected; 0220 expected.move_to(QPointF(100, 0)); 0221 expected.line_to(QPointF(100, 100)); 0222 expected.line_to(QPointF(0, 100)); 0223 COMPARE_MULTIBEZIER(output, expected); 0224 } 0225 0226 /* ____ 0227 * | | 0228 * |____| 0229 * __ 0230 * | 0231 * __| 0232 */ 0233 void test_process_square_mid_edge() 0234 { 0235 math::bezier::MultiBezier input; 0236 input.move_to(QPointF(0, 0)); 0237 input.line_to(QPointF(100, 0)); 0238 input.line_to(QPointF(100, 100)); 0239 input.line_to(QPointF(0, 100)); 0240 input.close(); 0241 math::bezier::MultiBezier output = process(0, 0.5, 0.125, input); 0242 math::bezier::MultiBezier expected; 0243 expected.move_to(QPointF(50, 0)); 0244 expected.line_to(QPointF(100, 0)); 0245 expected.line_to(QPointF(100, 100)); 0246 expected.line_to(QPointF(50, 100)); 0247 COMPARE_MULTIBEZIER(output, expected); 0248 } 0249 0250 /* ____ 0251 * | | 0252 * |____| 0253 * 0254 * | 0255 * |____ 0256 */ 0257 void test_process_square_end_corner() 0258 { 0259 math::bezier::MultiBezier input; 0260 input.move_to(QPointF(0, 0)); 0261 input.line_to(QPointF(100, 0)); 0262 input.line_to(QPointF(100, 100)); 0263 input.line_to(QPointF(0, 100)); 0264 input.close(); 0265 math::bezier::MultiBezier output = process(0, 0.5, 0.5, input); 0266 math::bezier::MultiBezier expected; 0267 expected.move_to(QPointF(100, 100)); 0268 expected.line_to(QPointF(0, 100)); 0269 expected.line_to(QPointF(0, 0)); 0270 COMPARE_MULTIBEZIER(output, expected); 0271 } 0272 0273 /* ____ 0274 * | | 0275 * |____| 0276 * 0277 * | 0278 * |__ 0279 */ 0280 void test_process_square_end_edge() 0281 { 0282 math::bezier::MultiBezier input; 0283 input.move_to(QPointF(0, 0)); 0284 input.line_to(QPointF(100, 0)); 0285 input.line_to(QPointF(100, 100)); 0286 input.line_to(QPointF(0, 100)); 0287 input.close(); 0288 math::bezier::MultiBezier output = process(0.625, 1, 0, input); 0289 math::bezier::MultiBezier expected; 0290 expected.move_to(QPointF(50, 100)); 0291 expected.line_to(QPointF(0, 100)); 0292 expected.line_to(QPointF(0, 0)); 0293 COMPARE_MULTIBEZIER(output, expected); 0294 } 0295 0296 /* ____ 0297 * | | 0298 * |____| 0299 * ____ 0300 * | 0301 * | 0302 */ 0303 void test_process_square_wrap_corner() 0304 { 0305 math::bezier::MultiBezier input; 0306 input.move_to(QPointF(0, 0)); 0307 input.line_to(QPointF(100, 0)); 0308 input.line_to(QPointF(100, 100)); 0309 input.line_to(QPointF(0, 100)); 0310 input.close(); 0311 math::bezier::MultiBezier output = process(0, 0.5, 0.75, input); 0312 math::bezier::MultiBezier expected; 0313 expected.move_to(QPointF(0, 100)); 0314 expected.line_to(QPointF(0, 0)); 0315 expected.line_to(QPointF(100, 0)); 0316 COMPARE_MULTIBEZIER(output, expected); 0317 } 0318 0319 /* ____ 0320 * | | 0321 * |____| 0322 * __ 0323 * | 0324 * |__ 0325 */ 0326 void test_process_square_wrap_edge() 0327 { 0328 math::bezier::MultiBezier input; 0329 input.move_to(QPointF(0, 0)); 0330 input.line_to(QPointF(100, 0)); 0331 input.line_to(QPointF(100, 100)); 0332 input.line_to(QPointF(0, 100)); 0333 input.close(); 0334 math::bezier::MultiBezier output = process(0, 0.5, 0.625, input); 0335 math::bezier::MultiBezier expected; 0336 expected.move_to(QPointF(50, 100)); 0337 expected.line_to(QPointF(0, 100)); 0338 expected.line_to(QPointF(0, 0)); 0339 expected.line_to(QPointF(50, 0)); 0340 COMPARE_MULTIBEZIER(output, expected); 0341 } 0342 0343 // Multi Line 0344 0345 /* 0346 * ==== ==== ==== ==== 0347 */ 0348 void test_process_multi_line_full() 0349 { 0350 math::bezier::MultiBezier input; 0351 0352 input.move_to(QPointF(0, 0)); 0353 input.line_to(QPointF(100, 0)); 0354 0355 input.move_to(QPointF(100, 0)); 0356 input.line_to(QPointF(200, 0)); 0357 0358 input.move_to(QPointF(200, 0)); 0359 input.line_to(QPointF(300, 0)); 0360 0361 input.move_to(QPointF(300, 0)); 0362 input.line_to(QPointF(400, 0)); 0363 0364 math::bezier::MultiBezier expected; 0365 0366 expected.move_to(QPointF(0, 0)); 0367 expected.line_to(QPointF(100, 0)); 0368 0369 expected.move_to(QPointF(100, 0)); 0370 expected.line_to(QPointF(200, 0)); 0371 0372 expected.move_to(QPointF(200, 0)); 0373 expected.line_to(QPointF(300, 0)); 0374 0375 expected.move_to(QPointF(300, 0)); 0376 expected.line_to(QPointF(400, 0)); 0377 0378 math::bezier::MultiBezier output = process(0, 1, 0, input); 0379 COMPARE_MULTIBEZIER(output, expected); 0380 } 0381 0382 /* 0383 * ==== ==== ---- ---- 0384 */ 0385 void test_process_multi_line_start_corner() 0386 { 0387 math::bezier::MultiBezier input; 0388 0389 input.move_to(QPointF(0, 0)); 0390 input.line_to(QPointF(100, 0)); 0391 0392 input.move_to(QPointF(100, 0)); 0393 input.line_to(QPointF(200, 0)); 0394 0395 input.move_to(QPointF(200, 0)); 0396 input.line_to(QPointF(300, 0)); 0397 0398 input.move_to(QPointF(300, 0)); 0399 input.line_to(QPointF(400, 0)); 0400 0401 math::bezier::MultiBezier expected; 0402 0403 expected.move_to(QPointF(0, 0)); 0404 expected.line_to(QPointF(100, 0)); 0405 0406 expected.move_to(QPointF(100, 0)); 0407 expected.line_to(QPointF(200, 0)); 0408 0409 math::bezier::MultiBezier output = process(0, 0.5, 0, input); 0410 COMPARE_MULTIBEZIER(output, expected); 0411 } 0412 0413 /* 0414 * ==== ==== ==-- ---- 0415 */ 0416 void test_process_multi_line_start_edge() 0417 { 0418 math::bezier::MultiBezier input; 0419 0420 input.move_to(QPointF(0, 0)); 0421 input.line_to(QPointF(100, 0)); 0422 0423 input.move_to(QPointF(100, 0)); 0424 input.line_to(QPointF(200, 0)); 0425 0426 input.move_to(QPointF(200, 0)); 0427 input.line_to(QPointF(300, 0)); 0428 0429 input.move_to(QPointF(300, 0)); 0430 input.line_to(QPointF(400, 0)); 0431 0432 math::bezier::MultiBezier expected; 0433 0434 expected.move_to(QPointF(0, 0)); 0435 expected.line_to(QPointF(100, 0)); 0436 0437 expected.move_to(QPointF(100, 0)); 0438 expected.line_to(QPointF(200, 0)); 0439 0440 expected.move_to(QPointF(200, 0)); 0441 expected.line_to(QPointF(250, 0)); 0442 0443 math::bezier::MultiBezier output = process(0, 0.625, 0, input); 0444 COMPARE_MULTIBEZIER(output, expected); 0445 } 0446 0447 /* 0448 * ---- ---- ==== ==== 0449 */ 0450 void test_process_multi_line_end_corner() 0451 { 0452 math::bezier::MultiBezier input; 0453 0454 input.move_to(QPointF(0, 0)); 0455 input.line_to(QPointF(100, 0)); 0456 0457 input.move_to(QPointF(100, 0)); 0458 input.line_to(QPointF(200, 0)); 0459 0460 input.move_to(QPointF(200, 0)); 0461 input.line_to(QPointF(300, 0)); 0462 0463 input.move_to(QPointF(300, 0)); 0464 input.line_to(QPointF(400, 0)); 0465 0466 math::bezier::MultiBezier expected; 0467 0468 expected.move_to(QPointF(200, 0)); 0469 expected.line_to(QPointF(300, 0)); 0470 0471 expected.move_to(QPointF(300, 0)); 0472 expected.line_to(QPointF(400, 0)); 0473 0474 math::bezier::MultiBezier output = process(0, 0.5, 0.5, input); 0475 COMPARE_MULTIBEZIER(output, expected); 0476 } 0477 0478 /* 0479 * ---- ---- --== ==== 0480 */ 0481 void test_process_multi_line_end_edge() 0482 { 0483 math::bezier::MultiBezier input; 0484 0485 input.move_to(QPointF(0, 0)); 0486 input.line_to(QPointF(100, 0)); 0487 0488 input.move_to(QPointF(100, 0)); 0489 input.line_to(QPointF(200, 0)); 0490 0491 input.move_to(QPointF(200, 0)); 0492 input.line_to(QPointF(300, 0)); 0493 0494 input.move_to(QPointF(300, 0)); 0495 input.line_to(QPointF(400, 0)); 0496 0497 math::bezier::MultiBezier expected; 0498 0499 expected.move_to(QPointF(250, 0)); 0500 expected.line_to(QPointF(300, 0)); 0501 0502 expected.move_to(QPointF(300, 0)); 0503 expected.line_to(QPointF(400, 0)); 0504 0505 math::bezier::MultiBezier output = process(0.625, 1, 0, input); 0506 COMPARE_MULTIBEZIER(output, expected); 0507 } 0508 0509 /* 0510 * ---- ==== ==== ---- 0511 */ 0512 void test_process_multi_line_mid_corner() 0513 { 0514 math::bezier::MultiBezier input; 0515 0516 input.move_to(QPointF(0, 0)); 0517 input.line_to(QPointF(100, 0)); 0518 0519 input.move_to(QPointF(100, 0)); 0520 input.line_to(QPointF(200, 0)); 0521 0522 input.move_to(QPointF(200, 0)); 0523 input.line_to(QPointF(300, 0)); 0524 0525 input.move_to(QPointF(300, 0)); 0526 input.line_to(QPointF(400, 0)); 0527 0528 math::bezier::MultiBezier expected; 0529 0530 expected.move_to(QPointF(100, 0)); 0531 expected.line_to(QPointF(200, 0)); 0532 0533 expected.move_to(QPointF(200, 0)); 0534 expected.line_to(QPointF(300, 0)); 0535 0536 math::bezier::MultiBezier output = process(0, 0.5, 0.25, input); 0537 COMPARE_MULTIBEZIER(output, expected); 0538 } 0539 0540 /* 0541 * --== ==== ==-- ---- 0542 */ 0543 void test_process_multi_line_mid_edge() 0544 { 0545 math::bezier::MultiBezier input; 0546 0547 input.move_to(QPointF(0, 0)); 0548 input.line_to(QPointF(100, 0)); 0549 0550 input.move_to(QPointF(100, 0)); 0551 input.line_to(QPointF(200, 0)); 0552 0553 input.move_to(QPointF(200, 0)); 0554 input.line_to(QPointF(300, 0)); 0555 0556 input.move_to(QPointF(300, 0)); 0557 input.line_to(QPointF(400, 0)); 0558 0559 math::bezier::MultiBezier expected; 0560 0561 expected.move_to(QPointF(50, 0)); 0562 expected.line_to(QPointF(100, 0)); 0563 0564 expected.move_to(QPointF(100, 0)); 0565 expected.line_to(QPointF(200, 0)); 0566 0567 expected.move_to(QPointF(200, 0)); 0568 expected.line_to(QPointF(250, 0)); 0569 0570 math::bezier::MultiBezier output = process(0.125, 0.625, 0, input); 0571 COMPARE_MULTIBEZIER(output, expected); 0572 } 0573 0574 /* 0575 * ==== ---- ---- ==== 0576 */ 0577 void test_process_multi_line_wrap_corner() 0578 { 0579 math::bezier::MultiBezier input; 0580 0581 input.move_to(QPointF(0, 0)); 0582 input.line_to(QPointF(100, 0)); 0583 0584 input.move_to(QPointF(100, 0)); 0585 input.line_to(QPointF(200, 0)); 0586 0587 input.move_to(QPointF(200, 0)); 0588 input.line_to(QPointF(300, 0)); 0589 0590 input.move_to(QPointF(300, 0)); 0591 input.line_to(QPointF(400, 0)); 0592 0593 math::bezier::MultiBezier expected; 0594 0595 expected.move_to(QPointF(300, 0)); 0596 expected.line_to(QPointF(400, 0)); 0597 0598 expected.move_to(QPointF(0, 0)); 0599 expected.line_to(QPointF(100, 0)); 0600 0601 math::bezier::MultiBezier output = process(0, 0.5, 0.75, input); 0602 COMPARE_MULTIBEZIER(output, expected); 0603 } 0604 0605 /* 0606 * ==-- ---- --== ==== 0607 */ 0608 void test_process_multi_line_wrap_edge() 0609 { 0610 math::bezier::MultiBezier input; 0611 0612 input.move_to(QPointF(0, 0)); 0613 input.line_to(QPointF(100, 0)); 0614 0615 input.move_to(QPointF(100, 0)); 0616 input.line_to(QPointF(200, 0)); 0617 0618 input.move_to(QPointF(200, 0)); 0619 input.line_to(QPointF(300, 0)); 0620 0621 input.move_to(QPointF(300, 0)); 0622 input.line_to(QPointF(400, 0)); 0623 0624 math::bezier::MultiBezier expected; 0625 0626 expected.move_to(QPointF(250, 0)); 0627 expected.line_to(QPointF(300, 0)); 0628 0629 expected.move_to(QPointF(300, 0)); 0630 expected.line_to(QPointF(400, 0)); 0631 0632 expected.move_to(QPointF(0, 0)); 0633 expected.line_to(QPointF(50, 0)); 0634 0635 math::bezier::MultiBezier output = process(0, 0.5, 0.625, input); 0636 COMPARE_MULTIBEZIER(output, expected); 0637 } 0638 0639 0640 /* 0641 * ==== ==== ---- ==== 0642 */ 0643 void test_process_multi_line_wrap_corner_same() 0644 { 0645 math::bezier::MultiBezier input; 0646 0647 input.move_to(QPointF(0, 0)); 0648 input.line_to(QPointF(100, 0)); 0649 0650 input.move_to(QPointF(100, 0)); 0651 input.line_to(QPointF(200, 0)); 0652 0653 input.move_to(QPointF(200, 0)); 0654 input.line_to(QPointF(300, 0)); 0655 0656 input.move_to(QPointF(300, 0)); 0657 input.line_to(QPointF(400, 0)); 0658 0659 math::bezier::MultiBezier expected; 0660 0661 expected.move_to(QPointF(300, 0)); 0662 expected.line_to(QPointF(400, 0)); 0663 0664 expected.move_to(QPointF(0, 0)); 0665 expected.line_to(QPointF(100, 0)); 0666 0667 expected.move_to(QPointF(100, 0)); 0668 expected.line_to(QPointF(200, 0)); 0669 0670 math::bezier::MultiBezier output = process(0, 0.75, 0.75, input); 0671 COMPARE_MULTIBEZIER(output, expected); 0672 } 0673 0674 /* 0675 * =--= ==== ==== ==== 0676 */ 0677 void test_process_multi_line_wrap_edge_same() 0678 { 0679 math::bezier::MultiBezier input; 0680 0681 input.move_to(QPointF(0, 0)); 0682 input.line_to(QPointF(100, 0)); 0683 0684 input.move_to(QPointF(100, 0)); 0685 input.line_to(QPointF(200, 0)); 0686 0687 input.move_to(QPointF(200, 0)); 0688 input.line_to(QPointF(300, 0)); 0689 0690 input.move_to(QPointF(300, 0)); 0691 input.line_to(QPointF(400, 0)); 0692 0693 math::bezier::MultiBezier expected; 0694 0695 expected.move_to(QPointF(75, 0)); 0696 expected.line_to(QPointF(100, 0)); 0697 0698 expected.move_to(QPointF(100, 0)); 0699 expected.line_to(QPointF(200, 0)); 0700 0701 expected.move_to(QPointF(200, 0)); 0702 expected.line_to(QPointF(300, 0)); 0703 0704 expected.move_to(QPointF(300, 0)); 0705 expected.line_to(QPointF(400, 0)); 0706 0707 expected.move_to(QPointF(0, 0)); 0708 expected.line_to(QPointF(25, 0)); 0709 0710 math::bezier::MultiBezier output = process(0, 14./16., 3./16., input); 0711 COMPARE_MULTIBEZIER(output, expected); 0712 } 0713 0714 // Multi Square 0715 0716 /* ____ ____ ____ ____ 0717 * | | | | | | | | 0718 * |____| |____| |____| |____| 0719 * ____ ____ ____ ____ 0720 * | | | | | | | | 0721 * |____| |____| |____| |____| 0722 */ 0723 void test_process_multi_square_full() 0724 { 0725 math::bezier::MultiBezier input; 0726 0727 input.move_to(QPointF(000, 0)); 0728 input.line_to(QPointF(100, 0)); 0729 input.line_to(QPointF(100, 100)); 0730 input.line_to(QPointF(000, 100)); 0731 input.close(); 0732 0733 input.move_to(QPointF(100, 0)); 0734 input.line_to(QPointF(200, 0)); 0735 input.line_to(QPointF(200, 100)); 0736 input.line_to(QPointF(100, 100)); 0737 input.close(); 0738 0739 input.move_to(QPointF(200, 0)); 0740 input.line_to(QPointF(300, 0)); 0741 input.line_to(QPointF(300, 100)); 0742 input.line_to(QPointF(200, 100)); 0743 input.close(); 0744 0745 input.move_to(QPointF(300, 0)); 0746 input.line_to(QPointF(400, 0)); 0747 input.line_to(QPointF(400, 100)); 0748 input.line_to(QPointF(300, 100)); 0749 input.close(); 0750 0751 math::bezier::MultiBezier expected; 0752 0753 expected.move_to(QPointF(000, 000)); 0754 expected.line_to(QPointF(100, 000)); 0755 expected.line_to(QPointF(100, 100)); 0756 expected.line_to(QPointF(000, 100)); 0757 expected.close(); 0758 0759 expected.move_to(QPointF(100, 0)); 0760 expected.line_to(QPointF(200, 0)); 0761 expected.line_to(QPointF(200, 100)); 0762 expected.line_to(QPointF(100, 100)); 0763 expected.close(); 0764 0765 expected.move_to(QPointF(200, 0)); 0766 expected.line_to(QPointF(300, 0)); 0767 expected.line_to(QPointF(300, 100)); 0768 expected.line_to(QPointF(200, 100)); 0769 expected.close(); 0770 0771 expected.move_to(QPointF(300, 0)); 0772 expected.line_to(QPointF(400, 0)); 0773 expected.line_to(QPointF(400, 100)); 0774 expected.line_to(QPointF(300, 100)); 0775 expected.close(); 0776 0777 math::bezier::MultiBezier output = process(0, 1, 0, input); 0778 0779 COMPARE_MULTIBEZIER(output, expected); 0780 } 0781 0782 /* ____ ____ ____ ____ 0783 * | | | | | | | | 0784 * |____| |____| |____| |____| 0785 * ____ ____ 0786 * | | | | 0787 * |____| |____| 0788 */ 0789 void test_process_multi_square_start_corner() 0790 { 0791 math::bezier::MultiBezier input; 0792 0793 input.move_to(QPointF(000, 0)); 0794 input.line_to(QPointF(100, 0)); 0795 input.line_to(QPointF(100, 100)); 0796 input.line_to(QPointF(000, 100)); 0797 input.close(); 0798 0799 input.move_to(QPointF(100, 0)); 0800 input.line_to(QPointF(200, 0)); 0801 input.line_to(QPointF(200, 100)); 0802 input.line_to(QPointF(100, 100)); 0803 input.close(); 0804 0805 input.move_to(QPointF(200, 0)); 0806 input.line_to(QPointF(300, 0)); 0807 input.line_to(QPointF(300, 100)); 0808 input.line_to(QPointF(200, 100)); 0809 input.close(); 0810 0811 input.move_to(QPointF(300, 0)); 0812 input.line_to(QPointF(400, 0)); 0813 input.line_to(QPointF(400, 100)); 0814 input.line_to(QPointF(300, 100)); 0815 input.close(); 0816 0817 math::bezier::MultiBezier expected; 0818 0819 expected.move_to(QPointF(000, 0)); 0820 expected.line_to(QPointF(100, 0)); 0821 expected.line_to(QPointF(100, 100)); 0822 expected.line_to(QPointF(000, 100)); 0823 expected.close(); 0824 0825 expected.move_to(QPointF(100, 0)); 0826 expected.line_to(QPointF(200, 0)); 0827 expected.line_to(QPointF(200, 100)); 0828 expected.line_to(QPointF(100, 100)); 0829 expected.close(); 0830 0831 math::bezier::MultiBezier output = process(0, 0.5, 0, input); 0832 0833 COMPARE_MULTIBEZIER(output, expected); 0834 } 0835 0836 /* ____ ____ ____ ____ 0837 * | | | | | | | | 0838 * |____| |____| |____| |____| 0839 * ____ ____ 0840 * | | | | 0841 * |____| |____| 0842 */ 0843 void test_process_multi_square_end_corner() 0844 { 0845 math::bezier::MultiBezier input; 0846 0847 input.move_to(QPointF(000, 0)); 0848 input.line_to(QPointF(100, 0)); 0849 input.line_to(QPointF(100, 100)); 0850 input.line_to(QPointF(000, 100)); 0851 input.close(); 0852 0853 input.move_to(QPointF(100, 0)); 0854 input.line_to(QPointF(200, 0)); 0855 input.line_to(QPointF(200, 100)); 0856 input.line_to(QPointF(100, 100)); 0857 input.close(); 0858 0859 input.move_to(QPointF(200, 0)); 0860 input.line_to(QPointF(300, 0)); 0861 input.line_to(QPointF(300, 100)); 0862 input.line_to(QPointF(200, 100)); 0863 input.close(); 0864 0865 input.move_to(QPointF(300, 0)); 0866 input.line_to(QPointF(400, 0)); 0867 input.line_to(QPointF(400, 100)); 0868 input.line_to(QPointF(300, 100)); 0869 input.close(); 0870 0871 math::bezier::MultiBezier expected; 0872 0873 expected.move_to(QPointF(200, 0)); 0874 expected.line_to(QPointF(300, 0)); 0875 expected.line_to(QPointF(300, 100)); 0876 expected.line_to(QPointF(200, 100)); 0877 expected.close(); 0878 0879 expected.move_to(QPointF(300, 0)); 0880 expected.line_to(QPointF(400, 0)); 0881 expected.line_to(QPointF(400, 100)); 0882 expected.line_to(QPointF(300, 100)); 0883 expected.close(); 0884 0885 math::bezier::MultiBezier output = process(0, 0.5, 0.5, input); 0886 0887 COMPARE_MULTIBEZIER(output, expected); 0888 } 0889 0890 /* ____ ____ ____ ____ 0891 * | | | | | | | | 0892 * |____| |____| |____| |____| 0893 * ____ ____ 0894 * | | | | 0895 * |____| |____| 0896 */ 0897 void test_process_multi_square_mid_corner() 0898 { 0899 math::bezier::MultiBezier input; 0900 0901 input.move_to(QPointF(000, 0)); 0902 input.line_to(QPointF(100, 0)); 0903 input.line_to(QPointF(100, 100)); 0904 input.line_to(QPointF(000, 100)); 0905 input.close(); 0906 0907 input.move_to(QPointF(100, 0)); 0908 input.line_to(QPointF(200, 0)); 0909 input.line_to(QPointF(200, 100)); 0910 input.line_to(QPointF(100, 100)); 0911 input.close(); 0912 0913 input.move_to(QPointF(200, 0)); 0914 input.line_to(QPointF(300, 0)); 0915 input.line_to(QPointF(300, 100)); 0916 input.line_to(QPointF(200, 100)); 0917 input.close(); 0918 0919 input.move_to(QPointF(300, 0)); 0920 input.line_to(QPointF(400, 0)); 0921 input.line_to(QPointF(400, 100)); 0922 input.line_to(QPointF(300, 100)); 0923 input.close(); 0924 0925 math::bezier::MultiBezier expected; 0926 0927 expected.move_to(QPointF(100, 0)); 0928 expected.line_to(QPointF(200, 0)); 0929 expected.line_to(QPointF(200, 100)); 0930 expected.line_to(QPointF(100, 100)); 0931 expected.close(); 0932 0933 expected.move_to(QPointF(200, 0)); 0934 expected.line_to(QPointF(300, 0)); 0935 expected.line_to(QPointF(300, 100)); 0936 expected.line_to(QPointF(200, 100)); 0937 expected.close(); 0938 0939 math::bezier::MultiBezier output = process(0, 0.5, 0.25, input); 0940 0941 COMPARE_MULTIBEZIER(output, expected); 0942 } 0943 0944 /* ____ ____ ____ ____ 0945 * | | | | | | | | 0946 * |____| |____| |____| |____| 0947 * ____ ____ 0948 * | | | | 0949 * |____| |____| 0950 */ 0951 void test_process_multi_square_wrap_corner() 0952 { 0953 math::bezier::MultiBezier input; 0954 0955 input.move_to(QPointF(000, 0)); 0956 input.line_to(QPointF(100, 0)); 0957 input.line_to(QPointF(100, 100)); 0958 input.line_to(QPointF(000, 100)); 0959 input.close(); 0960 0961 input.move_to(QPointF(100, 0)); 0962 input.line_to(QPointF(200, 0)); 0963 input.line_to(QPointF(200, 100)); 0964 input.line_to(QPointF(100, 100)); 0965 input.close(); 0966 0967 input.move_to(QPointF(200, 0)); 0968 input.line_to(QPointF(300, 0)); 0969 input.line_to(QPointF(300, 100)); 0970 input.line_to(QPointF(200, 100)); 0971 input.close(); 0972 0973 input.move_to(QPointF(300, 0)); 0974 input.line_to(QPointF(400, 0)); 0975 input.line_to(QPointF(400, 100)); 0976 input.line_to(QPointF(300, 100)); 0977 input.close(); 0978 0979 math::bezier::MultiBezier expected; 0980 0981 expected.move_to(QPointF(300, 0)); 0982 expected.line_to(QPointF(400, 0)); 0983 expected.line_to(QPointF(400, 100)); 0984 expected.line_to(QPointF(300, 100)); 0985 expected.close(); 0986 0987 expected.move_to(QPointF(000, 0)); 0988 expected.line_to(QPointF(100, 0)); 0989 expected.line_to(QPointF(100, 100)); 0990 expected.line_to(QPointF(000, 100)); 0991 expected.close(); 0992 0993 math::bezier::MultiBezier output = process(0, 0.5, 0.75, input); 0994 0995 COMPARE_MULTIBEZIER(output, expected); 0996 } 0997 0998 /* ____ ____ ____ ____ 0999 * | | | | | | | | 1000 * |____| |____| |____| |____| 1001 * ____ ____ ____ 1002 * | | | | | 1003 * |____| |____| | 1004 */ 1005 void test_process_multi_square_start_edge() 1006 { 1007 math::bezier::MultiBezier input; 1008 1009 input.move_to(QPointF(000, 0)); 1010 input.line_to(QPointF(100, 0)); 1011 input.line_to(QPointF(100, 100)); 1012 input.line_to(QPointF(000, 100)); 1013 input.close(); 1014 1015 input.move_to(QPointF(100, 0)); 1016 input.line_to(QPointF(200, 0)); 1017 input.line_to(QPointF(200, 100)); 1018 input.line_to(QPointF(100, 100)); 1019 input.close(); 1020 1021 input.move_to(QPointF(200, 0)); 1022 input.line_to(QPointF(300, 0)); 1023 input.line_to(QPointF(300, 100)); 1024 input.line_to(QPointF(200, 100)); 1025 input.close(); 1026 1027 input.move_to(QPointF(300, 0)); 1028 input.line_to(QPointF(400, 0)); 1029 input.line_to(QPointF(400, 100)); 1030 input.line_to(QPointF(300, 100)); 1031 input.close(); 1032 1033 math::bezier::MultiBezier expected; 1034 1035 expected.move_to(QPointF(000, 0)); 1036 expected.line_to(QPointF(100, 0)); 1037 expected.line_to(QPointF(100, 100)); 1038 expected.line_to(QPointF(000, 100)); 1039 expected.close(); 1040 1041 expected.move_to(QPointF(100, 0)); 1042 expected.line_to(QPointF(200, 0)); 1043 expected.line_to(QPointF(200, 100)); 1044 expected.line_to(QPointF(100, 100)); 1045 expected.close(); 1046 1047 expected.move_to(QPointF(200, 0)); 1048 expected.line_to(QPointF(300, 0)); 1049 expected.line_to(QPointF(300, 100)); 1050 1051 math::bezier::MultiBezier output = process(0, 0.625, 0, input); 1052 1053 COMPARE_MULTIBEZIER(output, expected); 1054 } 1055 1056 /* ____ ____ ____ ____ 1057 * | | | | | | | | 1058 * |____| |____| |____| |____| 1059 * ____ 1060 * | | | 1061 * |____ |____| 1062 */ 1063 void test_process_multi_square_end_edge() 1064 { 1065 math::bezier::MultiBezier input; 1066 1067 input.move_to(QPointF(000, 0)); 1068 input.line_to(QPointF(100, 0)); 1069 input.line_to(QPointF(100, 100)); 1070 input.line_to(QPointF(000, 100)); 1071 input.close(); 1072 1073 input.move_to(QPointF(100, 0)); 1074 input.line_to(QPointF(200, 0)); 1075 input.line_to(QPointF(200, 100)); 1076 input.line_to(QPointF(100, 100)); 1077 input.close(); 1078 1079 input.move_to(QPointF(200, 0)); 1080 input.line_to(QPointF(300, 0)); 1081 input.line_to(QPointF(300, 100)); 1082 input.line_to(QPointF(200, 100)); 1083 input.close(); 1084 1085 input.move_to(QPointF(300, 0)); 1086 input.line_to(QPointF(400, 0)); 1087 input.line_to(QPointF(400, 100)); 1088 input.line_to(QPointF(300, 100)); 1089 input.close(); 1090 1091 math::bezier::MultiBezier expected; 1092 1093 expected.move_to(QPointF(300, 100)); 1094 expected.line_to(QPointF(200, 100)); 1095 expected.line_to(QPointF(200, 0)); 1096 1097 expected.move_to(QPointF(300, 0)); 1098 expected.line_to(QPointF(400, 0)); 1099 expected.line_to(QPointF(400, 100)); 1100 expected.line_to(QPointF(300, 100)); 1101 expected.close(); 1102 1103 math::bezier::MultiBezier output = process(0.625, 1, 0, input); 1104 1105 COMPARE_MULTIBEZIER(output, expected); 1106 } 1107 1108 /* ____ ____ ____ ____ 1109 * | | | | | | | | 1110 * |____| |____| |____| |____| 1111 * ____ 1112 * | | 1113 * | |____ 1114 */ 1115 void test_process_multi_square_wrap_edge() 1116 { 1117 math::bezier::MultiBezier input; 1118 1119 input.move_to(QPointF(000, 0)); 1120 input.line_to(QPointF(100, 0)); 1121 input.line_to(QPointF(100, 100)); 1122 input.line_to(QPointF(000, 100)); 1123 input.close(); 1124 1125 input.move_to(QPointF(100, 0)); 1126 input.line_to(QPointF(200, 0)); 1127 input.line_to(QPointF(200, 100)); 1128 input.line_to(QPointF(100, 100)); 1129 input.close(); 1130 1131 input.move_to(QPointF(200, 0)); 1132 input.line_to(QPointF(300, 0)); 1133 input.line_to(QPointF(300, 100)); 1134 input.line_to(QPointF(200, 100)); 1135 input.close(); 1136 1137 input.move_to(QPointF(300, 0)); 1138 input.line_to(QPointF(400, 0)); 1139 input.line_to(QPointF(400, 100)); 1140 input.line_to(QPointF(300, 100)); 1141 input.close(); 1142 1143 math::bezier::MultiBezier expected; 1144 1145 expected.move_to(QPointF(400, 100)); 1146 expected.line_to(QPointF(300, 100)); 1147 expected.line_to(QPointF(300, 0)); 1148 1149 expected.move_to(QPointF(000, 0)); 1150 expected.line_to(QPointF(100, 0)); 1151 expected.line_to(QPointF(100, 100)); 1152 1153 math::bezier::MultiBezier output = process(0, 2./8., 7./8., input); 1154 1155 COMPARE_MULTIBEZIER(output, expected); 1156 } 1157 1158 /* ____ ____ ____ ____ 1159 * | | | | | | | | 1160 * |____| |____| |____| |____| 1161 * ____ 1162 * | | 1163 * |____ | 1164 */ 1165 void test_process_multi_square_mid_edge() 1166 { 1167 math::bezier::MultiBezier input; 1168 1169 input.move_to(QPointF(000, 0)); 1170 input.line_to(QPointF(100, 0)); 1171 input.line_to(QPointF(100, 100)); 1172 input.line_to(QPointF(000, 100)); 1173 input.close(); 1174 1175 input.move_to(QPointF(100, 0)); 1176 input.line_to(QPointF(200, 0)); 1177 input.line_to(QPointF(200, 100)); 1178 input.line_to(QPointF(100, 100)); 1179 input.close(); 1180 1181 input.move_to(QPointF(200, 0)); 1182 input.line_to(QPointF(300, 0)); 1183 input.line_to(QPointF(300, 100)); 1184 input.line_to(QPointF(200, 100)); 1185 input.close(); 1186 1187 input.move_to(QPointF(300, 0)); 1188 input.line_to(QPointF(400, 0)); 1189 input.line_to(QPointF(400, 100)); 1190 input.line_to(QPointF(300, 100)); 1191 input.close(); 1192 1193 math::bezier::MultiBezier expected; 1194 1195 expected.move_to(QPointF(200, 100)); 1196 expected.line_to(QPointF(100, 100)); 1197 expected.line_to(QPointF(100, 0)); 1198 1199 expected.move_to(QPointF(200, 0)); 1200 expected.line_to(QPointF(300, 0)); 1201 expected.line_to(QPointF(300, 100)); 1202 1203 math::bezier::MultiBezier output = process(3./8., 5./8., 0, input); 1204 1205 COMPARE_MULTIBEZIER(output, expected); 1206 } 1207 }; 1208 1209 QTEST_GUILESS_MAIN(TestTrimPath) 1210 #include "test_trim_path.moc" 1211