Skip to content

Commit

Permalink
Enhanced offset to allow holes to grow outside of the Face Issue #702
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Sep 20, 2024
1 parent debdf84 commit 043629e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/build123d/operations_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,14 @@ def offset(
inner_wires.append(offset_wire)
except:
pass
new_face = Face(outer_wire, inner_wires)
# inner wires may go beyond the outer wire so subtract faces
new_face = Face(outer_wire)
if inner_wires:
inner_faces = [Face(w) for w in inner_wires]
new_face = new_face.cut(*inner_faces)
if isinstance(new_face, Compound):
new_face = new_face.unwrap(fully=True)

if (new_face.normal_at() - face.normal_at()).length > 0.001:
new_face = -new_face
new_faces.append(new_face)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_build_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ def test_face_offset(self):
offset(amount=1, kind=Kind.INTERSECTION)
self.assertAlmostEqual(test.sketch.area, 9, 5)

def test_face_offset_with_holes(self):
sk = Rectangle(100, 100) - GridLocations(80, 80, 2, 2) * Circle(5)
sk2 = offset(sk, -5)
self.assertTrue(sk2.face().is_valid())
self.assertLess(sk2.area, sk.area)
self.assertEqual(len(sk2), 1)

def test_box_offset(self):
with BuildPart() as test:
Box(10, 10, 10)
Expand Down

0 comments on commit 043629e

Please sign in to comment.