~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenlib/intern/math_vector_inline.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: math_vector_inline.c 28651 2010-05-07 15:18:04Z blendix $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
19
17
 *
20
18
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
19
 * All rights reserved.
22
 
 
 
20
 *
23
21
 * The Original Code is: some of this file.
24
22
 *
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 * */
27
25
 
 
26
/** \file blender/blenlib/intern/math_vector_inline.c
 
27
 *  \ingroup bli
 
28
 */
 
29
 
 
30
 
28
31
#include "BLI_math.h"
29
32
 
30
 
#ifndef BLI_MATH_VECTOR_INLINE
31
 
#define BLI_MATH_VECTOR_INLINE
 
33
#ifndef __MATH_VECTOR_INLINE_C__
 
34
#define __MATH_VECTOR_INLINE_C__
32
35
 
33
36
/********************************** Init *************************************/
34
37
 
35
38
MINLINE void zero_v2(float r[2])
36
39
{
37
 
        r[0]= 0.0f;
38
 
        r[1]= 0.0f;
 
40
        r[0] = 0.0f;
 
41
        r[1] = 0.0f;
39
42
}
40
43
 
41
44
MINLINE void zero_v3(float r[3])
42
45
{
43
 
        r[0]= 0.0f;
44
 
        r[1]= 0.0f;
45
 
        r[2]= 0.0f;
 
46
        r[0] = 0.0f;
 
47
        r[1] = 0.0f;
 
48
        r[2] = 0.0f;
46
49
}
47
50
 
48
51
MINLINE void zero_v4(float r[4])
49
52
{
50
 
        r[0]= 0.0f;
51
 
        r[1]= 0.0f;
52
 
        r[2]= 0.0f;
53
 
        r[3]= 0.0f;
 
53
        r[0] = 0.0f;
 
54
        r[1] = 0.0f;
 
55
        r[2] = 0.0f;
 
56
        r[3] = 0.0f;
54
57
}
55
58
 
56
59
MINLINE void copy_v2_v2(float r[2], const float a[2])
57
60
{
58
 
        r[0]= a[0];
59
 
        r[1]= a[1];
 
61
        r[0] = a[0];
 
62
        r[1] = a[1];
60
63
}
61
64
 
62
65
MINLINE void copy_v3_v3(float r[3], const float a[3])
63
66
{
64
 
        r[0]= a[0];
65
 
        r[1]= a[1];
66
 
        r[2]= a[2];
 
67
        r[0] = a[0];
 
68
        r[1] = a[1];
 
69
        r[2] = a[2];
67
70
}
68
71
 
69
72
MINLINE void copy_v4_v4(float r[4], const float a[4])
70
73
{
71
 
        r[0]= a[0];
72
 
        r[1]= a[1];
73
 
        r[2]= a[2];
74
 
        r[3]= a[3];
 
74
        r[0] = a[0];
 
75
        r[1] = a[1];
 
76
        r[2] = a[2];
 
77
        r[3] = a[3];
 
78
}
 
79
 
 
80
MINLINE void copy_v2_fl(float r[2], float f)
 
81
{
 
82
        r[0] = f;
 
83
        r[1] = f;
 
84
}
 
85
 
 
86
MINLINE void copy_v3_fl(float r[3], float f)
 
87
{
 
88
        r[0] = f;
 
89
        r[1] = f;
 
90
        r[2] = f;
 
91
}
 
92
 
 
93
MINLINE void copy_v4_fl(float r[4], float f)
 
94
{
 
95
        r[0] = f;
 
96
        r[1] = f;
 
97
        r[2] = f;
 
98
        r[3] = f;
 
99
}
 
100
 
 
101
/* short */
 
102
MINLINE void copy_v2_v2_char(char r[2], const char a[2])
 
103
{
 
104
        r[0] = a[0];
 
105
        r[1] = a[1];
 
106
}
 
107
 
 
108
MINLINE void copy_v3_v3_char(char r[3], const char a[3])
 
109
{
 
110
        r[0] = a[0];
 
111
        r[1] = a[1];
 
112
        r[2] = a[2];
 
113
}
 
