|
66 | 66 | Procedure LoadFromSaveToStream;
|
67 | 67 | End;
|
68 | 68 |
|
69 |
| - { TOtherTests } |
| 69 | + { TGeneralTests } |
70 | 70 |
|
71 |
| - TOtherTests = Class(TTestCase) |
| 71 | + TGeneralTests = Class(TTestCase) |
72 | 72 | protected
|
| 73 | + //Procedure SetUp; override; |
| 74 | + //Procedure TearDown; override; |
73 | 75 | published
|
74 |
| - Procedure Convolve1D; |
75 |
| - Procedure ConvolveAVG; |
| 76 | + Procedure RectIsInRect; |
| 77 | + Procedure RectIsNotInRect; |
76 | 78 | End;
|
77 | 79 |
|
78 | 80 | Implementation
|
|
430 | 432 | m.free;
|
431 | 433 | End;
|
432 | 434 |
|
433 |
| -{ TOtherTests } |
| 435 | +{ TGeneralTests } |
434 | 436 |
|
435 |
| -Procedure TOtherTests.Convolve1D; |
| 437 | +Procedure TGeneralTests.RectIsInRect; |
436 | 438 | Var
|
437 |
| - a, b, c: TVectorN; |
| 439 | + TL1, BR1, TL2, BR2: TVector2; |
438 | 440 | Begin
|
439 | 441 | (*
|
440 |
| - * Falten mit "nicht symmetrischem" filter kern |
| 442 | + * Overlapping Edges |
441 | 443 | *)
|
442 |
| - a := VN([1, 2, 3]); |
443 |
| - b := VN([4, 5, 6]); |
444 |
| - c := Convolve(a, b); |
445 |
| - AssertEquals('Invalid len', 5, length(c)); |
446 |
| - AssertEquals('Invalid result [0]', 4, c[0]); |
447 |
| - AssertEquals('Invalid result [1]', 13, c[1]); |
448 |
| - AssertEquals('Invalid result [2]', 28, c[2]); |
449 |
| - AssertEquals('Invalid result [3]', 27, c[3]); |
450 |
| - AssertEquals('Invalid result [4]', 18, c[4]); |
| 444 | + TL1 := v2(-1, 1); |
| 445 | + BR1 := v2(1, -1); |
| 446 | + TL2 := v2(0.5, 2); |
| 447 | + BR2 := v2(2, 0.5); |
| 448 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 449 | + TL2 := v2(0.5, -2); |
| 450 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 451 | + BR2 := v2(-2, -0.5); |
| 452 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 453 | + TL2 := v2(-0.5, 2); |
| 454 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 455 | + (* |
| 456 | + * Overlapping Sides |
| 457 | + *) |
| 458 | + TL2 := v2(0.5, 0.5); |
| 459 | + BR2 := v2(2, -0.5); |
| 460 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 461 | + BR2 := v2(-0.5, -2); |
| 462 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 463 | + TL2 := v2(-2, 0.5); |
| 464 | + BR2 := v2(-0.5, -0.5); |
| 465 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 466 | + TL2 := v2(0.5, 2); |
| 467 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 468 | + (* |
| 469 | + * complete in each other |
| 470 | + *) |
| 471 | + TL2 := v2(-2, 2); |
| 472 | + BR2 := v2(2, -2); |
| 473 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 474 | + TL2 := v2(-0.5, 0.5); |
| 475 | + BR2 := v2(0.5, -0.5); |
| 476 | + AssertTrue(RectIntersectRect(TL1, BR1, TL2, BR2)); |
451 | 477 | End;
|
452 | 478 |
|
453 |
| -Procedure TOtherTests.ConvolveAVG; |
| 479 | +Procedure TGeneralTests.RectIsNotInRect; |
454 | 480 | Var
|
455 |
| - a, b, c: TVectorN; |
| 481 | + TL1, BR1, TL2, BR2: TVector2; |
456 | 482 | Begin
|
457 |
| - (* |
458 |
| - * Faltung als Mittelwert filter |
459 |
| - *) |
460 |
| - a := vn([0, 0, 10, 10, 10, 0, 0]); |
461 |
| - b := vn([0.5, 0.5]); |
462 |
| - c := Convolve(a, b); |
463 |
| - AssertEquals('Invalid len', 8, length(c)); |
464 |
| - AssertEquals('Invalid result [0]', 0, c[0]); |
465 |
| - AssertEquals('Invalid result [1]', 0, c[1]); |
466 |
| - AssertEquals('Invalid result [2]', 5, c[2]); |
467 |
| - AssertEquals('Invalid result [3]', 10, c[3]); |
468 |
| - AssertEquals('Invalid result [4]', 10, c[4]); |
469 |
| - AssertEquals('Invalid result [5]', 5, c[5]); |
470 |
| - AssertEquals('Invalid result [6]', 0, c[6]); |
471 |
| - AssertEquals('Invalid result [7]', 0, c[7]); |
| 483 | + // Above |
| 484 | + TL1 := v2(-1, 1); |
| 485 | + BR1 := v2(1, -1); |
| 486 | + TL2 := v2(-2.5, 3.5); |
| 487 | + BR2 := v2(-1.5, 1.5); |
| 488 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 489 | + TL2 := v2(-0.5, 3.5); |
| 490 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 491 | + BR2 := v2(0.5, 1.5); |
| 492 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 493 | + TL2 := v2(1.5, 3.5); |
| 494 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 495 | + BR2 := v2(2.5, 1.5); |
| 496 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 497 | + // Side by side |
| 498 | + TL2 := v2(-2.5, 3.5); // left |
| 499 | + BR2 := v2(-1.5, 1.5); |
| 500 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 501 | + TL2 := v2(-2.5, 0.5); |
| 502 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 503 | + BR2 := v2(-1.5, -0.5); |
| 504 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 505 | + TL2 := v2(-2.5, -1.5); |
| 506 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 507 | + BR2 := v2(-1.5, -2.5); |
| 508 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 509 | + TL2 := v2(2.5, 3.5); // right |
| 510 | + BR2 := v2(1.5, 1.5); |
| 511 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 512 | + TL2 := v2(2.5, 0.5); |
| 513 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 514 | + BR2 := v2(1.5, -0.5); |
| 515 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 516 | + TL2 := v2(2.5, -1.5); |
| 517 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 518 | + BR2 := v2(1.5, -2.5); |
| 519 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 520 | + // Below |
| 521 | + TL2 := v2(-2.5, -3.5); |
| 522 | + BR2 := v2(-1.5, -1.5); |
| 523 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 524 | + TL2 := v2(-0.5, -3.5); |
| 525 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 526 | + BR2 := v2(0.5, -1.5); |
| 527 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 528 | + TL2 := v2(1.5, -3.5); |
| 529 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
| 530 | + BR2 := v2(2.5, -1.5); |
| 531 | + AssertFalse(RectIntersectRect(TL1, BR1, TL2, BR2)); |
472 | 532 | End;
|
473 | 533 |
|
474 | 534 | Initialization
|
|
479 | 539 | RegisterTest(TMatrix3x3Tests);
|
480 | 540 | RegisterTest(TMatrix4x4Tests);
|
481 | 541 | RegisterTest(TMatrixNxMTests);
|
482 |
| - RegisterTest(TOtherTests); |
483 |
| - |
| 542 | + RegisterTest(TGeneralTests); |
484 | 543 | End.
|
485 | 544 |
|
0 commit comments