-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcompose.go
60 lines (50 loc) · 1.09 KB
/
compose.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 sample
import (
"github.com/EliCDavis/vector/vector2"
"github.com/EliCDavis/vector/vector3"
)
func ComposeFloat(f2fs ...FloatToFloat) FloatToFloat {
if len(f2fs) == 0 {
panic("can not create a composition without any functions")
}
if len(f2fs) == 1 {
return f2fs[0]
}
return func(f float64) float64 {
result := f2fs[0](f)
for i := 1; i < len(f2fs); i++ {
result = f2fs[i](result)
}
return result
}
}
func ComposeVec2(f2fs ...Vec2ToVec2) Vec2ToVec2 {
if len(f2fs) == 0 {
panic("can not create a composition without any functions")
}
if len(f2fs) == 1 {
return f2fs[0]
}
return func(f vector2.Float64) vector2.Float64 {
result := f2fs[0](f)
for i := 1; i < len(f2fs); i++ {
result = f2fs[i](result)
}
return result
}
}
func ComposeVec3(f2fs ...Vec3ToVec3) Vec3ToVec3 {
if len(f2fs) == 0 {
panic("can not create a composition without any functions")
}
if len(f2fs) == 1 {
return f2fs[0]
}
return func(f vector3.Float64) vector3.Float64 {
result := f2fs[0](f)
for i := 1; i < len(f2fs); i++ {
result = f2fs[i](result)
}
return result
}
}