diff --git a/docs/assets/ttt/ttt-ppp0101.py b/docs/assets/ttt/ttt-ppp0101.py index 8a78180e..b36acb24 100644 --- a/docs/assets/ttt/ttt-ppp0101.py +++ b/docs/assets/ttt/ttt-ppp0101.py @@ -41,7 +41,7 @@ l3 = Line(l2 @ 1, (0, 8)) mirror(about=Plane.YZ) make_face() - extrude(amount=115/2, both=True, mode=Mode.SUBTRACT) + extrude(amount=115 / 2, both=True, mode=Mode.SUBTRACT) show_object(p) print(f"\npart mass = {p.part.volume*densa:0.2f}") diff --git a/docs/pack_demo.py b/docs/pack_demo.py index a5231541..7fd62594 100644 --- a/docs/pack_demo.py +++ b/docs/pack_demo.py @@ -10,8 +10,6 @@ """ - - # [import] from build123d import * from ocp_vscode import * @@ -24,8 +22,6 @@ b4 = Box(24, 24, 24, align=(Align.MAX, Align.MAX, Align.CENTER), mode=Mode.SUBTRACT) - - # [Export SVG files] def write_svg(part, filename: str, view_port_origin=(-100, 100, 150)): """Save an image of the BuildPart object as SVG""" @@ -39,12 +35,15 @@ def write_svg(part, filename: str, view_port_origin=(-100, 100, 150)): exporter.write(f"assets/{filename}.svg") - - write_svg( Compound( - [b1, b2, b3, b4,], - "pack_demo_initial_state" + [ + b1, + b2, + b3, + b4, + ], + "pack_demo_initial_state", ), "pack_demo_initial_state.svg", (50, 0, 100), @@ -52,11 +51,7 @@ def write_svg(part, filename: str, view_port_origin=(-100, 100, 150)): # [pack 2D] -xy_pack = pack( - [b1, b2, b3, b4], - padding=5, - align_z=False -) +xy_pack = pack([b1, b2, b3, b4], padding=5, align_z=False) write_svg(Compound(xy_pack), "pack_demo_packed_xy.svg", (50, 0, 100)) @@ -64,15 +59,11 @@ def write_svg(part, filename: str, view_port_origin=(-100, 100, 150)): # [Pack and align_z] -z_pack = pack( - [b1, b2, b3, b4], - padding=5, - align_z=True -) +z_pack = pack([b1, b2, b3, b4], padding=5, align_z=True) write_svg(Compound(z_pack), "pack_demo_packed_z.svg", (50, 0, 100)) # [bounding box] print(Compound(xy_pack).bounding_box()) -print(Compound(z_pack).bounding_box()) \ No newline at end of file +print(Compound(z_pack).bounding_box()) diff --git a/examples/boxes_on_faces.py b/examples/boxes_on_faces.py index 5698f7a3..002cf57a 100644 --- a/examples/boxes_on_faces.py +++ b/examples/boxes_on_faces.py @@ -23,6 +23,7 @@ limitations under the License. """ + # [Imports] import build123d as bd from ocp_vscode import * @@ -38,4 +39,4 @@ if "show_object" in locals(): show_object(bp.part.wrapped, name="box on faces") -# [End] \ No newline at end of file +# [End] diff --git a/examples/boxes_on_faces_algebra.py b/examples/boxes_on_faces_algebra.py index 7f440583..b6cd56bc 100644 --- a/examples/boxes_on_faces_algebra.py +++ b/examples/boxes_on_faces_algebra.py @@ -11,4 +11,4 @@ if "show_object" in locals(): show_object(b, name="box on faces") -# [End] \ No newline at end of file +# [End] diff --git a/examples/build123d_logo.py b/examples/build123d_logo.py index f5f03733..57db7b84 100644 --- a/examples/build123d_logo.py +++ b/examples/build123d_logo.py @@ -17,6 +17,7 @@ image_files: - "example_build123d_logo_01.png" """ + # [Imports] from build123d import * from build123d import Shape @@ -118,4 +119,4 @@ def add_svg_shape(svg: ExportSVG, shape: Shape, color: tuple[float, float, float show_object(three_d, name="three_d") show_object(extension_lines, name="extension_lines") show_object(build, name="build") -# [End] \ No newline at end of file +# [End] diff --git a/examples/circuit_board.py b/examples/circuit_board.py index c222e409..0619bc19 100644 --- a/examples/circuit_board.py +++ b/examples/circuit_board.py @@ -46,4 +46,4 @@ extrude(amount=pcb_height) show_object(pcb.part.wrapped) -# [End] \ No newline at end of file +# [End] diff --git a/examples/circuit_board_algebra.py b/examples/circuit_board_algebra.py index 7e0e015a..132fa27a 100644 --- a/examples/circuit_board_algebra.py +++ b/examples/circuit_board_algebra.py @@ -1,6 +1,7 @@ """ for details see `circuit_board.py` """ + # [Imports] from itertools import product from build123d import * @@ -23,4 +24,4 @@ pcb = extrude(pcb, pcb_height) show(pcb) -# [End] \ No newline at end of file +# [End] diff --git a/examples/dual_color_3mf.py b/examples/dual_color_3mf.py index b2c35d47..1f02c330 100644 --- a/examples/dual_color_3mf.py +++ b/examples/dual_color_3mf.py @@ -27,6 +27,7 @@ limitations under the License. """ + from build123d import * from ocp_vscode import * diff --git a/examples/joints.py b/examples/joints.py index f143af5e..0bfb669a 100644 --- a/examples/joints.py +++ b/examples/joints.py @@ -1,6 +1,7 @@ """ Experimental Joint development file """ + from build123d import * from ocp_vscode import * diff --git a/examples/lego.py b/examples/lego.py index cbd7cadd..1a3d8d99 100644 --- a/examples/lego.py +++ b/examples/lego.py @@ -26,6 +26,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + from build123d import * from ocp_vscode import * diff --git a/examples/packed_boxes.py b/examples/packed_boxes.py index f037d2ca..1e53a08a 100644 --- a/examples/packed_boxes.py +++ b/examples/packed_boxes.py @@ -7,20 +7,24 @@ desc: Demo packing a bunch of boxes in 2D. """ + import functools import operator import random import build123d as bd random.seed(123456) -test_boxes = [bd.Box(random.randint(1, 20), random.randint(1, 20), random.randint(1, 5)) - for _ in range(50)] +test_boxes = [ + bd.Box(random.randint(1, 20), random.randint(1, 20), random.randint(1, 5)) + for _ in range(50) +] packed = bd.pack(test_boxes, 3) + # Lifted from https://build123d.readthedocs.io/en/latest/import_export.html#d-to-2d-projection def export_svg(parts, name): part = functools.reduce(operator.add, parts, bd.Part()) - view_port_origin=(0, 0, 150) + view_port_origin = (0, 0, 150) visible, hidden = part.project_to_viewport(view_port_origin) max_dimension = max(*bd.Compound(children=visible + hidden).bounding_box().size) exporter = bd.ExportSVG(scale=100 / max_dimension) @@ -30,5 +34,6 @@ def export_svg(parts, name): exporter.add_shape(hidden, layer="Hidden") exporter.write(f"../docs/assets/{name}.svg") + export_svg(test_boxes, "packed_boxes_input") export_svg(packed, "packed_boxes_output") diff --git a/examples/python_logo.py b/examples/python_logo.py index cacd020a..a926ccdb 100644 --- a/examples/python_logo.py +++ b/examples/python_logo.py @@ -25,6 +25,7 @@ limitations under the License. """ + from build123d import * from ocp_vscode import show diff --git a/examples/roller_coaster.py b/examples/roller_coaster.py index 75be1d95..4e513d8d 100644 --- a/examples/roller_coaster.py +++ b/examples/roller_coaster.py @@ -25,6 +25,7 @@ See the License for the specific language governing permissions and limitations under the License. """ + from build123d import * from ocp_vscode import show_object diff --git a/src/build123d/objects_curve.py b/src/build123d/objects_curve.py index 0bce7c78..90f92873 100644 --- a/src/build123d/objects_curve.py +++ b/src/build123d/objects_curve.py @@ -584,7 +584,9 @@ def __init__( else: jern_workplane = copy.copy(WorkplaneList._get_context().workplanes[0]) jern_workplane.origin = start - start_tangent = Vector(tangent).transform(jern_workplane.reverse_transform, is_direction=True) + start_tangent = Vector(tangent).transform( + jern_workplane.reverse_transform, is_direction=True + ) arc_direction = copysign(1.0, arc_size) self.center_point = start + start_tangent.rotate( diff --git a/src/build123d/pack.py b/src/build123d/pack.py index 88ca5804..63b01cfa 100644 --- a/src/build123d/pack.py +++ b/src/build123d/pack.py @@ -119,7 +119,9 @@ def grow_down(w, h): return [(t[1], t[2]) for t in sorted(translations, key=lambda t: t[0])] -def pack(objects: Collection[Shape], padding: float, align_z: bool = False) -> Collection[Shape]: +def pack( + objects: Collection[Shape], padding: float, align_z: bool = False +) -> Collection[Shape]: """Pack objects in a squarish area in Plane.XY. Args: @@ -138,7 +140,9 @@ def pack(objects: Collection[Shape], padding: float, align_z: bool = False) -> C length_fn=lambda o: bounding_boxes[cast(Shape, o)].Y, ) translated = [ - Location((t[0] - o.bounding_box().min.X, t[1] - o.bounding_box().min.Y, 0)) * Pos((0, 0, -o.bounding_box().min.Z if align_z else 0)) * o + Location((t[0] - o.bounding_box().min.X, t[1] - o.bounding_box().min.Y, 0)) + * Pos((0, 0, -o.bounding_box().min.Z if align_z else 0)) + * o for (o, t) in zip(objects, translations) ] diff --git a/tests/test_build_common.py b/tests/test_build_common.py index a4c6e0e7..55e44f1e 100644 --- a/tests/test_build_common.py +++ b/tests/test_build_common.py @@ -329,7 +329,7 @@ def test_hex_major_radius(self): self.assertAlmostEqual(hloc.radius, 1, 7) self.assertAlmostEqual(hloc.diagonal, 2, 7) self.assertAlmostEqual(hloc.apothem, 3**0.5 / 2, 7) - + def test_centering(self): with BuildSketch(): with GridLocations(4, 4, 2, 2, align=(Align.CENTER, Align.CENTER)) as l: diff --git a/tests/test_build_line.py b/tests/test_build_line.py index e851ce2c..d2576845 100644 --- a/tests/test_build_line.py +++ b/tests/test_build_line.py @@ -209,21 +209,23 @@ def test_jern_arc(self): j1 = JernArc((1, 0), (0, 1), 1, 90) self.assertTupleAlmostEquals((jern.line @ 1).to_tuple(), (0, 1, 0), 5) self.assertAlmostEqual(j1.radius, 1) - self.assertAlmostEqual(j1.length, pi/2) + self.assertAlmostEqual(j1.length, pi / 2) with BuildLine(Plane.XY.offset(1)) as offset_l: off1 = JernArc((1, 0), (0, 1), 1, 90) self.assertTupleAlmostEquals((offset_l.line @ 1).to_tuple(), (0, 1, 1), 5) self.assertAlmostEqual(off1.radius, 1) - self.assertAlmostEqual(off1.length, pi/2) + self.assertAlmostEqual(off1.length, pi / 2) plane_iso = Plane(origin=(0, 0, 0), x_dir=(1, 1, 0), z_dir=(1, -1, 1)) with BuildLine(plane_iso) as iso_l: iso1 = JernArc((0, 0), (0, 1), 1, 180) - self.assertTupleAlmostEquals((iso_l.line @ 1).to_tuple(), (-sqrt(2), -sqrt(2), 0), 5) + self.assertTupleAlmostEquals( + (iso_l.line @ 1).to_tuple(), (-sqrt(2), -sqrt(2), 0), 5 + ) self.assertAlmostEqual(iso1.radius, 1) self.assertAlmostEqual(iso1.length, pi) - + with BuildLine() as full_l: l1 = JernArc(start=(0, 0, 0), tangent=(1, 0, 0), radius=1, arc_size=360) l2 = JernArc(start=(0, 0, 0), tangent=(1, 0, 0), radius=1, arc_size=300) diff --git a/tests/test_exporters.py b/tests/test_exporters.py index 8422d049..69a30a17 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -168,5 +168,6 @@ def test_color(self): svg.add_shape(sketch) svg.write("test-colors.svg") + if __name__ == "__main__": unittest.main()