From 9904a412a3f2a9cba308dd48eddcc205a4d9278a Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 15 Mar 2023 11:17:39 -0300 Subject: [PATCH] Refactor hex vents into helper function --- notebook_nueva/battery_holder.py | 21 ++------------------- notebook_nueva/utils.py | 22 +++++++++++++++++++++- notebook_nueva/zero_holder.py | 20 ++------------------ 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/notebook_nueva/battery_holder.py b/notebook_nueva/battery_holder.py index 57f6beb..df3c6fb 100644 --- a/notebook_nueva/battery_holder.py +++ b/notebook_nueva/battery_holder.py @@ -1,6 +1,6 @@ import cadquery as cq -from utils import extrude_shape, punch_hole, punch_hole2 +from utils import extrude_shape, punch_hole2, hex_vents stand_positions = [(3.5, 3.5), (61.5, 3.5), (61.5, 52.5), (3.5, 52.5)] stands = ( @@ -71,24 +71,7 @@ elements = [ ] -hex_size = 6 -vent_positions = [] -for x in range(1, width // hex_size): - for y in range(1, int(height // hex_size / 0.8)): - vent_positions.append( - ( - (x + (y % 2) / 2) * hex_size - hex_size * 0.2, - y * hex_size * 0.8 + hex_size * 0.2, - ) - ) - -vents = [ - { - "x": 0, - "y": 0, - "shape": cq.Sketch().push(vent_positions).regularPolygon((hex_size) / 2, 6), - } -] +vents = hex_vents(size=6, width=width, height=height) # Hole distances are relative to the rightmost pillar diff --git a/notebook_nueva/utils.py b/notebook_nueva/utils.py index 7335894..baed6c9 100644 --- a/notebook_nueva/utils.py +++ b/notebook_nueva/utils.py @@ -33,4 +33,24 @@ def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth): .center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"]) .placeSketch(hole["shape"]) .cutBlind(-depth) - ) \ No newline at end of file + ) + +def hex_vents(*, size, width, height): + vent_positions = [] + for x in range(1, width // size): + for y in range(1, int(height // size / 0.8)): + vent_positions.append( + ( + (x + (y % 2) / 2) * size - size * 0.2, + y * size * 0.8 + size * 0.2, + ) + ) + vents = [ + { + "x": 0, + "y": 0, + "shape": cq.Sketch().push(vent_positions).regularPolygon((size) / 2, 6), + } + ] + + return vents \ No newline at end of file diff --git a/notebook_nueva/zero_holder.py b/notebook_nueva/zero_holder.py index 8f9ec5d..daf8d10 100644 --- a/notebook_nueva/zero_holder.py +++ b/notebook_nueva/zero_holder.py @@ -1,6 +1,6 @@ import cadquery as cq -from utils import extrude_shape, punch_hole2 +from utils import extrude_shape, punch_hole2, hex_vents width = 65 height = 30 @@ -42,23 +42,7 @@ elements = [ }, ] -hex_size = 6 -vent_positions = [] -for x in range(1, width // hex_size): - for y in range(1, int(height // hex_size / 0.8)): - vent_positions.append( - ( - (x + (y % 2) / 2) * hex_size - hex_size * 0.2, - y * hex_size * 0.8 + hex_size * 0.2, - ) - ) -vents = [ - { - "x": 0, - "y": 0, - "shape": cq.Sketch().push(vent_positions).regularPolygon((hex_size) / 2, 6), - } -] +vents = hex_vents(size=6, width=width, height=height) holes = [ # One hole for everything TODO: improve