CadQuery / CadQuery/cadquery

Compound containing empty Compound raises during Volume()

Open
#2,078 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

When computing the volume of a `compound` that itself contains an empty `compound`, a `StopIteration` exception is raised.

However the volume of the inner empty `compound` itself is computed to be `0.0` as expected.

## To Reproduce

```python
from cadquery.occ_impl.shapes import compound

empty_compound = compound()

empty_volume = empty_compound.Volume() # returns 0.0
print("empty compound volume:", empty_volume)

bad = compound(empty_compound) # top-level non-empty, first child empty
volume = bad.Volume() # raises StopIteration

print("bad compound volume:", volume) # this line is never reached
```

Output:

```
empty compound volume: 0.0
Traceback (most recent call last):
File "/tmp/cq _vol_test.py", line 9, in
volume = bad.Volume() # raises StopIteration
File "/home/john/src/klu/.venv/lib/python3.14/site-packages/cadquery/occ_impl/shapes.py", line 1118, in Volume
return Shape.computeMass(self, tol)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/home/john/src/klu/.venv/lib/python3.14/site-packages/cadquery/occ_impl/shapes.py", line 824, in computeMass
calc_function = Shape._mass_calc_function(obj)
File "/home/john/src/klu/.venv/lib/python3.14/site-packages/cadquery/occ_impl/shapes.py", line 804, in _mass_calc_function
child = next(iter(child))
StopIteration
```

## Environment

OS: Arch Linux

Was CadQuery installed using Conda?: No, installed with pip

Version: 2.8.0, Python 3.14.6

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.