| 662 | |
| 663 | template <class T> |
| 664 | void |
| 665 | testCenter (const char* type) |
| 666 | { |
| 667 | cout << " center() for type " << type << endl; |
| 668 | |
| 669 | // |
| 670 | // Center of empty box. |
| 671 | // |
| 672 | { |
| 673 | IMATH_INTERNAL_NAMESPACE::Box<T> b; |
| 674 | assert (b.center () == T (0)); |
| 675 | } |
| 676 | |
| 677 | // |
| 678 | // Center of non-empty, has-volume box. |
| 679 | // Boxes are: |
| 680 | // 2D: [(-1, -1), (1, 1) ] |
| 681 | // 3D: [(-1, -1, -1), (1, 1, 1) ] |
| 682 | // 4D: [(-1, -1, -1, -1), (1, 1, 1, 1) ] |
| 683 | // |
| 684 | // and |
| 685 | // |
| 686 | // 2D: [(-2, -4), ( 8, 2) ] |
| 687 | // 3D: [(-2, -4, -6), (12, 8, 2) ] |
| 688 | // 4D: [(-2, -4, -6, -8), (16, 12, 8, 4) ] |
| 689 | // |
| 690 | { |
| 691 | IMATH_INTERNAL_NAMESPACE::Box<T> b0 (T (-1), T (1)); |
| 692 | assert (b0.center () == T (0)); |
| 693 | |
| 694 | T p0; |
| 695 | T p1; |
| 696 | for (unsigned int i = 0; i < T::dimensions (); i++) |
| 697 | { |
| 698 | int lo = 1 << (i + 1); |
| 699 | int hi = 1 << (T::dimensions () - i); |
| 700 | p0[i] = -static_cast<typename T::BaseType>(lo); |
| 701 | p1[i] = static_cast<typename T::BaseType>(hi); |
| 702 | } |
| 703 | IMATH_INTERNAL_NAMESPACE::Box<T> b1 (p0, p1); |
| 704 | assert (b1.center () == (p1 + p0) / 2); |
| 705 | } |
| 706 | |
| 707 | // |
| 708 | // Center of non-empty, no-volume box. |
| 709 | // Boxes are: |
| 710 | // 2D: [(0, 0), (0, 2) ] |
| 711 | // 3D: [(0, 0, 0), (0, 0, 2) ] |
| 712 | // 4D: [(0, 0, 0, 0), (0, 0, 0, 2)] |
| 713 | // |
| 714 | { |
| 715 | T min (0); |
| 716 | T max = min; |
| 717 | max[T::dimensions () - 1] = 2; |
| 718 | |
| 719 | IMATH_INTERNAL_NAMESPACE::Box<T> b (min, max); |
| 720 | |
| 721 | assert (b.center () == max / 2); |
nothing calls this directly
no test coverage detected