summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_vector.h
blob: 039114b8f1466bc3f6ebc7db494177c6c756d019 (plain) (blame)
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
/* EINA - EFL data type library
 * Copyright (C) 2016 Sergey Osadchy
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_VECTOR_H_
#define EINA_VECTOR_H_

#include "eina_matrix.h"
#include "eina_quaternion.h"

/**
 * @file
 * @ender_group{Eina_Vector_Type}
 * @ender_group{Eina_Vector2}
 * @ender_group{Eina_Vector3}
 */

typedef struct _Eina_Vector2 Eina_Vector2;
typedef struct _Eina_Vector3 Eina_Vector3;

/**
 * @}
 * @defgroup Eina_Vector2 Vectors in floating point
 * @ingroup Eina_Basic
 * @brief Vector definition and operations
 * @{
 */

struct _Eina_Vector2
{
   double x;
   double y;
};

/**
 * @}
 * @defgroup Eina_Vector3 Vectors in floating point
 * @ingroup Eina_Basic
 * @brief Vector definition and operations
 * @{
 */

struct _Eina_Vector3
{
   double x;
   double y;
   double z;
};

/**
 * @brief Set parameters to vector.
 *
 * @param dst The resulting vector.
 * @param x The x component.
 * @param y The y component.
 *
 * @since 1.17
 */
static inline void eina_vector2_set(Eina_Vector2 *dst, double x, double y);

/**
 * @brief Set array to vector.
 *
 * @param dst The resulting vector.
 * @param v The the array[2] for set.
 *
 * Set to vector first 2 elements from array.
 *
 * @since 1.17
 */
static inline void eina_vector2_array_set(Eina_Vector2 *dst, const double *v);

/**
 * @brief Copy vector.
 *
 * @param dst The vector copy.
 * @param src The vector for copy.
 *
 * @since 1.17
 */
static inline void eina_vector2_copy(Eina_Vector2 *dst, const Eina_Vector2 *src);

/**
 * @brief Make negative vector.
 *
 * @param out The resulting vector.
 * @param v The current vector.
 *
 * @since 1.17
 */
static inline void eina_vector2_negate(Eina_Vector2 *out, const Eina_Vector2 *v);

/**
 * @brief Add two vectors.
 *
 * @param out The resulting vector.
 * @param a The first member of the add.
 * @param b The second member of the add.
 *
 * @since 1.17
 */
static inline void eina_vector2_add(Eina_Vector2 *out, const Eina_Vector2 *a, const Eina_Vector2 *b);

/**
 * @brief Subtract two vectors
 *
 * @param out The resulting vector
 * @param a The first member of the subtract
 * @param b The second member of the subtract
 *
 * @since 1.17
 */
static inline void eina_vector2_subtract(Eina_Vector2 *out, const Eina_Vector2 *a, const Eina_Vector2 *b);

/**
 * @brief Scale vector.
 *
 * @param out The resulting vector.
 * @param v The vector for scale.
 * @param scale The scale value.
 *
 * @since 1.17
 */
static inline void eina_vector2_scale(Eina_Vector2 *out, const Eina_Vector2 *v, double scale);

/**
 * @brief Return the dot product of the two vectors.
 *
 * @param a The first member.
 * @param b The second member.
 * @return The dot product.
 *
 * @since 1.17
 */
static inline double eina_vector2_dot_product(const Eina_Vector2 *a, const Eina_Vector2 *b);

/**
 * @brief Return the length of the given vector.
 *
 * @param v The vector.
 * @return The length.
 *
 * @since 1.17
 */
static inline double eina_vector2_length_get(const Eina_Vector2 *v);

/**
 * @brief Return the length in square of the given vector.
 *
 * @param v The vector.
 * @return The length in square.
 *
 * @since 1.17
 */
static inline double eina_vector2_length_square_get(const Eina_Vector2 *v);

/**
 * @brief Return the distance between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The distance.
 *
 * @since 1.17
 */
static inline double eina_vector2_distance_get(const Eina_Vector2 *a, const Eina_Vector2 *b);

/**
 * @brief Return the distance in square between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The distance in square.
 *
 * @since 1.17
 */
static inline double eina_vector2_distance_square_get(const Eina_Vector2 *a, const Eina_Vector2 *b);

