LEFT | RIGHT |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software Foundation, | 15 * along with this program; if not, write to the Free Software Foundation, |
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 * | 17 * |
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. |
19 * All rights reserved. | 19 * All rights reserved. |
20 * | 20 |
21 * The Original Code is: some of this file. | 21 * The Original Code is: some of this file. |
22 * | 22 * |
23 * ***** END GPL LICENSE BLOCK ***** | 23 * ***** END GPL LICENSE BLOCK ***** |
24 * */ | 24 * */ |
25 | 25 |
26 /** \file blender/blenlib/intern/math_vector_inline.c | 26 /** \file blender/blenlib/intern/math_vector_inline.c |
27 * \ingroup bli | 27 * \ingroup bli |
28 */ | 28 */ |
29 | 29 |
30 #ifndef __MATH_VECTOR_INLINE_C__ | |
31 #define __MATH_VECTOR_INLINE_C__ | |
32 | 30 |
33 #include "BLI_math.h" | 31 #include "BLI_math.h" |
34 | 32 |
| 33 #ifndef BLI_MATH_VECTOR_INLINE_H |
| 34 #define BLI_MATH_VECTOR_INLINE_H |
| 35 |
35 /********************************** Init *************************************/ | 36 /********************************** Init *************************************/ |
36 | 37 |
37 MINLINE void zero_v2(float r[2]) | 38 MINLINE void zero_v2(float r[2]) |
38 { | 39 { |
39 » r[0] = 0.0f; | 40 » r[0]= 0.0f; |
40 » r[1] = 0.0f; | 41 » r[1]= 0.0f; |
41 } | 42 } |
42 | 43 |
43 MINLINE void zero_v3(float r[3]) | 44 MINLINE void zero_v3(float r[3]) |
44 { | 45 { |
45 » r[0] = 0.0f; | 46 » r[0]= 0.0f; |
46 » r[1] = 0.0f; | 47 » r[1]= 0.0f; |
47 » r[2] = 0.0f; | 48 » r[2]= 0.0f; |
48 } | 49 } |
49 | 50 |
50 MINLINE void zero_v4(float r[4]) | 51 MINLINE void zero_v4(float r[4]) |
51 { | 52 { |
52 » r[0] = 0.0f; | 53 » r[0]= 0.0f; |
53 » r[1] = 0.0f; | 54 » r[1]= 0.0f; |
54 » r[2] = 0.0f; | 55 » r[2]= 0.0f; |
55 » r[3] = 0.0f; | 56 » r[3]= 0.0f; |
56 } | 57 } |
57 | 58 |
58 MINLINE void copy_v2_v2(float r[2], const float a[2]) | 59 MINLINE void copy_v2_v2(float r[2], const float a[2]) |
59 { | 60 { |
60 » r[0] = a[0]; | 61 » r[0]= a[0]; |
61 » r[1] = a[1]; | 62 » r[1]= a[1]; |
62 } | 63 } |
63 | 64 |
64 MINLINE void copy_v3_v3(float r[3], const float a[3]) | 65 MINLINE void copy_v3_v3(float r[3], const float a[3]) |
65 { | 66 { |
66 » r[0] = a[0]; | 67 » r[0]= a[0]; |
67 » r[1] = a[1]; | 68 » r[1]= a[1]; |
68 » r[2] = a[2]; | 69 » r[2]= a[2]; |
69 } | 70 } |
70 | 71 |
71 MINLINE void copy_v4_v4(float r[4], const float a[4]) | 72 MINLINE void copy_v4_v4(float r[4], const float a[4]) |
72 { | 73 { |
73 » r[0] = a[0]; | 74 » r[0]= a[0]; |
74 » r[1] = a[1]; | 75 » r[1]= a[1]; |
75 » r[2] = a[2]; | 76 » r[2]= a[2]; |
76 » r[3] = a[3]; | 77 » r[3]= a[3]; |
77 } | |
78 | |
79 MINLINE void copy_v2_fl(float r[2], float f) | |
80 { | |
81 » r[0] = f; | |
82 » r[1] = f; | |
83 } | |
84 | |
85 MINLINE void copy_v3_fl(float r[3], float f) | |
86 { | |
87 » r[0] = f; | |
88 » r[1] = f; | |
89 » r[2] = f; | |
90 } | |
91 | |
92 MINLINE void copy_v4_fl(float r[4], float f) | |
93 { | |
94 » r[0] = f; | |
95 » r[1] = f; | |
96 » r[2] = f; | |
97 » r[3] = f; | |
98 } | 78 } |
99 | 79 |
100 /* short */ | 80 /* short */ |
101 MINLINE void copy_v2_v2_char(char r[2], const char a[2]) | 81 MINLINE void copy_v2_v2_char(char r[2], const char a[2]) |
102 { | 82 { |
103 » r[0] = a[0]; | 83 » r[0]= a[0]; |
104 » r[1] = a[1]; | 84 » r[1]= a[1]; |
105 } | 85 } |
106 | 86 |
107 MINLINE void copy_v3_v3_char(char r[3], const char a[3]) | 87 MINLINE void copy_v3_v3_char(char r[3], const char a[3]) |
108 { | 88 { |
109 » r[0] = a[0]; | 89 » r[0]= a[0]; |
110 » r[1] = a[1]; | 90 » r[1]= a[1]; |
111 » r[2] = a[2]; | 91 » r[2]= a[2]; |
112 } | 92 } |
113 | 93 |
114 MINLINE void copy_v4_v4_char(char r[4], const char a[4]) | 94 MINLINE void copy_v4_v4_char(char r[4], const char a[4]) |
115 { | 95 { |
116 » r[0] = a[0]; | 96 » r[0]= a[0]; |
117 » r[1] = a[1]; | 97 » r[1]= a[1]; |
118 » r[2] = a[2]; | 98 » r[2]= a[2]; |
119 » r[3] = a[3]; | 99 » r[3]= a[3]; |
120 } | 100 } |
121 | 101 |
122 /* short */ | 102 /* short */ |
123 MINLINE void zero_v3_int(int r[3]) | |
124 { | |
125 r[0] = 0; | |
126 r[1] = 0; | |
127 r[2] = 0; | |
128 } | |
129 | |
130 MINLINE void copy_v2_v2_short(short r[2], const short a[2]) | 103 MINLINE void copy_v2_v2_short(short r[2], const short a[2]) |
131 { | 104 { |
132 » r[0] = a[0]; | 105 » r[0]= a[0]; |
133 » r[1] = a[1]; | 106 » r[1]= a[1]; |
134 } | 107 } |
135 | 108 |
136 MINLINE void copy_v3_v3_short(short r[3], const short a[3]) | 109 MINLINE void copy_v3_v3_short(short r[3], const short a[3]) |
137 { | 110 { |
138 » r[0] = a[0]; | 111 » r[0]= a[0]; |
139 » r[1] = a[1]; | 112 » r[1]= a[1]; |
140 » r[2] = a[2]; | 113 » r[2]= a[2]; |
141 } | 114 } |
142 | 115 |
143 MINLINE void copy_v4_v4_short(short r[4], const short a[4]) | 116 MINLINE void copy_v4_v4_short(short r[4], const short a[4]) |
144 { | 117 { |
145 » r[0] = a[0]; | 118 » r[0]= a[0]; |
146 » r[1] = a[1]; | 119 » r[1]= a[1]; |
147 » r[2] = a[2]; | 120 » r[2]= a[2]; |
148 » r[3] = a[3]; | 121 » r[3]= a[3]; |
149 } | 122 } |
150 | 123 |
151 /* int */ | 124 /* int */ |
152 MINLINE void copy_v2_v2_int(int r[2], const int a[2]) | 125 MINLINE void copy_v2_v2_int(int r[2], const int a[2]) |
153 { | 126 { |
154 » r[0] = a[0]; | 127 » r[0]= a[0]; |
155 » r[1] = a[1]; | 128 » r[1]= a[1]; |
156 } | 129 } |
157 | 130 |
158 MINLINE void copy_v3_v3_int(int r[3], const int a[3]) | 131 MINLINE void copy_v3_v3_int(int r[3], const int a[3]) |
159 { | 132 { |
160 » r[0] = a[0]; | 133 » r[0]= a[0]; |
161 » r[1] = a[1]; | 134 » r[1]= a[1]; |
162 » r[2] = a[2]; | 135 » r[2]= a[2]; |
163 } | 136 } |
164 | 137 |
165 MINLINE void copy_v4_v4_int(int r[4], const int a[4]) | 138 MINLINE void copy_v4_v4_int(int r[4], const int a[4]) |
166 { | 139 { |
167 » r[0] = a[0]; | 140 » r[0]= a[0]; |
168 » r[1] = a[1]; | 141 » r[1]= a[1]; |
169 » r[2] = a[2]; | 142 » r[2]= a[2]; |
170 » r[3] = a[3]; | 143 » r[3]= a[3]; |
171 } | |
172 | |
173 /* double -> float */ | |
174 MINLINE void copy_v2fl_v2db(float r[2], const double a[2]) | |
175 { | |
176 » r[0] = (float)a[0]; | |
177 » r[1] = (float)a[1]; | |
178 } | |
179 | |
180 MINLINE void copy_v3fl_v3db(float r[3], const double a[3]) | |
181 { | |
182 » r[0] = (float)a[0]; | |
183 » r[1] = (float)a[1]; | |
184 » r[2] = (float)a[2]; | |
185 } | |
186 | |
187 MINLINE void copy_v4fl_v4db(float r[4], const double a[4]) | |
188 { | |
189 » r[0] = (float)a[0]; | |
190 » r[1] = (float)a[1]; | |
191 » r[2] = (float)a[2]; | |
192 » r[3] = (float)a[3]; | |
193 } | |
194 | |
195 /* float -> double */ | |
196 MINLINE void copy_v2db_v2fl(double r[2], const float a[2]) | |
197 { | |
198 » r[0] = (double)a[0]; | |
199 » r[1] = (double)a[1]; | |
200 } | |
201 | |
202 MINLINE void copy_v3db_v3fl(double r[3], const float a[3]) | |
203 { | |
204 » r[0] = (double)a[0]; | |
205 » r[1] = (double)a[1]; | |
206 » r[2] = (double)a[2]; | |
207 } | |
208 | |
209 MINLINE void copy_v4db_v4fl(double r[4], const float a[4]) | |
210 { | |
211 » r[0] = (double)a[0]; | |
212 » r[1] = (double)a[1]; | |
213 » r[2] = (double)a[2]; | |
214 » r[3] = (double)a[3]; | |
215 } | 144 } |
216 | 145 |
217 MINLINE void swap_v2_v2(float a[2], float b[2]) | 146 MINLINE void swap_v2_v2(float a[2], float b[2]) |
218 { | 147 { |
219 SWAP(float, a[0], b[0]); | 148 SWAP(float, a[0], b[0]); |
220 SWAP(float, a[1], b[1]); | 149 SWAP(float, a[1], b[1]); |
221 } | 150 } |
222 | 151 |
223 MINLINE void swap_v3_v3(float a[3], float b[3]) | 152 MINLINE void swap_v3_v3(float a[3], float b[3]) |
224 { | 153 { |
225 SWAP(float, a[0], b[0]); | 154 SWAP(float, a[0], b[0]); |
226 SWAP(float, a[1], b[1]); | 155 SWAP(float, a[1], b[1]); |
227 SWAP(float, a[2], b[2]); | 156 SWAP(float, a[2], b[2]); |
228 } | 157 } |
229 | 158 |
230 MINLINE void swap_v4_v4(float a[4], float b[4]) | 159 MINLINE void swap_v4_v4(float a[4], float b[4]) |
231 { | 160 { |
232 SWAP(float, a[0], b[0]); | 161 SWAP(float, a[0], b[0]); |
233 SWAP(float, a[1], b[1]); | 162 SWAP(float, a[1], b[1]); |
234 SWAP(float, a[2], b[2]); | 163 SWAP(float, a[2], b[2]); |
235 SWAP(float, a[3], b[3]); | 164 SWAP(float, a[3], b[3]); |
236 } | 165 } |
237 | 166 |
238 /* float args -> vec */ | |
239 MINLINE void copy_v3_fl3(float v[3], float x, float y, float z) | |
240 { | |
241 v[0] = x; | |
242 v[1] = y; | |
243 v[2] = z; | |
244 } | |
245 | |
246 MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w) | |
247 { | |
248 v[0] = x; | |
249 v[1] = y; | |
250 v[2] = z; | |
251 v[3] = w; | |
252 } | |
253 | |
254 /********************************* Arithmetic ********************************/ | 167 /********************************* Arithmetic ********************************/ |
255 | |
256 MINLINE void add_v2_fl(float r[2], float f) | |
257 { | |
258 r[0] += f; | |
259 r[1] += f; | |
260 } | |
261 | |
262 | 168 |
263 MINLINE void add_v3_fl(float r[3], float f) | 169 MINLINE void add_v3_fl(float r[3], float f) |
264 { | 170 { |
265 r[0] += f; | 171 r[0] += f; |
266 r[1] += f; | 172 r[1] += f; |
267 r[2] += f; | 173 r[2] += f; |
268 } | 174 } |
269 | 175 |
270 MINLINE void add_v4_fl(float r[4], float f) | 176 MINLINE void add_v4_fl(float r[4], float f) |
271 { | 177 { |
272 r[0] += f; | 178 r[0] += f; |
273 r[1] += f; | 179 r[1] += f; |
274 r[2] += f; | 180 r[2] += f; |
275 r[3] += f; | 181 r[3] += f; |
276 } | 182 } |
277 | 183 |
278 MINLINE void add_v2_v2(float r[2], const float a[2]) | 184 MINLINE void add_v2_v2(float r[2], const float a[2]) |
279 { | 185 { |
280 r[0] += a[0]; | 186 r[0] += a[0]; |
281 r[1] += a[1]; | 187 r[1] += a[1]; |
282 } | 188 } |
283 | 189 |
284 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]) | 190 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]) |
285 { | 191 { |
286 » r[0] = a[0] + b[0]; | 192 » r[0]= a[0] + b[0]; |
287 » r[1] = a[1] + b[1]; | 193 » r[1]= a[1] + b[1]; |
288 } | |
289 | |
290 MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2]) | |
291 { | |
292 » r[0] = a[0] + b[0]; | |
293 » r[1] = a[1] + b[1]; | |
294 } | 194 } |
295 | 195 |
296 MINLINE void add_v3_v3(float r[3], const float a[3]) | 196 MINLINE void add_v3_v3(float r[3], const float a[3]) |
297 { | 197 { |
298 r[0] += a[0]; | 198 r[0] += a[0]; |
299 r[1] += a[1]; | 199 r[1] += a[1]; |
300 r[2] += a[2]; | 200 r[2] += a[2]; |
301 } | 201 } |
302 | 202 |
303 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]) | 203 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]) |
304 { | 204 { |
305 » r[0] = a[0] + b[0]; | 205 » r[0]= a[0] + b[0]; |
306 » r[1] = a[1] + b[1]; | 206 » r[1]= a[1] + b[1]; |
307 » r[2] = a[2] + b[2]; | 207 » r[2]= a[2] + b[2]; |
308 } | |
309 | |
310 MINLINE void add_v4_v4(float r[4], const float a[4]) | |
311 { | |
312 » r[0] += a[0]; | |
313 » r[1] += a[1]; | |
314 » r[2] += a[2]; | |
315 » r[3] += a[3]; | |
316 } | |
317 | |
318 MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4]) | |
319 { | |
320 » r[0] = a[0] + b[0]; | |
321 » r[1] = a[1] + b[1]; | |
322 » r[2] = a[2] + b[2]; | |
323 » r[3] = a[3] + b[3]; | |
324 } | 208 } |
325 | 209 |
326 MINLINE void sub_v2_v2(float r[2], const float a[2]) | 210 MINLINE void sub_v2_v2(float r[2], const float a[2]) |
327 { | 211 { |
328 r[0] -= a[0]; | 212 r[0] -= a[0]; |
329 r[1] -= a[1]; | 213 r[1] -= a[1]; |
330 } | 214 } |
331 | 215 |
332 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]) | 216 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]) |
333 { | 217 { |
334 » r[0] = a[0] - b[0]; | 218 » r[0]= a[0] - b[0]; |
335 » r[1] = a[1] - b[1]; | 219 » r[1]= a[1] - b[1]; |
336 } | |
337 | |
338 MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2]) | |
339 { | |
340 » r[0] = a[0] - b[0]; | |
341 » r[1] = a[1] - b[1]; | |
342 } | 220 } |
343 | 221 |
344 MINLINE void sub_v3_v3(float r[3], const float a[3]) | 222 MINLINE void sub_v3_v3(float r[3], const float a[3]) |
345 { | 223 { |
346 r[0] -= a[0]; | 224 r[0] -= a[0]; |
347 r[1] -= a[1]; | 225 r[1] -= a[1]; |
348 r[2] -= a[2]; | 226 r[2] -= a[2]; |
349 } | 227 } |
350 | 228 |
351 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]) | 229 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]) |
352 { | 230 { |
353 » r[0] = a[0] - b[0]; | 231 » r[0]= a[0] - b[0]; |
354 » r[1] = a[1] - b[1]; | 232 » r[1]= a[1] - b[1]; |
355 » r[2] = a[2] - b[2]; | 233 » r[2]= a[2] - b[2]; |
356 } | 234 } |
357 | 235 |
358 MINLINE void sub_v4_v4(float r[4], const float a[4]) | 236 MINLINE void sub_v4_v4(float r[4], const float a[4]) |
359 { | 237 { |
360 r[0] -= a[0]; | 238 r[0] -= a[0]; |
361 r[1] -= a[1]; | 239 r[1] -= a[1]; |
362 r[2] -= a[2]; | 240 r[2] -= a[2]; |
363 r[3] -= a[3]; | 241 r[3] -= a[3]; |
364 } | 242 } |
365 | 243 |
366 MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]) | 244 MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]) |
367 { | 245 { |
368 » r[0] = a[0] - b[0]; | 246 » r[0]= a[0] - b[0]; |
369 » r[1] = a[1] - b[1]; | 247 » r[1]= a[1] - b[1]; |
370 » r[2] = a[2] - b[2]; | 248 » r[2]= a[2] - b[2]; |
371 » r[3] = a[3] - b[3]; | 249 » r[3]= a[3] - b[3]; |
372 } | 250 } |
| 251 |
373 | 252 |
374 MINLINE void mul_v2_fl(float r[2], float f) | 253 MINLINE void mul_v2_fl(float r[2], float f) |
375 { | 254 { |
376 » r[0] *= f; | 255 » r[0]*= f; |
377 » r[1] *= f; | 256 » r[1]*= f; |
378 } | 257 } |
379 | 258 |
380 MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f) | 259 MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f) |
381 { | 260 { |
382 » r[0] = a[0] * f; | 261 » r[0]= a[0]*f; |
383 » r[1] = a[1] * f; | 262 » r[1]= a[1]*f; |
384 } | 263 } |
385 | 264 |
386 MINLINE void mul_v3_fl(float r[3], float f) | 265 MINLINE void mul_v3_fl(float r[3], float f) |
387 { | 266 { |
388 r[0] *= f; | 267 r[0] *= f; |
389 r[1] *= f; | 268 r[1] *= f; |
390 r[2] *= f; | 269 r[2] *= f; |
391 } | 270 } |
392 | 271 |
393 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f) | 272 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f) |
394 { | 273 { |
395 » r[0] = a[0] * f; | 274 » r[0]= a[0]*f; |
396 » r[1] = a[1] * f; | 275 » r[1]= a[1]*f; |
397 » r[2] = a[2] * f; | 276 » r[2]= a[2]*f; |
398 } | 277 } |
399 | 278 |
400 MINLINE void mul_v2_v2(float r[2], const float a[2]) | 279 MINLINE void mul_v2_v2(float r[2], const float a[2]) |
401 { | 280 { |
402 r[0] *= a[0]; | 281 r[0] *= a[0]; |
403 r[1] *= a[1]; | 282 r[1] *= a[1]; |
404 } | 283 } |
405 | 284 |
406 MINLINE void mul_v3_v3(float r[3], const float a[3]) | 285 MINLINE void mul_v3_v3(float r[3], const float a[3]) |
407 { | 286 { |
408 r[0] *= a[0]; | 287 r[0] *= a[0]; |
409 r[1] *= a[1]; | 288 r[1] *= a[1]; |
410 r[2] *= a[2]; | 289 r[2] *= a[2]; |
411 } | 290 } |
412 | 291 |
413 MINLINE void mul_v4_fl(float r[4], float f) | 292 MINLINE void mul_v4_fl(float r[4], float f) |
414 { | 293 { |
415 » r[0] *= f; | 294 » r[0]*= f; |
416 » r[1] *= f; | 295 » r[1]*= f; |
417 » r[2] *= f; | 296 » r[2]*= f; |
418 » r[3] *= f; | 297 » r[3]*= f; |
419 } | 298 } |
420 | 299 |
421 MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f) | 300 MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f) |
422 { | 301 { |
423 » r[0] = a[0] * f; | 302 » r[0] += a[0]*f; |
424 » r[1] = a[1] * f; | 303 » r[1] += a[1]*f; |
425 » r[2] = a[2] * f; | 304 } |
426 » r[3] = a[3] * f; | 305 |
427 } | 306 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f) |
428 | 307 { |
| 308 » r[0] += a[0]*f; |
| 309 » r[1] += a[1]*f; |
| 310 » r[2] += a[2]*f; |
| 311 } |
| 312 |
| 313 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]) |
| 314 { |
| 315 » r[0] += a[0]*b[0]; |
| 316 » r[1] += a[1]*b[1]; |
| 317 » r[2] += a[2]*b[2]; |
| 318 } |
| 319 |
| 320 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], floa
t f) |
| 321 { |
| 322 » r[0] = a[0] + b[0]*f; |
| 323 » r[1] = a[1] + b[1]*f; |
| 324 } |
| 325 |
| 326 MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], floa
t f) |
| 327 { |
| 328 » r[0] = a[0] + b[0]*f; |
| 329 » r[1] = a[1] + b[1]*f; |
| 330 » r[2] = a[2] + b[2]*f; |
| 331 } |
| 332 |
| 333 MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], cons
t float c[3]) |
| 334 { |
| 335 » r[0] = a[0] + b[0]*c[0]; |
| 336 » r[1] = a[1] + b[1]*c[1]; |
| 337 » r[2] = a[2] + b[2]*c[2]; |
| 338 } |
| 339 |
| 340 MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f) |
| 341 { |
| 342 » r[0] += a[0]*f; |
| 343 » r[1] += a[1]*f; |
| 344 » r[2] += a[2]*f; |
| 345 » r[3] += a[3]*f; |
| 346 } |
| 347 |
| 348 MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3]) |
| 349 { |
| 350 » r[0] = v1[0] * v2[0]; |
| 351 » r[1] = v1[1] * v2[1]; |
| 352 » r[2] = v1[2] * v2[2]; |
| 353 } |
| 354 |
| 355 MINLINE void negate_v2(float r[3]) |
| 356 { |
| 357 » r[0]= -r[0]; |
| 358 » r[1]= -r[1]; |
| 359 } |
| 360 |
| 361 MINLINE void negate_v2_v2(float r[2], const float a[2]) |
| 362 { |
| 363 » r[0]= -a[0]; |
| 364 » r[1]= -a[1]; |
| 365 } |
| 366 |
| 367 MINLINE void negate_v3(float r[3]) |
| 368 { |
| 369 » r[0]= -r[0]; |
| 370 » r[1]= -r[1]; |
| 371 » r[2]= -r[2]; |
| 372 } |
| 373 |
| 374 MINLINE void negate_v3_v3(float r[3], const float a[3]) |
| 375 { |
| 376 » r[0]= -a[0]; |
| 377 » r[1]= -a[1]; |
| 378 » r[2]= -a[2]; |
| 379 } |
| 380 |
| 381 MINLINE void negate_v4(float r[4]) |
| 382 { |
| 383 » r[0]= -r[0]; |
| 384 » r[1]= -r[1]; |
| 385 » r[2]= -r[2]; |
| 386 » r[3]= -r[3]; |
| 387 } |
| 388 |
| 389 MINLINE void negate_v4_v4(float r[4], const float a[4]) |
| 390 { |
| 391 » r[0]= -a[0]; |
| 392 » r[1]= -a[1]; |
| 393 » r[2]= -a[2]; |
| 394 » r[3]= -a[3]; |
| 395 } |
| 396 |
| 397 MINLINE float dot_v2v2(const float a[2], const float b[2]) |
| 398 { |
| 399 » return a[0]*b[0] + a[1]*b[1]; |
| 400 } |
| 401 |
| 402 MINLINE float dot_v3v3(const float a[3], const float b[3]) |
| 403 { |
| 404 » return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; |
| 405 } |
| 406 |
| 407 MINLINE float cross_v2v2(const float a[2], const float b[2]) |
| 408 { |
| 409 » return a[0]*b[1] - a[1]*b[0]; |
| 410 } |
| 411 |
| 412 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]) |
| 413 { |
| 414 » r[0]= a[1]*b[2] - a[2]*b[1]; |
| 415 » r[1]= a[2]*b[0] - a[0]*b[2]; |
| 416 » r[2]= a[0]*b[1] - a[1]*b[0]; |
| 417 } |
| 418 |
| 419 MINLINE void star_m3_v3(float rmat[][3], float a[3]) |
| 420 { |
| 421 » rmat[0][0]= rmat[1][1]= rmat[2][2]= 0.0; |
| 422 » rmat[0][1]= -a[2]; |
| 423 » rmat[0][2]= a[1]; |
| 424 » rmat[1][0]= a[2]; |
| 425 » rmat[1][2]= -a[0]; |
| 426 » rmat[2][0]= -a[1]; |
| 427 » rmat[2][1]= a[0]; |
| 428 } |
429 | 429 |
430 /*********************************** Length **********************************/ | 430 /*********************************** Length **********************************/ |
431 | 431 |
| 432 MINLINE float len_squared_v2(const float v[2]) |
| 433 { |
| 434 return v[0]*v[0] + v[1]*v[1]; |
| 435 } |
| 436 |
432 MINLINE float len_v2(const float v[2]) | 437 MINLINE float len_v2(const float v[2]) |
433 { | 438 { |
434 return (float)sqrtf(v[0]*v[0] + v[1]*v[1]); | 439 return (float)sqrtf(v[0]*v[0] + v[1]*v[1]); |
| 440 } |
| 441 |
| 442 MINLINE float len_v2v2(const float v1[2], const float v2[2]) |
| 443 { |
| 444 float x, y; |
| 445 |
| 446 x = v1[0]-v2[0]; |
| 447 y = v1[1]-v2[1]; |
| 448 return (float)sqrtf(x*x+y*y); |
| 449 } |
| 450 |
| 451 MINLINE float len_v3(const float a[3]) |
| 452 { |
| 453 return sqrtf(dot_v3v3(a, a)); |
| 454 } |
| 455 |
| 456 MINLINE float len_squared_v2v2(const float a[2], const float b[2]) |
| 457 { |
| 458 float d[2]; |
| 459 |
| 460 sub_v2_v2v2(d, b, a); |
| 461 return dot_v2v2(d, d); |
| 462 } |
| 463 |
| 464 MINLINE float len_v3v3(const float a[3], const float b[3]) |
| 465 { |
| 466 float d[3]; |
| 467 |
| 468 sub_v3_v3v3(d, b, a); |
| 469 return len_v3(d); |
| 470 } |
| 471 |
| 472 MINLINE float len_squared_v3v3(const float a[3], const float b[3]) |
| 473 { |
| 474 float d[3]; |
| 475 |
| 476 sub_v3_v3v3(d, b, a); |
| 477 return dot_v3v3(d, d); |
| 478 } |
| 479 |
| 480 MINLINE float normalize_v2_v2(float r[2], const float a[2]) |
| 481 { |
| 482 float d= dot_v2v2(a, a); |
| 483 |
| 484 if(d > 1.0e-35f) { |
| 485 d= sqrtf(d); |
| 486 mul_v2_v2fl(r, a, 1.0f/d); |
| 487 } else { |
| 488 zero_v2(r); |
| 489 d= 0.0f; |
| 490 } |
| 491 |
| 492 return d; |
| 493 } |
| 494 |
| 495 MINLINE float normalize_v2(float n[2]) |
| 496 { |
| 497 return normalize_v2_v2(n, n); |
| 498 } |
| 499 |
| 500 MINLINE float normalize_v3_v3(float r[3], const float a[3]) |
| 501 { |
| 502 float d= dot_v3v3(a, a); |
| 503 |
| 504 /* a larger value causes normalize errors in a |
| 505 scaled down models with camera xtreme close */ |
| 506 if(d > 1.0e-35f) { |
| 507 d= sqrtf(d); |
| 508 mul_v3_v3fl(r, a, 1.0f/d); |
| 509 } |
| 510 else { |
| 511 zero_v3(r); |
| 512 d= 0.0f; |
| 513 } |
| 514 |
| 515 return d; |
| 516 } |
| 517 |
| 518 MINLINE float normalize_v3(float n[3]) |
| 519 { |
| 520 return normalize_v3_v3(n, n); |
| 521 } |
| 522 |
| 523 MINLINE void normal_short_to_float_v3(float out[3], const short in[3]) |
| 524 { |
| 525 out[0] = in[0]*(1.0f/32767.0f); |
| 526 out[1] = in[1]*(1.0f/32767.0f); |
| 527 out[2] = in[2]*(1.0f/32767.0f); |
| 528 } |
| 529 |
| 530 MINLINE void normal_float_to_short_v3(short out[3], const float in[3]) |
| 531 { |
| 532 out[0] = (short)(in[0]*32767.0f); |
| 533 out[1] = (short)(in[1]*32767.0f); |
| 534 out[2] = (short)(in[2]*32767.0f); |
| 535 } |
| 536 |
| 537 /********************************* Comparison ********************************/ |
| 538 |
| 539 MINLINE int is_zero_v3(const float v[3]) |
| 540 { |
| 541 return (v[0] == 0 && v[1] == 0 && v[2] == 0); |
| 542 } |
| 543 |
| 544 MINLINE int is_zero_v4(const float v[4]) |
| 545 { |
| 546 return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0); |
| 547 } |
| 548 |
| 549 MINLINE int is_one_v3(const float v[3]) |
| 550 { |
| 551 return (v[0] == 1 && v[1] == 1 && v[2] == 1); |
| 552 } |
| 553 |
| 554 MINLINE int equals_v2v2(const float v1[2], const float v2[2]) |
| 555 { |
| 556 return ((v1[0]==v2[0]) && (v1[1]==v2[1])); |
| 557 } |
| 558 |
| 559 MINLINE int equals_v3v3(const float v1[3], const float v2[3]) |
| 560 { |
| 561 return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); |
| 562 } |
| 563 |
| 564 MINLINE int equals_v4v4(const float v1[4], const float v2[4]) |
| 565 { |
| 566 return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2
[3])); |
| 567 } |
| 568 |
| 569 MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit
) |
| 570 { |
| 571 if(fabsf(v1[0]-v2[0])<limit) |
| 572 if(fabsf(v1[1]-v2[1])<limit) |
| 573 if(fabsf(v1[2]-v2[2])<limit) |
| 574 return 1; |
| 575 |
| 576 return 0; |
| 577 } |
| 578 |
| 579 MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float l
imit) |
| 580 { |
| 581 float x,y,z; |
| 582 |
| 583 x=v1[0]-v2[0]; |
| 584 y=v1[1]-v2[1]; |
| 585 z=v1[2]-v2[2]; |
| 586 |
| 587 return ((x*x + y*y + z*z) < (limit*limit)); |
| 588 } |
| 589 |
| 590 MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit
) |
| 591 { |
| 592 if(fabsf(v1[0]-v2[0])<limit) |
| 593 if(fabsf(v1[1]-v2[1])<limit) |
| 594 if(fabsf(v1[2]-v2[2])<limit) |
| 595 if(fabsf(v1[3]-v2[3])<limit) |
| 596 return 1; |
| 597 |
| 598 return 0; |
| 599 } |
| 600 |
| 601 MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const flo
at pt[2]) |
| 602 { |
| 603 return ((l1[0]-pt[0]) * (l2[1]-pt[1])) - |
| 604 ((l2[0]-pt[0]) * (l1[1]-pt[1])); |
| 605 } |
| 606 |
| 607 #endif /* BLI_MATH_VECTOR_INLINE_H */ |
| 608 |
LEFT | RIGHT |