/
rand.go
36 lines (27 loc) · 1.23 KB
/
rand.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
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vxform
import (
"math/rand"
"github.com/emer/etable/minmax"
)
// Rand specifies random transforms
type Rand struct {
// min -- max range of X-axis (horizontal) translations to generate (as proportion of image size)
TransX minmax.F32 `desc:"min -- max range of X-axis (horizontal) translations to generate (as proportion of image size)"`
// min -- max range of Y-axis (vertical) translations to generate (as proportion of image size)
TransY minmax.F32 `desc:"min -- max range of Y-axis (vertical) translations to generate (as proportion of image size)"`
// min -- max range of scales to generate
Scale minmax.F32 `desc:"min -- max range of scales to generate"`
// min -- max range of rotations to generate (in degrees)
Rot minmax.F32 `desc:"min -- max range of rotations to generate (in degrees)"`
}
// Gen Generates new random transform values
func (rx *Rand) Gen(xf *XForm) {
trX := rx.TransX.ProjVal(rand.Float32())
trY := rx.TransY.ProjVal(rand.Float32())
sc := rx.Scale.ProjVal(rand.Float32())
rt := rx.Rot.ProjVal(rand.Float32())
xf.Set(trX, trY, sc, rt)
}