/**
 * @brief normalize vector.
 *
 * @param out The resulting vector.
 * @param v The vector for normalize.
 *
 * @since 1.17
 */
static inline void eina_vector2_normalize(Eina_Vector2 *out, const Eina_Vector2 *v);

/**
 * @brief Transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.17
 */
static inline void eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m, const Eina_Vector2 *v);

/**
 * @brief Homogeneous position transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.17
 */
static inline void eina_vector2_homogeneous_position_transform(Eina_Vector2 *out, const Eina_Matrix3 *m, const Eina_Vector2 *v);

/**
 * @brief Homogeneous direction transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.17
 */
static inline void eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out, const Eina_Matrix3 *m, const Eina_Vector2 *v);

/**
 * @brief Set parameters to vector.
 *
 * @param dst The resulting vector.
 * @param x The x component.
 * @param y The y component.
 * @param z The z component.
 *
 * @since 1.18
 */
static inline void eina_vector3_set(Eina_Vector3 *dst, double x, double y, double z);

/**
 * @brief Set array to vector.
 *
 * @param dst The resulting vector.
 * @param v The the array[3] for set.
 *
 * Set to vector first 3 elements from array.
 *
 * @since 1.18
 */
static inline void eina_vector3_array_set(Eina_Vector3 *dst, const double *v);

/**
 * @brief Copy vector.
 *
 * @param dst The vector copy.
 * @param src The vector for copy.
 *
 * @since 1.18
 */
static inline void eina_vector3_copy(Eina_Vector3 *dst, const Eina_Vector3 *src);

/**
 * @brief Make negative vector.
 *
 * @param out The resulting vector.
 * @param v The current vector.
 *
 * @since 1.18
 */
static inline void eina_vector3_negate(Eina_Vector3 *out, const Eina_Vector3 *v);

/**
 * @brief Add two vectors.
 *
 * @param out The resulting vector.
 * @param a The first member of the add.
 * @param b The second member of the add.
 *
 * @since 1.18
 */
static inline void eina_vector3_add(Eina_Vector3 *out, const Eina_Vector3 *a,
                           const Eina_Vector3 *b);

/**
 * @brief Subtract two vectors
 *
 * @param out The resulting vector
 * @param a The first member of the subtract
 * @param b The second member of the subtract
 *
 * @since 1.18
 */
static inline void eina_vector3_subtract(Eina_Vector3 *out, const Eina_Vector3 *a,
                                const Eina_Vector3 *b);

/**
 * @brief Scale vector.
 *
 * @param out The resulting vector.
 * @param v The vector for scale.
 * @param scale The scale value.
 *
 * @since 1.18
 */
static inline void eina_vector3_scale(Eina_Vector3 *out, const Eina_Vector3 *v, double scale);

/**
 * @brief Multiply two vectors
 *
 * @param out The resulting vector
 * @param a The first member
 * @param b The second member
 *
 * @since 1.18
 */
static inline void eina_vector3_multiply(Eina_Vector3 *out, const Eina_Vector3 *a,
                                const Eina_Vector3 *b);

/**
 * @brief Return the dot product of the two vectors.
 *
 * @param a The first member.
 * @param b The second member.
 * @return The dot product.
 *
 * @since 1.18
 */
static inline double eina_vector3_dot_product(const Eina_Vector3 *a, const Eina_Vector3 *b);

/**
 * @brief Create the cross product of the two vectors.
 *
 * @param out The resulting vector.
 * @param a The first member.
 * @param b The second member.
 *
 * @since 1.18
 */
static inline void eina_vector3_cross_product(Eina_Vector3 *out, const Eina_Vector3 *a,
                                     const Eina_Vector3 *b);

/**
 * @brief Return the length of the given vector.
 *
 * @param v The vector.
 * @return The length.
 *
 * @since 1.18
 */
static inline double eina_vector3_length_get(const Eina_Vector3 *v);

/**
 * @brief Return the length in square of the given vector.
 *
 * @param v The vector.
 * @return The length in square.
 *
 * @since 1.18
 */
static inline double eina_vector3_length_square_get(const Eina_Vector3 *v);

/**
 * @brief Return the distance between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The distance.
 *
 * @since 1.18
 */
static inline double eina_vector3_distance_get(const Eina_Vector3 *a, const Eina_Vector3 *b);

