-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_transform_test.go
119 lines (93 loc) · 2.86 KB
/
matrix_transform_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package vkm
import (
"testing"
"github.com/chewxy/math32"
)
func TestRotateX(t *testing.T) {
m0 := NewMatRotateX(math32.Pi)
pt := NewPt(0, 1, 1)
exp0 := NewPt(0, -1, -1)
res0 := m0.MultP(pt)
if !res0.EqualTo(exp0) {
t.Errorf("NewMatRotateX by pi radians failed! Expected: %+v Actual: %+v", exp0, res0)
}
m1 := NewMatRotateXDeg(90)
exp1 := NewPt(0, -1, 1)
res1 := m1.MultP(pt)
if !res1.EqualTo(exp1) {
t.Errorf("NewMatRotateXDeg by 90 degrees failed! Expected: %+v Actual: %+v", exp1, res1)
}
m2 := Identity()
exp2 := NewPt(0, 1, -1)
res2 := m2.RotateXDeg(-90).MultP(pt)
if !res2.EqualTo(exp2) {
t.Errorf("RotateXDeg by -90 degrees failed! Expected: %+v Actual: %+v", exp2, res2)
}
}
func TestRotateY(t *testing.T) {
m0 := NewMatRotateY(math32.Pi)
pt := NewPt(1, 1, 1)
exp0 := NewPt(-1, 1, -1)
res0 := m0.MultP(pt)
if !res0.EqualTo(exp0) {
t.Errorf("NewMatRotateY by pi radians failed! Expected: %+v Actual: %+v", exp0, res0)
}
m1 := NewMatRotateYDeg(90)
exp1 := NewPt(1, 1, -1)
res1 := m1.MultP(pt)
if !res1.EqualTo(exp1) {
t.Errorf("NewMatRotateYDeg by 90 degrees failed! Expected: %+v Actual: %+v", exp1, res1)
}
m2 := Identity()
exp2 := NewPt(-1, 1, 1)
res2 := m2.RotateYDeg(-90).MultP(pt)
if !res2.EqualTo(exp2) {
t.Errorf("RotateYDeg by -90 degrees failed! Expected: %+v Actual: %+v", exp2, res2)
}
}
func TestRotateZ(t *testing.T) {
m0 := NewMatRotateZ(math32.Pi)
pt := NewPt(1, 1, 1)
exp0 := NewPt(-1, -1, 1)
res0 := m0.MultP(pt)
if !res0.EqualTo(exp0) {
t.Errorf("NewMatRotateZ by pi radians failed! Expected: %+v Actual: %+v", exp0, res0)
}
m1 := NewMatRotateZDeg(90)
exp1 := NewPt(-1, 1, 1)
res1 := m1.MultP(pt)
if !res1.EqualTo(exp1) {
t.Errorf("NewMatRotateZDeg by 90 degrees failed! Expected: %+v Actual: %+v", exp1, res1)
}
m2 := Identity()
exp2 := NewPt(1, -1, 1)
res2 := m2.RotateZDeg(-90).MultP(pt)
if !res2.EqualTo(exp2) {
t.Errorf("RotateZDeg by -90 degrees failed! Expected: %+v Actual: %+v", exp2, res2)
}
}
func TestRotate(t *testing.T) {
// Rotation around Z
m0 := NewMatRotate(NewVec(0, 0, 1), math32.Pi)
pt := NewPt(1, 1, 1)
exp0 := NewPt(-1, -1, 1)
res0 := m0.MultP(pt)
if !res0.EqualTo(exp0) {
t.Errorf("NewMatRotate by pi radians around Z axis failed! Expected: %+v Actual: %+v", exp0, res0)
}
// Rotation around axis that the test point lives on, by an arbitrary angle of 5 radians.
// Should not change the point at all.
m1 := NewMatRotate(NewVec(1, 1, 1).Normalize(), 5)
exp1 := pt.Clone()
res1 := m1.MultP(pt)
if !res1.EqualTo(exp1) {
t.Errorf("NewMatRotate applied to point on rotation axis failed! Expected: %+v Actual: %+v", exp1, res1)
}
m2 := Identity()
exp2 := NewPt(1, 1, -1)
axis2 := NewVec(1, 0, 0)
res2 := m2.RotateDeg(axis2, -90).MultP(pt)
if !res2.EqualTo(exp2) {
t.Errorf("RotateDeg by -90 degrees around X axis failed! Expected: %+v Actual: %+v", exp2, res2)
}
}