114
 
 
115
MINLINE void copy_v4_v4_char(char r[4], const char a[4])
 
116
{
 
117
        r[0] = a[0];
 
118
        r[1] = a[1];
 
119
        r[2] = a[2];
 
120
        r[3] = a[3];
 
121
}
 
122
 
 
123
/* short */
 
124
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
 
125
{
 
126
        r[0] = a[0];
 
127
        r[1] = a[1];
 
128
}
 
129
 
 
130
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
 
131
{
 
132
        r[0] = a[0];
 
133
        r[1] = a[1];
 
134
        r[2] = a[2];
 
135
}
 
136
 
 
137
MINLINE void copy_v4_v4_short(short r[4], const short a[4])
 
138
{
 
139
        r[0] = a[0];
 
140
        r[1] = a[1];
 
141
        r[2] = a[2];
 
142
        r[3] = a[3];
 
143
}
 
144
 
 
145
/* int */
 
146
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
 
147
{
 
148
        r[0] = a[0];
 
149
        r[1] = a[1];
 
150
}
 
151
 
 
152
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
 
153
{
 
154
        r[0] = a[0];
 
155
        r[1] = a[1];
 
156
        r[2] = a[2];
 
157
}
 
158
 
 
159
MINLINE void copy_v4_v4_int(int r[4], const int a[4])
 
160
{
 
161
        r[0] = a[0];
 
162
        r[1] = a[1];
 
163
        r[2] = a[2];
 
164
        r[3] = a[3];
 
165
}
 
166
 
 
167
/* double -> float */
 
168
MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
 
169
{
 
170
        r[0] = (float)a[0];
 
171
        r[1] = (float)a[1];
 
172
}
 
173
 
 
174
MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
 
175
{
 
176
        r[0] = (float)a[0];
 
177
        r[1] = (float)a[1];
 
178
        r[2] = (float)a[2];
 
179
}
 
180
 
 
181
MINLINE void copy_v4fl_v4db(float r[4], const double a[4])
 
182
{
 
183
        r[0] = (float)a[0];
 
184
        r[1] = (float)a[1];
 
185
        r[2] = (float)a[2];
 
186
        r[3] = (float)a[3];
 
187
}
 
188
 
 
189
/* float -> double */
 
190
MINLINE void copy_v2db_v2fl(double r[2], const float a[2])
 
191
{
 
192
        r[0] = (double)a[0];
 
193
        r[1] = (double)a[1];
 
194
}
 
195
 
 
196
MINLINE void copy_v3db_v3fl(double r[3], const float a[3])
 
197
{
 
198
        r[0] = (double)a[0];
 
199
        r[1] = (double)a[1];
 
200
        r[2] = (double)a[2];
 
201
}
 
202
 
 
203
MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
 
204
{
 
205
        r[0] = (double)a[0];
 
206
        r[1] = (double)a[1];
 
207
        r[2] = (double)a[2];
 
208
        r[3] = (double)a[3];
75
209
}
76
210
 
77
211
MINLINE void swap_v2_v2(float a[2], float b[2])
97
231
 
98
232
/********************************* Arithmetic ********************************/
99
233
 
100
 
MINLINE void add_v2_v2(float *r, const float *a)
 
234
MINLINE void add_v3_fl(float r[3], float f)
 
235
{
 
236
        r[0] += f;
 
237
        r[1] += f;
 
238
        r[2] += f;
 
239
}
 
240
 
 
241
MINLINE void add_v4_fl(float r[4], float f)
 
242
{
 
243
        r[0] += f;
 
244
        r[1] += f;
 
245
        r[2] += f;
 
246
        r[3] += f;
 
247
}
 
248
 
 
249
MINLINE void add_v2_v2(float r[2], const float a[2])
101
250
{
102
251
        r[0] += a[0];
103
252
        r[1] += a[1];
104
253
}
105
254
 
106
 
MINLINE void add_v2_v2v2(float *r, const float *a, const float *b)
 
255
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
107
256
{
108
 
        r[0]= a[0] + b[0];
109
 
        r[1]= a[1] + b[1];
 
257
        r[0] = a[0] + b[0];
 
258
        r[1] = a[1] + b[1];
110
259
}
111
260
 
