-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameters.go
More file actions
94 lines (78 loc) · 1.78 KB
/
parameters.go
File metadata and controls
94 lines (78 loc) · 1.78 KB
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
86
87
88
89
90
91
92
93
94
package main
const (
step = .01
maximumVelocity = .5
separationRange = 6.
separationWeight = .02
alignmentRange = 19.
alignmentWeight = .01
cohesionRange = 19.
cohesionWeight = .0004
noiseWeight = .03
)
type Parameters struct {
maximumVelocity *FloatParam
separationRange *FloatParam
separationWeight *FloatParam
alignmentRange *FloatParam
alignmentWeight *FloatParam
cohesionRange *FloatParam
cohesionWeight *FloatParam
noiseWeight *FloatParam
trailLength *IntParam
}
func newParameters() *Parameters {
return &Parameters{
maximumVelocity: newFloatParam(maximumVelocity),
separationRange: newFloatParam(separationRange),
separationWeight: newFloatParam(separationWeight),
alignmentRange: newFloatParam(alignmentRange),
alignmentWeight: newFloatParam(alignmentWeight),
cohesionRange: newFloatParam(cohesionRange),
cohesionWeight: newFloatParam(cohesionWeight),
noiseWeight: newFloatParam(noiseWeight),
trailLength: newIntParam(trailLength),
}
}
type Param[T int | float64] interface {
value() T
increase()
decrease()
}
type IntParam struct {
field int
}
func (p *IntParam) value() int {
return p.field
}
func (p *IntParam) increase() {
p.field++
}
func (p *IntParam) decrease() {
if p.field > 0 {
p.field--
}
}
func newIntParam(value int) *IntParam {
return &IntParam{value}
}
var _ Param[int] = (*IntParam)(nil)
type FloatParam struct {
base float64
factor float64
}
func (p *FloatParam) value() float64 {
return p.base * p.factor
}
func (p *FloatParam) increase() {
p.factor += step
}
func (p *FloatParam) decrease() {
if p.factor > step {
p.factor -= step
}
}
func newFloatParam(value float64) *FloatParam {
return &FloatParam{value, 1}
}
var _ Param[float64] = (*FloatParam)(nil)