From 17cf84f68b652873325ab9f6dd9ce296d757e809 Mon Sep 17 00:00:00 2001 From: jdegenstein Date: Tue, 23 Jan 2024 10:06:25 -0600 Subject: [PATCH 1/4] operations_generic.py -> try offset with inner wires, silently drop otherwise --- src/build123d/operations_generic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index 5d00e218..057a3b2e 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -593,11 +593,12 @@ 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) new_faces.append(Face.make_from_wires(outer_wire, inner_wires)) if edges: if len(edges) == 1 and edges[0].geom_type() == "LINE": From 8372c3f7b6b42ba52dbfeefea33a464037bf3d36 Mon Sep 17 00:00:00 2001 From: jdegenstein Date: Tue, 23 Jan 2024 10:08:55 -0600 Subject: [PATCH 2/4] operations_generic.py -> except pass --- src/build123d/operations_generic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index 057a3b2e..3e58431c 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -599,6 +599,8 @@ def offset( 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": From 9919882e790f965914bb60374f03b944d2d9d58f Mon Sep 17 00:00:00 2001 From: jdegenstein Date: Tue, 23 Jan 2024 10:29:34 -0600 Subject: [PATCH 3/4] test_build_generic.py -> add offset test with inner wire that gets removed --- tests/test_build_generic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_build_generic.py b/tests/test_build_generic.py index 9c8d5bc4..77c7fe89 100644 --- a/tests/test_build_generic.py +++ b/tests/test_build_generic.py @@ -591,6 +591,14 @@ 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 area + 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_bad_type(self): with self.assertRaises(TypeError): offset(Vertex(), amount=1) From 911e120b24fdc838582d70f7a7b67260b018177c Mon Sep 17 00:00:00 2001 From: jdegenstein Date: Tue, 23 Jan 2024 10:48:48 -0600 Subject: [PATCH 4/4] test_build_generic.py -> add min_edge_length tests for offset --- tests/test_build_generic.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_build_generic.py b/tests/test_build_generic.py index 77c7fe89..95155557 100644 --- a/tests/test_build_generic.py +++ b/tests/test_build_generic.py @@ -592,12 +592,25 @@ def test_offset_algebra_wire(self): self.assertEqual(len(o_line.edges()), 19) def test_offset_face_with_inner_wire(self): - # offset amount causes the inner wire to have zero area + # 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):