Commit 523d4d60 authored by Antti Soininen's avatar Antti Soininen
Browse files

Throw instead of returning 0 if bounding box is invalid.

Re #19154
parent fad82185
......@@ -1578,7 +1578,7 @@ double Object::monteCarloVolume() const {
double Object::singleShotMonteCarloVolume(const int shotSize, const size_t seed) const {
const auto &boundingBox = getBoundingBox();
if (boundingBox.isNull()) {
return 0;
throw std::runtime_error("Cannot calculate volume: invalid bounding box.");
}
int totalHits = 0;
const double boundingDx = boundingBox.xMax() - boundingBox.xMin();
......
......@@ -942,6 +942,11 @@ public:
TS_ASSERT_DELTA(cuboid->volume(), correctVolume, 1e-3 * correctVolume)
}
void testVolumeThrowsWhenBoundingBoxIsInvalid() {
Object shape("This text gives an invalid Object.");
TS_ASSERT_THROWS(shape.volume(), std::runtime_error);
}
void testGetBoundingBoxForCylinder()
/**
Test bounding box for a object capped cylinder
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment