Skip to content

Commit

Permalink
Merge pull request #592 from greyltc/fix-empty-solve
Browse files Browse the repository at this point in the history
fix unconstrained assembly.solve()
  • Loading branch information
jmwright authored Jan 21, 2021
2 parents 53a76d4 + 48d7800 commit c0ebeba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cadquery/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ def solve(self) -> "Assembly":
for c in self.constraints:
constraints.append(((ents[c.objects[0]], ents[c.objects[1]]), c.toPOD()))

# check if any constraints were specified
if not constraints:
raise ValueError("At least one constraint required")

# instantiate the solver
solver = ConstraintSolver(locs, constraints, locked=[lock_ix])

Expand Down
6 changes: 6 additions & 0 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,9 @@ def test_duplicate_name(nested_assy):

with pytest.raises(ValueError):
nested_assy.add(None, name="SECOND")


def test_empty_solve(nested_assy):

with pytest.raises(ValueError):
nested_assy.solve()

0 comments on commit c0ebeba

Please sign in to comment.