Compound containing empty Compound raises during Volume()

Open Beginner friendly
#2,078 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in cadquery/occ_impl/shapes.py at Shape._mass_calc_function, around the line shown in the traceback, and reproduce the nested-empty-compound example from the issue. Verify that Volume() completes for a compound containing an empty compound while the inner empty compound still reports 0.0.

Written by the indexing model from the issue text.

Description

bug

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

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 <module>
    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

Dominant language
Python
Stars
5.8k
Forks
544
Avg merge
3d 2h
Merged PRs (30d)
5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CadQuery/cadquery

All issues in CadQuery/cadquery

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.