-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.stanza
60 lines (50 loc) · 2.09 KB
/
classes.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
defpackage classes :
import core
import collections
import math
import geom
import clipper
import font
import libfive
import utilities
import primitives
public defstruct Design :
connections : Vector<Connection>
shapes : Vector<Shape>
jointWidth : Float
jointLength : Float
pinDiameter : Float
woodThickness : Float
numPins : Int with : (setter => set-numPins)
public defstruct Connection :
maleIndex : Int
femaleIndex : Int
cPoint : V3f
cAngle : V3f
connectorTilt: Float
joint : (Float,Float, Float) -> [Shape, Tuple<Shape>]
public defn add_design_pins (design:Design, n_pins:Int) :
val current = numPins(design)
set-numPins(design, current + n_pins)
public defn new_design (joint_size:Float, wood_thickness:Float) :
Design(Vector<Connection>(), Vector<Shape>(), joint_size, joint_size, joint_size / 4.0f, wood_thickness, 0)
public defn add_shape (design:Design, shape:Shape) -> Int:
val i:Int = length(shapes(design))
add(shapes(design), shape)
i
public defn add_pins (shape:Shape, design:Design) :
var shape_pinned = shape
add_design_pins(design, 3)
shape_pinned = rem(shape_pinned, mov(connection_point(bounds(shape), V3f(0.25f, 0.5f, 0.5f)),pin_primitive(jointWidth(design) / 8.0f, woodThickness(design))))
shape_pinned = rem(shape_pinned, mov(connection_point(bounds(shape), V3f(0.5f, 0.5f, 0.5f)),pin_primitive(jointWidth(design) / 8.0f, woodThickness(design))))
shape_pinned = rem(shape_pinned, mov(connection_point(bounds(shape), V3f(0.75f, 0.5f, 0.5f)),pin_primitive(jointWidth(design) / 8.0f, woodThickness(design))))
shape_pinned
public defn get_shape (design:Design, index:Int) :
shapes(design)[index]
public defn set_shape (design:Design, index:Int, shape:Shape) :
shapes(design)[index] = shape
public defn num_shapes (design:Design) :
length(shapes(design))
public defn add_connection (design:Design, male_index:Int, female_index:Int, cp:V3f, cangle:V3f, c_align:Float, key:(Float,Float,Float) -> [Shape, Tuple<Shape>]) :
val connection = Connection(male_index, female_index, cp, cangle, c_align, key)
add(connections(design), connection)