| 26 | |
| 27 | |
| 28 | template<typename BoxType> void alignedbox(const BoxType& box) |
| 29 | { |
| 30 | /* this test covers the following files: |
| 31 | AlignedBox.h |
| 32 | */ |
| 33 | typedef typename BoxType::Scalar Scalar; |
| 34 | typedef NumTraits<Scalar> ScalarTraits; |
| 35 | typedef typename ScalarTraits::Real RealScalar; |
| 36 | typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType; |
| 37 | |
| 38 | const Index dim = box.dim(); |
| 39 | |
| 40 | VectorType p0 = VectorType::Random(dim); |
| 41 | VectorType p1 = VectorType::Random(dim); |
| 42 | while( p1 == p0 ){ |
| 43 | p1 = VectorType::Random(dim); } |
| 44 | RealScalar s1 = internal::random<RealScalar>(0,1); |
| 45 | |
| 46 | BoxType b0(dim); |
| 47 | BoxType b1(VectorType::Random(dim),VectorType::Random(dim)); |
| 48 | BoxType b2; |
| 49 | |
| 50 | kill_extra_precision(b1); |
| 51 | kill_extra_precision(p0); |
| 52 | kill_extra_precision(p1); |
| 53 | |
| 54 | b0.extend(p0); |
| 55 | b0.extend(p1); |
| 56 | VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1)); |
| 57 | VERIFY(b0.contains(b0.center())); |
| 58 | VERIFY_IS_APPROX(b0.center(),(p0+p1)/Scalar(2)); |
| 59 | |
| 60 | (b2 = b0).extend(b1); |
| 61 | VERIFY(b2.contains(b0)); |
| 62 | VERIFY(b2.contains(b1)); |
| 63 | VERIFY_IS_APPROX(b2.clamp(b0), b0); |
| 64 | |
| 65 | // intersection |
| 66 | BoxType box1(VectorType::Random(dim)); |
| 67 | box1.extend(VectorType::Random(dim)); |
| 68 | BoxType box2(VectorType::Random(dim)); |
| 69 | box2.extend(VectorType::Random(dim)); |
| 70 | |
| 71 | VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty()); |
| 72 | |
| 73 | // alignment -- make sure there is no memory alignment assertion |
| 74 | BoxType *bp0 = new BoxType(dim); |
| 75 | BoxType *bp1 = new BoxType(dim); |
| 76 | bp0->extend(*bp1); |
| 77 | delete bp0; |
| 78 | delete bp1; |
| 79 | |
| 80 | // sampling |
| 81 | for( int i=0; i<10; ++i ) |
| 82 | { |
| 83 | VectorType r = b0.sample(); |
| 84 | VERIFY(b0.contains(r)); |
| 85 | } |
no test coverage detected