template<typename BoxType> void alignedbox(const BoxType& _box) { /* this test covers the following files: AlignedBox.h */ typedef typename BoxType::Index Index; typedef typename BoxType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType; const Index dim = _box.dim(); VectorType p0 = VectorType::Random(dim); VectorType p1 = VectorType::Random(dim); while( p1 == p0 ){ p1 = VectorType::Random(dim); } RealScalar s1 = internal::random<RealScalar>(0,1); BoxType b0(dim); BoxType b1(VectorType::Random(dim),VectorType::Random(dim)); BoxType b2; kill_extra_precision(b1); kill_extra_precision(p0); kill_extra_precision(p1); b0.extend(p0); b0.extend(p1); VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1)); VERIFY(b0.contains(b0.center())); VERIFY(b0.center()==(p0+p1)/Scalar(2)); (b2 = b0).extend(b1); VERIFY(b2.contains(b0)); VERIFY(b2.contains(b1)); VERIFY_IS_APPROX(b2.clamp(b0), b0); // intersection BoxType box1(VectorType::Random(dim)); box1.extend(VectorType::Random(dim)); BoxType box2(VectorType::Random(dim)); box2.extend(VectorType::Random(dim)); VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty()); // alignment -- make sure there is no memory alignment assertion BoxType *bp0 = new BoxType(dim); BoxType *bp1 = new BoxType(dim); bp0->extend(*bp1); delete bp0; delete bp1; // sampling for( int i=0; i<10; ++i ) { VectorType r = b0.sample(); VERIFY(b0.contains(r)); } }
void alignedboxCastTests(const BoxType& _box) { // casting typedef typename BoxType::Index Index; typedef typename BoxType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType; const Index dim = _box.dim(); VectorType p0 = VectorType::Random(dim); VectorType p1 = VectorType::Random(dim); BoxType b0(dim); b0.extend(p0); b0.extend(p1); const int Dim = BoxType::AmbientDimAtCompileTime; typedef typename GetDifferentType<Scalar>::type OtherScalar; AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>(); VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0); AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>(); VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0); }
template<typename BoxType> void alignedbox(const BoxType& _box) { /* this test covers the following files: AlignedBox.h */ const int dim = _box.dim(); typedef typename BoxType::Scalar Scalar; typedef typename NumTraits<Scalar>::Real RealScalar; typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType; VectorType p0 = VectorType::Random(dim); VectorType p1 = VectorType::Random(dim); RealScalar s1 = ei_random<RealScalar>(0,1); BoxType b0(dim); BoxType b1(VectorType::Random(dim),VectorType::Random(dim)); BoxType b2; b0.extend(p0); b0.extend(p1); VERIFY(b0.contains(p0*s1+(Scalar(1)-s1)*p1)); VERIFY(!b0.contains(p0 + (1+s1)*(p1-p0))); (b2 = b0).extend(b1); VERIFY(b2.contains(b0)); VERIFY(b2.contains(b1)); VERIFY_IS_APPROX(b2.clamp(b0), b0); // casting const int Dim = BoxType::AmbientDimAtCompileTime; typedef typename GetDifferentType<Scalar>::type OtherScalar; AlignedBox<OtherScalar,Dim> hp1f = b0.template cast<OtherScalar>(); VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),b0); AlignedBox<Scalar,Dim> hp1d = b0.template cast<Scalar>(); VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),b0); }
double minimumOnVolumeObject(const BoxType &r, const VectorType &v) { ++calls; return r.squaredExteriorDistance(v); }
double minimumOnObjectVolume(const BallType &b, const BoxType &r) { ++calls; return SQR(std::max(0., r.exteriorDistance(b.center) - b.radius)); }
double minimumOnVolumeVolume(const BoxType &r1, const BoxType &r2) { ++calls; return r1.squaredExteriorDistance(r2); }
double minimumOnVolume(const BoxType &r) { ++calls; return r.squaredExteriorDistance(p); }
bool intersectVolumeObject(const BoxType &r, const VectorType &v) { ++calls; return r.contains(v); }
bool intersectObjectVolume(const BallType &b, const BoxType &r) { ++calls; return r.squaredExteriorDistance(b.center) < SQR(b.radius); }
bool intersectVolumeVolume(const BoxType &r1, const BoxType &r2) { ++calls; return !(r1.intersection(r2)).isNull(); }
bool intersectVolume(const BoxType &r) { ++calls; return r.contains(p); }
double minimumOnVolumeObject(const BoxType &r, const BallType &b) { ++calls; return SQR((std::max)(0., r.exteriorDistance(b.center) - b.radius)); }