mirror of
https://github.com/gumyr/build123d.git
synced 2026-01-06 09:14:03 -08:00
Added offset error handling Issue #480
This commit is contained in:
parent
d22cb389b9
commit
428c6da24c
2 changed files with 23 additions and 8 deletions
|
|
@ -1286,7 +1286,13 @@ class Mixin3D:
|
||||||
)
|
)
|
||||||
offset_builder.Build()
|
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)
|
offset_solid = self.__class__(offset_occt_solid)
|
||||||
|
|
||||||
# The Solid can be inverted, if so reverse
|
# The Solid can be inverted, if so reverse
|
||||||
|
|
|
||||||
|
|
@ -594,28 +594,37 @@ class OffsetTests(unittest.TestCase):
|
||||||
def test_offset_face_with_inner_wire(self):
|
def test_offset_face_with_inner_wire(self):
|
||||||
# offset amount causes the inner wire to have zero length
|
# offset amount causes the inner wire to have zero length
|
||||||
b = Rectangle(1, 1)
|
b = Rectangle(1, 1)
|
||||||
b -= RegularPolygon(.25, 3)
|
b -= RegularPolygon(0.25, 3)
|
||||||
b = offset(b, amount=0.125)
|
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)
|
self.assertEqual(len(b.face().inner_wires()), 0)
|
||||||
|
|
||||||
def test_offset_face_with_min_length(self):
|
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)
|
c = offset(c, amount=0.125, min_edge_length=0.1)
|
||||||
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
|
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
|
||||||
|
|
||||||
def test_offset_face_with_min_length_and_inner(self):
|
def test_offset_face_with_min_length_and_inner(self):
|
||||||
# offset amount causes the inner wire to have zero length
|
# offset amount causes the inner wire to have zero length
|
||||||
c = Circle(.5)
|
c = Circle(0.5)
|
||||||
c -= RegularPolygon(.25, 3)
|
c -= RegularPolygon(0.25, 3)
|
||||||
c = offset(c, amount=0.125, min_edge_length=0.1)
|
c = offset(c, amount=0.125, min_edge_length=0.1)
|
||||||
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
|
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
|
||||||
self.assertEqual(len(c.face().inner_wires()), 0)
|
self.assertEqual(len(c.face().inner_wires()), 0)
|
||||||
|
|
||||||
def test_offset_bad_type(self):
|
def test_offset_bad_type(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
offset(Vertex(), amount=1)
|
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):
|
class PolarLocationsTests(unittest.TestCase):
|
||||||
def test_errors(self):
|
def test_errors(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue