diff --git a/Eigen/src/Geometry/AlignedBox.h b/Eigen/src/Geometry/AlignedBox.h index a4e76d9fc..e97a8f295 100644 --- a/Eigen/src/Geometry/AlignedBox.h +++ b/Eigen/src/Geometry/AlignedBox.h @@ -173,7 +173,7 @@ class AlignedBox { } /** \returns the volume of the bounding box */ - EIGEN_DEVICE_FUNC inline Scalar volume() const { return sizes().prod(); } + EIGEN_DEVICE_FUNC inline Scalar volume() const { return isEmpty() ? Scalar(0) : sizes().prod(); } /** \returns an expression for the bounding box diagonal vector * if the length of the diagonal is needed: diagonal().norm() diff --git a/test/geo_alignedbox.cpp b/test/geo_alignedbox.cpp index f335b340f..da49c081f 100644 --- a/test/geo_alignedbox.cpp +++ b/test/geo_alignedbox.cpp @@ -51,6 +51,8 @@ void alignedbox(const BoxType& box) { kill_extra_precision(p0); kill_extra_precision(p1); + VERIFY(numext::equal_strict(b0.volume(), Scalar(0))); + b0.extend(p0); b0.extend(p1); VERIFY(b0.contains(p0 * s1 + (Scalar(1) - s1) * p1)); @@ -423,6 +425,8 @@ void alignedboxCastTests(const BoxType& box) { BoxType b0(dim); + VERIFY(numext::equal_strict(b0.volume(), Scalar(0))); + b0.extend(p0); b0.extend(p1);