Skip to content

Commit

Permalink
black reformat remaining docs, examples, tests and src
Browse files Browse the repository at this point in the history
standardizing on black across the entire repo
  • Loading branch information
jdegenstein committed Aug 9, 2024
1 parent 0add2df commit 9a3deb7
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/assets/ttt/ttt-ppp0101.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
29 changes: 10 additions & 19 deletions docs/pack_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"""



# [import]
from build123d import *
from ocp_vscode import *
Expand All @@ -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"""
Expand All @@ -39,40 +35,35 @@ 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),
)

# [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))


# [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())
print(Compound(z_pack).bounding_box())
3 changes: 2 additions & 1 deletion examples/boxes_on_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
limitations under the License.
"""

# [Imports]
import build123d as bd
from ocp_vscode import *
Expand All @@ -38,4 +39,4 @@

if "show_object" in locals():
show_object(bp.part.wrapped, name="box on faces")
# [End]
# [End]
2 changes: 1 addition & 1 deletion examples/boxes_on_faces_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

if "show_object" in locals():
show_object(b, name="box on faces")
# [End]
# [End]
3 changes: 2 additions & 1 deletion examples/build123d_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
image_files:
- "example_build123d_logo_01.png"
"""

# [Imports]
from build123d import *
from build123d import Shape
Expand Down Expand Up @@ -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]
# [End]
2 changes: 1 addition & 1 deletion examples/circuit_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
extrude(amount=pcb_height)

show_object(pcb.part.wrapped)
# [End]
# [End]
3 changes: 2 additions & 1 deletion examples/circuit_board_algebra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
for details see `circuit_board.py`
"""

# [Imports]
from itertools import product
from build123d import *
Expand All @@ -23,4 +24,4 @@
pcb = extrude(pcb, pcb_height)

show(pcb)
# [End]
# [End]
1 change: 1 addition & 0 deletions examples/dual_color_3mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
limitations under the License.
"""

from build123d import *
from ocp_vscode import *

Expand Down
1 change: 1 addition & 0 deletions examples/joints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Experimental Joint development file
"""

from build123d import *
from ocp_vscode import *

Expand Down
1 change: 1 addition & 0 deletions examples/lego.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
11 changes: 8 additions & 3 deletions examples/packed_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
1 change: 1 addition & 0 deletions examples/python_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
limitations under the License.
"""

from build123d import *
from ocp_vscode import show

Expand Down
1 change: 1 addition & 0 deletions examples/roller_coaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/build123d/objects_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions src/build123d/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions tests/test_build_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@ def test_color(self):
svg.add_shape(sketch)
svg.write("test-colors.svg")


if __name__ == "__main__":
unittest.main()

0 comments on commit 9a3deb7

Please sign in to comment.