112
 
MINLINE void add_v3_v3(float *r, const float *a)
 
261
MINLINE void add_v3_v3(float r[3], const float a[3])
113
262
{
114
263
        r[0] += a[0];
115
264
        r[1] += a[1];
116
265
        r[2] += a[2];
117
266
}
118
267
 
119
 
MINLINE void add_v3_v3v3(float *r, const float *a, const float *b)
 
268
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
120
269
{
121
 
        r[0]= a[0] + b[0];
122
 
        r[1]= a[1] + b[1];
123
 
        r[2]= a[2] + b[2];
 
270
        r[0] = a[0] + b[0];
 
271
        r[1] = a[1] + b[1];
 
272
        r[2] = a[2] + b[2];
124
273
}
125
274
 
126
 
MINLINE void sub_v2_v2(float *r, const float *a)
 
275
MINLINE void sub_v2_v2(float r[2], const float a[2])
127
276
{
128
277
        r[0] -= a[0];
129
278
        r[1] -= a[1];
130
279
}
131
280
 
132
 
MINLINE void sub_v2_v2v2(float *r, const float *a, const float *b)
 
281
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
133
282
{
134
 
        r[0]= a[0] - b[0];
135
 
        r[1]= a[1] - b[1];
 
283
        r[0] = a[0] - b[0];
 
284
        r[1] = a[1] - b[1];
136
285
}
137
286
 
138
 
MINLINE void sub_v3_v3(float *r, const float *a)
 
