Skip to content

Commit

Permalink
Added offset error handling Issue #480
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Jan 27, 2024
1 parent d22cb38 commit 428c6da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,13 @@ def offset_3d(
)
offset_builder.Build()

offset_occt_solid = offset_builder.Shape()
try:
offset_occt_solid = offset_builder.Shape()
except StdFail_NotDone as err:
raise RuntimeError(
"offset Error, an alternative kind may resolve this error"
) from err

offset_solid = self.__class__(offset_occt_solid)

# The Solid can be inverted, if so reverse
Expand Down
23 changes: 16 additions & 7 deletions tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,28 +594,37 @@ def test_offset_algebra_wire(self):
def test_offset_face_with_inner_wire(self):
# offset amount causes the inner wire to have zero length
b = Rectangle(1, 1)
b -= RegularPolygon(.25, 3)
b -= RegularPolygon(0.25, 3)
b = offset(b, amount=0.125)
self.assertAlmostEqual(b.area, 1 ** 2 + 2 * 0.125 * 2 + pi * 0.125 ** 2, 5)
self.assertAlmostEqual(b.area, 1**2 + 2 * 0.125 * 2 + pi * 0.125**2, 5)
self.assertEqual(len(b.face().inner_wires()), 0)

def test_offset_face_with_min_length(self):
c = Circle(.5)
c = Circle(0.5)
c = offset(c, amount=0.125, min_edge_length=0.1)
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)

def test_offset_face_with_min_length_and_inner(self):
# offset amount causes the inner wire to have zero length
c = Circle(.5)
c -= RegularPolygon(.25, 3)
c = Circle(0.5)
c -= RegularPolygon(0.25, 3)
c = offset(c, amount=0.125, min_edge_length=0.1)
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
self.assertEqual(len(c.face().inner_wires()), 0)

def test_offset_bad_type(self):
with self.assertRaises(TypeError):
offset(Vertex(), amount=1)

def test_offset_failure(self):
with BuildPart() as cup:
with BuildSketch():
Circle(35)
extrude(amount=50, taper=-3)
topf = cup.faces().sort_by(Axis.Z)[-1]
with self.assertRaises(RuntimeError):
offset(amount=-2, openings=topf)


class PolarLocationsTests(unittest.TestCase):
def test_errors(self):
Expand Down

0 comments on commit 428c6da

Please sign in to comment.