-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectorparam.go
55 lines (47 loc) · 1.54 KB
/
vectorparam.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
46
47
48
49
50
51
52
53
54
55
package engine
import (
"github.com/mumax/3/data"
"github.com/mumax/3/script"
"reflect"
"strings"
)
// vector input parameter, settable by user
type VectorParam struct {
inputParam
}
func (p *VectorParam) init(name, unit, desc string) {
p.inputParam.init(VECTOR, name, unit, nil) // no vec param has children (yet)
if !strings.HasPrefix(name, "_") { // don't export names beginning with "_" (e.g. from exciation)
DeclLValue(name, p, cat(desc, unit))
}
}
func (p *VectorParam) SetRegion(region int, f script.VectorFunction) {
if region == -1 {
p.setRegionsFunc(0, NREGION, f) //uniform
} else {
p.setRegionsFunc(region, region+1, f)
}
}
func (p *VectorParam) SetValue(v interface{}) {
f := v.(script.VectorFunction)
p.setRegionsFunc(0, NREGION, f)
}
func (p *VectorParam) setRegionsFunc(r1, r2 int, f script.VectorFunction) {
if Const(f) {
p.setRegions(r1, r2, slice(f.Float3()))
} else {
p.setFunc(r1, r2, func() []float64 {
return slice(f.Float3())
})
}
}
func (p *VectorParam) GetRegion(region int) [3]float64 {
v := p.getRegion(region)
return unslice(v)
}
func (p *VectorParam) Eval() interface{} { return p }
func (p *VectorParam) Type() reflect.Type { return reflect.TypeOf(new(VectorParam)) }
func (p *VectorParam) InputType() reflect.Type { return script.VectorFunction_t }
func (p *VectorParam) Region(r int) *vOneReg { return vOneRegion(p, r) }
func (p *VectorParam) Average() data.Vector { return unslice(qAverageUniverse(p)) }
func (p *VectorParam) Comp(c int) *comp { return Comp(p, c) }