1 | /* graphene-vec2.h: 2-coords vector |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2014 Emmanuele Bassi |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | * THE SOFTWARE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION) |
29 | #error "Only graphene.h can be included directly." |
30 | #endif |
31 | |
32 | #include "graphene-types.h" |
33 | |
34 | GRAPHENE_BEGIN_DECLS |
35 | |
36 | /** |
37 | * graphene_vec2_t: |
38 | * |
39 | * A structure capable of holding a vector with two dimensions, x and y. |
40 | * |
41 | * The contents of the #graphene_vec2_t structure are private and should |
42 | * never be accessed directly. |
43 | */ |
44 | struct _graphene_vec2_t |
45 | { |
46 | /*< private >*/ |
47 | GRAPHENE_ALIGNED_DECL (GRAPHENE_PRIVATE_FIELD (graphene_simd4f_t, value), 16); |
48 | }; |
49 | |
50 | GRAPHENE_AVAILABLE_IN_1_0 |
51 | graphene_vec2_t * graphene_vec2_alloc (void); |
52 | GRAPHENE_AVAILABLE_IN_1_0 |
53 | void graphene_vec2_free (graphene_vec2_t *v); |
54 | GRAPHENE_AVAILABLE_IN_1_0 |
55 | graphene_vec2_t * graphene_vec2_init (graphene_vec2_t *v, |
56 | float x, |
57 | float y); |
58 | GRAPHENE_AVAILABLE_IN_1_0 |
59 | graphene_vec2_t * graphene_vec2_init_from_vec2 (graphene_vec2_t *v, |
60 | const graphene_vec2_t *src); |
61 | GRAPHENE_AVAILABLE_IN_1_0 |
62 | graphene_vec2_t * graphene_vec2_init_from_float (graphene_vec2_t *v, |
63 | const float *src); |
64 | GRAPHENE_AVAILABLE_IN_1_0 |
65 | void graphene_vec2_to_float (const graphene_vec2_t *v, |
66 | float *dest); |
67 | GRAPHENE_AVAILABLE_IN_1_0 |
68 | void graphene_vec2_add (const graphene_vec2_t *a, |
69 | const graphene_vec2_t *b, |
70 | graphene_vec2_t *res); |
71 | GRAPHENE_AVAILABLE_IN_1_0 |
72 | void graphene_vec2_subtract (const graphene_vec2_t *a, |
73 | const graphene_vec2_t *b, |
74 | graphene_vec2_t *res); |
75 | GRAPHENE_AVAILABLE_IN_1_0 |
76 | void graphene_vec2_multiply (const graphene_vec2_t *a, |
77 | const graphene_vec2_t *b, |
78 | graphene_vec2_t *res); |
79 | GRAPHENE_AVAILABLE_IN_1_0 |
80 | void graphene_vec2_divide (const graphene_vec2_t *a, |
81 | const graphene_vec2_t *b, |
82 | graphene_vec2_t *res); |
83 | GRAPHENE_AVAILABLE_IN_1_0 |
84 | float graphene_vec2_dot (const graphene_vec2_t *a, |
85 | const graphene_vec2_t *b); |
86 | GRAPHENE_AVAILABLE_IN_1_0 |
87 | float graphene_vec2_length (const graphene_vec2_t *v); |
88 | GRAPHENE_AVAILABLE_IN_1_0 |
89 | void graphene_vec2_normalize (const graphene_vec2_t *v, |
90 | graphene_vec2_t *res); |
91 | GRAPHENE_AVAILABLE_IN_1_2 |
92 | void graphene_vec2_scale (const graphene_vec2_t *v, |
93 | float factor, |
94 | graphene_vec2_t *res); |
95 | GRAPHENE_AVAILABLE_IN_1_2 |
96 | void graphene_vec2_negate (const graphene_vec2_t *v, |
97 | graphene_vec2_t *res); |
98 | GRAPHENE_AVAILABLE_IN_1_2 |
99 | bool graphene_vec2_near (const graphene_vec2_t *v1, |
100 | const graphene_vec2_t *v2, |
101 | float epsilon); |
102 | GRAPHENE_AVAILABLE_IN_1_2 |
103 | bool graphene_vec2_equal (const graphene_vec2_t *v1, |
104 | const graphene_vec2_t *v2); |
105 | |
106 | GRAPHENE_AVAILABLE_IN_1_0 |
107 | void graphene_vec2_min (const graphene_vec2_t *a, |
108 | const graphene_vec2_t *b, |
109 | graphene_vec2_t *res); |
110 | GRAPHENE_AVAILABLE_IN_1_0 |
111 | void graphene_vec2_max (const graphene_vec2_t *a, |
112 | const graphene_vec2_t *b, |
113 | graphene_vec2_t *res); |
114 | GRAPHENE_AVAILABLE_IN_1_10 |
115 | void graphene_vec2_interpolate (const graphene_vec2_t *v1, |
116 | const graphene_vec2_t *v2, |
117 | double factor, |
118 | graphene_vec2_t *res); |
119 | |
120 | GRAPHENE_AVAILABLE_IN_1_0 |
121 | float graphene_vec2_get_x (const graphene_vec2_t *v); |
122 | GRAPHENE_AVAILABLE_IN_1_0 |
123 | float graphene_vec2_get_y (const graphene_vec2_t *v); |
124 | |
125 | GRAPHENE_AVAILABLE_IN_1_0 |
126 | const graphene_vec2_t * graphene_vec2_zero (void); |
127 | GRAPHENE_AVAILABLE_IN_1_0 |
128 | const graphene_vec2_t * graphene_vec2_one (void); |
129 | GRAPHENE_AVAILABLE_IN_1_0 |
130 | const graphene_vec2_t * graphene_vec2_x_axis (void); |
131 | GRAPHENE_AVAILABLE_IN_1_0 |
132 | const graphene_vec2_t * graphene_vec2_y_axis (void); |
133 | |
134 | GRAPHENE_END_DECLS |
135 | |