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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: some of this file.
*
* ***** END GPL LICENSE BLOCK *****
* */
/** \file blender/blenlib/intern/math_vector_inline.c
* \ingroup bli
*/
#ifndef __MATH_VECTOR_INLINE_C__
#define __MATH_VECTOR_INLINE_C__
#include "BLI_math.h"
/********************************** Init *************************************/
MINLINE void zero_v2(float r[2])
{
r[0] = 0.0f;
r[1] = 0.0f;
}
MINLINE void zero_v3(float r[3])
{
r[0] = 0.0f;
r[1] = 0.0f;
r[2] = 0.0f;
}
MINLINE void zero_v4(float r[4])
{
r[0] = 0.0f;
r[1] = 0.0f;
r[2] = 0.0f;
r[3] = 0.0f;
}
MINLINE void copy_v2_v2(float r[2], const float a[2])
{
r[0] = a[0];
r[1] = a[1];
}
MINLINE void copy_v3_v3(float r[3], const float a[3])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
}
MINLINE void copy_v4_v4(float r[4], const float a[4])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
r[3] = a[3];
}
MINLINE void copy_v2_fl(float r[2], float f)
{
r[0] = f;
r[1] = f;
}
MINLINE void copy_v3_fl(float r[3], float f)
{
r[0] = f;
r[1] = f;
r[2] = f;
}
MINLINE void copy_v4_fl(float r[4], float f)
{
r[0] = f;
r[1] = f;
r[2] = f;
r[3] = f;
}
/* short */
MINLINE void copy_v2_v2_char(char r[2], const char a[2])
{
r[0] = a[0];
r[1] = a[1];
}
MINLINE void copy_v3_v3_char(char r[3], const char a[3])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
}
MINLINE void copy_v4_v4_char(char r[4], const char a[4])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
r[3] = a[3];
}
/* short */
MINLINE void zero_v3_int(int r[3])
{
r[0] = 0;
r[1] = 0;
r[2] = 0;
}
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
{
r[0] = a[0];
r[1] = a[1];
}
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
}
MINLINE void copy_v4_v4_short(short r[4], const short a[4])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
r[3] = a[3];
}
/* int */
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
{
r[0] = a[0];
r[1] = a[1];
}
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
}
MINLINE void copy_v4_v4_int(int r[4], const int a[4])
{
r[0] = a[0];
r[1] = a[1];
r[2] = a[2];
r[3] = a[3];
}
/* double -> float */
MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
{
r[0] = (float)a[0];
r[1] = (float)a[1];
}
MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
{
r[0] = (float)a[0];
r[1] = (float)a[1];
r[2] = (float)a[2];
}
MINLINE void copy_v4fl_v4db(float r[4], const double a[4])
{
r[0] = (float)a[0];
r[1] = (float)a[1];
r[2] = (float)a[2];
r[3] = (float)a[3];
}
/* float -> double */
MINLINE void copy_v2db_v2fl(double r[2], const float a[2])
{
r[0] = (double)a[0];
r[1] = (double)a[1];
}
MINLINE void copy_v3db_v3fl(double r[3], const float a[3])
{
r[0] = (double)a[0];
r[1] = (double)a[1];
r[2] = (double)a[2];
}
MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
{
r[0] = (double)a[0];
r[1] = (double)a[1];
r[2] = (double)a[2];
r[3] = (double)a[3];
}
MINLINE void swap_v2_v2(float a[2], float b[2])
{
SWAP(float, a[0], b[0]);
SWAP(float, a[1], b[1]);
}
MINLINE void swap_v3_v3(float a[3], float b[3])
{
SWAP(float, a[0], b[0]);
SWAP(float, a[1], b[1]);
SWAP(float, a[2], b[2]);
}
MINLINE void swap_v4_v4(float a[4], float b[4])
{
SWAP(float, a[0], b[0]);
SWAP(float, a[1], b[1]);
SWAP(float, a[2], b[2]);
SWAP(float, a[3], b[3]);
}
/********************************* Arithmetic ********************************/
MINLINE void add_v2_fl(float r[2], float f)
{
r[0] += f;
r[1] += f;
}
MINLINE void add_v3_fl(float r[3], float f)
{
r[0] += f;
r[1] += f;
r[2] += f;
}
MINLINE void add_v4_fl(float r[4], float f)
{
r[0] += f;
r[1] += f;
r[2] += f;
r[3] += f;
}
MINLINE void add_v2_v2(float r[2], const float a[2])
{
r[0] += a[0];
r[1] += a[1];
}
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
{
r[0] = a[0] + b[0];
r[1] = a[1] + b[1];
}
MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2])
{
r[0] = a[0] + b[0];
r[1] = a[1] + b[1];
}
MINLINE void add_v3_v3(float r[3], const float a[3])
{
r[0] += a[0];
r[1] += a[1];
r[2] += a[2];
}
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
{
r[0] = a[0] + b[0];
r[1] = a[1] + b[1];
r[2] = a[2] + b[2];
}
MINLINE void add_v4_v4(float r[4], const float a[4])
{
r[0] += a[0];
r[1] += a[1];
r[2] += a[2];
r[3] += a[3];
}
MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4])
{
r[0] = a[0] + b[0];
r[1] = a[1] + b[1];
r[2] = a[2] + b[2];
r[3] = a[3] + b[3];
}
MINLINE void sub_v2_v2(float r[2], const float a[2])
{
r[0] -= a[0];
r[1] -= a[1];
}
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
{
r[0] = a[0] - b[0];
r[1] = a[1] - b[1];
}
MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2])
{
r[0] = a[0] - b[0];
r[1] = a[1] - b[1];
}
MINLINE void sub_v3_v3(float r[3], const float a[3])
{
r[0] -= a[0];
r[1] -= a[1];
r[2] -= a[2];
}
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
{
r[0] = a[0] - b[0];
r[1] = a[1] - b[1];
r[2] = a[2] - b[2];
}
MINLINE void sub_v4_v4(float r[4], const float a[4])
{
r[0] -= a[0];
r[1] -= a[1];
r[2] -= a[2];
r[3] -= a[3];
}
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
{
r[0] = a[0] - b[0];
r[1] = a[1] - b[1];
r[2] = a[2] - b[2];
r[3] = a[3] - b[3];
}
MINLINE void mul_v2_fl(float r[2], float f)
{
r[0] *= f;
r[1] *= f;
}
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
{
r[0] = a[0] * f;
r[1] = a[1] * f;
}
MINLINE void mul_v3_fl(float r[3], float f)
{
r[0] *= f;
r[1] *= f;
r[2] *= f;
}
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
{
r[0] = a[0] * f;
r[1] = a[1] * f;
r[2] = a[2] * f;
}
MINLINE void mul_v2_v2(float r[2], const float a[2])
{
r[0] *= a[0];
r[1] *= a[1];
}
MINLINE void mul_v3_v3(float r[3], const float a[3])
{
r[0] *= a[0];
r[1] *= a[1];
r[2] *= a[2];
}
MINLINE void mul_v4_fl(float r[4], float f)
{
r[0] *= f;
r[1] *= f;
r[2] *= f;
r[3] *= f;
}
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
{
r[0] = a[0] * f;
r[1] = a[1] * f;
r[2] = a[2] * f;
r[3] = a[3] * f;
}
/* note: could add a matrix inline */
MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3])
{
return (mat[0][3] * co[0]) +
(mat[1][3] * co[1]) +
(mat[2][3] * co[2]) + mat[3][3];
}
/**
* Has the effect of mul_m3_v3(), on a single axis.
*/
MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3])
{
return M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
}
MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3])
{
return M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
}
MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3])
{
return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
{
r[0] += a[0] * f;
r[1] += a[1] * f;
}
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
{
r[0] += a[0] * f;
r[1] += a[1] * f;
r[2] += a[2] * f;
}
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
{
r[0] += a[0] * b[0];
r[1] += a[1] * b[1];
r[2] += a[2] * b[2];
}
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
{
r[0] = a[0] + b[0] * f;
r[1] = a[1] + b[1] * f;
}
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
{
r[0] = a[0] + b[0] * f;
r[1] = a[1] + b[1] * f;
r[2] = a[2] + b[2] * f;
}
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
{
r[0] = a[0] + b[0] * c[0];
r[1] = a[1] + b[1] * c[1];
r[2] = a[2] + b[2] * c[2];
}
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
{
r[0] += a[0] * f;
r[1] += a[1] * f;
r[2] += a[2] * f;
r[3] += a[3] * f;
}
MINLINE void madd_v4_v4v4(float r[4], const float a[4], const float b[4])
{
r[0] += a[0] * b[0];
r[1] += a[1] * b[1];
r[2] += a[2] * b[2];
r[3] += a[3] * b[3];
}
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
{
r[0] = v1[0] * v2[0];
r[1] = v1[1] * v2[1];
r[2] = v1[2] * v2[2];
}
MINLINE void negate_v2(float r[2])
{
r[0] = -r[0];
r[1] = -r[1];
}
MINLINE void negate_v2_v2(float r[2], const float a[2])
{
r[0] = -a[0];
r[1] = -a[1];
}
MINLINE void negate_v3(float r[3])
{
r[0] = -r[0];
r[1] = -r[1];
r[2] = -r[2];
}
MINLINE void negate_v3_v3(float r[3], const float a[3])
{
r[0] = -a[0];
r[1] = -a[1];
r[2] = -a[2];
}
MINLINE void negate_v4(float r[4])
{
r[0] = -r[0];
r[1] = -r[1];
r[2] = -r[2];
r[3] = -r[3];
}
MINLINE void negate_v4_v4(float r[4], const float a[4])
{
r[0] = -a[0];
r[1] = -a[1];
r[2] = -a[2];
r[3] = -a[3];
}
/* could add more... */
MINLINE void negate_v3_short(short r[3])
{
r[0] = -r[0];
r[1] = -r[1];
r[2] = -r[2];
}
MINLINE float dot_v2v2(const float a[2], const float b[2])
{
return a[0] * b[0] + a[1] * b[1];
}
MINLINE float dot_v3v3(const float a[3], const float b[3])
{
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
MINLINE float cross_v2v2(const float a[2], const float b[2])
{
return a[0] * b[1] - a[1] * b[0];
}
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
{
BLI_assert(r != a && r != b);
r[0] = a[1] * b[2] - a[2] * b[1];
r[1] = a[2] * b[0] - a[0] * b[2];
r[2] = a[0] * b[1] - a[1] * b[0];
}
/* Newell's Method */
/* excuse this fairly specific function,
* its used for polygon normals all over the place
* could use a better name */
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
{
n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
}
MINLINE void star_m3_v3(float rmat[3][3], float a[3])
{
rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
rmat[0][1] = -a[2];
rmat[0][2] = a[1];
rmat[1][0] = a[2];
rmat[1][2] = -a[0];
rmat[2][0] = -a[1];
rmat[2][1] = a[0];
}
/*********************************** Length **********************************/
MINLINE float len_squared_v2(const float v[2])
{
return v[0] * v[0] + v[1] * v[1];
}
MINLINE float len_squared_v3(const float v[3])
{
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
}
MINLINE float len_manhattan_v2(const float v[2])
{
return fabsf(v[0]) + fabsf(v[1]);
}
MINLINE int len_manhattan_v2_int(const int v[2])
{
return ABS(v[0]) + ABS(v[1]);
}
MINLINE float len_manhattan_v3(const float v[3])
{
return fabsf(v[0]) + fabsf(v[1]) + fabsf(v[2]);
}
MINLINE float len_v2(const float v[2])
{
return sqrtf(v[0] * v[0] + v[1] * v[1]);
}
MINLINE float len_v2v2(const float v1[2], const float v2[2])
{
float x, y;
x = v1[0] - v2[0];
y = v1[1] - v2[1];
return sqrtf(x * x + y * y);
}
MINLINE float len_v3(const float a[3])
{
return sqrtf(dot_v3v3(a, a));
}
MINLINE float len_squared_v2v2(const float a[2], const float b[2])
{
float d[2];
sub_v2_v2v2(d, b, a);
return dot_v2v2(d, d);
}
MINLINE float len_squared_v3v3(const float a[3], const float b[3])
{
float d[3];
sub_v3_v3v3(d, b, a);
return dot_v3v3(d, d);
}
MINLINE float len_manhattan_v2v2(const float a[2], const float b[2])
{
float d[2];
sub_v2_v2v2(d, b, a);
return len_manhattan_v2(d);
}
MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2])
{
int d[2];
sub_v2_v2v2_int(d, b, a);
return len_manhattan_v2_int(d);
}
MINLINE float len_manhattan_v3v3(const float a[3], const float b[3])
{
float d[3];
sub_v3_v3v3(d, b, a);
return len_manhattan_v3(d);
}
MINLINE float len_v3v3(const float a[3], const float b[3])
{
float d[3];
sub_v3_v3v3(d, b, a);
return len_v3(d);
}
MINLINE float normalize_v2_v2(float r[2], const float a[2])
{
float d = dot_v2v2(a, a);
if (d > 1.0e-35f) {
d = sqrtf(d);
mul_v2_v2fl(r, a, 1.0f / d);
}
else {
zero_v2(r);
d = 0.0f;
}
return d;
}
MINLINE float normalize_v2(float n[2])
{
return normalize_v2_v2(n, n);
}
MINLINE float normalize_v3_v3(float r[3], const float a[3])
{
float d = dot_v3v3(a, a);
/* a larger value causes normalize errors in a
* scaled down models with camera extreme close */
if (d > 1.0e-35f) {
d = sqrtf(d);
mul_v3_v3fl(r, a, 1.0f / d);
}
else {
zero_v3(r);
d = 0.0f;
}
return d;
}
MINLINE double normalize_v3_d(double n[3])
{
double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
/* a larger value causes normalize errors in a
* scaled down models with camera extreme close */
if (d > 1.0e-35) {
double mul;
d = sqrt(d);
mul = 1.0 / d;
n[0] *= mul;
n[1] *= mul;
n[2] *= mul;
}
else {
n[0] = n[1] = n[2] = 0;
d = 0.0;
}
return d;
}
MINLINE float normalize_v3(float n[3])
{
return normalize_v3_v3(n, n);
}
MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
{
out[0] = in[0] * (1.0f / 32767.0f);
out[1] = in[1] * (1.0f / 32767.0f);
out[2] = in[2] * (1.0f / 32767.0f);
}
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
{
out[0] = (short) (in[0] * 32767.0f);
out[1] = (short) (in[1] * 32767.0f);
out[2] = (short) (in[2] * 32767.0f);
}
/********************************* Comparison ********************************/
MINLINE bool is_zero_v2(const float v[2])
{
return (v[0] == 0 && v[1] == 0);
}
MINLINE bool is_zero_v3(const float v[3])
{
return (v[0] == 0 && v[1] == 0 && v[2] == 0);
}
MINLINE bool is_zero_v4(const float v[4])
{
return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
}
MINLINE bool is_finite_v2(const float v[2])
{
return (finite(v[0]) && finite(v[1]));
}
MINLINE bool is_finite_v3(const float v[3])
{
return (finite(v[0]) && finite(v[1]) && finite(v[2]));
}
MINLINE bool is_finite_v4(const float v[4])
{
return (finite(v[0]) && finite(v[1]) && finite(v[2]) && finite(v[3]));
}
MINLINE bool is_one_v3(const float v[3])
{
return (v[0] == 1 && v[1] == 1 && v[2] == 1);
}
MINLINE bool equals_v2v2(const float v1[2], const float v2[2])
{
return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
}
MINLINE bool equals_v3v3(const float v1[3], const float v2[3])
{
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
}
MINLINE bool equals_v4v4(const float v1[4], const float v2[4])
{
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
}
MINLINE bool compare_v2v2(const float v1[2], const float v2[2], const float limit)
{
if (fabsf(v1[0] - v2[0]) < limit)
if (fabsf(v1[1] - v2[1]) < limit)
return true;
return false;
}
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], const float limit)
{
if (fabsf(v1[0] - v2[0]) < limit)
if (fabsf(v1[1] - v2[1]) < limit)
if (fabsf(v1[2] - v2[2]) < limit)
return true;
return false;
}
MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
{
float x, y, z;
x = v1[0] - v2[0];
y = v1[1] - v2[1];
z = v1[2] - v2[2];
return ((x * x + y * y + z * z) < (limit * limit));
}
MINLINE bool compare_v4v4(const float v1[4], const float v2[4], const float limit)
{
if (fabsf(v1[0] - v2[0]) < limit)
if (fabsf(v1[1] - v2[1]) < limit)
if (fabsf(v1[2] - v2[2]) < limit)
if (fabsf(v1[3] - v2[3]) < limit)
return true;
return false;
}
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
{
return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
((l2[0] - pt[0]) * (l1[1] - pt[1])));
}
#endif /* __MATH_VECTOR_INLINE_C__ */
|