forked from zri/math3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math4d_test.go
593 lines (533 loc) · 39.7 KB
/
math4d_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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
This code is an incomplete port of the C++ algebra library WildMagic5 (geometrictools.com)
Note that this code uses column major matrixes, just like OpenGl
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
*/
package math3d
import "math"
import "fmt"
import "testing"
const ε3d = 0.0001
const ε4d = 0.00001
var a4Array, aT4Array, aI4Array, b4Array, bI4Array, p4Array, pI4Array, va4Array, v04Array, v14Array [][]float32
var setup4 bool
func Setup4() {
// randomly generated test data. Products and inverts generated by numpy
a4Array = [][]float32{[]float32{1, 9, 5, -6, 5, -2, -2, 7, 2, -4, 6, 9, -4, -1, 1, -7}, []float32{-1, -4, 4, 0, 1, 3, 3, 4, 1, 6, 0, 9, -2, 4, 8, 2}, []float32{-8, 1, -4, 6, -7, 3, 5, -7, -1, 2, -4, 6, 4, 6, -9, 3}, []float32{6, 5, 6, 3, 7, -5, -2, 7, 6, -8, 9, -3, -8, -1, -7, 3}, []float32{2, -6, -9, -8, -5, 2, -1, 2, -4, 1, -7, 1, 4, -3, 6, -9}, []float32{6, 2, -7, 2, -9, 2, 4, 4, -6, -9, 8, 1, 8, 4, -8, 7}, []float32{-2, -1, -4, 1, 4, -8, 5, 5, -4, -7, 1, -7, -8, 5, 5, -8}, []float32{9, 3, -2, 8, -3, -5, -8, 6, 8, 5, 1, 2, -6, 4, -7, -7}, []float32{7, 5, 2, -8, -7, 3, 8, 6, 7, 0, 2, -7, 4, 2, -9, 1}, []float32{-7, -7, 1, 4, -5, 3, 9, 5, -3, 7, -7, -3, 6, -7, -4, -1}, []float32{-7, 7, -4, -3, 5, 1, 1, -5, -1, -1, 3, 7, -4, -9, 7, 2}, []float32{-1, 5, 5, 4, 1, -5, -2, 3, 3, 3, -6, 8, -9, 4, 1, -8}, []float32{3, 6, 0, 7, 6, -1, 3, 1, 3, -2, -2, 5, -6, 4, 2, -1}, []float32{-6, 7, -2, 7, 9, -6, -2, 6, -5, 1, 1, -3, 0, 0, 1, 8}, []float32{0, -7, 2, -7, -9, -2, -3, -2, -6, 9, 5, 1, 2, 6, 5, 7}, []float32{2, 4, 7, 2, 6, -8, -5, -5, -1, -9, 7, 0, 5, 4, -3, -1}, []float32{-2, 6, -2, -4, -9, 8, -8, -6, 3, -1, -6, 9, -2, -1, 1, 0}, []float32{1, -1, -8, -4, -5, 6, 3, 2, 6, 9, 8, 8, 8, 1, 5, -8}, []float32{-7, 2, 4, 8, -6, 9, 2, 9, 9, 7, -4, -6, 4, 8, 0, -5}, []float32{-7, -8, 8, 7, 1, 1, -8, -6, 8, 0, -7, 5, -6, 5, -3, 6}, []float32{3, 4, -5, -2, 7, -1, 9, 0, 8, 2, 1, 7, -5, 8, -3, 6}, []float32{2, -4, -4, -7, -6, 9, -2, -1, 4, 5, -5, -8, -7, 7, -3, -6}, []float32{-7, -3, 3, 8, -5, 8, 0, 1, 9, 3, 4, 5, 2, 7, 3, -3}, []float32{5, 2, 2, -8, 7, 2, 7, -5, -6, -8, -1, 8, -6, 5, 3, 3}, []float32{1, -8, -4, 8, 1, 6, 0, -5, 5, -5, -2, -6, -8, 4, -9, 6}, []float32{-1, -6, -3, -6, 2, 6, 5, 6, 5, 0, -6, 6, 7, -9, 9, -4}, []float32{6, 6, -3, 7, 3, 5, -9, -8, -6, 4, -8, -4, -1, 6, -1, 8}, []float32{-9, 6, 6, -9, 7, -3, 5, -5, -5, -1, -7, -9, 0, 8, -9, -5}, []float32{8, -3, -3, -2, 7, 3, 5, 7, -1, -4, 9, 5, -5, -5, 9, -6}, []float32{9, -8, -2, 1, -2, -4, -1, -6, 6, 4, 2, -8, 5, 1, -7, 4}}
aT4Array = [][]float32{[]float32{1, 5, 2, -4, 9, -2, -4, -1, 5, -2, 6, 1, -6, 7, 9, -7}, []float32{-1, 1, 1, -2, -4, 3, 6, 4, 4, 3, 0, 8, 0, 4, 9, 2}, []float32{-8, -7, -1, 4, 1, 3, 2, 6, -4, 5, -4, -9, 6, -7, 6, 3}, []float32{6, 7, 6, -8, 5, -5, -8, -1, 6, -2, 9, -7, 3, 7, -3, 3}, []float32{2, -5, -4, 4, -6, 2, 1, -3, -9, -1, -7, 6, -8, 2, 1, -9}, []float32{6, -9, -6, 8, 2, 2, -9, 4, -7, 4, 8, -8, 2, 4, 1, 7}, []float32{-2, 4, -4, -8, -1, -8, -7, 5, -4, 5, 1, 5, 1, 5, -7, -8}, []float32{9, -3, 8, -6, 3, -5, 5, 4, -2, -8, 1, -7, 8, 6, 2, -7}, []float32{7, -7, 7, 4, 5, 3, 0, 2, 2, 8, 2, -9, -8, 6, -7, 1}, []float32{-7, -5, -3, 6, -7, 3, 7, -7, 1, 9, -7, -4, 4, 5, -3, -1}, []float32{-7, 5, -1, -4, 7, 1, -1, -9, -4, 1, 3, 7, -3, -5, 7, 2}, []float32{-1, 1, 3, -9, 5, -5, 3, 4, 5, -2, -6, 1, 4, 3, 8, -8}, []float32{3, 6, 3, -6, 6, -1, -2, 4, 0, 3, -2, 2, 7, 1, 5, -1}, []float32{-6, 9, -5, 0, 7, -6, 1, 0, -2, -2, 1, 1, 7, 6, -3, 8}, []float32{0, -9, -6, 2, -7, -2, 9, 6, 2, -3, 5, 5, -7, -2, 1, 7}, []float32{2, 6, -1, 5, 4, -8, -9, 4, 7, -5, 7, -3, 2, -5, 0, -1}, []float32{-2, -9, 3, -2, 6, 8, -1, -1, -2, -8, -6, 1, -4, -6, 9, 0}, []float32{1, -5, 6, 8, -1, 6, 9, 1, -8, 3, 8, 5, -4, 2, 8, -8}, []float32{-7, -6, 9, 4, 2, 9, 7, 8, 4, 2, -4, 0, 8, 9, -6, -5}, []float32{-7, 1, 8, -6, -8, 1, 0, 5, 8, -8, -7, -3, 7, -6, 5, 6}, []float32{3, 7, 8, -5, 4, -1, 2, 8, -5, 9, 1, -3, -2, 0, 7, 6}, []float32{2, -6, 4, -7, -4, 9, 5, 7, -4, -2, -5, -3, -7, -1, -8, -6}, []float32{-7, -5, 9, 2, -3, 8, 3, 7, 3, 0, 4, 3, 8, 1, 5, -3}, []float32{5, 7, -6, -6, 2, 2, -8, 5, 2, 7, -1, 3, -8, -5, 8, 3}, []float32{1, 1, 5, -8, -8, 6, -5, 4, -4, 0, -2, -9, 8, -5, -6, 6}, []float32{-1, 2, 5, 7, -6, 6, 0, -9, -3, 5, -6, 9, -6, 6, 6, -4}, []float32{6, 3, -6, -1, 6, 5, 4, 6, -3, -9, -8, -1, 7, -8, -4, 8}, []float32{-9, 7, -5, 0, 6, -3, -1, 8, 6, 5, -7, -9, -9, -5, -9, -5}, []float32{8, 7, -1, -5, -3, 3, -4, -5, -3, 5, 9, 9, -2, 7, 5, -6}, []float32{9, -2, 6, 5, -8, -4, 4, 1, -2, -1, 2, -7, 1, -6, -8, 4}}
aI4Array = [][]float32{[]float32{.122265, .422136, -.011583, .302445, .0186615, -.20399, -.03861, -.269627, .0662806, .0341055, .104247, .111326, -.0630631, -.207207, .027027, -.261261}, []float32{-.0909091, .727273, -.272727, -.227273, -.189394, .0151515, -.0265152, .0890152, .0378788, .19697, -.094697, .032197, .136364, -.0909091, .159091, -.0340909}, []float32{-.118661, -.0212982, .0943205, -.0010142, -.169371, .149087, .339757, .00709939, -.197262, .0927992, .374746, -.138438, -.0948276, .00862069, .318966, -.0948276}, []float32{-.0679114, .0708402, -.066264, -.163646, .0439319, -.029654, -.0730368, -.0477759, .129782, -.062603, .10507, .121362, .136372, .0329489, .044115, .164195}, []float32{-.114706, -.405882, .238235, .0382353, -.360294, -.544118, .786765, .286765, .0264706, .170588, -.208824, -.00882353, .0867647, .114706, -.295588, -.195588}, []float32{-.312887, -.146877, -.0236353, .176702, -.247608, -.00112549, -.126618, .0894766, -.503658, -.115926, -.0416432, .216095, -.0765335, .0360158, .0517727, .136747}, []float32{-.257845, -.0879218, .0461812, -.12759, -.0497336, -.0479574, -.0657194, .0213144, -.0615749, .0834813, -.0337478, .0740083, .188277, .110124, -.108348, .062167}, []float32{-.630658, .38786, .876543, -.13786, .692387, -.437243, -.802469, .187243, .289095, -.247942, -.419753, -.00205761, .647119, -.334362, -.790123, .0843621}, []float32{-.182494, .172197, .384439, .197941, .159611, .0406178, -.141876, .0400458, -.0680778, .108124, .171625, .00800915, -.201945, .203089, .290618, .200229}, []float32{-.0916976, .151797, .05886, .215613, -.0656753, .142503, .116481, .100372, -.0173482, -.160471, -.205081, -.256506, -.0210657, .555143, .358116, .6171}, []float32{-.0792541, .0454545, .0151515, -.0582751, .103341, .151515, .161616, -.031857, .0986791, .242424, .191919, .0823621, -.03885, -.0757576, .0858586, -.048174}, []float32{-.0758621, -.193103, -.0206897, -.131034, .00558292, -.158949, .0577997, .000985222, .0988506, .0091954, -.0942529, -.0413793, .100493, .138916, .0403941, .017734}, []float32{.0748299, .0226757, -.145125, -.179138, .153061, -.0748299, -.221088, -.108844, -.0918367, .244898, .132653, .265306, -.0204082, .0544218, .251701, .170068}, []float32{-.0533981, -.121359, -.354369, .00485437, .0133495, -.21966, -.411408, -.00121359, -.203883, -.281553, -.262136, .291262, .0254854, .0351942, .032767, .0885922}, []float32{-.0224315, -.118804, -.00692329, -.0553863, -.089172, -.101911, .10828, -.133758, .136527, .0193852, .0174467, .139574, -.0146774, .107449, -.103295, .173636}, []float32{-.305476, -.268012, .426513, .729107, .354467, .244957, -.400576, -.51585, .412104, .276657, -.311239, -.559078, -1.34582, -1.1902, 1.46398, 2.25937}, []float32{-.0628743, -.011976, -.0359281, -.437126, .417665, -.134731, .0958084, .332335, .291916, -.158683, .0239521, .458084, .261976, -.116766, .149701, .488024}, []float32{.0399588, -.0881671, .0610982, .0190771, .101573, .111369, .0456303, .0226863, -.121165, .00928074, -.0239753, .0389276, -.023073, -.0684455, .0518175, -.0787574}, []float32{.562341, -.310433, .407125, -.147583, -.0839695, .0916031, -.0381679, .0763359, .645038, -.385496, .20229, .0954198, .315522, -.101781, .264631, -.195929}, []float32{-.0446283, -.0675041, .05096, -.0579044, -.101409, -.0916054, -.0352328, .0560662, -.0350286, -.110192, -.0423815, -.0340074, .0223652, -.0462623, .0591299, .0450368}, []float32{.066343, .0151025, .0582524, -.0458468, .100324, .0960086, -.0582524, .101402, -.0404531, .110032, -.0517799, .0469256, -.0987055, -.0604099, .100324, .0167206}, []float32{-.0723297, -.0504626, .111859, -.0563499, -.125315, -.0176619, .0891505, .0302775, -.421362, -.596299, .10513, .450799, .148865, .336417, -.079058, -.291001}, []float32{-.0548809, -.0142457, .0686595, -.0366651, -.0359645, .105558, .0322279, -.00700607, .133816, -.152499, -.0354974, .246847, .0133115, .0843064, .0854741, -.127277}, []float32{-.21438, .0990794, -.106094, -.12363, -.122315, .00131521, -.134152, .0337571, .0517317, .106971, .0889961, .0789128, -.276633, .0889961, -.0775975, -.0491013}, []float32{.227226, .31901, -.0522516, -.0893778, .0821588, .215194, -.0869715, -.017188, -.0694397, -.106566, -.0687521, -.0649708, .144036, .122035, -.114816, -.0385012}, []float32{2.18644, 1.88136, .169492, -.20339, 2.18079, 1.91525, .0734463, -.288136, -.59322, -.440678, -.0847458, .101695, -2.41525, -2.00847, -.059322, .271186}, []float32{.0834073, .0301686, -.0563443, -.0709849, -.291038, .256433, -.228926, .396628, -.303461, .18811, -.263088, .322094, .190772, -.16504, .131766, -.141083}, []float32{-.0325481, .0752817, -.0360191, .0481393, .0382383, -.00802322, -.0800615, .0833049, .0463184, .0274838, -.0448959, -.0300444, -.0221919, -.062308, -.0472858, -.0126323}, []float32{.0760921, .0676728, -.0359015, .0236696, -.0946783, .122478, -.149484, .0498809, -.0230342, .081811, -.0246227, .0826052, -.0190627, -.0357427, .117554, -.104051}, []float32{.0574746, -.0583454, .054717, .00754717, -.0685051, -.0516691, .0509434, .0415094, .0423803, -.103628, .0150943, -.135849, .0194485, -.0955007, -.054717, -.00754717}}
b4Array = [][]float32{[]float32{-1, 5, 2, 0, 0, 0, -1, -4, 5, 4, 2, -9, 7, -6, -4, 0}, []float32{5, 9, -4, -5, 1, 7, 6, -7, -2, 5, 4, 9, -6, -4, 4, -3}, []float32{-5, 0, 1, -4, -6, -2, -9, -2, -3, 6, 6, -5, -4, -2, -3, -4}, []float32{-1, -4, -1, -4, 0, 9, 5, 2, 3, 7, 7, 8, -3, 4, 6, -5}, []float32{6, 9, -9, -4, 4, 1, -5, -1, 4, -5, 7, 2, 4, -3, -4, -7}, []float32{-9, -2, 0, -8, -8, 0, -9, 2, 3, -8, 2, 0, 7, -5, -3, -2}, []float32{6, 0, 5, 1, 4, -7, 6, -4, -9, 7, -7, -7, -4, 0, 7, -5}, []float32{8, 8, 7, -3, 1, -2, 7, 7, -8, -5, -3, -5, 9, -4, -9, 2}, []float32{0, -3, 4, 0, -3, 0, 7, -9, 8, -1, -1, -5, -6, -2, 3, 8}, []float32{-1, 3, -5, -2, 0, -5, -6, -5, -8, -5, 5, 4, -7, -7, -4, -7}, []float32{5, 3, 4, -5, -9, -7, 0, -4, 2, -5, -5, 1, 1, 0, 5, 7}, []float32{-5, 4, -5, -1, 9, 3, 8, -3, 2, 3, -4, -5, -5, -2, 6, -5}, []float32{8, -6, 1, -5, -2, -9, -3, -4, -1, -3, -1, 1, 0, 4, 6, 1}, []float32{4, 8, -9, -5, 9, -6, 9, -7, -6, 7, -1, -2, -2, 3, -6, -4}, []float32{-2, 7, 6, -1, -3, 0, -2, 8, 9, 6, 5, 4, -4, 9, 9, 2}, []float32{4, -5, -7, 7, -8, 5, 6, 4, 8, -1, 9, 5, -3, -5, -6, -3}, []float32{-2, 1, 7, -3, 9, -2, 2, 6, 7, -2, -1, -9, 4, -4, 0, -8}, []float32{-4, -4, 9, -3, -1, 8, 1, -1, -2, 5, -3, 8, 8, -2, 3, 3}, []float32{7, 2, -2, 9, -4, 9, -7, 7, 5, 0, -6, -6, 9, 7, 3, -8}, []float32{5, 3, -7, 7, 1, -1, 5, -5, -7, 9, -4, -4, 4, 3, -4, -1}, []float32{-8, -7, -8, 6, -1, 7, 4, 9, -3, -3, -6, -3, 7, 6, 1, 1}, []float32{4, -8, -8, -8, 1, -4, -3, 8, 2, -7, -7, -6, 2, 1, 0, 8}, []float32{4, 2, -3, 8, 0, 2, -3, -5, -8, -1, -3, -4, -8, 1, -6, -4}, []float32{7, -7, 4, 2, -6, 0, 1, -4, -8, -3, -1, -7, 3, -1, 2, -5}, []float32{7, -5, 8, -4, 2, -8, 4, -1, -4, 9, 6, -2, -3, 1, 3, 2}, []float32{3, -9, -7, 3, -8, 6, 8, -4, -4, -4, 6, -6, -6, 4, 1, 5}, []float32{3, 0, -2, -2, -7, 4, 6, -3, 7, -2, 7, 1, 5, 0, -6, 2}, []float32{5, -9, -2, 9, -6, 6, 5, 2, -9, -4, -3, -1, -9, -9, 0, 5}, []float32{-6, 4, 2, 9, -4, 5, 6, 7, -4, 4, -8, -5, -5, 7, -5, -1}, []float32{4, 4, -5, 7, -3, -9, -8, 8, 8, 2, -1, -8, -7, 7, 1, 2}}
bI4Array = [][]float32{[]float32{.0770791, -.146045, .0649087, .107505, .403651, .182556, -.0811359, .115619, -.470588, -.529412, .235294, -.235294, .117647, -.117647, -.0588235, .0588235}, []float32{-.157616, .116556, -.0807947, -.251656, .11479, -.01766, .0728477, .0684327, -.146799, .137969, -.00662252, -.0971302, -.0335541, -.0256071, .0556291, -.0507726}, []float32{-.402985, -.108209, .0820896, .354478, -.179104, .132463, .175373, -.106343, .238806, -.0932836, -.0671642, -.108209, .313433, .11194, -.119403, -.470149}, []float32{1.80282, .981221, .192488, -.741784, .15493, .300469, -.0798122, -.131455, .0704225, -.13615, .14554, .122066, -.873239, -.511737, -.00469484, .286385}, []float32{.0516373, .0688497, .111251, -.00755668, .125945, -.165407, .0193115, -.0428212, .0806045, -.225861, .0923594, .0125945, -.070529, .239295, .00251889, -.13602}, []float32{-.0295594, -.0368098, -.0435025, .0814278, -.00948132, -.0306748, -.127161, .00725042, .00641383, -.0674847, .056609, -.09314, -.0893753, .0490798, .0807306, -.0934189}, []float32{.149635, .0583942, .0583942, -.0985401, .155892, -.0855057, .0573514, .0192909, .0346715, -.0474453, -.0474453, .111314, -.0711679, -.113139, -.113139, .0346715}, []float32{.0763606, .0417663, .0435944, .077345, -.0617353, -.127689, -.17705, -.0883139, .0797356, .0988609, .0897202, -.00210941, -.108283, .0015469, -.146534, -.0341724}, []float32{-.670588, .2, .694118, .658824, -1.65098, .533333, 1.22353, 1.36471, -.988235, .4, .917647, 1.02353, -.545098, .133333, .482353, .576471}, []float32{-.106337, .0794844, -.0590763, -.0601504, .0907626, -.163802, -.0606874, .056391, -.169173, -.191729, -.093985, .131579, .112245, .193878, .173469, -.214286}, []float32{.0906056, -.0345732, .102766, .0302814, -.0715308, -.0779685, -.133763, -.0765379, .0920362, .0569862, -.0245589, .101812, -.0786838, -.0357654, .00286123, .0658083}, []float32{-.0876953, .0178131, .0622088, -.0553576, .206632, .114278, -.0778295, -.0320636, .0419293, .0696081, -.0953686, .0452179, .0553576, .0200055, -.145519, -.0775555}, []float32{.103704, -.125926, .0814815, -.0666667, -.037037, -.026455, -.243386, -.047619, .0222222, .0444444, .0888889, .2, .0148148, -.160847, .440212, -.00952381}, []float32{.0938347, .0121135, -.047731, -.114627, .0885916, -.00397758, .105225, -.156391, -.00903996, .0412222, .0913036, -.106491, .0330862, -.0708733, -.034171, -.150244}, []float32{-.0160966, -.0315225, .0791415, -.0402414, .639839, .169685, .0207914, -.400402, -.61167, -.197854, .0073776, .470825, -.158954, .0637156, .0315225, .102616}, []float32{.00807217, -.0851535, .00079139, -.093384, .00854701, -.031339, -.116809, -.216524, -.0555556, .037037, .0925926, .0740741, .0887939, .0633112, .00870529, -.0272238}, []float32{0, .0588235, .117647, -.0882353, .05, -.0411765, .267647, -.350735, .125, .0441176, -.0367647, .0275735, -.025, .05, -.075, .00625}, []float32{-.0500494, .0286467, -.0493908, .0912084, -.0139941, .116562, .0059269, .00905499, .0930194, .0487323, .0194271, .057458, .0311162, -.0474152, .116233, .0386895}, []float32{.0693499, -.034851, .0300399, .0249941, -.0185989, .0651842, -.0376672, .0643628, -.00287491, -.0340882, -.103614, .0446491, .0606665, .00504576, -.0380192, -.0238207}, []float32{.0897239, .140337, -.0306748, .0490798, .266104, .31365, .122699, -.196319, .238497, .347393, .0552147, -.288344, .203221, .11273, .0245399, -.239264}, []float32{.073922, -.116016, -.151608, .145791, -.0965092, .137577, .221081, .00410678, -.0390144, -.00821355, -.137577, -.104723, .100616, -.00513347, -.127652, .0595483}, []float32{.541667, .0333333, -.633333, .0333333, -.583333, -.466667, .866667, .533333, .791667, .433333, -1.23333, -.566667, -.0625, .05, .05, .05}, []float32{.25, .4, .65, -.65, -.666667, -.8, -2.13333, 1.8, -.444444, -.533333, -1.08889, .866667, 0, -.2, -.2, .2}, []float32{-.0153492, -.137375, .00230238, .100537, -.0943975, .105142, -.13584, .0683039, .0890253, .396777, -.213354, .0168841, .0452801, .0552571, -.056792, -.146585}, []float32{.186029, -.253607, -.134396, .110858, .0652999, -.162491, -.0022779, .0470767, .0721336, -.0167046, .00911162, .145027, .138193, -.274108, -.214123, .425209}, []float32{-.245033, -.31457, .125828, .0463576, .0264901, .155629, -.162252, -.0860927, -.384106, -.506623, .352649, .248344, -.238411, -.400662, .210265, .274834}, []float32{.0801887, .0377358, .0754717, .0990566, -.0436321, .273585, .0471698, .34316, -.0448113, .0377358, .0754717, -.0259434, -.334906, .0188679, .0377358, .174528}, []float32{-.000297796, -.0494342, -.0821918, .00387135, .0911257, .126861, .150685, -.184634, -.175104, -.067302, -.328767, .276355, .16349, .139369, .123288, -.125372}, []float32{-.0329861, -.336806, -.657986, .635417, -.09375, -.0625, -.34375, .4375, -.130208, .302083, .244792, -.28125, .159722, -.263889, -.340278, .291667}, []float32{.0686139, -.0533205, -.0188757, -.10237, .0454671, -.0232847, .0356848, .0767429, .00275558, -.122623, -.149352, -.116561, .0796363, -.0438137, -.116285, -.0686139}}
p4Array = [][]float32{[]float32{-18, 61, 27, -81, 34, -25, -20, 26, 91, -20, -16, -38, -40, 26, 23, -5}, []float32{-17, -17, -4, 69, -22, 29, 42, -11, -43, 15, 68, -74, -34, 42, 72, 48}, []float32{22, -38, -59, 26, 30, 38, 17, 25, -19, -40, -61, -4, -41, -72, -113, 5}, []float32{3, 75, 79, 19, -34, -59, -4, -89, 30, -45, -1, 47, -22, -14, -28, -41}, []float32{-80, 81, -19, 36, -18, -44, 20, 2, -44, -3, -22, -6, 0, 30, 57, 62}, []float32{-77, 34, -38, -48, 105, -34, -22, 68, 157, -57, 94, 28, -79, 13, -73, -70}, []float32{16, -21, 19, 25, -73, 91, -28, -24, -33, 56, -118, 52, -41, 0, -101, -23}, []float32{163, 44, 18, 20, 89, 2, -86, 26, 79, 41, 70, 10, -51, 7, 70, 67}, []float32{49, -7, 37, -119, 19, 1, 3, -19, 58, -9, 5, -66, -84, -5, 42, 35}, []float32{-29, -19, 66, 25, -102, -110, 32, -4, 80, 12, -50, -36, 33, 80, -4, 14}, []float32{-109, -50, -23, -18, 13, 3, -10, -63, 17, -11, 16, 61, 77, 16, -41, 77}, []float32{40, 18, 49, -59, -69, -23, -19, 9, -40, -13, 81, -22, 123, -5, 25, 32}, []float32{12, -44, 27, -32, 47, -32, 12, -22, 30, 26, 41, -4, -58, -10, -26, 15}, []float32{37, -83, 77, -43, -18, 112, -169, -23, -11, -48, 71, 28, -22, 31, -49, -34}, []float32{67, -51, -39, -62, 5, -99, -83, -23, 26, -3, -20, 100, -5, 107, 88, 80}, []float32{26, -7, 61, 59, 63, -40, -105, 0, 124, -47, 16, -8, -33, 3, -32, 39}, []float32{28, 6, 0, 92, 10, 15, -39, 195, -21, -19, 25, -33, 2, -2, -17, -9}, []float32{-19, -44, 20, -78, 24, 79, -42, 39, 15, 72, 63, 61, -107, 17, 34, -9}, []float32{35, 60, 0, -137, 13, 132, -36, -75, -39, 39, -61, 202, -49, 45, -79, 132}, []float32{-71, 80, -51, -48, 38, -88, 54, 40, 109, -24, -48, 79, 20, -32, 55, -61}, []float32{-27, 10, 20, 67, -82, -83, -114, 6, -20, -3, -55, 70, 83, 136, 96, 57}, []float32{-18, 21, 24, -80, -21, 25, 35, 124, -5, -25, -12, -26, -39, 43, 56, 82}, []float32{-116, -15, -27, -85, -28, 7, -15, -84, -36, 25, -78, 21, 8, 12, -18, -19}, []float32{-17, -33, 4, 28, -34, -65, 13, -18, 38, 37, -15, -13, -87, 30, -16, -68}, []float32{-17, 31, -24, 28, 34, -58, 17, -20, 51, -9, -10, -23, -30, -67, -84, 58}, []float32{93, -39, -65, 9, -98, 22, 70, -18, 3, 3, -65, 81, 81, -169, -71, -17}, []float32{-10, 30, -39, -19, -129, 38, 9, -46, -122, 32, 4, -16, -12, 26, -17, -1}, []float32{-54, 174, 30, -120, 53, -56, -44, 27, 125, 148, 26, -85, 78, 129, 67, 0}, []float32{-14, -9, 32, 68, -109, 112, -43, 52, -39, 47, -123, -87, 44, -51, -82, -119}, []float32{37, 111, 22, 17, 38, -16, 37, -50, 84, -64, -72, 42, -67, 25, -22, 107}}
pI4Array = [][]float32{[]float32{.00422126, .0422674, .0144181, .0418288, .0400902, .106432, -.0170573, .0336213, -.0369824, -.0338784, .0440609, .0880839, .00458021, .059467, -.00136271, .0453857}, []float32{-.0451234, -.1059, .00751054, .0521749, .00500033, .0913439, -.0268496, -.0276482, -.026281, -.097147, .0215524, .0487428, .00308382, -.00921801, -.00351529, .00886849}, []float32{.0163388, .00312396, .0690544, -.0453381, -.0256927, .0389208, .0599125, -.013072, .0109726, -.0261591, -.0688539, .0186548, .011985, -.00512019, -.127112, .0615899}, []float32{-.155502, .0621234, -.203626, -.44034, -.0256063, .00273028, -.0463966, -.0709794, .024771, .00393686, .0259544, .032686, .0752669, -.0369554, .107381, .213805}, []float32{-.02844, -.0403097, .0454722, .0222144, .0419445, .0372648, -.0915074, -.0344125, .075668, .107379, -.181506, -.0649652, -.0898615, -.116751, .211146, .0925063}, []float32{.0340416, .0123588, .0113867, -.00678246, .0740528, .0164295, .00977885, -.0309074, -.0066803, -.010783, .00121369, -.0054087, -.0176991, .000348617, -.0123004, -.00673067}, []float32{-.0636352, -.0219335, .0117787, -.0196516, -.0358427, -.00269347, .00879302, -.016269, .017299, .00752454, -.00574023, -.00202631, .0374714, .00605625, .00421037, .000451072}, []float32{.0434153, -.0253149, -.0459938, .00372865, -.15781, .105314, .192449, -.0224841, .0427366, -.0338401, -.0454347, .00715607, .00488491, .00508283, -.00764769, .0126362}, []float32{-.0259995, .101501, .0244178, .0127473, .0275295, .146819, -.103774, -.0223852, -.0249764, .153163, .0182797, .0326962, -.0284942, .0807803, .0218423, .0167317}, []float32{.00682269, -.0287269, -.00642605, -.0369152, .00229996, .0314787, .0189028, .0534941, .0269633, .035125, .0341048, .0495849, -.0215209, -.102129, -.0831247, -.13307}, []float32{-.00178929, .021499, .0181079, .00282659, -.0126143, -.0416938, -.0459278, -.000677514, -.00778409, -.000848976, .0146325, -.0141063, .00026567, -.0132874, -.00077311, .00279009}, []float32{.00733854, .00698484, -.00525551, .00795278, -.0259532, -.0632355, .00837056, -.0243114, -.00767541, -.0137563, .0139711, -.000677424, -.0262663, -.0259814, .0105938, -.00258793}, []float32{-.0176367, .0281011, .00681952, .00540858, .0165029, -.0610565, -.0330478, -.0631561, -.00377929, .0298312, .0490804, .048778, -.063744, .119661, .0894096, .130024}, []float32{.00196136, -.00464395, -.0294797, -.0236164, -.0302231, -.0450082, -.0624654, .0172279, -.0202962, -.0374125, -.041179, .0170651, .00042501, .015886, .0214675, -.0230166}, []float32{.0145676, .00233507, .0022357, .0091666, -.0207682, -.135928, .0556662, -.124757, .0254604, .143565, -.0656943, .143125, .000681463, .024028, -.00205015, .0224989}, []float32{.0933543, .0883424, -.0994049, -.161619, .229546, .215424, -.264432, -.401504, -.0314335, -.0385847, .041093, .0559825, .0355432, .0265209, -.0300537, -.0342943}, []float32{.0357961, -.0162909, -.0047552, .0303804, -.0340954, .00343211, -.051836, -.0841031, .00705849, -.00482674, .002983, -.0433636, .00219873, .00473428, .00482784, -.00376123}, []float32{.00478981, .00090187, .00415958, -.00941091, .0103533, .0136505, .00479087, .00189497, .00498719, -.00652643, .0104186, -.000888904, -.0185488, -.0095934, -.00104435, .00099552}, []float32{.0691878, -.0388451, .0422552, -.0149259, -.0199213, .0197144, -.000647329, -.00848395, -.0515016, .0331683, -.00901394, -.0208128, .00165176, -.00128988, .0105116, -.00752878}, []float32{-.0160636, -.0178028, .00382997, .00592634, -.0523715, -.0511335, -.0142986, -.0108377, -.0542555, -.0406674, -.0194756, -.00919682, -.0267121, -.0156801, -.00880336, -.0170572}, []float32{-.0149923, -.0355112, .0335409, -.01983, -.00194928, .0358291, -.0246717, .0288183, .0124898, -.0101894, -.00517666, -.0072511, .00544635, -.0166165, .0187441, -.0101279}, []float32{.228469, .360948, -.00565601, -.32472, -.185114, -.299692, -.0579058, .254233, .323759, .497197, .0423255, -.422575, -.0153701, -.0107233, -.00123003, .0130257}, []float32{.0502219, -.115262, -.0485754, .231212, -.196154, .402133, .158026, -.725658, -.0906015, .189154, .0650267, -.359064, -.016908, .0262494, .0177487, -.0734236}, []float32{-.00759923, .00749224, .012461, -.00749459, -.0185459, -.0176667, -.0214795, .00114631, -.0833247, -.0119776, -.0829711, -.0152775, .0211464, -.0145615, -.00589642, -.00101677}, []float32{.0467345, .032621, .00884799, -.00780418, .00842671, -.00814794, .00547146, -.00470798, .0352745, .0361439, -.0195941, -.0123357, .0849945, .0598071, -.0174806, -.0100993}, []float32{-1.40837, -1.21203, -.0780484, .165844, .7015, .592322, .0347776, -.0900774, -2.75368, -2.34715, -.14693, .327309, -2.18356, -1.86056, -.103959, .25985}, []float32{-.00829971, .00994458, -.0199603, .0196087, -.0321117, .0210778, -.0273654, .0783879, -.0425721, .0268035, -.029388, .0461172, -.0115811, -.0269709, .0276197, .0187884}, []float32{-.00577349, -.00212595, .00747551, -.00171195, .0129618, .0214878, -.0114735, .01276, -.018235, -.038897, .013388, -.00764937, .00850067, .0223897, -.0166536, .01736}, []float32{.0324216, -.120026, .142428, -.13805, -.0016382, -.0577591, .0726023, -.0792544, -.0387857, .0582663, -.0795713, .0614716, .0394162, -.0597752, .0763779, -.0678393}, []float32{.00480539, .0104842, .00635447, .00164139, .00721318, -.0124767, -.00235888, -.00605032, -3.78342e-05, .0327839, -.00197258, .0160999, .00131588, .0162206, .00412453, .0150975}}
va4Array = [][]float32{[]float32{4, 1, -4, -1, -7, 2, -5, -7, -1, -3, 5, -7, -7, 8, 8, -3}, []float32{7, -9, -2, -2, 5, 4, 5, -1, -1, 7, 3, 1, -6, 7, 0, -5}, []float32{8, -9, 0, -5, -5, 0, -2, 0, -9, 9, 0, -7, -2, -8, -8, -4}, []float32{8, 3, -8, -2, 3, -5, -7, 7, -6, -4, 8, 4, -9, -3, 9, 1}, []float32{-3, 7, 3, 4, 2, 9, -8, 5, 0, 7, -6, -9, -2, 7, -5, 2}, []float32{6, -4, 1, -6, -7, -3, 6, -6, -2, 2, 4, -2, -6, 6, -6, 9}, []float32{-3, 0, 7, -9, -6, 6, 7, 2, 3, -1, -4, -9, 9, 4, 8, -7}, []float32{9, 5, 3, 3, 0, 9, 1, -8, -9, -2, 4, -9, 4, 0, 9, 3}, []float32{7, -7, 4, -4, 1, 1, -3, -5, -4, 2, -9, -4, -9, -6, -7, -2}, []float32{-5, 8, -7, 9, -1, 0, 9, -4, 1, -8, 7, 3, 0, -1, -6, 6}, []float32{-7, 9, 0, -7, -3, 3, 2, -2, 8, -4, 9, -4, -8, 9, -2, 4}, []float32{4, 3, 0, 6, 4, 1, 9, -7, 8, 7, 4, 8, -4, 7, -3, 2}, []float32{-5, -2, 0, 6, -2, 3, -5, -9, 6, 7, 6, 0, 1, -1, 6, 1}, []float32{-6, -4, -2, 7, -6, -9, 9, 4, 5, 8, -8, -1, 8, -8, -4, 2}, []float32{-3, 7, 6, 2, -4, 7, -8, -9, -5, 3, -7, -8, 8, -2, 8, 2}, []float32{-1, -2, -4, 5, -2, -4, 1, 9, -1, 7, 2, -1, -1, 4, 1, 8}, []float32{5, 4, 0, -4, 9, -1, 2, 2, -1, 3, -1, -8, 8, 7, 3, 5}, []float32{-3, 3, -3, 1, -1, -3, -9, -7, 0, 6, -5, -7, 1, 9, 4, -4}, []float32{-4, -3, -9, 6, -1, -4, -8, 3, -3, -7, -8, 4, -6, -5, -2, 7}, []float32{-8, -4, -6, -6, -7, -9, 7, -7, 1, -9, -8, 6, 3, 4, 8, 6}, []float32{1, 7, 2, 6, -1, -9, -5, -5, -5, 1, -3, 4, 1, -6, -4, -3}, []float32{-2, -2, -9, -5, -8, 2, 5, -9, -4, 9, 1, -4, -4, -3, 5, -1}, []float32{0, -5, 0, 5, 2, -3, -8, 8, 7, -1, -7, 6, 3, 0, 3, 1}, []float32{0, -4, -5, -9, 6, -1, 1, 0, -5, 0, 1, -5, -1, 3, 8, -1}, []float32{3, 1, 0, -1, -4, 7, 0, -4, 2, 0, 1, 2, -9, -2, 2, 4}, []float32{2, 9, 4, -8, 9, 6, 6, 8, -9, 1, 5, -9, -9, 3, 5, 8}, []float32{6, 2, -1, 1, -7, 3, -9, -4, 1, 3, -8, 7, 1, 8, -5, -2}, []float32{3, 3, -5, 6, 6, 7, 2, -5, 7, 0, 6, -7, 2, -4, 5, -7}, []float32{8, 2, 5, 0, -6, 2, -4, -9, 1, 2, -7, 3, 1, -1, 3, -2}, []float32{-8, 2, 8, -9, 0, -6, -2, -9, 7, -1, 1, 8, -7, -2, 9, 2}}
v04Array = [][]float32{[]float32{-7, 0, 9, 6}, []float32{-1, -1, -5, -1}, []float32{-5, -5, 3, -6}, []float32{0, -4, 9, -8}, []float32{-1, 3, -7, -2}, []float32{-5, 5, 2, -4}, []float32{1, 9, -4, 5}, []float32{4, 5, -7, 3}, []float32{4, 6, -4, 6}, []float32{-2, -6, 6, 5}, []float32{-1, 1, 2, 8}, []float32{-1, -9, 5, -8}, []float32{-6, 7, -9, -7}, []float32{8, -9, 0, -5}, []float32{3, 3, -3, -8}, []float32{-9, -8, -4, -3}, []float32{8, -5, -5, 5}, []float32{1, -1, 3, -4}, []float32{1, -6, 9, -6}, []float32{3, 4, 5, -7}, []float32{-4, 7, 0, 3}, []float32{1, -1, -9, 7}, []float32{0, 6, -3, 8}, []float32{2, 8, -9, -4}, []float32{2, -1, -6, 4}, []float32{-1, -6, 3, -5}, []float32{-3, -4, -8, -4}, []float32{-6, -2, 2, -4}, []float32{-3, -2, -6, 3}, []float32{-6, -1, -7, 8}}
v14Array = [][]float32{[]float32{-79, 14, 121, -74}, []float32{-1, -37, -18, 3}, []float32{-30, 120, 58, 28}, []float32{6, 8, 28, 0}, []float32{13, -43, 25, 70}, []float32{-45, -15, 57, -40}, []float32{-24, 78, 126, 10}, []float32{111, 79, 16, 44}, []float32{-4, -66, -8, -42}, []float32{22, -69, -28, 54}, []float32{-44, 58, 4, 29}, []float32{32, -33, -37, 81}, []float32{-45, -23, -131, -106}, []float32{-34, 89, -77, 10}, []float32{-70, 49, -49, -13}, []float32{32, 10, 17, -137}, []float32{40, 57, 10, 23}, []float32{-6, -12, -25, 3}, []float32{11, -12, -21, -18}, []float32{-68, -121, -86, -58}, []float32{-8, -109, -55, -68}, []float32{14, -106, 12, 33}, []float32{15, -15, -3, 38}, []float32{97, -28, -43, 31}, []float32{-38, -13, 2, 6}, []float32{-38, -57, -50, -107}, []float32{-2, -74, 123, -35}, []float32{-24, -16, 18, -12}, []float32{-15, -25, 44, -6}, []float32{-57, -15, 19, 23}}
setup4 = true
}
func makeA() Matrix4 {
m, _ := NewMatrix4V([]float32{1, 2, 3, 4,
5, 6, -7, 8,
9, 10, 11, 12,
13, 14, 15, -16},
true)
return m
}
func makeB() Matrix4 {
m, _ := NewMatrix4V([]float32{1, 0, 0, 0,
0, 0, 1, 0,
0, 1, 0, 0,
0, 0, 0, 1},
true)
return m
}
func makeC() Matrix4 {
m, _ := NewMatrix4V([]float32{0, 0, 1, 0,
1, 0, 0, 0,
0, 0, 0, 1,
0, 1, 0, 0},
true)
return m
}
func makeD() Matrix4 {
m, _ := NewMatrix4V([]float32{1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1},
true)
return m
}
func Test_4Approximates1(t *testing.T) {
A := makeA()
B := makeB()
C := makeC()
if A.ApproxEquals(B, ε4d) {
t.Fail()
}
if A.ApproxEquals(C, ε4d) {
t.Fail()
}
if C.ApproxEquals(B, ε4d) {
t.Fail()
}
}
func Test_4Approximates2(t *testing.T) {
B := makeB()
b := makeB().MulS(1.0 + ε4d/2)
C := makeC()
c := makeC().MulS(1.0 + ε4d/2)
D := makeD()
d := makeD().MulS(1.0 + ε4d/2)
if !B.ApproxEquals(b, ε4d) {
fmt.Println(B)
fmt.Println(b)
t.Fail()
}
if !C.ApproxEquals(c, ε4d) {
fmt.Println(C)
fmt.Println(c)
t.Fail()
}
if !D.ApproxEquals(d, ε4d) {
fmt.Println(D)
fmt.Println(d)
t.Fail()
}
}
func Test_4Transpose1(t *testing.T) {
// Testing Transpose(), not ITranspose()
A := makeA()
a := A.Transpose()
B := makeB()
b := makeB().Transpose()
C := makeC()
c := makeC().Transpose()
D := makeD()
d := makeD().Transpose()
if A.Equal(a) {
fmt.Println("A", A)
fmt.Println("a", a)
t.Fail()
}
if !B.Equal(b) {
fmt.Println("B", B)
fmt.Println("b", b)
t.Fail()
}
if C.Equal(c) {
fmt.Println("C", C)
fmt.Println("c", c)
t.Fail()
}
if !D.Equal(d) {
fmt.Println("D", D)
fmt.Println("d", d)
t.Fail()
}
}
func Test_4Transpose2(t *testing.T) {
// Testing ITranspose(), not Transpose()
// ITranspose() should alter the original too
//if !setup3 {
// Setup3()
//}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
a := A.ITranspose()
if !A.Equal(a) {
fmt.Println("ITranspose() should alter the original")
fmt.Println("A", A)
fmt.Println("a", a)
t.Fail()
}
}
}
func Test_4Mutiply0(t *testing.T) {
I := NewMatrix4().Identity()
A := makeA()
ai := makeA().MustInverse()
da := A.Det()
B := makeB()
bi := makeB().MustInverse()
C := makeC()
ci := makeC().MustInverse()
a := A.Mul(ai)
if !I.ApproxEquals(a, ε4d) {
fmt.Println("a=", A)
fmt.Println("det(a)=", da)
fmt.Println("ai=", A)
fmt.Println("I=", a)
t.Fail()
}
b := B.Mul(bi)
if !I.ApproxEquals(b, ε4d) {
fmt.Println("b", b)
fmt.Println("I", I)
t.Fail()
}
c := C.Mul(ci)
if !I.ApproxEquals(c, ε4d) {
fmt.Println("c", c)
fmt.Println("i", I)
t.Fail()
}
}
func Test_4Mutiply2(t *testing.T) {
A := makeA()
da := A.Det()
B := makeB()
bi := makeB().MustInverse()
C := makeC()
ci := makeC().MustInverse()
a := A.Mul(B).Mul(C).Mul(ci).Mul(bi)
if !A.ApproxEquals(a, ε4d) {
fmt.Println("a=", A)
fmt.Println("det(a)=", da)
fmt.Println("ai=", A)
fmt.Println("I=", a)
t.Fail()
}
}
func Test_4Copy1(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
//fmt.Println("A",A)
a := A
//fmt.Println("a",a)
for j := 0; j < 16; j++ {
a[j] = a[j] * 0.001
}
if A.ApproxEquals(a, ε4d) {
fmt.Println("failed to copy 'A'. changes to the copy modifies original. (ApproxEquals)")
fmt.Println("A =", A)
fmt.Println("copy=", a)
fmt.Println()
t.Fail()
}
// test NotEqual while we're at it
/*if !a.NotEqual(A) {
fmt.Println("failed to copy 'A'. changes to the copy modifies original. (!NotEqual())")
fmt.Println("A =", A)
fmt.Println("copy=", a)
fmt.Println()
t.Fail()
}*/
// test NotEqual while we're at it
if a.Equal(A) {
fmt.Println("failed to copy 'A'. changes to the copy modifies original. (Equal())")
fmt.Println("A =", A)
fmt.Println("copy=", a)
fmt.Println()
t.Fail()
}
}
}
func Test_4Inv1(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
B, _ := NewMatrix4V(b4Array[i], true)
AI, _ := NewMatrix4V(aI4Array[i], true)
BI, _ := NewMatrix4V(bI4Array[i], true)
ai := A.MustInverse()
bi := B.MustInverse()
if !AI.ApproxEquals(ai, ε4d) {
fmt.Println("failed to inverse 'A'. Expected result as 'AI', got 'ai'")
fmt.Println("A =", A)
fmt.Println("AI =", AI)
fmt.Println("ai =", ai)
fmt.Println()
t.Fail()
}
if !BI.ApproxEquals(bi, ε4d) {
fmt.Println("failed to inverse 'B'. Expected result as 'BI', got 'bi'")
fmt.Println("B =", B)
fmt.Println("BI =", BI)
fmt.Println("bi =", bi)
fmt.Println()
t.Fail()
}
}
}
func Test_4Transpose3(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
att, _ := NewMatrix4V(A, false)
att = att.ITranspose().Transpose()
if !att.Equal(A) {
fmt.Println("failed to double transpose 'A'. Expected result as 'A', got 'att'")
fmt.Println("A =", A)
fmt.Println("att=", att)
fmt.Println()
t.Fail()
}
// test NotEqual while we're at it
if !att.Equal(A) {
fmt.Println("failed to double transpose 'A'. Expected result as 'A', got 'att'")
fmt.Println("A =", A)
fmt.Println("att=", att)
fmt.Println()
t.Fail()
}
}
}
func Test_4Transpose4(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
//fmt.Println("A",strings.Replace(A.String(),"],[","],\n[",-1))
AT, _ := NewMatrix4V(aT4Array[i], true)
at := A.ITranspose()
//fmt.Println("A",strings.Replace(A.String(),"],[","],\n[",-1))
//fmt.Println("at", strings.Replace(at.String(),"],[","],\n[",-1))
if !at.Equal(AT) {
fmt.Println("failed to transpose 'A'. Expected result as 'AT', got 'at' (!Equal)")
fmt.Println("A =", A)
fmt.Println("AT =", AT)
fmt.Println("at =", at)
fmt.Println()
t.Fail()
}
// test NotEqual while we're at it
if !at.Equal(AT) {
fmt.Println("failed to transpose 'A'. Expected result as 'AT', got 'at' (NotEqual)")
fmt.Println("A =", A)
fmt.Println("AT =", AT)
fmt.Println("at =", at)
fmt.Println()
t.Fail()
}
}
}
func Test_4Transpose5(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
at := A.ITranspose()
B, _ := NewMatrix4V(b4Array[i], true)
bt := B.Transpose()
btat := bt.Mul(at)
P, _ := NewMatrix4V(p4Array[i], true)
pt := P.ITranspose()
if !pt.ApproxEquals(btat, ε4d) {
fmt.Println("failed to transpose and multiply 'Bt*At'. Expected result as 'Pt', got 'btat'")
fmt.Println("A\t=", A)
fmt.Println("B\t=", B)
fmt.Println("Pt\t=", pt)
fmt.Println("btat\t=", btat)
fmt.Println()
t.Fail()
}
}
}
func Test_4Mutiply1(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
B, _ := NewMatrix4V(b4Array[i], true)
P, _ := NewMatrix4V(p4Array[i], true)
p := A.Mul(B)
if !P.ApproxEquals(p, ε4d) {
fmt.Println("failed to multiply 'A*B'. Expected result as 'P', got 'p'")
fmt.Println("A =", A)
fmt.Println("B =", B)
fmt.Println("P =", P)
fmt.Println("p =", p)
fmt.Println()
t.Fail()
}
}
}
func Test_4Mutiply3(t *testing.T) {
if !setup4 {
Setup4()
}
I := NewMatrix4().Identity()
for i := 0; i < len(a4Array); i++ {
A, _ := NewMatrix4V(a4Array[i], true)
B, _ := NewMatrix4V(b4Array[i], true)
at := A.ITranspose()
ati := at.MustInverse()
bt := B.ITranspose()
bti := bt.MustInverse()
ai := A.MustInverse()
bi := B.MustInverse()
p := A.Mul(B).Mul(at).Mul(bt).Mul(bti).Mul(ati).Mul(bi).Mul(ai)
// Allow the ε to be larger, we're multiplying a long chain of matrixes
if !I.ApproxEquals(p, ε4d*100) {
fmt.Println("failed to multiply 'A*B*At*Bt*Inv(Bt)*Inv(At)*Inv(B)*Inv(A)'. Expected result as 'I', got 'p'")
fmt.Println("A =", A)
fmt.Println("B =", B)
fmt.Println("I =", I)
fmt.Println("p =", p)
fmt.Println()
t.Fail()
}
}
}
func Test_4Quat1(t *testing.T) {
m := NewQuaternion(.0, 0, 0, 0)
p, _ := NewQuaternion(.0, 1, -1, 1).Normalize(ε4d)
q, _ := NewQuaternion(math.Pi/2., -1., 1., -1.).Normalize(ε4d)
if p.ApproxEquals(q, ε4d) {
fmt.Println("P!=Q test failed")
fmt.Println("P =", p)
fmt.Println("Q =", q)
fmt.Println()
t.Fail()
}
m.Slerp(.0, p, q)
if !m.ApproxEquals(p, ε4d) {
fmt.Println("Slerp(t=0.0) should give us a vector like p, instead we got m")
fmt.Println("p =", p)
fmt.Println("m =", m)
t.Fail()
}
m.Slerp(1., p, q)
if !m.ApproxEquals(q, ε4d) {
fmt.Println("Slerp(t=1.0) should give us a vector like p, instead we got m")
fmt.Println("p =", p)
fmt.Println("m =", m)
t.Fail()
}
/*
fmt.Println("p =", p)
fmt.Println("q =", q)
for i:=0.;i<=1.0;i+=0.1 {
m.Slerp(float32(i),p,q)
fmt.Println("m =", m)
}
*/
}
func Test_4Quat2(t *testing.T) {
p := NewQuaternion(.0, 1, 0, 0)
q := NewQuaternionCopy(p)
q[1] = p[1] * ε4d * 2.
if p.Equal(q) {
fmt.Println("P!=Q test failed (Equal)")
fmt.Println("P =", p)
fmt.Println("Q =", q)
fmt.Println()
t.Fail()
}
if !p.NotEqual(q) {
fmt.Println("P!=Q test failed (!NotEqual)")
fmt.Println("P =", p)
fmt.Println("Q =", q)
fmt.Println()
t.Fail()
}
if p.ApproxEquals(q, ε4d) {
fmt.Println("P!=Q test failed (ApproxEquals)")
fmt.Println("P =", p)
fmt.Println("Q =", q)
fmt.Println()
t.Fail()
}
}
func Test_4Quat3(t *testing.T) {
P1 := NewQuaternion(1, 2, 3, 4)
P1N := NewQuaternion(0.182574, 0.365148, 0.547723, 0.730297)
p1n, _ := P1.Copy().Normalize(internalε)
if !p1n.ApproxEquals(P1N, ε4d) {
fmt.Println("Failed to normalize 'P1'. Expected results as 'P1N' got 'p1'")
fmt.Println("P1 =", P1)
fmt.Println("P1N =", P1N)
fmt.Println("p1n =", p1n)
fmt.Println()
t.Fail()
}
P2 := NewQuaternion(4, 3, 2, -1)
P2N := NewQuaternion(0.730297, 0.547723, 0.365148, -0.182574)
p2n, _ := P2.Copy().Normalize(internalε)
if !p2n.ApproxEquals(P2N, ε4d) {
fmt.Println("Failed to normalize 'P2'. Expected results as 'P2N' got 'p2'")
fmt.Println("P2 =", P2)
fmt.Println("P2N =", P2N)
fmt.Println("p2n =", p2n)
fmt.Println()
t.Fail()
}
D := float32(0.4000007)
d := P1N.Dot(P2N)
if !ApproxEquals(d, D, ε4d) {
fmt.Println("Failed to calculate Q1.Dot(Q2). Expected results as 'D' got 'd'")
fmt.Println("Q1 =", P1N)
fmt.Println("Q2 =", P2N)
fmt.Println("D =", D)
fmt.Println("d =", d)
fmt.Println()
t.Fail()
}
mdata := []float32{-0.666667, 0.133333, 0.733333, 0.000000,
0.666667, -0.333333, 0.666667, 0.000000,
0.333333, 0.933333, 0.133333, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000}[:]
M, _ := NewMatrix4V(mdata, true)
m := p1n.RotationMatrix()
if !m.ApproxEquals(M, ε4d) {
fmt.Println("Failed generate rotation matrix. Expected results as 'M' got 'm'")
fmt.Println("M =", M)
fmt.Println("m =", m)
fmt.Println()
t.Fail()
}
v0 := NewVector4(1., 0, 0, 0.)
r1 := v0.Copy().MultiplyM(m)
R1 := NewVector4(-0.666667, 0.133333, 0.733333, 0.000000)
if !r1.ApproxEquals(R1, ε4d) {
fmt.Println("Failed multiply v0*m. Expected results as 'R1' got 'r1'")
fmt.Println("m\t=", m)
fmt.Println("R1\t=", R1)
fmt.Println("r1\t=", r1)
fmt.Println()
t.Fail()
}
//fmt.Println("M =", M)
q := M.Quaternion()
if !q.ApproxEquals(P1N, ε4d) {
fmt.Println("Failed to run Quaternion(). Expected results as 'P1N' got 'q'")
fmt.Println("P1N =", P1N)
fmt.Println("q =", q)
fmt.Println()
t.Fail()
}
}
func Test_4VectorMul_1(t *testing.T) {
if !setup4 {
Setup4()
}
for i := 0; i < len(v04Array); i++ {
V0 := NewVector4V(v04Array[i])
v0 := V0.Add(V0).Add(V0).Sub(V0)
M, _ := NewMatrix4V(va4Array[i], true)
V1 := NewVector4V(v14Array[i])
V1 = V1.Add(V1)
v1 := v0.MultiplyM(M)
if !v1.ApproxEquals(V1, ε3d) {
fmt.Println("failed to multiply 'V0' with 'M', Expected result as 'V1', got 'v1'")
fmt.Println("V0 =", V0)
fmt.Println("M =", M)
fmt.Println("V1 =", V1)
fmt.Println("v1 =", v1)
fmt.Println()
t.Fail()
}
}
}