287
MINLINE void sub_v3_v3(float r[3], const float a[3])
139
288
{
140
289
        r[0] -= a[0];
141
290
        r[1] -= a[1];
144
293
 
145
294
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
146
295
{
147
 
        r[0]= a[0] - b[0];
148
 
        r[1]= a[1] - b[1];
149
 
        r[2]= a[2] - b[2];
150
 
}
151
 
 
152
 
MINLINE void mul_v2_fl(float *v1, float f)
153
 
{
154
 
        v1[0]*= f;
155
 
        v1[1]*= f;
 
296
        r[0] = a[0] - b[0];
 
297
        r[1] = a[1] - b[1];
 
298
        r[2] = a[2] - b[2];
 
299
}
 
300
 
 
301
MINLINE void sub_v4_v4(float r[4], const float a[4])
 
302
{
 
303
        r[0] -= a[0];
 
304
        r[1] -= a[1];
 
305
        r[2] -= a[2];
 
306
        r[3] -= a[3];
 
307
}
 
308
 
 
309
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
 
310
{
 
311
        r[0] = a[0] - b[0];
 
312
        r[1] = a[1] - b[1];
 
313
        r[2] = a[2] - b[2];
 
314
        r[3] = a[3] - b[3];
 
315
}
 
316
 
 
317
MINLINE void mul_v2_fl(float r[2], float f)
 
318
{
 
319
        r[0] *= f;
 
320
        r[1] *= f;
156
321
}
157
322
 
158
323
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
159
324
{
160
 
        r[0]= a[0]*f;
161
 
        r[1]= a[1]*f;
 
325
        r[0] = a[0] * f;
 
326
        r[1] = a[1] * f;
162
327
}
163
328
 
164
329
MINLINE void mul_v3_fl(float r[3], float f)
170
335
 
171
336
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
172
337
{
173
 
        r[0]= a[0]*f;
174
 
        r[1]= a[1]*f;
175
 
        r[2]= a[2]*f;
 
338
        r[0] = a[0] * f;
 
339
        r[1] = a[1] * f;
 
340
        r[2] = a[2] * f;
176
341
}
177
342
 
178
343
MINLINE void mul_v2_v2(float r[2], const float a[2])
190
355
 
191
356
MINLINE void mul_v4_fl(float r[4], float f)
192
357
{
193
 
        r[0]*= f;
194
 
        r[1]*= f;
195
 
        r[2]*= f;
196
 
        r[3]*= f;
 
358
        r[0] *= f;
 
359
        r[1] *= f;
 
360
        r[2] *= f;
 
361
        r[3] *= f;
197
362
}
198
363
 
199
364
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
200
365
{
201
 
        r[0] += a[0]*f;
202
 
        r[1] += a[1]*f;
 
366
        r[0] += a[0] * f;
 
367
        r[1] += a[1] * f;
203
368
}
204
369
 
205
370
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
206
371
{
207
 
        r[0] += a[0]*f;
208
 
        r[1] += a[1]*f;
209
 
        r[2] += a[2]*f;
 
372
        r[0] += a[0] * f;
 
373
        r[1] += a[1] * f;
 
374
        r[2] += a[2] * f;
210
375
}
211
376
 
212
377
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
213
378
{
214
 
        r[0] += a[0]*b[0];
215
 
        r[1] += a[1]*b[1];
216
 
        r[2] += a[2]*b[2];
 
379
        r[0] += a[0] * b[0];
 
380
        r[1] += a[1] * b[1];
 
381
        r[2] += a[2] * b[2];
217
382
}
218
383
 
219
384
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
220
385
{
221
 
        r[0] = a[0] + b[0]*f;
222
 
        r[1] = a[1] + b[1]*f;
 
386
        r[0] = a[0] + b[0] * f;
 
387
        r[1] = a[1] + b[1] * f;
223
388
}
224
389
 
225
390
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
226
391
{
227
 
        r[0] = a[0] + b[0]*f;
228
 
        r[1] = a[1] + b[1]*f;
229
 
        r[2] = a[2] + b[2]*f;
 
392
        r[0] = a[0] + b[0] * f;
 
393
        r[1] = a[1] + b[1] * f;
 
394
        r[2] = a[2] + b[2] * f;
230
395
}
231
396
 
232
397
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
233
398
{
234
 
        r[0] = a[0] + b[0]*c[0];
235
 
        r[1] = a[1] + b[1]*c[1];
236
 
        r[2] = a[2] + b[2]*c[2];
 
399
        r[0] = a[0] + b[0] * c[0];
 
400
        r[1] = a[1] + b[1] * c[1];
 
401
        r[2] = a[2] + b[2] * c[2];
237
402
}
238
403
 
239
404
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
240
405
{
241
 
        r[0] += a[0]*f;
242
 
        r[1] += a[1]*f;
243
 
        r[2] += a[2]*f;
244
 
        r[3] += a[3]*f;
245
 
}
246
 
 
247
 
MINLINE void mul_v3_v3v3(float *v, const float *v1, const float *v2)
248
 
{
249
 
        v[0] = v1[0] * v2[0];
250
 
        v[1] = v1[1] * v2[1];
251
 
        v[2] = v1[2] * v2[2];
 
406
        r[0] += a[0] * f;
 
407
        r[1] += a[1] * f;
 
408
        r[2] += a[2] * f;
 
409
        r[3] += a[3] * f;
 
410
}
 
411
 
 
412
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
 
413
{
 
414
        r[0] = v1[0] * v2[0];
 
415
        r[1] = v1[1] * v2[1];
 
416
        r[2] = v1[2] * v2[2];
 
417
}
 
418
 
 
419
MINLINE void negate_v2(float r[3])
 
420
{
 
421
        r[0] = -r[0];
 
422
        r[1] = -r[1];
 
423
}
 
424
 
 
425
MINLINE void negate_v2_v2(float r[2], const float a[2])
 
426
{
 
427
        r[0] = -a[0];
 
428
        r[1] = -a[1];
252
429
}
253
430
 
254
431
MINLINE void negate_v3(float r[3])
255
432
{
256
 
        r[0]= -r[0];
257
 
        r[1]= -r[1];
258
 
        r[2]= -r[2];
 
433
        r[0] = -r[0];
 
434
        r[1] = -r[1];
 
435
        r[2] = -r[2];
259
436
}
260
437
 
261
438
MINLINE void negate_v3_v3(float r[3], const float a[3])
262
439
{
263
 
        r[0]= -a[0];
264
 
        r[1]= -a[1];
265
 
        r[2]= -a[2];
 
440
        r[0] = -a[0];
 
441
        r[1] = -a[1];
 
442
        r[2] = -a[2];
 
443
}
 
444
 
 
445
MINLINE void negate_v4(float r[4])
 
446
{
 
447
        r[0] = -r[0];
 
448
        r[1] = -r[1];
 
449
        r[2] = -r[2];
 
450
        r[3] = -r[3];
 
451
}
 
452
 
 
453
MINLINE void negate_v4_v4(float r[4], const float a[4])
 
454
{
 
455
        r[0] = -a[0];
 
456
        r[1] = -a[1];
 
457
        r[2] = -a[2];
 
458
        r[3] = -a[3];
266
459
}
267
460
 
268
461
MINLINE float dot_v2v2(const float a[2], const float b[2])
269
462
{
270
 
        return a[0]*b[0] + a[1]*b[1];
 
463
        return a[0] * b[0] + a[1] * b[1];
271
464
}
272
465
 
273
466
MINLINE float dot_v3v3(const float a[3], const float b[3])
274
467
{
275
 
        return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
 
468
        return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
276
469
}
277
470
 
278
471
MINLINE float cross_v2v2(const float a[2], const float b[2])
279
472
{
280
 
         return a[0]*b[1] - a[1]*b[0];
 
473
        return a[0] * b[1] - a[1] * b[0];
281
474
}
282
475
 
283
476
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
284
477
{
285
 
        r[0]= a[1]*b[2] - a[2]*b[1];
286
 
        r[1]= a[2]*b[0] - a[0]*b[2];
287
 
        r[2]= a[0]*b[1] - a[1]*b[0];
288
 
}
289
 
 
290
 
MINLINE void star_m3_v3(float mat[][3], float *vec)
291
 
{
292
 
        mat[0][0]= mat[1][1]= mat[2][2]= 0.0;
293
 
        mat[0][1]= -vec[2];     
294
 
        mat[0][2]= vec[1];
295
 
        mat[1][0]= vec[2];      
296
 
        mat[1][2]= -vec[0];
297
 
        mat[2][0]= -vec[1];     
298
 
        mat[2][1]= vec[0];
 
478
        r[0] = a[1] * b[2] - a[2] * b[1];
 
479
        r[1] = a[2] * b[0] - a[0] * b[2];
 
480
        r[2] = a[0] * b[1] - a[1] * b[0];
 
481
}
 
482
 
 
483
/* Newell's Method */
 
484
/* excuse this fairly spesific function,
 
485
 * its used for polygon normals all over the place
 
486
 * could use a better name */
 
487
MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
 
488
{
 
489
        n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
 
490
        n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
 
491
        n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
 
492
}
 
493
 
 
494
MINLINE void star_m3_v3(float rmat[][3], float a[3])
 
495
{
 
496
        rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
 
497
        rmat[0][1] = -a[2];
 
498
        rmat[0][2] = a[1];
 
499
        rmat[1][0] = a[2];
 
500
        rmat[1][2] = -a[0];
 
501
        rmat[2][0] = -a[1];
 
502
        rmat[2][1] = a[0];
299
503
}
300
504
 
301
505
/*********************************** Length **********************************/
302
506
 
 
507
MINLINE float len_squared_v2(const float v[2])
 
508
{
 
509
        return v[0] * v[0] + v[1] * v[1];
 
510
}
 
511
 
 
512
MINLINE float len_squared_v3(const float v[3])
 
513
{
 
514
        return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
 
515
}
 
516
 
303
517
MINLINE float len_v2(const float v[2])
304
518
{
305
 
        return (float)sqrt(v[0]*v[0] + v[1]*v[1]);
 
519
        return sqrtf(v[0] * v[0] + v[1] * v[1]);
306
520
}
307
521
 
308
522
MINLINE float len_v2v2(const float v1[2], const float v2[2])
309
523
{
310
524
        float x, y;
311
525
 
312
 
        x = v1[0]-v2[0];
313
 
        y = v1[1]-v2[1];
314
 
        return (float)sqrt(x*x+y*y);
 
526
        x = v1[0] - v2[0];
 
527
        y = v1[1] - v2[1];
 
528
        return sqrtf(x * x + y * y);
315
529
}
316
530
 
317
531
MINLINE float len_v3(const float a[3])
319
533
        return sqrtf(dot_v3v3(a, a));
320
534
}
321
535
 
 
536
MINLINE float len_squared_v2v2(const float a[2], const float b[2])
 
