Skip to content

Commit b2a7431

Browse files
authored
Merge branch 'gumyr:dev' into dev
2 parents ca1eed0 + c6b0cd1 commit b2a7431

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

src/build123d/operations_sketch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ def trace(
146146
context._add_to_context(*new_faces, mode=mode)
147147
context.pending_edges = ShapeList()
148148

149-
return Sketch(Compound.make_compound(new_faces).wrapped)
149+
combined_faces = Face.fuse(*new_faces) if len(new_faces) > 1 else new_faces[0]
150+
return Sketch(combined_faces.wrapped)

src/build123d/topology.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,13 @@ def offset_3d(
12861286
)
12871287
offset_builder.Build()
12881288

1289-
offset_occt_solid = offset_builder.Shape()
1289+
try:
1290+
offset_occt_solid = offset_builder.Shape()
1291+
except (StdFail_NotDone, Standard_Failure) as err:
1292+
raise RuntimeError(
1293+
"offset Error, an alternative kind may resolve this error"
1294+
) from err
1295+
12901296
offset_solid = self.__class__(offset_occt_solid)
12911297

12921298
# The Solid can be inverted, if so reverse

tests/test_build_generic.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -594,28 +594,37 @@ def test_offset_algebra_wire(self):
594594
def test_offset_face_with_inner_wire(self):
595595
# offset amount causes the inner wire to have zero length
596596
b = Rectangle(1, 1)
597-
b -= RegularPolygon(.25, 3)
597+
b -= RegularPolygon(0.25, 3)
598598
b = offset(b, amount=0.125)
599-
self.assertAlmostEqual(b.area, 1 ** 2 + 2 * 0.125 * 2 + pi * 0.125 ** 2, 5)
599+
self.assertAlmostEqual(b.area, 1**2 + 2 * 0.125 * 2 + pi * 0.125**2, 5)
600600
self.assertEqual(len(b.face().inner_wires()), 0)
601601

602602
def test_offset_face_with_min_length(self):
603-
c = Circle(.5)
603+
c = Circle(0.5)
604604
c = offset(c, amount=0.125, min_edge_length=0.1)
605605
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
606-
606+
607607
def test_offset_face_with_min_length_and_inner(self):
608608
# offset amount causes the inner wire to have zero length
609-
c = Circle(.5)
610-
c -= RegularPolygon(.25, 3)
609+
c = Circle(0.5)
610+
c -= RegularPolygon(0.25, 3)
611611
c = offset(c, amount=0.125, min_edge_length=0.1)
612612
self.assertAlmostEqual(c.area, pi * (0.5 + 0.125) ** 2, 5)
613613
self.assertEqual(len(c.face().inner_wires()), 0)
614-
614+
615615
def test_offset_bad_type(self):
616616
with self.assertRaises(TypeError):
617617
offset(Vertex(), amount=1)
618618

619+
def test_offset_failure(self):
620+
with BuildPart() as cup:
621+
with BuildSketch():
622+
Circle(35)
623+
extrude(amount=50, taper=-3)
624+
topf = cup.faces().sort_by(Axis.Z)[-1]
625+
with self.assertRaises(RuntimeError):
626+
offset(amount=-2, openings=topf)
627+
619628

620629
class PolarLocationsTests(unittest.TestCase):
621630
def test_errors(self):

tests/test_build_sketch.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def test_trapezoid(self):
387387
Trapezoid(6, 2, 150)
388388

389389
with BuildSketch() as test:
390-
t = Trapezoid(12,8,135,90)
390+
t = Trapezoid(12, 8, 135, 90)
391391
self.assertEqual(t.width, 12)
392392
self.assertEqual(t.trapezoid_height, 8)
393393
self.assertEqual(t.left_side_angle, 135)
@@ -462,6 +462,12 @@ def test_trace(self):
462462
with self.assertRaises(ValueError):
463463
trace()
464464

465+
line = Polyline((0, 0), (10, 10), (20, 10))
466+
test = trace(line, 4)
467+
self.assertEqual(len(test.faces()), 3)
468+
test = trace(line, 4).clean()
469+
self.assertEqual(len(test.faces()), 1)
470+
465471

466472
if __name__ == "__main__":
467473
unittest.main(failfast=True)

0 commit comments

Comments
 (0)