From 5f11db695b74db219e0d06682728c9eda90cac5c Mon Sep 17 00:00:00 2001 From: Sven Strothoff Date: Sun, 28 Jul 2013 23:59:37 +0200 Subject: [PATCH] bug #502: add bool intersects() methods to AlignedBox --- Eigen/src/Geometry/AlignedBox.h | 4 ++++ test/geo_alignedbox.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Eigen/src/Geometry/AlignedBox.h b/Eigen/src/Geometry/AlignedBox.h index 8e186d57a..b6a2f0e24 100644 --- a/Eigen/src/Geometry/AlignedBox.h +++ b/Eigen/src/Geometry/AlignedBox.h @@ -185,6 +185,10 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) inline bool contains(const AlignedBox& b) const { return (m_min.array()<=(b.min)().array()).all() && ((b.max)().array()<=m_max.array()).all(); } + /** \returns true if the box \a b is intersecting the box \c *this. */ + inline bool intersects(const AlignedBox& b) const + { return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); } + /** Extends \c *this such that it contains the point \a p and returns a reference to \c *this. */ template inline AlignedBox& extend(const MatrixBase& a_p) diff --git a/test/geo_alignedbox.cpp b/test/geo_alignedbox.cpp index 8e36adbe3..e2792ed18 100644 --- a/test/geo_alignedbox.cpp +++ b/test/geo_alignedbox.cpp @@ -54,6 +54,13 @@ template void alignedbox(const BoxType& _box) 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);