-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.stanza
85 lines (81 loc) · 4.45 KB
/
connection.stanza
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
defpackage connection :
import core
import collections
import math
import geom
import clipper
import font
import libfive
import primitives
import utilities
import classes
;;Connection Functions
;; add pin hole to wood at specified pin locations, will probably have to 3d print the pins.
public defn add_pin (shape:Shape, pin_location:V3f, pin_diameter:Float, design:Design) :
var pinned_shape = shape
val primitive = pin_primitive(pin_diameter, woodThickness(design))
val pin_centered = mov(pin_location, primitive)
pinned_shape = rem(pinned_shape, pin_centered)
[pinned_shape, pin_centered]
;; add connector joints to the male, female shapes.
public defn add_connectors (design:Design) :
val joint_width = jointWidth(design)
val joint_length = jointLength(design)
val wood_thickness = woodThickness(design)
for connection in connections(design) do :
var c_point = cPoint(connection)
var c_angle = cAngle(connection)
var c_align = connectorTilt(connection)
var male_shape = get_shape(design, maleIndex(connection))
var female_shape = get_shape(design, femaleIndex(connection))
var joint_function = joint(connection)
val [joint_male_shape, num_pins] = add_connection_male(male_shape, c_point, c_angle, c_align, joint_function, joint_width, joint_length, wood_thickness)
val joint_female_shape = add_connection_female(female_shape, c_point, c_angle, c_align, joint_function, joint_width, joint_length, wood_thickness)
add_design_pins(design, num_pins)
set_shape(design, maleIndex(connection), joint_male_shape)
set_shape(design, femaleIndex(connection), joint_female_shape)
public defn add_connection_male (shape:Shape, c_point:V3f, c_angle:V3f, c_align:Float, joint:(Float, Float, Float) -> [Shape, Tuple<Shape>], w:Float, l:Float, wood_thickness:Float) -> [Shape, Int]:
val [connector, pin_locations] = joint(w, l, wood_thickness)
var pinned_connector = center_z(connector)
for pin in pin_locations do :
pinned_connector = rem(pinned_connector, center_z(pin))
pinned_connector = rot-y(c_align, pinned_connector)
val connector_cp = connection_point(bounds(pinned_connector), V3f(0.5f, 0.0f, 0.5f))
val new_connector_cp = times(magnitude(connector_cp), -1.0f * c_angle)
var rotated_connector = rot(connector_cp, new_connector_cp, pinned_connector)
if y(c_angle) == -1.0f :
rotated_connector = rot-z(180.0f, rotated_connector)
val shape_connector = union(attach(rotated_connector, new_connector_cp, shape, c_point))
[shape_connector, length(pin_locations)]
;;var rotated_cp = y3f(magnitude(cp))
;;var rotated_shape = rot(cp, rotated_cp, shape)
;;val [connector, pin_locations] = key(width, l)
;;var pinned_connector = connector
;;for pin_location in pin_locations do :
;; pinned_connector = rem(pinned_connector, pin_location)
;;var connector_cp = connection_point(bounds(connector), V3f(0.5f, 0.0f, 0.5f))
;;var joint = union(attach(pinned_connector, connector_cp, rotated_shape, rotated_cp))
;;rot(rotated_cp, cp, joint)
public defn add_connection_female (shape:Shape, c_point:V3f, c_angle:V3f, c_align:Float, joint:(Float, Float, Float) -> [Shape, Tuple<Shape>], w:Float, l:Float, wood_thickness:Float) -> Shape :
val [connector, pin_locations] = joint(w, l, wood_thickness)
var pinned_connector = center_z(connector)
for pin in pin_locations do :
pinned_connector = bit-or(pinned_connector, center_z(pin))
pinned_connector = rot-y(c_align, pinned_connector)
val connector_cp = connection_point(bounds(pinned_connector), V3f(0.5f, 0.0f, 0.5f))
val new_connector_cp = times(magnitude(connector_cp), -1.0f * normalize(c_angle))
var rotated_connector = rot(connector_cp, new_connector_cp, pinned_connector)
if y(c_angle) == -1.0f :
rotated_connector = rot-z(180.0f, rotated_connector)
val attached_pieces = to-array<Shape>(attach(rotated_connector, new_connector_cp, shape, c_point))
val shape_connector = rem(attached_pieces[1], attached_pieces[0])
shape_connector
;;var rotated_cp = y3f(magnitude(cp))
;;var rotated_shape = rot(cp, rotated_cp, shape)
;;val [connector, pin_locations] = key(width, length)
;;var pinned_connector = connector
;;for pin_location in pin_locations do :
;; pinned_connector = bit-or(pinned_connector, pin_location)
;;var connector_cp = connection_point(bounds(connector), V3f(0.5f, 0.0f, 0.5f))
;;val connected = to-array<Shape>(attach(pinned_connector, connector_cp, rotated_shape, rotated_cp))
;;rot(rotated_cp, cp, rem(connected[1], connected[0]))