-
Notifications
You must be signed in to change notification settings - Fork 7
/
rotateDeg_test.go
236 lines (199 loc) · 6.56 KB
/
rotateDeg_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package govec
import (
"testing"
)
func TestV2F_RotateDeg(t *testing.T) {
type expected struct {
X float64
Y float64
}
tt := []struct {
name string
degrees float64
expected expected
}{
{name: "0", expected: expected{X: 0, Y: 1}},
{name: "90", degrees: 90, expected: expected{X: -1, Y: 0}},
{name: "180", degrees: 180, expected: expected{X: 0, Y: -1}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V2F[float64]{X: 0, Y: 1}
v2 := v1.RotateDeg(tc.degrees)
if !almostEqual(v2.X, tc.expected.X, 1e-10) {
t.Errorf("V2F RotateDeg failed expected %v: got %v", tc.expected.X, v2.X)
}
if !almostEqual(v2.Y, tc.expected.Y, 1e-10) {
t.Errorf("V2F RotateDeg failed expected %v: got %v", tc.expected.Y, v2.Y)
}
})
}
}
func TestV2I_RotateDeg(t *testing.T) {
type expected struct {
X float64
Y float64
}
tt := []struct {
name string
degrees float64
expected expected
}{
{name: "0", expected: expected{X: 0, Y: 1}},
{name: "90", degrees: 90, expected: expected{X: -1, Y: 0}},
{name: "180", degrees: 180, expected: expected{X: 0, Y: -1}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V2I[int]{X: 0, Y: 1}
v2 := v1.RotateDeg(tc.degrees)
if !almostEqual(v2.X, tc.expected.X, 1e-10) {
t.Errorf("V2I RotateDeg failed expected %v: got %v", tc.expected.X, v2.X)
}
if !almostEqual(v2.Y, tc.expected.Y, 1e-10) {
t.Errorf("V2I RotateDeg failed expected %v: got %v", tc.expected.Y, v2.Y)
}
})
}
}
func TestV2F_RotateDegInPlace(t *testing.T) {
type expected struct {
X float64
Y float64
}
tt := []struct {
name string
degrees float64
expected expected
}{
{name: "0", expected: expected{X: 0, Y: 1}},
{name: "90", degrees: 90, expected: expected{X: -1, Y: 0}},
{name: "180", degrees: 180, expected: expected{X: 0, Y: -1}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V2F[float64]{X: 0, Y: 1}
v1.RotateDegInPlace(tc.degrees)
if !almostEqual(v1.X, tc.expected.X, 1e-10) {
t.Errorf("V2F RotateDegInPlace failed expected %v: got %v", tc.expected.X, v1.X)
}
if !almostEqual(v1.Y, tc.expected.Y, 1e-10) {
t.Errorf("V2F RotateDegInPlace failed expected %v: got %v", tc.expected.Y, v1.Y)
}
})
}
}
func TestV3F_RotateDeg(t *testing.T) {
type expected struct {
X float64
Y float64
Z float64
}
tt := []struct {
name string
degrees float64
axis axis
expected expected
}{
{name: "z0", axis: zAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "z90", degrees: 90, axis: zAxis, expected: expected{X: -1, Y: 0, Z: 0}},
{name: "z180", degrees: 180, axis: zAxis, expected: expected{X: 0, Y: -1, Z: 0}},
{name: "y0", axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "y90", degrees: 90, axis: yAxis, expected: expected{X: -1, Y: 1, Z: 0}},
{name: "y180", degrees: 180, axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x0", axis: xAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x90", degrees: 90, axis: xAxis, expected: expected{X: 0, Y: 0, Z: 0}},
{name: "x180", degrees: 180, axis: xAxis, expected: expected{X: 0, Y: -1, Z: 0}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V3F[float64]{X: 0, Y: 1, Z: 0}
v2 := v1.RotateDeg(tc.degrees, tc.axis)
if !almostEqual(v2.X, tc.expected.X, 1e-10) {
t.Errorf("V3F RotateDeg failed expected %v: got %v", tc.expected.X, v2.X)
}
if !almostEqual(v2.Y, tc.expected.Y, 1e-10) {
t.Errorf("V3F RotateDeg failed expected %v: got %v", tc.expected.Y, v2.Y)
}
if !almostEqual(v2.Z, tc.expected.Z, 1e-10) {
t.Errorf("V3F RotateDeg failed expected %v: got %v", tc.expected.Z, v2.Z)
}
})
}
}
func TestV3I_RotateDeg(t *testing.T) {
type expected struct {
X float64
Y float64
Z float64
}
tt := []struct {
name string
degrees float64
axis axis
expected expected
}{
{name: "z0", axis: zAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "z90", degrees: 90, axis: zAxis, expected: expected{X: -1, Y: 0, Z: 0}},
{name: "z180", degrees: 180, axis: zAxis, expected: expected{X: 0, Y: -1, Z: 0}},
{name: "y0", axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "y90", degrees: 90, axis: yAxis, expected: expected{X: -1, Y: 1, Z: 0}},
{name: "y180", degrees: 180, axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x0", axis: xAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x90", degrees: 90, axis: xAxis, expected: expected{X: 0, Y: 0, Z: 0}},
{name: "x180", degrees: 180, axis: xAxis, expected: expected{X: 0, Y: -1, Z: 0}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V3I[int]{X: 0, Y: 1, Z: 0}
v2 := v1.RotateDeg(tc.degrees, tc.axis)
if !almostEqual(v2.X, tc.expected.X, 1e-10) {
t.Errorf("V3I RotateDeg failed expected %v: got %v", tc.expected.X, v2.X)
}
if !almostEqual(v2.Y, tc.expected.Y, 1e-10) {
t.Errorf("V3I RotateDeg failed expected %v: got %v", tc.expected.Y, v2.Y)
}
if !almostEqual(v2.Z, tc.expected.Z, 1e-10) {
t.Errorf("V3I RotateDeg failed expected %v: got %v", tc.expected.Z, v2.Z)
}
})
}
}
func TestV3F_RotateDegInPlace(t *testing.T) {
type expected struct {
X float64
Y float64
Z float64
}
tt := []struct {
name string
degrees float64
axis axis
expected expected
}{
{name: "z0", axis: zAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "z90", degrees: 90, axis: zAxis, expected: expected{X: -1, Y: 0, Z: 0}},
{name: "z180", degrees: 180, axis: zAxis, expected: expected{X: 0, Y: -1, Z: 0}},
{name: "y0", axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "y90", degrees: 90, axis: yAxis, expected: expected{X: -1, Y: 1, Z: 0}},
{name: "y180", degrees: 180, axis: yAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x0", axis: xAxis, expected: expected{X: 0, Y: 1, Z: 0}},
{name: "x90", degrees: 90, axis: xAxis, expected: expected{X: 0, Y: 0, Z: 0}},
{name: "x180", degrees: 180, axis: xAxis, expected: expected{X: 0, Y: -1, Z: 0}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v1 := V3F[float64]{X: 0, Y: 1, Z: 0}
v1.RotateDegInPlace(tc.degrees, tc.axis)
if !almostEqual(v1.X, tc.expected.X, 1e-10) {
t.Errorf("V3F RotateDegInPlace failed expected %v: got %v", tc.expected.X, v1.X)
}
if !almostEqual(v1.Y, tc.expected.Y, 1e-10) {
t.Errorf("V3F RotateDegInPlace failed expected %v: got %v", tc.expected.Y, v1.Y)
}
if !almostEqual(v1.Z, tc.expected.Z, 1e-10) {
t.Errorf("V3F RotateDegInPlace failed expected %v: got %v", tc.expected.Z, v1.Z)
}
})
}
}