537
{
 
538
        float d[2];
 
539
 
 
540
        sub_v2_v2v2(d, b, a);
 
541
        return dot_v2v2(d, d);
 
542
}
 
543
 
322
544
MINLINE float len_v3v3(const float a[3], const float b[3])
323
545
{
324
546
        float d[3];
337
559
 
338
560
MINLINE float normalize_v2_v2(float r[2], const float a[2])
339
561
{
340
 
        float d= dot_v2v2(a, a);
 
562
        float d = dot_v2v2(a, a);
341
563
 
342
 
        if(d > 1.0e-35f) {
343
 
                d= sqrtf(d);
344
 
                mul_v2_v2fl(r, a, 1.0f/d);
345
 
        } else {
 
564
        if (d > 1.0e-35f) {
 
565
                d = sqrtf(d);
 
566
                mul_v2_v2fl(r, a, 1.0f / d);
 
567
        }
 
568
        else {
346
569
                zero_v2(r);
347
 
                d= 0.0f;
 
570
                d = 0.0f;
348
571
        }
349
572
 
350
573
        return d;
357
580
 
358
581
MINLINE float normalize_v3_v3(float r[3], const float a[3])
359
582
{
360
 
        float d= dot_v3v3(a, a);
 
583
        float d = dot_v3v3(a, a);
361
584
 
362
585
        /* a larger value causes normalize errors in a
363
 
           scaled down models with camera xtreme close */
364
 
        if(d > 1.0e-35f) {
365
 
                d= sqrtf(d);
366
 
                mul_v3_v3fl(r, a, 1.0f/d);
 
586
         * scaled down models with camera xtreme close */
 
587
        if (d > 1.0e-35f) {
 
588
                d = sqrtf(d);
 
589
                mul_v3_v3fl(r, a, 1.0f / d);
367
590
        }
368
591
        else {
369
592
                zero_v3(r);
370
 
                d= 0.0f;
 
593
                d = 0.0f;
 
594
        }
 
595
 
 
596
        return d;
 
597
}
 
598
 
 
599
MINLINE double normalize_v3_d(double n[3])
 
600
{
 
601
        double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
 
602
 
 
603
        /* a larger value causes normalize errors in a
 
604
         * scaled down models with camera xtreme close */
 
605
        if (d > 1.0e-35) {
 
606
                double mul;
 
607
 
 
608
                d = sqrt(d);
 
609
                mul = 1.0 / d;
 
610
 
 
611
                n[0] *= mul;
 
612
                n[1] *= mul;
 
613
                n[2] *= mul;
 
614
        }
 
615
        else {
 
616
                n[0] = n[1] = n[2] = 0;
 
617
                d = 0.0;
371
618
        }
372
619
 
373
620
        return d;
378
625
        return normalize_v3_v3(n, n);
379
626
}
380
627
 
381
 
MINLINE void normal_short_to_float_v3(float *out, const short *in)
 
628
MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
382
629
{
383
 
        out[0] = in[0]*(1.0f/32767.0f);
384
 
        out[1] = in[1]*(1.0f/32767.0f);
385
 
        out[2] = in[2]*(1.0f/32767.0f);
 
630
        out[0] = in[0] * (1.0f / 32767.0f);
 
631
        out[1] = in[1] * (1.0f / 32767.0f);
 
632
        out[2] = in[2] * (1.0f / 32767.0f);
386
633
}
387
634
 
388
 
MINLINE void normal_float_to_short_v3(short *out, const float *in)
 
635
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
389
636
{
390
 
        out[0] = (short)(in[0]*32767.0f);
391
 
        out[1] = (short)(in[1]*32767.0f);
392
 
        out[2] = (short)(in[2]*32767.0f);
 
637
        out[0] = (short) (in[0] * 32767.0f);
 
638
        out[1] = (short) (in[1] * 32767.0f);
 
639
        out[2] = (short) (in[2] * 32767.0f);
393
640
}
394
641
 
395
642
/********************************* Comparison ********************************/
396
643
 
397
 
MINLINE int is_zero_v3(float *v)
 
644
 
 
645
MINLINE int is_zero_v2(const float v[3])
 
646
{
 
647
        return (v[0] == 0 && v[1] == 0);
 
648
}
 
649
 
 
650
MINLINE int is_zero_v3(const float v[3])
398
651
{
399
652
        return (v[0] == 0 && v[1] == 0 && v[2] == 0);
400
653
}
401
654
 
402
 
MINLINE int is_one_v3(float *v)
 
655
MINLINE int is_zero_v4(const float v[4])
 
656
{
 
657
        return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
 
658
}
 
659
 
 
660
MINLINE int is_one_v3(const float v[3])
403
661
{
404
662
        return (v[0] == 1 && v[1] == 1 && v[2] == 1);
405
663
}
406
664
 
407
 
MINLINE int equals_v3v3(float *v1, float *v2)
408
 
{
409
 
        return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
410
 
}
411
 
 
412
 
MINLINE int compare_v3v3(float *v1, float *v2, float limit)
413
 
{
414
 
        if(fabs(v1[0]-v2[0])<limit)
415
 
                if(fabs(v1[1]-v2[1])<limit)
416
 
                        if(fabs(v1[2]-v2[2])<limit)
 
665
MINLINE int equals_v2v2(const float v1[2], const float v2[2])
 
666
{
 
667
        return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
 
668
}
 
669
 
 
670
MINLINE int equals_v3v3(const float v1[3], const float v2[3])
 
671
{
 
672
        return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
 
673
}
 
674
 
 
675
MINLINE int equals_v4v4(const float v1[4], const float v2[4])
 
676
{
 
677
        return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
 
678
}
 
679
 
 
680
MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit)
 
681
{
 
682
        if (fabsf(v1[0] - v2[0]) < limit)
 
683
                if (fabsf(v1[1] - v2[1]) < limit)
 
684
                        if (fabsf(v1[2] - v2[2]) < limit)
417
685
                                return 1;
418
686
 
419
687
        return 0;
420
688
}
421
689
 
422
 
MINLINE int compare_len_v3v3(float *v1, float *v2, float limit)
 
690
MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
423
691
{
424
 
        float x,y,z;
425
 
 
426
 
        x=v1[0]-v2[0];
427
 
        y=v1[1]-v2[1];
428
 
        z=v1[2]-v2[2];
429
 
 
430
 
        return ((x*x + y*y + z*z) < (limit*limit));
 
692
        float x, y, z;
 
693
 
 
694
        x = v1[0] - v2[0];
 
695
        y = v1[1] - v2[1];
 
696
        z = v1[2] - v2[2];
 
697
 
 
698
        return ((x * x + y * y + z * z) < (limit * limit));
431
699
}
432
700
 
433
 
MINLINE int compare_v4v4(float *v1, float *v2, float limit)
 
701
MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit)
434
702
{
435
 
        if(fabs(v1[0]-v2[0])<limit)
436
 
                if(fabs(v1[1]-v2[1])<limit)
437
 
                        if(fabs(v1[2]-v2[2])<limit)
438
 
                                if(fabs(v1[3]-v2[3])<limit)
 
703
        if (fabsf(v1[0] - v2[0]) < limit)
 
704
                if (fabsf(v1[1] - v2[1]) < limit)
 
705
                        if (fabsf(v1[2] - v2[2]) < limit)
 
706
                                if (fabsf(v1[3] - v2[3]) < limit)
439
707
                                        return 1;
440
708
 
441
709
        return 0;
442
710
}
443
711
 
444
 
#endif /* BLI_MATH_VECTOR_INLINE */
 
712
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
 
713
{
 
714
        return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
 
715
                ((l2[0] - pt[0]) * (l1[1] - pt[1])));
 
716
}
445
717
 
 
718
#endif /* __MATH_VECTOR_INLINE_C__ */