/**
 * @brief Return the distance in square between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The distance in square.
 *
 * @since 1.18
 */
static inline double eina_vector3_distance_square_get(const Eina_Vector3 *a,
                                             const Eina_Vector3 *b);

/**
 * @brief Return the angle between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The angle.
 *
 * @since 1.18
 */
static inline double eina_vector3_angle_get(const Eina_Vector3 *a, const Eina_Vector3 *b);

/**
 * @brief normalize vector.
 *
 * @param out The resulting vector.
 * @param v The not NULL vector for normalize.
 *
 * @since 1.18
 */
static inline void eina_vector3_normalize(Eina_Vector3 *out, const Eina_Vector3 *v);

/**
 * @brief Transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.18
 */
static inline void eina_vector3_transform(Eina_Vector3 *out, const Eina_Matrix3 *m,
                                 const Eina_Vector3 *v);

/**
 * @brief Homogeneous direction transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.18
 */
static inline void eina_vector3_homogeneous_direction_transform(Eina_Vector3 *out, const Eina_Matrix4 *m,
                                                               const Eina_Vector3 *v);

/**
 * @brief Homogeneous position transform vector.
 *
 * @param out The resulting vector.
 * @param m The matrix for transform.
 * @param v The vector for transform.
 *
 * @since 1.18
 */
static inline void eina_vector3_homogeneous_position_transform(Eina_Vector3 *out, const Eina_Matrix4 *m,
                                                               const Eina_Vector3 *v);


/**
 * @brief Rotate vector.
 *
 * @param out The resulting vector.
 * @param v The vector for rotate.
 * @param q The quaternion in radians for rotate.
 *
 * @since 1.18
 */
static inline void eina_vector3_quaternion_rotate(Eina_Vector3 *out, const Eina_Vector3 *v,
                                                  const Eina_Quaternion *q);

/**
 * @brief Create orthogonal projection on plane between vector and normal.
 *
 * @param out The resulting vector.
 * @param v The vector for projection.
 * @param normal The normal for projection.
 *
 * @since 1.18
 */
static inline void eina_vector3_orthogonal_projection_on_plane(Eina_Vector3 *out, const Eina_Vector3 *v,
                                                               const Eina_Vector3 *normal);

/**
 * @brief Plane by points between three vectors.
 *
 * @param out The resulting quaternion of plane.
 * @param a The first member.
 * @param b The second member.
 * @param c The third member.
 *
 * @since 1.18
 */
static inline void eina_vector3_plane_by_points(Eina_Quaternion *out, const Eina_Vector3 *a,
                                                const Eina_Vector3 *b, const Eina_Vector3 *c);

/**
 * @brief Homogeneous position set.
 *
 * @param out The resulting vector.
 * @param v The quaternion for position.
 *
 * @since 1.18
 */
static inline void eina_vector3_homogeneous_position_set(Eina_Vector3 *out, const Eina_Quaternion *v);

/**
 * @brief Homogeneous direction set.
 *
 * @param out The resulting vector.
 * @param v The quaternion for direction.
 *
 * @since 1.18
 */
static inline void eina_vector3_homogeneous_direction_set(Eina_Vector3 *out, const Eina_Quaternion *v);

/**
 * @brief Check the equivalent between of two vectors.
 *
 * @param a The first vector.
 * @param b The second vector.
 * @return The EINA_TRUE if equivalent.
 *
 * @since 1.18
 */
static inline Eina_Bool eina_vector3_equivalent(Eina_Vector3 *a, const Eina_Vector3 *b);

/**
 * @brief Check the equivalent between of two triangles of vectors.
 *
 * @param v0 The first member of first triangle.
 * @param v1 The second member of first triangle.
 * @param v2 The third member of first triangle.
 * @param w0 The first member of second triangle.
 * @param w1 The second member of second triangle.
 * @param w2 The third member of second triangle.
 * @return The EINA_TRUE if equivalent.
 *
 * @since 1.18
 */
static inline Eina_Bool eina_vector3_triangle_equivalent(Eina_Vector3 *v0, Eina_Vector3 *v1,
                                                         Eina_Vector3 *v2, Eina_Vector3 *w0,
                                                         Eina_Vector3 *w1, Eina_Vector3 *w2);

/** @} */

#include "eina_inline_vector.x"

#endif