-
Notifications
You must be signed in to change notification settings - Fork 126
/
params.go
45 lines (38 loc) · 1019 Bytes
/
params.go
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
package main
// Params represents params for GoThree.js library.
type Params struct {
Angle float64 `json:"angle"`
AngleSecond float64 `json:"angle2"`
Caps bool `json:"allCaps"`
Distance int `json:"distance"`
DistanceSecond int `json:"distance2"`
AutoAngle bool `json:"autoAngle"`
}
func GuessParams(c Commands) *Params {
goroutines := make(map[int]int) // map[depth]number
var totalG int
// calculate number of goroutines in each depth level
for _, cmd := range c.cmds {
depth := c.gd[cmd.Name]
if cmd.Command == CmdCreate {
totalG++
goroutines[depth]++
}
}
// special case for simple programs
angle := 360.0 / float64(goroutines[1])
if goroutines[1] < 3 {
angle = 60.0
}
params := &Params{
Angle: angle,
Caps: totalG < 5, // value from head
Distance: 80,
AutoAngle: true,
}
if gs, ok := goroutines[2]; ok {
params.AngleSecond = 360.0 / float64(gs/goroutines[1])
params.DistanceSecond = 20
}
return params
}