-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransform.go
60 lines (50 loc) · 1.43 KB
/
transform.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
56
57
58
59
60
package texture
import (
g2d "github.com/jphsd/graphics2d"
"image/color"
)
// Transform applies an affine transform to the values passed into the Eval2 function.
type Transform struct {
Name string
Src Field
Xfm *g2d.Aff3
}
func NewTransform(src Field, xfm *g2d.Aff3) *Transform {
return &Transform{"Transform", src, xfm}
}
// Eval2 implements the Field interface.
func (t *Transform) Eval2(x, y float64) float64 {
pt := []float64{x, y}
pts := t.Xfm.Apply(pt)
return t.Src.Eval2(pts[0][0], pts[0][1])
}
// TransformVF applies an affine transform to the values passed into the Eval2 function.
type TransformVF struct {
Name string
Src VectorField
Xfm *g2d.Aff3
}
func NewTransformVF(src VectorField, xfm *g2d.Aff3) *TransformVF {
return &TransformVF{"TransformVF", src, xfm}
}
// Eval2 implements the VectorField interface.
func (t *TransformVF) Eval2(x, y float64) []float64 {
pt := []float64{x, y}
pts := t.Xfm.Apply(pt)
return t.Src.Eval2(pts[0][0], pts[0][1])
}
// TransformCF applies an affine transform to the values passed into the Eval2 function.
type TransformCF struct {
Name string
Src ColorField
Xfm *g2d.Aff3
}
func NewTransformCF(src ColorField, xfm *g2d.Aff3) *TransformCF {
return &TransformCF{"TransformCF", src, xfm}
}
// Eval2 implements the ColorField interface.
func (t *TransformCF) Eval2(x, y float64) color.Color {
pt := []float64{x, y}
pts := t.Xfm.Apply(pt)
return t.Src.Eval2(pts[0][0], pts[0][1])
}