Skip to content

Commit

Permalink
Merge pull request gumyr#491 from jdegenstein/try_offset
Browse files Browse the repository at this point in the history
Fix offset of faces with holes
  • Loading branch information
gumyr authored Jan 23, 2024
2 parents 61a3610 + 911e120 commit aeafb3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,14 @@ def offset(
outer_wire = outer_wire.fix_degenerate_edges(min_edge_length)
inner_wires = []
for inner_wire in face.inner_wires():
offset_wire = inner_wire.offset_2d(-amount, kind=kind)
if min_edge_length is not None:
inner_wires.append(offset_wire.fix_degenerate_edges(min_edge_length))
else:
inner_wires.append(offset_wire)
try:
offset_wire = inner_wire.offset_2d(-amount, kind=kind)
if min_edge_length is not None:
inner_wires.append(offset_wire.fix_degenerate_edges(min_edge_length))
else:
inner_wires.append(offset_wire)
except:
pass
new_faces.append(Face.make_from_wires(outer_wire, inner_wires))
if edges:
if len(edges) == 1 and edges[0].geom_type() == "LINE":
Expand Down
21 changes: 21 additions & 0 deletions tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,27 @@ def test_offset_algebra_wire(self):
o_line = offset(line, amount=3.177)
self.assertEqual(len(o_line.edges()), 19)

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 = offset(b, amount=0.125)
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 = 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 = 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)
Expand Down

0 comments on commit aeafb3a

Please sign in to comment.