forked from hschendel/stl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmat4_test.go
66 lines (61 loc) · 1.07 KB
/
mat4_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
64
65
66
package stl
import (
"testing"
)
func BenchmarkMultMat4(b *testing.B) {
r := Mat4{
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
}
s := Mat4{
Vec4{9, 2, 1, -6},
Vec4{8, 3, 0, -5},
Vec4{7, 4, -1, -4},
Vec4{6, 5, -2, -3},
}
var t Mat4
for i := 0; i < b.N; i++ {
r.MultMat4(&s, &t)
}
}
func TestMultMat4(t *testing.T) {
m := Mat4{
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
Vec4{1, 2, 3, 4},
}
var r Mat4
m.MultMat4(&Mat4Identity, &r)
if m != r {
t.Errorf("Result: %v, Expected: %v", r, m)
}
}
func BenchmarkMultVec3(b *testing.B) {
m := Mat4{
Vec4{9, 2, 1, -6},
Vec4{8, 3, 0, -5},
Vec4{7, 4, -1, -4},
Vec4{6, 5, -2, -3},
}
v := Vec3{-1000, 234, 1000}
for i := 0; i < b.N; i++ {
_ = m.MultVec3(v)
}
}
func TestMultVec3(t *testing.T) {
m := Mat4{
Vec4{1, 0, 0, 1000},
Vec4{0, 2, 0, 500},
Vec4{0, 0, 1, 250},
Vec4{0, 0, 0, 1},
}
v := Vec3{1, 1, 1}
r := m.MultVec3(v)
expected := Vec3{1001, 502, 251}
if r != expected {
t.Errorf("MultVec3 result: %v, expected: %v", v, expected)
}
}