forked from faiface/pixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_test.go
63 lines (60 loc) · 1.19 KB
/
matrix_test.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
61
62
63
package pixel_test
import (
"math/rand"
"testing"
"github.com/faiface/pixel"
)
func BenchmarkMatrix(b *testing.B) {
b.Run("Moved", func(b *testing.B) {
m := pixel.IM
for i := 0; i < b.N; i++ {
m = m.Moved(pixel.V(4.217, -132.99))
}
})
b.Run("ScaledXY", func(b *testing.B) {
m := pixel.IM
for i := 0; i < b.N; i++ {
m = m.ScaledXY(pixel.V(-5.1, 9.3), pixel.V(2.1, 0.98))
}
})
b.Run("Rotated", func(b *testing.B) {
m := pixel.IM
for i := 0; i < b.N; i++ {
m = m.Rotated(pixel.V(-5.1, 9.3), 1.4)
}
})
b.Run("Chained", func(b *testing.B) {
var m1, m2 pixel.Matrix
for i := range m1 {
m1[i] = rand.Float64()
m2[i] = rand.Float64()
}
for i := 0; i < b.N; i++ {
m1 = m1.Chained(m2)
}
})
b.Run("Project", func(b *testing.B) {
var m pixel.Matrix
for i := range m {
m[i] = rand.Float64()
}
u := pixel.V(1, 1)
for i := 0; i < b.N; i++ {
u = m.Project(u)
}
})
b.Run("Unproject", func(b *testing.B) {
again:
var m pixel.Matrix
for i := range m {
m[i] = rand.Float64()
}
if (m[0]*m[3])-(m[1]*m[2]) == 0 { // zero determinant, not invertible
goto again
}
u := pixel.V(1, 1)
for i := 0; i < b.N; i++ {
u = m.Unproject(u)
}
})
}