SH4ZAM! 0.9.1
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_vector.h
Go to the documentation of this file.
1/*! \file
2 * \brief Vector types and operations.
3 * \ingroup vector
4 *
5 * This file provides types and mathematical routines for representing and
6 * operating on vectors.
7 *
8 * \author 2025, 2026 Falco Girgis
9 * \author 2025 Paul Cercueil
10 *
11 * \copyright MIT License
12 */
13
14#ifndef SHZ_VECTOR_H
15#define SHZ_VECTOR_H
16
17#include <math.h>
18#include <float.h>
19
20#include "shz_scalar.h"
21#include "shz_trig.h"
22
23/** \defgroup vector Vector
24 * \brief API for vector math.
25 *
26 * The Vector API provides structures representing commonly-used vector types
27 * as well as routines implementing various mathematical operations on them.
28 */
29
30SHZ_DECLS_BEGIN
31
32/*! 2D Vector type
33 *
34 * Structure for holding coordinates of a 2-dimensional vector.
35 *
36 * \sa shz_vec3_t, shz_vec4_t
37 */
38typedef struct shz_vec2 {
39 union {
40 float e[2]; //!< <X, Y> coordinates as an array
41 struct {
42 float x; //!< X coordinate
43 float y; //!< Y coordinate
44 };
45 };
46} shz_vec2_t;
47
48//! Alternate typedef for the shz_vec2 struct for those who hate POSIX-style.
49typedef shz_vec2_t shz_vec2;
50
51/*! 3D Vector type
52 *
53 * Structure for holding coordinates of a 3-dimensional vector.
54 *
55 * \sa shz_vec2_t, shz_vec4_t
56 */
57typedef struct shz_vec3 {
58 union {
59 float e[3]; //!< <X, Y, Z> coordinates as an array
60 struct {
61 union {
62 struct {
63 float x; //!< X coordinate
64 float y; //!< Y coordinate
65 };
66 shz_vec2_t xy; //!< Inner 2D vector containing <X, Y> coords
67 };
68 float z; //!< Z coordinate
69 };
70 };
71} shz_vec3_t;
72
73//! Alternate typedef for the shz_vec3 struct for those who hate POSIX-style.
74typedef shz_vec3_t shz_vec3;
75
76/*! 4D Vector type
77 *
78 * Structure for holding coordinates of a 4-dimensional vector.
79 *
80 * \sa shz_vec2_t, shz_vec3_t
81 */
82typedef struct shz_vec4 {
83 union {
84 float e SHZ_SIMD(16); //!< <X, Y, Z, W> coordinates as an array.
85 struct {
86 union {
87 struct {
88 float x; //!< X coordinate
89 float y; //!< Y coordinate
90 float z; //!< Z coordinate
91 };
92 shz_vec3_t xyz; //!< <X, Y, Z> coordinates as a 3D vector
93 };
94 float w; //!< W coordinate
95 };
96 struct {
97 shz_vec2_t xy; //!< <X, Y> coordinates as a 2D vector
98 shz_vec2_t zw; //!< <Z, W> coordinates as a 2D vector
99 };
100 };
101} shz_vec4_t;
102
103
104//! Alternate typedef for the shz_vec4 struct for those who hate POSIX-style.
105typedef shz_vec4_t shz_vec4;
106
107/*! \name Initializers
108 \brief Component-based initialization routines.
109 @{
110*/
111
112//! Returns a 2D vector with the given \p x, and \p y coordinates.
113SHZ_INLINE shz_vec2_t shz_vec2_init(float x, float y) SHZ_NOEXCEPT;
114
115//! Returns a 3D vector with the given \p x, \p y, and \p z coordinates.
116SHZ_INLINE shz_vec3_t shz_vec3_init(float x, float y, float z) SHZ_NOEXCEPT;
117
118//! Returns a 4D vector with the given \p x, \p y, \p z, and \p w coordinates.
119SHZ_INLINE shz_vec4_t shz_vec4_init(float x, float y, float z, float w) SHZ_NOEXCEPT;
120
121//! Returns a 2D vector with the value of each component equal to \p v.
122SHZ_INLINE shz_vec2_t shz_vec2_fill(float v) SHZ_NOEXCEPT;
123
124//! Returns a 3D vector with the value of each compoonent equal to \p v.
125SHZ_INLINE shz_vec3_t shz_vec3_fill(float v) SHZ_NOEXCEPT;
126
127//! Returns a 4D vector with the value of each component equal to \p v.
128SHZ_INLINE shz_vec4_t shz_vec4_fill(float v) SHZ_NOEXCEPT;
129
130//! @}
131
132/*! \name Component-wise Operations
133 \brief Routines which apply to each vector component.
134 @{
135*/
136
137//! Returns a 2D vector whose components are the absolute values of the given vector's components.
138SHZ_INLINE shz_vec2_t shz_vec2_abs(shz_vec2_t vec) SHZ_NOEXCEPT;
139
140//! Returns a 3D vector whose components are the absolute values of the given vector's components.
141SHZ_INLINE shz_vec3_t shz_vec3_abs(shz_vec3_t vec) SHZ_NOEXCEPT;
142
143//! Returns a 4D vector whose components are the absolute values of the given vector's components.
144SHZ_INLINE shz_vec4_t shz_vec4_abs(shz_vec4_t vec) SHZ_NOEXCEPT;
145
146//! Returns a 2D vector whose components are the negative values of the given vector's components.
147SHZ_INLINE shz_vec2_t shz_vec2_neg(shz_vec2_t vec) SHZ_NOEXCEPT;
148
149//! Returns a 3D vector whose components are the negative values of the given vector's components.
150SHZ_INLINE shz_vec3_t shz_vec3_neg(shz_vec3_t vec) SHZ_NOEXCEPT;
151
152//! Returns a 4D vector whose components are the negative values of the given vector's components.
153SHZ_INLINE shz_vec4_t shz_vec4_neg(shz_vec4_t vec) SHZ_NOEXCEPT;
154
155//! Returns the 2D vector whose components have been inverted or reciprocated.
156SHZ_INLINE shz_vec2_t shz_vec2_inv(shz_vec2_t vec) SHZ_NOEXCEPT;
157
158//! Returns the 3D vector whose components have been inverted or reciprocated.
159SHZ_INLINE shz_vec3_t shz_vec3_inv(shz_vec3_t vec) SHZ_NOEXCEPT;
160
161//! Returns the 4D vector whose components have been inverted or reciprocated.
162SHZ_INLINE shz_vec4_t shz_vec4_inv(shz_vec4_t vec) SHZ_NOEXCEPT;
163
164//! Returns the maximum value of both of the given vector's components.
165SHZ_INLINE float shz_vec2_max(shz_vec2_t vec) SHZ_NOEXCEPT;
166
167//! Returns the maximum value of the given vector's 3 components.
168SHZ_INLINE float shz_vec3_max(shz_vec3_t vec) SHZ_NOEXCEPT;
169
170//! Returns the maximum value of the given vector's 4 componetns.
171SHZ_INLINE float shz_vec4_max(shz_vec4_t vec) SHZ_NOEXCEPT;
172
173//! Retuns the minimum value of both of the given vector's components.
174SHZ_INLINE float shz_vec2_min(shz_vec2_t vec) SHZ_NOEXCEPT;
175
176//! Returns the minimum value of the given vector's 3 components.
177SHZ_INLINE float shz_vec3_min(shz_vec3_t vec) SHZ_NOEXCEPT;
178
179//! Returns the minimum value of the given vector's 4 components.
180SHZ_INLINE float shz_vec4_min(shz_vec4_t vec) SHZ_NOEXCEPT;
181
182//! Clamps the values of the given 2D \p vec between \p min and \p max, returning a new vector.
183SHZ_INLINE shz_vec2_t shz_vec2_clamp(shz_vec2_t vec, float min, float max) SHZ_NOEXCEPT;
184
185//! Clamps the values of the given 3D \p vec between \p min and \p max, returning a new vector.
186SHZ_INLINE shz_vec3_t shz_vec3_clamp(shz_vec3_t vec, float min, float max) SHZ_NOEXCEPT;
187
188//! Clamps the values of the given 4D \p vec between \p min and \p max, returning a new vector.
189SHZ_INLINE shz_vec4_t shz_vec4_clamp(shz_vec4_t vec, float min, float max) SHZ_NOEXCEPT;
190
191//! Returns a 2D vector whose components are the floor of the given vector's components.
192SHZ_INLINE shz_vec2_t shz_vec2_floor(shz_vec2_t vec) SHZ_NOEXCEPT;
193
194//! Returns a 3D vector whose components are the floor of the given vector's components.
195SHZ_INLINE shz_vec3_t shz_vec3_floor(shz_vec3_t vec) SHZ_NOEXCEPT;
196
197//! Returns a 4D vector whose components are the floor of the given vector's components.
198SHZ_INLINE shz_vec4_t shz_vec4_floor(shz_vec4_t vec) SHZ_NOEXCEPT;
199
200//! Returns a 2D vector whose components are the ceil of the given vector's components.
201SHZ_INLINE shz_vec2_t shz_vec2_ceil(shz_vec2_t vec) SHZ_NOEXCEPT;
202
203//! Returns a 3D vector whose components are the ceil of the given vector's components.
204SHZ_INLINE shz_vec3_t shz_vec3_ceil(shz_vec3_t vec) SHZ_NOEXCEPT;
205
206//! Returns a 4D vector whose components are the ceil of the given vector's components.
207SHZ_INLINE shz_vec4_t shz_vec4_ceil(shz_vec4_t vec) SHZ_NOEXCEPT;
208
209//! Returns a 2D vector whose components are the rounded values of the given vector's components.
210SHZ_INLINE shz_vec2_t shz_vec2_round(shz_vec2_t vec) SHZ_NOEXCEPT;
211
212//! Returns a 3D vector whose components are the rounded values of the given vector's components.
213SHZ_INLINE shz_vec3_t shz_vec3_round(shz_vec3_t vec) SHZ_NOEXCEPT;
214
215//! Returns a 4D vector whose components are the rounded values of the given vector's components.
216SHZ_INLINE shz_vec4_t shz_vec4_round(shz_vec4_t vec) SHZ_NOEXCEPT;
217
218//! Returns a 2D vector whose components are the fractional parts of the given vector's components.
219SHZ_INLINE shz_vec2_t shz_vec2_fract(shz_vec2_t vec) SHZ_NOEXCEPT;
220
221//! Returns a 3D vector whose components are the fractional parts of the given vector's components.
222SHZ_INLINE shz_vec3_t shz_vec3_fract(shz_vec3_t vec) SHZ_NOEXCEPT;
223
224//! Returns a 4D vector whose components are the fractional parts of the given vector's components.
225SHZ_INLINE shz_vec4_t shz_vec4_fract(shz_vec4_t vec) SHZ_NOEXCEPT;
226
227//! Returns a 2D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
228SHZ_INLINE shz_vec2_t shz_vec2_sign(shz_vec2_t vec) SHZ_NOEXCEPT;
229
230//! Returns a 3D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
231SHZ_INLINE shz_vec3_t shz_vec3_sign(shz_vec3_t vec) SHZ_NOEXCEPT;
232
233//! Returns a 4D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
234SHZ_INLINE shz_vec4_t shz_vec4_sign(shz_vec4_t vec) SHZ_NOEXCEPT;
235
236//! Returns a 2D vector whose components are saturated (clamped to [0, 1]) values of the given vector's components.
237SHZ_INLINE shz_vec2_t shz_vec2_saturate(shz_vec2_t vec) SHZ_NOEXCEPT;
238
239//! Returns a 3D vector whose components are saturated (clamped to [0, 1]) values of the given vector's components.
240SHZ_INLINE shz_vec3_t shz_vec3_saturate(shz_vec3_t vec) SHZ_NOEXCEPT;
241
242//! Returns a 4D vector whose components are saturated (clamped to [0, 1]) values of the given vector's components.
243SHZ_INLINE shz_vec4_t shz_vec4_saturate(shz_vec4_t vec) SHZ_NOEXCEPT;
244
245//! Returns a 2D vector whose components are the pairwise minimums of the two given vectors' components.
246SHZ_INLINE shz_vec2_t shz_vec2_minv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT;
247
248//! Returns a 3D vector whose components are the pairwise minimums of the two given vectors' components.
249SHZ_INLINE shz_vec3_t shz_vec3_minv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT;
250
251//! Returns a 4D vector whose components are the pairwise minimums of the two given vectors' components.
252SHZ_INLINE shz_vec4_t shz_vec4_minv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT;
253
254//! Returns a 2D vector whose components are the pairwise maximums of the two given vectors' components.
255SHZ_INLINE shz_vec2_t shz_vec2_maxv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT;
256
257//! Returns a 3D vector whose components are the pairwise maximums of the two given vectors' components.
258SHZ_INLINE shz_vec3_t shz_vec3_maxv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT;
259
260//! Returns a 4D vector whose components are the pairwise maximums of the two given vectors' components.
261SHZ_INLINE shz_vec4_t shz_vec4_maxv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT;
262
263//! Returns true if the values of each element within the two 2D vectors are approximately equal based on relative or absolute tolerance.
264SHZ_INLINE bool shz_vec2_equal(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT;
265
266//! Returns true if the values of each element within the two 3D vectors are approximately equal based on relative or absolute tolerance.
267SHZ_INLINE bool shz_vec3_equal(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT;
268
269//! Returns true if the values of each element within the two 4D vectors are approximately equal based on relative or absolute tolerance.
270SHZ_INLINE bool shz_vec4_equal(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT;
271
272//! For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f
273SHZ_INLINE shz_vec2_t shz_vec2_stepv( shz_vec2_t vec, shz_vec2_t edge) SHZ_NOEXCEPT;
274
275//! For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f
276SHZ_INLINE shz_vec3_t shz_vec3_stepv(shz_vec3_t vec, shz_vec3_t edge) SHZ_NOEXCEPT;
277
278//! For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f
279SHZ_INLINE shz_vec4_t shz_vec4_stepv(shz_vec4_t vec, shz_vec4_t edge) SHZ_NOEXCEPT;
280
281//! For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f
282SHZ_INLINE shz_vec2_t shz_vec2_step(shz_vec2_t vec, float edge) SHZ_NOEXCEPT;
283
284//! For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f
285SHZ_INLINE shz_vec3_t shz_vec3_step(shz_vec3_t vec, float edge) SHZ_NOEXCEPT;
286
287//! For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f
288SHZ_INLINE shz_vec4_t shz_vec4_step(shz_vec4_t vec, float edge) SHZ_NOEXCEPT;
289
290//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
291SHZ_INLINE shz_vec2_t shz_vec2_smoothstep(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
292
293//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between
294SHZ_INLINE shz_vec3_t shz_vec3_smoothstep(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
295
296//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between
297SHZ_INLINE shz_vec4_t shz_vec4_smoothstep(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
298
299//! For each component: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between.
300SHZ_INLINE shz_vec2_t shz_vec2_smoothstepv(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_NOEXCEPT;
301
302//! For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between.
303SHZ_INLINE shz_vec3_t shz_vec3_smoothstepv(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_NOEXCEPT;
304
305//! For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between.
306SHZ_INLINE shz_vec4_t shz_vec4_smoothstepv(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_NOEXCEPT;
307
308//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between. Accepts inverse edges.
309SHZ_INLINE shz_vec2_t shz_vec2_smoothstep_safe(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
310
311//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between. Accepts inverse edges.
312SHZ_INLINE shz_vec3_t shz_vec3_smoothstep_safe(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
313
314//! For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between. Accepts inverse edges.
315SHZ_INLINE shz_vec4_t shz_vec4_smoothstep_safe(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT;
316
317//! For each component: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between. Accepts inverse edges.
318SHZ_INLINE shz_vec2_t shz_vec2_smoothstepv_safe(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_NOEXCEPT;
319
320//! For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between. Accepts inverse edges.
321SHZ_INLINE shz_vec3_t shz_vec3_smoothstepv_safe(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_NOEXCEPT;
322
323//! For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-between. Accepts inverse edges.
324SHZ_INLINE shz_vec4_t shz_vec4_smoothstepv_safe(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_NOEXCEPT;
325
326//! Returns a 2D vector whose components are the inverse square root of the given vector's components.
327SHZ_INLINE shz_vec2_t shz_vec2_inv_sqrtf(shz_vec2_t vec) SHZ_NOEXCEPT;
328
329//! Returns a 3D vector whose components are the inverse square root of the given vector's components.
330SHZ_INLINE shz_vec3_t shz_vec3_inv_sqrtf(shz_vec3_t vec) SHZ_NOEXCEPT;
331
332//! Returns a 4D vector whose components are the inverse square root of the given vector's components.
333SHZ_INLINE shz_vec4_t shz_vec4_inv_sqrtf(shz_vec4_t vec) SHZ_NOEXCEPT;
334
335//! Returns a 2D vector whose components are the square root of the given vector's components.
336SHZ_INLINE shz_vec2_t shz_vec2_sqrtf(shz_vec2_t vec) SHZ_NOEXCEPT;
337
338//! Returns a 3D vector whose components are the square root of the given vector's components.
339SHZ_INLINE shz_vec3_t shz_vec3_sqrtf(shz_vec3_t vec) SHZ_NOEXCEPT;
340
341//! Returns a 4D vector whose components are the square root of the given vector's components.
342SHZ_INLINE shz_vec4_t shz_vec4_sqrtf(shz_vec4_t vec) SHZ_NOEXCEPT;
343
344
345//! @}
346
347/*! \name Arithmetic
348 \brief Routines for basic vector arithmetic operations.
349 @{
350*/
351
352//! Returns a 2D vector whose components are the sums of the given vectors' components.
353SHZ_INLINE shz_vec2_t shz_vec2_add(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
354
355//! Returns a 3D vector whose components are the sums of the given vectors' components.
356SHZ_INLINE shz_vec3_t shz_vec3_add(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
357
358//! Returns a 4D vector whose components are the sums of the given vectors' components.
359SHZ_INLINE shz_vec4_t shz_vec4_add(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
360
361//! Returns a 2D vector whose components are equal to the values of \p vec1 minus \p vec2.
362SHZ_INLINE shz_vec2_t shz_vec2_sub(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
363
364//! Returns a 3D vector whose components are equal to the values of \p vec1 minus \p vec2.
365SHZ_INLINE shz_vec3_t shz_vec3_sub(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
366
367//! Returns a 4D vector whose components are equal to the values of \p vec1 minus \p vec2.
368SHZ_INLINE shz_vec4_t shz_vec4_sub(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
369
370//! Returns a 2D vector whose component values are those of \p vec1 times \p vec2.
371SHZ_INLINE shz_vec2_t shz_vec2_mul(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
372
373//! Returns a 3D vector whose component values are those of \p vec1 times \p vec2.
374SHZ_INLINE shz_vec3_t shz_vec3_mul(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
375
376//! Returns a 4D vector whose component values are those of \p vec1 times \p vec2.
377SHZ_INLINE shz_vec4_t shz_vec4_mul(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
378
379//! Returns a 2D vector whose component values are those of \p vec1 divided by \p vec2.
380SHZ_INLINE shz_vec2_t shz_vec2_div(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
381
382//! Returns a 3D vector whose component values are those of \p vec1 divided by \p vec2.
383SHZ_INLINE shz_vec3_t shz_vec3_div(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
384
385//! Returns a 4D vector whose component values are those of \p vec1 divided by \p vec2.
386SHZ_INLINE shz_vec4_t shz_vec4_div(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
387
388//! Returns a 2D vector whose component values are those of the given vector multiplied by a factor.
389SHZ_INLINE shz_vec2_t shz_vec2_scale(shz_vec2_t vec, float factor) SHZ_NOEXCEPT;
390
391//! Returns a 3D vector whose component values are those of the given vector multiplied by a factor.
392SHZ_INLINE shz_vec3_t shz_vec3_scale(shz_vec3_t vec, float factor) SHZ_NOEXCEPT;
393
394//! Returns a 4D vector whose component values are those of the given vector multiplied by a factor.
395SHZ_INLINE shz_vec4_t shz_vec4_scale(shz_vec4_t vec, float factor) SHZ_NOEXCEPT;
396
397//! @}
398
399/*! \name Magnitude
400 \brief Math routines for vector length and normalization.
401 @{
402*/
403
404//! Returns the squared magnitude of the given 2D vector.
405SHZ_INLINE float shz_vec2_magnitude_sqr(shz_vec2_t vec) SHZ_NOEXCEPT;
406
407//! Returns the squared magnitude of the given 4D vector.
408SHZ_INLINE float shz_vec4_magnitude_sqr(shz_vec4_t vec) SHZ_NOEXCEPT;
409
410//! Returns the squared magnitude of the given 3D vector.
411SHZ_INLINE float shz_vec3_magnitude_sqr(shz_vec3_t vec) SHZ_NOEXCEPT;
412
413//! Returns the magnitude of the given 2D vector.
414SHZ_INLINE float shz_vec2_magnitude(shz_vec2_t vec) SHZ_NOEXCEPT;
415
416//! Returns the magnitude of the given 3D vector.
417SHZ_INLINE float shz_vec3_magnitude(shz_vec3_t vec) SHZ_NOEXCEPT;
418
419//! Returns the magnitude of the given 4D vector.
420SHZ_INLINE float shz_vec4_magnitude(shz_vec4_t vec) SHZ_NOEXCEPT;
421
422//! Returns the inverse magnitude of the given 2D vector.
423SHZ_INLINE float shz_vec2_magnitude_inv(shz_vec2_t vec) SHZ_NOEXCEPT;
424
425//! Returns the inverse magnitude of the given 3D vector.
426SHZ_INLINE float shz_vec3_magnitude_inv(shz_vec3_t vec) SHZ_NOEXCEPT;
427
428//! Returns the inverse magnitude of the given 4D vector.
429SHZ_INLINE float shz_vec4_magnitude_inv(shz_vec4_t vec) SHZ_NOEXCEPT;
430
431//! Returns a normalized unit vector from the given 2D vector.
432SHZ_INLINE shz_vec2_t shz_vec2_normalize(shz_vec2_t vec) SHZ_NOEXCEPT;
433
434//! Returns a normalized unit vector from the given 3D vector.
435SHZ_INLINE shz_vec3_t shz_vec3_normalize(shz_vec3_t vec) SHZ_NOEXCEPT;
436
437//! Returns a normalized unit vector from the given 4D vector.
438SHZ_INLINE shz_vec4_t shz_vec4_normalize(shz_vec4_t vec) SHZ_NOEXCEPT;
439
440/*! SAFELY returns a normalized unit vector from the given 2D vector.
441
442 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
443*/
444SHZ_INLINE shz_vec2_t shz_vec2_normalize_safe(shz_vec2_t vec) SHZ_NOEXCEPT;
445
446/*! SAFELY returns a normalized unit vector from the given 3D vector.
447
448 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
449*/
450SHZ_INLINE shz_vec3_t shz_vec3_normalize_safe(shz_vec3_t vec) SHZ_NOEXCEPT;
451
452/*! SAFELY returns a normalized unit vector from the given 4D vector.
453
454 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
455*/
456SHZ_INLINE shz_vec4_t shz_vec4_normalize_safe(shz_vec4_t vec) SHZ_NOEXCEPT;
457
458//! @}
459
460/*! \name Binary Operations
461 \brief Linear algebra operations performed with multiple vectors.
462 @{
463*/
464
465//! Returns the dot product between the two given 2D vectors.
466SHZ_INLINE float shz_vec2_dot(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
467
468//! Returns the two dot products taken between the 2D vector \p l and 2D vectors \p r1 and \p r2.
469SHZ_INLINE shz_vec2_t shz_vec2_dot2(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2) SHZ_NOEXCEPT;
470
471//! Returns the three dot products taken between the 2D vector \p l and 2D vectors \p r1, \p r2, and \p r3.
472SHZ_INLINE shz_vec3_t shz_vec2_dot3(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2, shz_vec2_t r3) SHZ_NOEXCEPT;
473
474//! Returns the dot product between the two given 3D vectors.
475SHZ_INLINE float shz_vec3_dot(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
476
477//! Returns the two dot products taken between the 3D vector \p l and 3D vectors \p r1 and \p r2.
478SHZ_INLINE shz_vec2_t shz_vec3_dot2(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2) SHZ_NOEXCEPT;
479
480//! Returns the three dot products taken between the 3D vector \p l and 3D vectors \p r1, \p r2, and \p r3.
481SHZ_INLINE shz_vec3_t shz_vec3_dot3(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2, shz_vec3_t r3) SHZ_NOEXCEPT;
482
483//! Returns the dot product between the two given 4D vectors.
484SHZ_INLINE float shz_vec4_dot(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
485
486//! Returns the two dot products taken between the 4D vector \p l and 4D vectors \p r1 and \p r2.
487SHZ_INLINE shz_vec2_t shz_vec4_dot2(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2) SHZ_NOEXCEPT;
488
489//! Returns the three dot products taken between the 4D vector \p l and 4D vectors \p r1, \p r2, and \p r3.
490SHZ_INLINE shz_vec3_t shz_vec4_dot3(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2, shz_vec4_t r3) SHZ_NOEXCEPT;
491
492//! Returns the distance between the two given 2D vectors.
493SHZ_INLINE float shz_vec2_distance(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
494
495//! Returns the distance between the two given 3D vectors.
496SHZ_INLINE float shz_vec3_distance(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
497
498//! Returns the distance between the two given 4D vectors.
499SHZ_INLINE float shz_vec4_distance(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
500
501//! Returns the squared-distance between the two given 2D vectors.
502SHZ_INLINE float shz_vec2_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
503
504//! Returns the squared-distance between the two given 3D vectors.
505SHZ_INLINE float shz_vec3_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
506
507//! Returns the squared-distance between the two given 4D vectors.
508SHZ_INLINE float shz_vec4_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
509
510//! Returns the given 2D vector, translated towards the \p target by the given \p max_distance.
511SHZ_INLINE shz_vec2_t shz_vec2_move(shz_vec2_t vec, shz_vec2_t target, float max_distance) SHZ_NOEXCEPT;
512
513//! Returns the given 3D vector, translated towards the \p target by the given \p max_distance.
514SHZ_INLINE shz_vec3_t shz_vec3_move(shz_vec3_t vec, shz_vec3_t target, float max_distance) SHZ_NOEXCEPT;
515
516//! Returns the given 4D vector, translated towards the \p target by the given \p max_distance.
517SHZ_INLINE shz_vec4_t shz_vec4_move(shz_vec4_t vec, shz_vec4_t target, float max_distance) SHZ_NOEXCEPT;
518
519//! Returns a 2D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
520SHZ_INLINE shz_vec2_t shz_vec2_lerp(shz_vec2_t a, shz_vec2_t b, float t) SHZ_NOEXCEPT;
521
522//! Returns a 3D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
523SHZ_INLINE shz_vec3_t shz_vec3_lerp(shz_vec3_t a, shz_vec3_t b, float t) SHZ_NOEXCEPT;
524
525//! Returns a 4D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
526SHZ_INLINE shz_vec4_t shz_vec4_lerp(shz_vec4_t a, shz_vec4_t b, float t) SHZ_NOEXCEPT;
527
528//! Reflects the given 2D \p incidence vector against a surface with the given \p normal, returning the result.
529SHZ_INLINE shz_vec2_t shz_vec2_reflect(shz_vec2_t incidence, shz_vec2_t normal) SHZ_NOEXCEPT;
530
531//! Reflects the given 3D \p incidence vector against a surface with the given \p normal, returning the result.
532SHZ_INLINE shz_vec3_t shz_vec3_reflect(shz_vec3_t incidence, shz_vec3_t normal) SHZ_NOEXCEPT;
533
534//! Reflects the given 4D \p incidence vector against a surface with the given \p normal, returning the result.
535SHZ_INLINE shz_vec4_t shz_vec4_reflect(shz_vec4_t incidence, shz_vec4_t normal) SHZ_NOEXCEPT;
536
537//! Refracts the given 2D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
538SHZ_INLINE shz_vec2_t shz_vec2_refract(shz_vec2_t incidence, shz_vec2_t normal, float eta) SHZ_NOEXCEPT;
539
540//! Refracts the given 3D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
541SHZ_INLINE shz_vec3_t shz_vec3_refract(shz_vec3_t incidence, shz_vec3_t normal, float eta) SHZ_NOEXCEPT;
542
543//! Refracts the given 4D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
544SHZ_INLINE shz_vec4_t shz_vec4_refract(shz_vec4_t incidence, shz_vec4_t normal, float eta) SHZ_NOEXCEPT;
545
546/*! Returns the cross product, as a scalar, between two 2D vectors.
547
548 \note
549 The definition of the cross-product is ambiguous in 2D space, but the geometric
550 interpretation here is that the result is the magnitude of the orthogonal vector
551 created from the given two along the Z-axis.
552*/
553SHZ_INLINE float shz_vec2_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
554
555//! Returns the vector produced by taking the cross-product of the two given 3D vectors.
556SHZ_INLINE shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
557
558//! Returns the resulting vector from projecting the given 2D vector along the given (unit) axis
559SHZ_INLINE shz_vec2_t shz_vec2_project(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT;
560
561//! Returns the resulting vector from projecting the given 3D vector along the given (unit) axis
562SHZ_INLINE shz_vec3_t shz_vec3_project(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
563
564//! Returns the resulting vector from projecting the given 4D vector along the given (unit) axis
565SHZ_INLINE shz_vec4_t shz_vec4_project(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT;
566
567/*! Returns the resulting vector from projecting the given 2D vector along the given (unit) axis
568
569 \note
570 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
571*/
572SHZ_INLINE shz_vec2_t shz_vec2_project_safe(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT;
573
574/*! Returns the resulting vector from projecting the given 3D vector along the given (unit) axis
575
576 \note
577 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
578*/
579SHZ_INLINE shz_vec3_t shz_vec3_project_safe(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
580
581/*! Returns the resulting vector from projecting the given 4D vector along the given (unit) axis
582
583 \note
584 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
585*/
586SHZ_INLINE shz_vec4_t shz_vec4_project_safe(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT;
587
588//! Returns the rejection of the given vector, \p vec, onto another vector, \p onto.
589SHZ_INLINE shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
590
591//! @}
592
593/*! \name Miscellaneous
594 \brief Other specialized vector routines.
595 @{
596*/
597
598//! Returns the 3D vector "triple product" between vector's \p a, \p b, and \p c.
599SHZ_INLINE float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT;
600
601//! Returns a vector which is perpendicular to the given vector.
602SHZ_INLINE shz_vec3_t shz_vec3_perp(shz_vec3_t vec) SHZ_NOEXCEPT;
603
604//! Computes barycentric coordinates `<u, v, w>` for point p, within the plane of the triangle with vertices \p a, \p b, and \p c.
605SHZ_INLINE shz_vec3_t shz_vec3_barycenter(shz_vec3_t p, shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT;
606
607//! Returns 2 3D vectors which are normalized and orthogonal to the two input vectors.
608SHZ_INLINE void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t* out1, shz_vec3_t* out2) SHZ_NOEXCEPT;
609
610//! Calculates the cubic hermite interpolation between two vectors and their tangents.
611SHZ_INLINE shz_vec3_t shz_vec3_cubic_hermite(shz_vec3_t vec, shz_vec3_t tangent1, shz_vec3_t vec2, shz_vec3_t tangent2, float amounht) SHZ_NOEXCEPT;
612
613//! @}
614
615/*! \name Angles
616 \brief Routines for working with vectors and angles.
617 @{
618*/
619
620//! Returns the angle formed between the given 2D vectors in radians.
621SHZ_INLINE float shz_vec2_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
622
623//! Returns the angle formed between the given 3D vectors in radians.
624SHZ_INLINE float shz_vec3_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
625
626//! Returns the angle formed between the positive X axis and the given 2D vector, in radians.
627SHZ_INLINE float shz_vec2_angle(shz_vec2_t vec) SHZ_NOEXCEPT;
628
629//! Returns the angles formed between the positive X axis and the given 3D vector, in radians.
630SHZ_INLINE shz_vec3_t shz_vec3_angles(shz_vec3_t vec) SHZ_NOEXCEPT;
631
632//! Returns the 2D unit vector representing a rotation from the positive X axis.
633SHZ_INLINE shz_vec2_t shz_vec2_from_sincos(shz_sincos_t sincos) SHZ_NOEXCEPT;
634
635//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis.
636SHZ_INLINE shz_vec3_t shz_vec3_from_sincos(shz_sincos_t azimuth, shz_sincos_t elevation) SHZ_NOEXCEPT;
637
638//! Returns the 2D unit vector representing a rotation from the positive X axis in radians.
639SHZ_INLINE shz_vec2_t shz_vec2_from_angle(float radians) SHZ_NOEXCEPT;
640
641//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in radians.
642SHZ_INLINE shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) SHZ_NOEXCEPT;
643
644//! Returns the 2D unit vector representing a rotation from the positive X axis in degrees.
645SHZ_INLINE shz_vec2_t shz_vec2_from_angle_deg(float degrees) SHZ_NOEXCEPT;
646
647//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in degrees.
648SHZ_INLINE shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) SHZ_NOEXCEPT;
649
650//! Rotates the given 2D vector about the Z axis by the given angle in radians.
651SHZ_INLINE shz_vec2_t shz_vec2_rotate(shz_vec2_t vec, float radians) SHZ_NOEXCEPT;
652
653/*! Rotates the given 3D vector about the X axis by the given angle in radians.
654
655 \warning
656 This routine should only be used for one-off rotations of a single vector.
657 To rotate multiple vectors in a batch, use the XMTRX API.
658
659 \sa shz_xmtrx_apply_rotation_x()
660*/
661SHZ_INLINE shz_vec3_t shz_vec3_rotate_x(shz_vec3_t vec, float radians) SHZ_NOEXCEPT;
662
663/*! Rotates the given 3D vector about the Y axis by the given angle in radians.
664
665 \warning
666 This routine should only be used for one-off rotations of a single vector.
667 To rotate multiple vectors in a batch, use the XMTRX API.
668
669 \sa shz_xmtrx_apply_rotation_y()
670*/
671SHZ_INLINE shz_vec3_t shz_vec3_rotate_y(shz_vec3_t vec, float radians) SHZ_NOEXCEPT;
672
673/*! Rotates the given 3D vector about the Z axis by the given angle in radians.
674
675 \warning
676 This routine should only be used for one-off rotations of a single vector.
677 To rotate multiple vectors in a batch, use the XMTRX API.
678
679 \sa shz_xmtrx_apply_rotation_z()
680*/
681SHZ_INLINE shz_vec3_t shz_vec3_rotate_z(shz_vec3_t vec, float radians) SHZ_NOEXCEPT;
682
683//! @}
684
685/*! \name Extending
686 \brief Routines for extending vectors into other dimensions.
687 @{
688 */
689
690//! Extends a 2D vector to 3D, using \p z as the value of the Z component.
691SHZ_INLINE shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) SHZ_NOEXCEPT;
692
693//! Extends a 2D vector to 4D, using \p z and \p w as the values of the Z and W components.
694SHZ_INLINE shz_vec4_t shz_vec2_vec4(shz_vec2_t vec, float z, float w) SHZ_NOEXCEPT;
695
696//! Extends a 3D vector to 4D, using \p w as the value of the W component.
697SHZ_INLINE shz_vec4_t shz_vec3_vec4(shz_vec3_t vec, float w) SHZ_NOEXCEPT;
698
699//! @}
700
701/*! \name Swizzling
702 \brief Routines for swizzling the order of a vector's components.
703 @{
704 */
705
706 //! Returns a 2D vector whose elements are equal to the source vector's values at the given indices.
707 SHZ_INLINE shz_vec2_t shz_vec2_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) SHZ_NOEXCEPT;
708
709 //! Returns a 3D vector whose elements are equal to the source vector's values at the given indices.
710 SHZ_INLINE shz_vec3_t shz_vec3_swizzle(shz_vec3_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx) SHZ_NOEXCEPT;
711
712 //! Returns a new 2D vector whose elements are equal to the source vector's values at the given indices.
713 SHZ_INLINE shz_vec4_t shz_vec4_swizzle(shz_vec4_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx, unsigned w_idx) SHZ_NOEXCEPT;
714
715 //! @}
716
717SHZ_DECLS_END
718
719/*! \name Adapters
720 \brief Macros for converting between SH4ZAM and other compatible formats.
721 @{
722*/
723
724//! Dereferences the given pointer to a sequence of 2 floats as a shz_vec2_t.
725#define shz_vec2_deref(ptr) (*((SHZ_ALIASING shz_vec2_t*)(ptr)))
726
727//! Dereferences the given pointer to a sequence of 3 floats as a shz_vec3_t.
728#define shz_vec3_deref(ptr) (*((SHZ_ALIASING shz_vec3_t*)(ptr)))
729
730//! Dereferences the given pointer to a sequence of 4 floats as a shz_vec4_t.
731#define shz_vec4_deref(ptr) (*((SHZ_ALIASING shz_vec4_t*)(ptr)))
732
733//! Converts the given \p value or expression to the equivalent 2D SH4ZAM vector value.
734#define shz_vec2_from(value) SHZ_CONVERT(shz_vec2_t, value)
735
736//! Converts the given \p value or expression to the equivalent 3D SH4ZAM vector value.
737#define shz_vec3_from(value) SHZ_CONVERT(shz_vec3_t, value)
738
739//! Converts the given \p value or expression to the equivalent 4D SH4ZAM vector value.
740#define shz_vec4_from(value) SHZ_CONVERT(shz_vec4_t, value)
741
742//! Converts the given 2D \p vector into a value of the given \p type.
743#define shz_vec2_to(type, vector) SHZ_CONVERT(type, vector)
744
745//! Converts the given 3D \p vector into a value of the given \p type.
746#define shz_vec3_to(type, vector) SHZ_CONVERT(type, vector)
747
748//! Converts the given 4D \p vector into a value of the given \p type.
749#define shz_vec4_to(type, vector) SHZ_CONVERT(type, vector)
750
751//! @}
752
753/*! \name Type-Generic Routines
754 \brief Generalized vector routines for C and C++.
755 @{
756*/
757
758#ifndef __cplusplus
759
760 //! C type-generic vector absolute value.
761# define shz_vec_abs(vec)
762 _Generic((vec),
763 shz_vec2_t: shz_vec2_abs,
764 shz_vec3_t: shz_vec3_abs,
765 shz_vec4_t: shz_vec4_abs)(vec)
766
767 //! C type-generic vector negation.
768# define shz_vec_neg(vec)
769 _Generic((vec),
770 shz_vec2_t: shz_vec2_neg,
771 shz_vec3_t: shz_vec3_neg,
772 shz_vec4_t: shz_vec4_neg)(vec)
773
774 //! C type-generic vector inversion.
775# define shz_vec_inv(vec)
776 _Generic((vec),
777 shz_vec2_t: shz_vec2_inv,
778 shz_vec3_t: shz_vec3_inv,
779 shz_vec4_t: shz_vec4_inv)(vec)
780
781 //! C type-generic vector maximum value.
782# define shz_vec_max(vec)
783 _Generic((vec),
784 shz_vec2_t: shz_vec2_max,
785 shz_vec3_t: shz_vec3_max,
786 shz_vec4_t: shz_vec4_max)(vec)
787
788 //! C type-generic vector minimum value.
789# define shz_vec_min(vec)
790 _Generic((vec),
791 shz_vec2_t: shz_vec2_min,
792 shz_vec3_t: shz_vec3_min,
793 shz_vec4_t: shz_vec4_min)(vec)
794
795 //! C type-generic vector minimum value.
796# define shz_vec_clamp(vec, min, max)
797 _Generic((vec),
798 shz_vec2_t: shz_vec2_clamp,
799 shz_vec3_t: shz_vec3_clamp,
800 shz_vec4_t: shz_vec4_clamp)(vec, min, max)
801
802 //! C type-generic vector equals.
803# define shz_vec_equal(vec1, vec2)
804 _Generic((vec1),
805 shz_vec2_t: shz_vec2_equal,
806 shz_vec3_t: shz_vec3_equal,
807 shz_vec4_t: shz_vec4_equal)(vec1, vec2)
808
809 //! C type-generic vector addition.
810# define shz_vec_add(vec1, vec2)
811 _Generic((vec1),
812 shz_vec2_t: shz_vec2_add,
813 shz_vec3_t: shz_vec3_add,
814 shz_vec4_t: shz_vec4_add)(vec1, vec2)
815
816 //! C type-generic vector subtraction.
817# define shz_vec_sub(vec1, vec2)
818 _Generic((vec1),
819 shz_vec2_t: shz_vec2_sub,
820 shz_vec3_t: shz_vec3_sub,
821 shz_vec4_t: shz_vec4_sub)(vec1, vec2)
822
823 //! C type-generic vector multiplication.
824# define shz_vec_mul(vec1, vec2)
825 _Generic((vec1),
826 shz_vec2_t: shz_vec2_mul,
827 shz_vec3_t: shz_vec3_mul,
828 shz_vec4_t: shz_vec4_mul)(vec1, vec2)
829
830 //! C type-generic vector division.
831# define shz_vec_div(vec1, vec2)
832 _Generic((vec1),
833 shz_vec2_t: shz_vec2_div,
834 shz_vec3_t: shz_vec3_div,
835 shz_vec4_t: shz_vec4_div)(vec1, vec2)
836
837 //! C type-generic vector scaling.
838# define shz_vec_scale(vec, factor)
839 _Generic((vec),
840 shz_vec2_t: shz_vec2_scale,
841 shz_vec3_t: shz_vec3_scale,
842 shz_vec4_t: shz_vec4_scale)(vec, factor)
843
844 //! C type-generic vector dot product.
845# define shz_vec_dot(vec1, vec2)
846 _Generic((vec1),
847 shz_vec2_t: shz_vec2_dot,
848 shz_vec3_t: shz_vec3_dot,
849 shz_vec4_t: shz_vec4_dot)(vec1, vec2)
850
851 //! C type-generic vector chained double dot product.
852# define shz_vec_dot2(l, r1, r2)
853 _Generic((l),
854 shz_vec2_t: shz_vec2_dot2,
855 shz_vec3_t: shz_vec3_dot2,
856 shz_vec4_t: shz_vec4_dot2)(l, r1, r2)
857
858 //! C type-generic vector chained triple dot product.
859# define shz_vec_dot3(l, r1, r2, r3)
860 _Generic((l),
861 shz_vec2_t: shz_vec2_dot3,
862 shz_vec3_t: shz_vec3_dot3,
863 shz_vec4_t: shz_vec4_dot3)(l, r1, r2, r3)
864
865 //! C type-generic vector squared magnitude.
866# define shz_vec_magnitude_sqr(vec)
867 _Generic((vec),
868 shz_vec2_t: shz_vec2_magnitude_sqr,
869 shz_vec3_t: shz_vec3_magnitude_sqr,
870 shz_vec4_t: shz_vec4_magnitude_sqr)(vec)
871
872 //! C type-generic vector magnitude.
873# define shz_vec_magnitude(vec)
874 _Generic((vec),
875 shz_vec2_t: shz_vec2_magnitude,
876 shz_vec3_t: shz_vec3_magnitude,
877 shz_vec4_t: shz_vec4_magnitude)(vec)
878
879 //! C type-generic vector inverse magnitude.
880# define shz_vec_magnitude_inv(vec)
881 _Generic((vec),
882 shz_vec2_t: shz_vec2_magnitude_inv,
883 shz_vec3_t: shz_vec3_magnitude_inv,
884 shz_vec4_t: shz_vec4_magnitude_inv)(vec)
885
886 //! C type-generic vector normalization.
887# define shz_vec_normalize(vec)
888 _Generic((vec),
889 shz_vec2_t: shz_vec2_normalize,
890 shz_vec3_t: shz_vec3_normalize,
891 shz_vec4_t: shz_vec4_normalize)(vec)
892
893 //! C type-generic safe vector normalization.
894# define shz_vec_normalize_safe(vec)
895 _Generic((vec),
896 shz_vec2_t: shz_vec2_normalize_safe,
897 shz_vec3_t: shz_vec3_normalize_safe,
898 shz_vec4_t: shz_vec4_normalize_safe)(vec)
899
900 //! C type-generic vector distance.
901# define shz_vec_distance(vec1, vec2)
902 _Generic((vec1),
903 shz_vec2_t: shz_vec2_distance,
904 shz_vec3_t: shz_vec3_distance,
905 shz_vec4_t: shz_vec4_distance)(vec1, vec2)
906
907 //! C type-generic vector move.
908# define shz_vec_move(vec, target, maxdist)
909 _Generic((vec),
910 shz_vec2_t: shz_vec2_move,
911 shz_vec3_t: shz_vec3_move,
912 shz_vec4_t: shz_vec4_move)(vec, target, maxdist)
913
914 //! C type-generic vector squared distance.
915# define shz_vec_distance_sqr(vec1, vec2)
916 _Generic((vec1),
917 shz_vec2_t: shz_vec2_distance_sqr,
918 shz_vec3_t: shz_vec3_distance_sqr,
919 shz_vec4_t: shz_vec4_distance_sqr)(vec1, vec2)
920
921 //! C type-generic linear interpolation between two vectors.
922# define shz_vec_lerp(vec1, vec2, t)
923 _Generic((vec1),
924 shz_vec2_t: shz_vec2_lerp,
925 shz_vec3_t: shz_vec3_lerp,
926 shz_vec4_t: shz_vec4_lerp)(vec1, vec2, t)
927
928 //! C type-generic vector reflection.
929# define shz_vec_reflect(incidence, normal)
930 _Generic((incidence),
931 shz_vec2_t: shz_vec2_reflect,
932 shz_vec3_t: shz_vec3_reflect,
933 shz_vec4_t: shz_vec4_reflect)(incidence, normal)
934
935 //! C type-generic vector refraction.
936# define shz_vec_refract(incidence, normal, eta)
937 _Generic((incidence),
938 shz_vec2_t: shz_vec2_refract,
939 shz_vec3_t: shz_vec3_refract,
940 shz_vec4_t: shz_vec4_refract)(incidence, normal, eta)
941
942 //! C type-generic vector cross-product.
943# define shz_vec_cross(vec1, vec2)
944 _Generic((vec1),
945 shz_vec2_t: shz_vec2_cross,
946 shz_vec3_t: shz_vec3_cross)(vec1, vec2)
947
948 //! C type-generic vector projection.
949# define shz_vec_project(vec1, vec2)
950 _Generic((vec1),
951 shz_vec2_t: shz_vec2_project,
952 shz_vec3_t: shz_vec3_project,
953 shz_vec4_t: shz_vec4_project)(vec1, vec2)
954
955 //! C type-generic safe vector projection.
956# define shz_vec_project_safe(vec1, vec2)
957 _Generic((vec1),
958 shz_vec2_t: shz_vec2_project_safe,
959 shz_vec3_t: shz_vec3_project_safe,
960 shz_vec4_t: shz_vec4_project_safe)(vec1, vec2)
961
962 //! C type-generic angle-from-vector extraction.
963# define shz_vec_angles(vec)
964 _Generic((vec),
965 shz_vec2_t: shz_vec2_angle,
966 shz_vec3_t: shz_vec3_angles)(vec)
967
968 //! C type-generic angle between two vectors.
969# define shz_vec_angle_between(vec1, vec2)
970 _Generic((vec1),
971 shz_vec2_t: shz_vec2_angle_between,
972 shz_vec3_t: shz_vec3_angle_between)(vec1, vec2)
973
974 //! C type-generic vector swizzling.
975# define shz_vec_swizzle(vec, ...)
976 _Generic((vec),
977 shz_vec2_t: shz_vec2_swizzle,
978 shz_vec3_t: shz_vec3_swizzle,
979 shz_vec4_t: shz_vec4_swizzle)(vec, __VA_ARGS__)
980
981 //! C type-generic component-wise floor.
982# define shz_vec_floor(vec)
983 _Generic((vec),
984 shz_vec2_t: shz_vec2_floor,
985 shz_vec3_t: shz_vec3_floor,
986 shz_vec4_t: shz_vec4_floor)(vec)
987
988 //! C type-generic component-wise ceil.
989# define shz_vec_ceil(vec)
990 _Generic((vec),
991 shz_vec2_t: shz_vec2_ceil,
992 shz_vec3_t: shz_vec3_ceil,
993 shz_vec4_t: shz_vec4_ceil)(vec)
994
995 //! C type-generic component-wise round.
996# define shz_vec_round(vec)
997 _Generic((vec),
998 shz_vec2_t: shz_vec2_round,
999 shz_vec3_t: shz_vec3_round,
1000 shz_vec4_t: shz_vec4_round)(vec)
1001
1002 //! C type-generic component-wise fract.
1003# define shz_vec_fract(vec)
1004 _Generic((vec),
1005 shz_vec2_t: shz_vec2_fract,
1006 shz_vec3_t: shz_vec3_fract,
1007 shz_vec4_t: shz_vec4_fract)(vec)
1008
1009 //! C type-generic component-wise sign.
1010# define shz_vec_sign(vec)
1011 _Generic((vec),
1012 shz_vec2_t: shz_vec2_sign,
1013 shz_vec3_t: shz_vec3_sign,
1014 shz_vec4_t: shz_vec4_sign)(vec)
1015
1016 //! C type-generic component-wise saturate.
1017# define shz_vec_saturate(vec)
1018 _Generic((vec),
1019 shz_vec2_t: shz_vec2_saturate,
1020 shz_vec3_t: shz_vec3_saturate,
1021 shz_vec4_t: shz_vec4_saturate)(vec)
1022
1023 //! C type-generic pairwise minimum.
1024# define shz_vec_minv(a, b)
1025 _Generic((a),
1026 shz_vec2_t: shz_vec2_minv,
1027 shz_vec3_t: shz_vec3_minv,
1028 shz_vec4_t: shz_vec4_minv)(a, b)
1029
1030 //! C type-generic pairwise maximum.
1031# define shz_vec_maxv(a, b)
1032 _Generic((a),
1033 shz_vec2_t: shz_vec2_maxv,
1034 shz_vec3_t: shz_vec3_maxv,
1035 shz_vec4_t: shz_vec4_maxv)(a, b)
1036
1037 //! C type-generic inv_sqrtf
1038# define shz_vec_inv_sqrtf(vec)
1039 _Generic((vec),
1040 shz_vec2_t: shz_vec2_inv_sqrtf,
1041 shz_vec3_t: shz_vec3_inv_sqrtf,
1042 shz_vec4_t: shz_vec4_inv_sqrtf)(vec)
1043
1044 //! C type-generic sqrtf
1045# define shz_vec_sqrtf(vec)
1046 _Generic((vec),
1047 shz_vec2_t: shz_vec2_sqrtf,
1048 shz_vec3_t: shz_vec3_sqrtf,
1049 shz_vec4_t: shz_vec4_sqrtf)(vec)
1050
1051 //! C type-generic component-wise step
1052# define shz_vec_stepv(vec, edge)
1053 _Generic((vec),
1054 shz_vec2_t: shz_vec2_stepv,
1055 shz_vec3_t: shz_vec3_stepv,
1056 shz_vec4_t: shz_vec4_stepv)(vec, edge)
1057
1058 //! C type-generic step
1059# define shz_vec_step(vec, edge)
1060 _Generic((vec),
1061 shz_vec2_t: shz_vec2_step,
1062 shz_vec3_t: shz_vec3_step,
1063 shz_vec4_t: shz_vec4_step)(vec, edge)
1064
1065 //! C type-generic component-wise smoothstep
1066# define shz_vec_smoothstepv(vec, edge0, edge1)
1067 _Generic((vec),
1068 shz_vec2_t: shz_vec2_smoothstepv,
1069 shz_vec3_t: shz_vec3_smoothstepv,
1070 shz_vec4_t: shz_vec4_smoothstepv)(vec, edge0, edge1)
1071
1072 //! C type-generic smoothstep
1073# define shz_vec_smoothstep(vec, edge0, edge1)
1074 _Generic((vec),
1075 shz_vec2_t: shz_vec2_smoothstep,
1076 shz_vec3_t: shz_vec3_smoothstep,
1077 shz_vec4_t: shz_vec4_smoothstep)(vec, edge0, edge1)
1078
1079 //! C type-generic component-wise smoothstep_safe
1080# define shz_vec_smoothstepv_safe(vec, edge0, edge1)
1081 _Generic((vec),
1082 shz_vec2_t: shz_vec2_smoothstepv_safe,
1083 shz_vec3_t: shz_vec3_smoothstepv_safe,
1084 shz_vec4_t: shz_vec4_smoothstepv_safe)(vec, edge0, edge1)
1085
1086 //! C type-generic smoothstep_safe
1087# define shz_vec_smoothstep_safe(vec, edge0, edge1)
1088 _Generic((vec),
1089 shz_vec2_t: shz_vec2_smoothstep_safe,
1090 shz_vec3_t: shz_vec3_smoothstep_safe,
1091 shz_vec4_t: shz_vec4_smoothstep_safe)(vec, edge0, edge1)
1092
1093#else // C++ generics (because it's too dumb to support _Generic()).
1094
1095 //! C++ type-generic vector absolute value.
1096 SHZ_INLINE shz_vec2_t shz_vec_abs(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_abs(vec); }
1097 SHZ_INLINE shz_vec3_t shz_vec_abs(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_abs(vec); }
1098 SHZ_INLINE shz_vec4_t shz_vec_abs(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_abs(vec); }
1099
1100 //! C++ type-generic vector negation.
1101 SHZ_INLINE shz_vec2_t shz_vec_neg(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_neg(vec); }
1102 SHZ_INLINE shz_vec3_t shz_vec_neg(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_neg(vec); }
1103 SHZ_INLINE shz_vec4_t shz_vec_neg(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_neg(vec); }
1104
1105 //! C++ type-generic vector inversion.
1106 SHZ_INLINE shz_vec2_t shz_vec_inv(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_inv(vec); }
1107 SHZ_INLINE shz_vec3_t shz_vec_inv(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_inv(vec); }
1108 SHZ_INLINE shz_vec4_t shz_vec_inv(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_inv(vec); }
1109
1110 //! C++ type-generic vector maximum value.
1111 SHZ_INLINE float shz_vec_max(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_max(vec); }
1112 SHZ_INLINE float shz_vec_max(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_max(vec); }
1113 SHZ_INLINE float shz_vec_max(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_max(vec); }
1114
1115 //! C++ type-generic vector minimum value.
1116 SHZ_INLINE float shz_vec_min(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_min(vec); }
1117 SHZ_INLINE float shz_vec_min(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_min(vec); }
1118 SHZ_INLINE float shz_vec_min(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_min(vec); }
1119
1120 //! C++ type-generic vector clamp.
1121 SHZ_INLINE shz_vec2_t shz_vec_clamp(shz_vec2_t vec, float min, float max) SHZ_NOEXCEPT { return shz_vec2_clamp(vec, min, max); }
1122 SHZ_INLINE shz_vec3_t shz_vec_clamp(shz_vec3_t vec, float min, float max) SHZ_NOEXCEPT { return shz_vec3_clamp(vec, min, max); }
1123 SHZ_INLINE shz_vec4_t shz_vec_clamp(shz_vec4_t vec, float min, float max) SHZ_NOEXCEPT { return shz_vec4_clamp(vec, min, max); }
1124
1125 //! C++ type-generic vector equality.
1126 SHZ_INLINE bool shz_vec_equal(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_equal(vec1, vec2); }
1127 SHZ_INLINE bool shz_vec_equal(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_equal(vec1, vec2); }
1128 SHZ_INLINE bool shz_vec_equal(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_equal(vec1, vec2); }
1129
1130 //! C++ type-generic vector addition.
1131 SHZ_INLINE shz_vec2_t shz_vec_add(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_add(vec1, vec2); }
1132 SHZ_INLINE shz_vec3_t shz_vec_add(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_add(vec1, vec2); }
1133 SHZ_INLINE shz_vec4_t shz_vec_add(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_add(vec1, vec2); }
1134
1135 //! C++ type-generic vector subtraction.
1136 SHZ_INLINE shz_vec2_t shz_vec_sub(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_sub(vec1, vec2); }
1137 SHZ_INLINE shz_vec3_t shz_vec_sub(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_sub(vec1, vec2); }
1138 SHZ_INLINE shz_vec4_t shz_vec_sub(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_sub(vec1, vec2); }
1139
1140 //! C++ type-generic component-wise multiplication.
1141 SHZ_INLINE shz_vec2_t shz_vec_mul(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_mul(vec1, vec2); }
1142 SHZ_INLINE shz_vec3_t shz_vec_mul(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_mul(vec1, vec2); }
1143 SHZ_INLINE shz_vec4_t shz_vec_mul(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_mul(vec1, vec2); }
1144
1145 //! C++ type-generic component-wise division.
1146 SHZ_INLINE shz_vec2_t shz_vec_div(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_div(vec1, vec2); }
1147 SHZ_INLINE shz_vec3_t shz_vec_div(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_div(vec1, vec2); }
1148 SHZ_INLINE shz_vec4_t shz_vec_div(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_div(vec1, vec2); }
1149
1150 //! C++ type-generic uniform scaling.
1151 SHZ_INLINE shz_vec2_t shz_vec_scale(shz_vec2_t vec, float factor) SHZ_NOEXCEPT { return shz_vec2_scale(vec, factor); }
1152 SHZ_INLINE shz_vec3_t shz_vec_scale(shz_vec3_t vec, float factor) SHZ_NOEXCEPT { return shz_vec3_scale(vec, factor); }
1153 SHZ_INLINE shz_vec4_t shz_vec_scale(shz_vec4_t vec, float factor) SHZ_NOEXCEPT { return shz_vec4_scale(vec, factor); }
1154
1155 //! C++ type-generic dot product.
1156 SHZ_INLINE float shz_vec_dot(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_dot(vec1, vec2); }
1157 SHZ_INLINE float shz_vec_dot(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_dot(vec1, vec2); }
1158 SHZ_INLINE float shz_vec_dot(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_dot(vec1, vec2); }
1159
1160 //! C++ type-generic dual dot product.
1161 SHZ_INLINE shz_vec2_t shz_vec_dot2(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2) SHZ_NOEXCEPT { return shz_vec2_dot2(l, r1, r2); }
1162 SHZ_INLINE shz_vec2_t shz_vec_dot2(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2) SHZ_NOEXCEPT { return shz_vec3_dot2(l, r1, r2); }
1163 SHZ_INLINE shz_vec2_t shz_vec_dot2(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2) SHZ_NOEXCEPT { return shz_vec4_dot2(l, r1, r2); }
1164
1165 //! C++ type-generic triple dot product.
1166 SHZ_INLINE shz_vec3_t shz_vec_dot3(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2, shz_vec2_t r3) SHZ_NOEXCEPT { return shz_vec2_dot3(l, r1, r2, r3); }
1167 SHZ_INLINE shz_vec3_t shz_vec_dot3(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2, shz_vec3_t r3) SHZ_NOEXCEPT { return shz_vec3_dot3(l, r1, r2, r3); }
1168 SHZ_INLINE shz_vec3_t shz_vec_dot3(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2, shz_vec4_t r3) SHZ_NOEXCEPT { return shz_vec4_dot3(l, r1, r2, r3); }
1169
1170 //! C++ type-generic squared magnitude.
1171 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude_sqr(vec); }
1172 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude_sqr(vec); }
1173 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude_sqr(vec); }
1174
1175 //! C++ type-generic magnitude.
1176 SHZ_INLINE float shz_vec_magnitude(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude(vec); }
1177 SHZ_INLINE float shz_vec_magnitude(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude(vec); }
1178 SHZ_INLINE float shz_vec_magnitude(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude(vec); }
1179
1180 //! C++ type-generic inverse magnitude.
1181 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude_inv(vec); }
1182 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude_inv(vec); }
1183 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude_inv(vec); }
1184
1185 //! C++ type-generic vector normalization.
1186 SHZ_INLINE shz_vec2_t shz_vec_normalize(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_normalize(vec); }
1187 SHZ_INLINE shz_vec3_t shz_vec_normalize(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_normalize(vec); }
1188 SHZ_INLINE shz_vec4_t shz_vec_normalize(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_normalize(vec); }
1189
1190 //! C++ type-generic safe vector normalization, avoids divide-by-zero.
1191 SHZ_INLINE shz_vec2_t shz_vec_normalize_safe(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_normalize_safe(vec); }
1192 SHZ_INLINE shz_vec3_t shz_vec_normalize_safe(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_normalize_safe(vec); }
1193 SHZ_INLINE shz_vec4_t shz_vec_normalize_safe(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_normalize_safe(vec); }
1194
1195 //! C++ type-generic distance between two points.
1196 SHZ_INLINE float shz_vec_distance(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_distance(vec1, vec2); }
1197 SHZ_INLINE float shz_vec_distance(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_distance(vec1, vec2); }
1198 SHZ_INLINE float shz_vec_distance(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_distance(vec1, vec2); }
1199
1200 //! C++ type-generic squared distance between two points.
1201 SHZ_INLINE float shz_vec_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_distance_sqr(vec1, vec2); }
1202 SHZ_INLINE float shz_vec_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_distance_sqr(vec1, vec2); }
1203 SHZ_INLINE float shz_vec_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_distance_sqr(vec1, vec2); }
1204
1205 //! C++ type-generic moving of one vector towards another.
1206 SHZ_INLINE shz_vec2_t shz_vec_move(shz_vec2_t vec, shz_vec2_t target, float maxdist) SHZ_NOEXCEPT { return shz_vec2_move(vec, target, maxdist); }
1207 SHZ_INLINE shz_vec3_t shz_vec_move(shz_vec3_t vec, shz_vec3_t target, float maxdist) SHZ_NOEXCEPT { return shz_vec3_move(vec, target, maxdist); }
1208 SHZ_INLINE shz_vec4_t shz_vec_move(shz_vec4_t vec, shz_vec4_t target, float maxdist) SHZ_NOEXCEPT { return shz_vec4_move(vec, target, maxdist); }
1209
1210 //! C++ type-generic linear interpolation between two vectors.
1211 SHZ_INLINE shz_vec2_t shz_vec_lerp(shz_vec2_t vec1, shz_vec2_t vec2, float t) SHZ_NOEXCEPT { return shz_vec2_lerp(vec1, vec2, t); }
1212 SHZ_INLINE shz_vec3_t shz_vec_lerp(shz_vec3_t vec1, shz_vec3_t vec2, float t) SHZ_NOEXCEPT { return shz_vec3_lerp(vec1, vec2, t); }
1213 SHZ_INLINE shz_vec4_t shz_vec_lerp(shz_vec4_t vec1, shz_vec4_t vec2, float t) SHZ_NOEXCEPT { return shz_vec4_lerp(vec1, vec2, t); }
1214
1215 //! C++ type-generic reflection of a vector over a surface normal.
1216 SHZ_INLINE shz_vec2_t shz_vec_reflect(shz_vec2_t incidence, shz_vec2_t normal) SHZ_NOEXCEPT { return shz_vec2_reflect(incidence, normal); }
1217 SHZ_INLINE shz_vec3_t shz_vec_reflect(shz_vec3_t incidence, shz_vec3_t normal) SHZ_NOEXCEPT { return shz_vec3_reflect(incidence, normal); }
1218 SHZ_INLINE shz_vec4_t shz_vec_reflect(shz_vec4_t incidence, shz_vec4_t normal) SHZ_NOEXCEPT { return shz_vec4_reflect(incidence, normal); }
1219
1220 //! C++ type-generic refraction of a vector over a surface normal.
1221 SHZ_INLINE shz_vec2_t shz_vec_refract(shz_vec2_t incidence, shz_vec2_t normal, float eta) SHZ_NOEXCEPT { return shz_vec2_refract(incidence, normal, eta); }
1222 SHZ_INLINE shz_vec3_t shz_vec_refract(shz_vec3_t incidence, shz_vec3_t normal, float eta) SHZ_NOEXCEPT { return shz_vec3_refract(incidence, normal, eta); }
1223 SHZ_INLINE shz_vec4_t shz_vec_refract(shz_vec4_t incidence, shz_vec4_t normal, float eta) SHZ_NOEXCEPT { return shz_vec4_refract(incidence, normal, eta); }
1224
1225 //! C++ type-generic cross product (2D returns scalar, 3D returns vector).
1226 SHZ_INLINE float shz_vec_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_cross(vec1, vec2); }
1227 SHZ_INLINE shz_vec3_t shz_vec_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_cross(vec1, vec2); }
1228
1229 //! C++ type-generic projection of the first vector onto the second.
1230 SHZ_INLINE shz_vec2_t shz_vec_project(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_project(vec1, vec2); }
1231 SHZ_INLINE shz_vec3_t shz_vec_project(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_project(vec1, vec2); }
1232 SHZ_INLINE shz_vec4_t shz_vec_project(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_project(vec1, vec2); }
1233
1234 //! C++ type-generic safe projection, avoiding division-by-zero.
1235 SHZ_INLINE shz_vec2_t shz_vec_project_safe(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_project_safe(vec1, vec2); }
1236 SHZ_INLINE shz_vec3_t shz_vec_project_safe(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_project_safe(vec1, vec2); }
1237 SHZ_INLINE shz_vec4_t shz_vec_project_safe(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_project_safe(vec1, vec2); }
1238
1239 //! C++ type-generic angles from the +X axis (2D returns float, 3D returns vec2).
1240 SHZ_INLINE float shz_vec_angles(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_angle(vec); }
1241 SHZ_INLINE shz_vec3_t shz_vec_angles(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_angles(vec); }
1242
1243 //! C++ type-generic angle between two vectors.
1244 SHZ_INLINE float shz_vec_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_angle_between(vec1, vec2); }
1245 SHZ_INLINE float shz_vec_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_angle_between(vec1, vec2); }
1246
1247 //! C++ type-generic swizzle.
1248 SHZ_INLINE shz_vec2_t shz_vec_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) SHZ_NOEXCEPT {
1249 return shz_vec2_swizzle(vec, x_idx, y_idx);
1250 }
1251 SHZ_INLINE shz_vec3_t shz_vec_swizzle(shz_vec3_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx) SHZ_NOEXCEPT {
1252 return shz_vec3_swizzle(vec, x_idx, y_idx, z_idx);
1253 }
1254 SHZ_INLINE shz_vec4_t shz_vec_swizzle(shz_vec4_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx, unsigned w_idx) SHZ_NOEXCEPT {
1255 return shz_vec4_swizzle(vec, x_idx, y_idx, z_idx, w_idx);
1256 }
1257
1258 //! C++ type-generic component-wise floor.
1259 SHZ_INLINE shz_vec2_t shz_vec_floor(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_floor(vec); }
1260 SHZ_INLINE shz_vec3_t shz_vec_floor(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_floor(vec); }
1261 SHZ_INLINE shz_vec4_t shz_vec_floor(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_floor(vec); }
1262
1263 //! C++ type-generic component-wise ceil.
1264 SHZ_INLINE shz_vec2_t shz_vec_ceil(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_ceil(vec); }
1265 SHZ_INLINE shz_vec3_t shz_vec_ceil(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_ceil(vec); }
1266 SHZ_INLINE shz_vec4_t shz_vec_ceil(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_ceil(vec); }
1267
1268 //! C++ type-generic component-wise round.
1269 SHZ_INLINE shz_vec2_t shz_vec_round(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_round(vec); }
1270 SHZ_INLINE shz_vec3_t shz_vec_round(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_round(vec); }
1271 SHZ_INLINE shz_vec4_t shz_vec_round(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_round(vec); }
1272
1273 //! C++ type-generic component-wise fract.
1274 SHZ_INLINE shz_vec2_t shz_vec_fract(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_fract(vec); }
1275 SHZ_INLINE shz_vec3_t shz_vec_fract(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_fract(vec); }
1276 SHZ_INLINE shz_vec4_t shz_vec_fract(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_fract(vec); }
1277
1278 //! C++ type-generic component-wise sign.
1279 SHZ_INLINE shz_vec2_t shz_vec_sign(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_sign(vec); }
1280 SHZ_INLINE shz_vec3_t shz_vec_sign(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_sign(vec); }
1281 SHZ_INLINE shz_vec4_t shz_vec_sign(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_sign(vec); }
1282
1283 //! C++ type-generic component-wise saturate.
1284 SHZ_INLINE shz_vec2_t shz_vec_saturate(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_saturate(vec); }
1285 SHZ_INLINE shz_vec3_t shz_vec_saturate(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_saturate(vec); }
1286 SHZ_INLINE shz_vec4_t shz_vec_saturate(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_saturate(vec); }
1287
1288 //! C++ type-generic component-wise minimum.
1289 SHZ_INLINE shz_vec2_t shz_vec_minv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT { return shz_vec2_minv(a, b); }
1290 SHZ_INLINE shz_vec3_t shz_vec_minv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT { return shz_vec3_minv(a, b); }
1291 SHZ_INLINE shz_vec4_t shz_vec_minv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT { return shz_vec4_minv(a, b); }
1292
1293 //! C++ type-generic component-wise maximum.
1294 SHZ_INLINE shz_vec2_t shz_vec_maxv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT { return shz_vec2_maxv(a, b); }
1295 SHZ_INLINE shz_vec3_t shz_vec_maxv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT { return shz_vec3_maxv(a, b); }
1296 SHZ_INLINE shz_vec4_t shz_vec_maxv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT { return shz_vec4_maxv(a, b); }
1297
1298 //! C++ type-generic vector inverse square root.
1299 SHZ_INLINE shz_vec2_t shz_vec_inv_sqrtf(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_inv_sqrtf(vec); }
1300 SHZ_INLINE shz_vec3_t shz_vec_inv_sqrtf(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_inv_sqrtf(vec); }
1301 SHZ_INLINE shz_vec4_t shz_vec_inv_sqrtf(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_inv_sqrtf(vec); }
1302
1303 //! C++ type-generic vector square root.
1304 SHZ_INLINE shz_vec2_t shz_vec_sqrtf(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_sqrtf(vec); }
1305 SHZ_INLINE shz_vec3_t shz_vec_sqrtf(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_sqrtf(vec); }
1306 SHZ_INLINE shz_vec4_t shz_vec_sqrtf(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_sqrtf(vec); }
1307
1308 //! C++ type-generic step: 0 per component if vec[i] < edge, else 1.
1309 SHZ_INLINE shz_vec2_t shz_vec_step(shz_vec2_t vec, float edge) SHZ_NOEXCEPT { return shz_vec2_step (vec, edge); }
1310 SHZ_INLINE shz_vec2_t shz_vec_step(shz_vec2_t vec, shz_vec2_t edge) SHZ_NOEXCEPT { return shz_vec2_stepv(vec, edge); }
1311 SHZ_INLINE shz_vec3_t shz_vec_step(shz_vec3_t vec, float edge) SHZ_NOEXCEPT { return shz_vec3_step (vec, edge); }
1312 SHZ_INLINE shz_vec3_t shz_vec_step(shz_vec3_t vec, shz_vec3_t edge) SHZ_NOEXCEPT { return shz_vec3_stepv(vec, edge); }
1313 SHZ_INLINE shz_vec4_t shz_vec_step(shz_vec4_t vec, float edge) SHZ_NOEXCEPT { return shz_vec4_step (vec, edge); }
1314 SHZ_INLINE shz_vec4_t shz_vec_step(shz_vec4_t vec, shz_vec4_t edge) SHZ_NOEXCEPT { return shz_vec4_stepv(vec, edge); }
1315
1316 //! C++ type-generic smoothstep: 0 at/below edge0, 1 at/above edge1, smooth in-between. Undefined for edge0 > edge1.
1317 SHZ_INLINE shz_vec2_t shz_vec_smoothstep(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec2_smoothstep (vec, edge0, edge1); }
1318 SHZ_INLINE shz_vec2_t shz_vec_smoothstep(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_NOEXCEPT { return shz_vec2_smoothstepv(vec, edge0, edge1); }
1319 SHZ_INLINE shz_vec3_t shz_vec_smoothstep(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec3_smoothstep (vec, edge0, edge1); }
1320 SHZ_INLINE shz_vec3_t shz_vec_smoothstep(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_NOEXCEPT { return shz_vec3_smoothstepv(vec, edge0, edge1); }
1321 SHZ_INLINE shz_vec4_t shz_vec_smoothstep(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec4_smoothstep (vec, edge0, edge1); }
1322 SHZ_INLINE shz_vec4_t shz_vec_smoothstep(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_NOEXCEPT { return shz_vec4_smoothstepv(vec, edge0, edge1); }
1323
1324 //! C++ type-generic smoothstep with safe edge ordering (accepts edge0 > edge1).
1325 SHZ_INLINE shz_vec2_t shz_vec_smoothstep_safe(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec2_smoothstep_safe (vec, edge0, edge1); }
1326 SHZ_INLINE shz_vec2_t shz_vec_smoothstep_safe(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_NOEXCEPT { return shz_vec2_smoothstepv_safe(vec, edge0, edge1); }
1327 SHZ_INLINE shz_vec3_t shz_vec_smoothstep_safe(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec3_smoothstep_safe (vec, edge0, edge1); }
1328 SHZ_INLINE shz_vec3_t shz_vec_smoothstep_safe(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_NOEXCEPT { return shz_vec3_smoothstepv_safe(vec, edge0, edge1); }
1329 SHZ_INLINE shz_vec4_t shz_vec_smoothstep_safe(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT { return shz_vec4_smoothstep_safe (vec, edge0, edge1); }
1330 SHZ_INLINE shz_vec4_t shz_vec_smoothstep_safe(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_NOEXCEPT { return shz_vec4_smoothstepv_safe(vec, edge0, edge1); }
1331
1332#endif
1333
1334#include "inline/shz_vector.inl.h"
1335
1336//! @}
1337
1338#endif // SHZ_VECTOR_H
shz_vec2_t shz_vec2_inv_sqrtf(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the inverse square root of the given vector's components.
float shz_vec3_max(shz_vec3_t vec) noexcept
Returns the maximum value of the given vector's 3 components.
shz_vec3_t shz_vec3_scale(shz_vec3_t vec, float factor) noexcept
Returns a 3D vector whose component values are those of the given vector multiplied by a factor.
shz_vec3_t shz_vec3_add(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns a 3D vector whose components are the sums of the given vectors' components.
float shz_vec2_max(shz_vec2_t vec) noexcept
Returns the maximum value of both of the given vector's components.
shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns the vector produced by taking the cross-product of the two given 3D vectors.
float shz_vec3_magnitude(shz_vec3_t vec) noexcept
Returns the magnitude of the given 3D vector.
float shz_vec3_magnitude_sqr(shz_vec3_t vec) noexcept
Returns the squared magnitude of the given 3D vector.
shz_vec3_t shz_vec3_step(shz_vec3_t vec, float edge) noexcept
For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f.
shz_vec4_t shz_vec4_sub(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns a 4D vector whose components are equal to the values of vec1 minus vec2.
shz_vec2_t shz_vec2_step(shz_vec2_t vec, float edge) noexcept
For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f.
shz_vec3_t shz_vec3_normalize(shz_vec3_t vec) noexcept
Returns a normalized unit vector from the given 3D vector.
shz_vec3_t shz_vec3_inv_sqrtf(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the inverse square root of the given vector's components.
shz_vec2_t shz_vec2_inv(shz_vec2_t vec) noexcept
Returns the 2D vector whose components have been inverted or reciprocated.
shz_vec4_t shz_vec4_abs(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the absolute values of the given vector's components.
shz_vec3_t shz_vec3_sqrtf(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the square root of the given vector's components.
float shz_vec2_cross(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns the cross product, as a scalar, between two 2D vectors.
shz_vec3_t shz_vec3_smoothstepv_safe(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) noexcept
For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-bet...
shz_vec4_t shz_vec4_lerp(shz_vec4_t a, shz_vec4_t b, float t) noexcept
Returns a 4D vector that is linearly interpolated from a to b by the given 0.0f-1....
shz_vec4_t shz_vec4_move(shz_vec4_t vec, shz_vec4_t target, float max_distance) noexcept
Returns the given 4D vector, translated towards the target by the given max_distance.
shz_vec2_t shz_vec2_normalize_safe(shz_vec2_t vec) noexcept
SAFELY returns a normalized unit vector from the given 2D vector.
float shz_vec4_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns the squared-distance between the two given 4D vectors.
shz_vec2_t shz_vec2_smoothstep_safe(shz_vec2_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
shz_vec3_t shz_vec3_rotate_x(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the X axis by the given angle in radians.
shz_vec2_t shz_vec2_dot2(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2) noexcept
Returns the two dot products taken between the 2D vector l and 2D vectors r1 and r2.
shz_vec3_t shz_vec3_round(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the rounded values of the given vector's components.
float shz_vec3_magnitude_inv(shz_vec3_t vec) noexcept
Returns the inverse magnitude of the given 3D vector.
shz_vec4_t shz_vec4_mul(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns a 4D vector whose component values are those of vec1 times vec2.
shz_vec4_t shz_vec4_normalize(shz_vec4_t vec) noexcept
Returns a normalized unit vector from the given 4D vector.
shz_vec2_t shz_vec2_scale(shz_vec2_t vec, float factor) noexcept
Returns a 2D vector whose component values are those of the given vector multiplied by a factor.
shz_vec2_t shz_vec2_project_safe(shz_vec2_t vec, shz_vec2_t onto) noexcept
Returns the resulting vector from projecting the given 2D vector along the given (unit) axis.
float shz_vec2_dot(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns the dot product between the two given 2D vectors.
shz_vec3_t shz_vec3
Alternate typedef for the shz_vec3 struct for those who hate POSIX-style.
Definition shz_vector.h:74
shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) noexcept
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...
shz_vec4_t shz_vec4_smoothstep(shz_vec4_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
shz_vec3_t shz_vec3_fill(float v) noexcept
Returns a 3D vector with the value of each compoonent equal to v.
shz_vec2_t shz_vec2_add(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns a 2D vector whose components are the sums of the given vectors' components.
shz_vec2_t shz_vec2_refract(shz_vec2_t incidence, shz_vec2_t normal, float eta) noexcept
Refracts the given 2D incidence vector against a surface with the given normal using the given refrac...
shz_vec4_t shz_vec4_sign(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) noexcept
Extends a 2D vector to 3D, using z as the value of the Z component.
shz_vec4_t shz_vec4_sqrtf(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the square root of the given vector's components.
shz_vec4_t shz_vec4_maxv(shz_vec4_t a, shz_vec4_t b) noexcept
Returns a 4D vector whose components are the pairwise maximums of the two given vectors' components.
shz_vec3_t shz_vec3_angles(shz_vec3_t vec) noexcept
Returns the angles formed between the positive X axis and the given 3D vector, in radians.
shz_vec2_t shz_vec2_normalize(shz_vec2_t vec) noexcept
Returns a normalized unit vector from the given 2D vector.
shz_vec2_t shz_vec4_dot2(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2) noexcept
Returns the two dot products taken between the 4D vector l and 4D vectors r1 and r2.
shz_vec3_t shz_vec3_perp(shz_vec3_t vec) noexcept
Returns a vector which is perpendicular to the given vector.
shz_vec3_t shz_vec3_neg(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the negative values of the given vector's components.
float shz_vec3_distance(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns the distance between the two given 3D vectors.
shz_vec4_t shz_vec4_neg(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the negative values of the given vector's components.
shz_vec3_t shz_vec3_cubic_hermite(shz_vec3_t vec, shz_vec3_t tangent1, shz_vec3_t vec2, shz_vec3_t tangent2, float amounht) noexcept
Calculates the cubic hermite interpolation between two vectors and their tangents.
shz_vec3_t shz_vec3_abs(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the absolute values of the given vector's components.
shz_vec2_t shz_vec2_from_angle(float radians) noexcept
Returns the 2D unit vector representing a rotation from the positive X axis in radians.
shz_vec3_t shz_vec3_init(float x, float y, float z) noexcept
Returns a 3D vector with the given x, y, and z coordinates.
shz_vec3_t shz_vec3_sign(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec2_t shz_vec2_from_sincos(shz_sincos_t sincos) noexcept
Returns the 2D unit vector representing a rotation from the positive X axis.
shz_vec3_t shz_vec3_dot3(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2, shz_vec3_t r3) noexcept
Returns the three dot products taken between the 3D vector l and 3D vectors r1, r2,...
float shz_vec4_magnitude_inv(shz_vec4_t vec) noexcept
Returns the inverse magnitude of the given 4D vector.
shz_vec3_t shz_vec3_div(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns a 3D vector whose component values are those of vec1 divided by vec2.
shz_vec4_t shz_vec4_fill(float v) noexcept
Returns a 4D vector with the value of each component equal to v.
shz_vec4_t shz_vec4_saturate(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec3_t shz_vec3_floor(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the floor of the given vector's components.
shz_vec3_t shz_vec3_stepv(shz_vec3_t vec, shz_vec3_t edge) noexcept
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
shz_vec4_t shz_vec4_minv(shz_vec4_t a, shz_vec4_t b) noexcept
Returns a 4D vector whose components are the pairwise minimums of the two given vectors' components.
shz_vec4_t shz_vec4_step(shz_vec4_t vec, float edge) noexcept
For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f.
shz_vec3_t shz_vec3_swizzle(shz_vec3_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx) noexcept
Returns a 3D vector whose elements are equal to the source vector's values at the given indices.
void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t *out1, shz_vec3_t *out2) noexcept
Returns 2 3D vectors which are normalized and orthogonal to the two input vectors.
shz_vec4_t shz_vec4_smoothstepv_safe(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) noexcept
For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-bet...
shz_vec2_t shz_vec2_round(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the rounded values of the given vector's components.
shz_vec4_t shz_vec4_inv_sqrtf(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the inverse square root of the given vector's components.
shz_vec4_t shz_vec4_inv(shz_vec4_t vec) noexcept
Returns the 4D vector whose components have been inverted or reciprocated.
shz_vec2_t shz_vec2_reflect(shz_vec2_t incidence, shz_vec2_t normal) noexcept
Reflects the given 2D incidence vector against a surface with the given normal, returning the result.
float shz_vec3_dot(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns the dot product between the two given 3D vectors.
shz_vec2_t shz_vec2_mul(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns a 2D vector whose component values are those of vec1 times vec2.
shz_vec3_t shz_vec3_reflect(shz_vec3_t incidence, shz_vec3_t normal) noexcept
Reflects the given 3D incidence vector against a surface with the given normal, returning the result.
shz_vec2_t shz_vec2_smoothstep(shz_vec2_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
shz_vec3_t shz_vec3_smoothstepv(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) noexcept
For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-bet...
shz_vec2_t shz_vec2_neg(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the negative values of the given vector's components.
shz_vec2_t shz_vec2_sqrtf(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the square root of the given vector's components.
shz_vec2_t shz_vec2_lerp(shz_vec2_t a, shz_vec2_t b, float t) noexcept
Returns a 2D vector that is linearly interpolated from a to b by the given 0.0f-1....
shz_vec4_t shz_vec4_div(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns a 4D vector whose component values are those of vec1 divided by vec2.
shz_vec3_t shz_vec3_smoothstep(shz_vec3_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
shz_vec3_t shz_vec3_barycenter(shz_vec3_t p, shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) noexcept
Computes barycentric coordinates <u, v, w> for point p, within the plane of the triangle with vertice...
shz_vec2_t shz_vec2_ceil(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the ceil of the given vector's components.
shz_vec2_t shz_vec2_maxv(shz_vec2_t a, shz_vec2_t b) noexcept
Returns a 2D vector whose components are the pairwise maximums of the two given vectors' components.
float shz_vec4_magnitude(shz_vec4_t vec) noexcept
Returns the magnitude of the given 4D vector.
shz_vec2_t shz_vec2_saturate(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec3_t shz_vec3_move(shz_vec3_t vec, shz_vec3_t target, float max_distance) noexcept
Returns the given 3D vector, translated towards the target by the given max_distance.
shz_vec3_t shz_vec3_rotate_y(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the Y axis by the given angle in radians.
shz_vec3_t shz_vec3_normalize_safe(shz_vec3_t vec) noexcept
SAFELY returns a normalized unit vector from the given 3D vector.
shz_vec2_t shz_vec2_init(float x, float y) noexcept
Returns a 2D vector with the given x, and y coordinates.
float shz_vec3_min(shz_vec3_t vec) noexcept
Returns the minimum value of the given vector's 3 components.
shz_vec3_t shz_vec3_from_sincos(shz_sincos_t azimuth, shz_sincos_t elevation) noexcept
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis.
float shz_vec4_dot(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns the dot product between the two given 4D vectors.
shz_vec4_t shz_vec4_smoothstepv(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) noexcept
For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-bet...
bool shz_vec4_equal(shz_vec4_t a, shz_vec4_t b) noexcept
Returns true if the values of each element within the two 4D vectors are approximately equal based on...
float shz_vec2_magnitude_sqr(shz_vec2_t vec) noexcept
Returns the squared magnitude of the given 2D vector.
float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) noexcept
Returns the 3D vector "triple product" between vector's a, b, and c.
shz_vec4_t shz_vec4_project_safe(shz_vec4_t vec, shz_vec4_t onto) noexcept
Returns the resulting vector from projecting the given 4D vector along the given (unit) axis.
shz_vec2_t shz_vec2_smoothstepv_safe(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) noexcept
For each component: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-betwe...
float shz_vec4_distance(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns the distance between the two given 4D vectors.
shz_vec4_t shz_vec4_swizzle(shz_vec4_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx, unsigned w_idx) noexcept
Returns a new 2D vector whose elements are equal to the source vector's values at the given indices.
shz_vec3_t shz_vec3_saturate(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec4_t shz_vec4_stepv(shz_vec4_t vec, shz_vec4_t edge) noexcept
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
shz_vec2_t shz_vec2_smoothstepv(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) noexcept
For each component: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-betwe...
shz_vec4_t shz_vec4_project(shz_vec4_t vec, shz_vec4_t onto) noexcept
Returns the resulting vector from projecting the given 4D vector along the given (unit) axis.
shz_vec2_t shz_vec2_project(shz_vec2_t vec, shz_vec2_t onto) noexcept
Returns the resulting vector from projecting the given 2D vector along the given (unit) axis.
shz_vec4_t shz_vec4_refract(shz_vec4_t incidence, shz_vec4_t normal, float eta) noexcept
Refracts the given 4D incidence vector against a surface with the given normal using the given refrac...
float shz_vec3_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns the squared-distance between the two given 3D vectors.
shz_vec4_t shz_vec4_ceil(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the ceil of the given vector's components.
float shz_vec2_min(shz_vec2_t vec) noexcept
Retuns the minimum value of both of the given vector's components.
shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) noexcept
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...
shz_vec4_t shz_vec4_normalize_safe(shz_vec4_t vec) noexcept
SAFELY returns a normalized unit vector from the given 4D vector.
float shz_vec2_magnitude(shz_vec2_t vec) noexcept
Returns the magnitude of the given 2D vector.
shz_vec2_t shz_vec2_from_angle_deg(float degrees) noexcept
Returns the 2D unit vector representing a rotation from the positive X axis in degrees.
shz_vec3_t shz_vec3_lerp(shz_vec3_t a, shz_vec3_t b, float t) noexcept
Returns a 3D vector that is linearly interpolated from a to b by the given 0.0f-1....
float shz_vec2_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns the squared-distance between the two given 2D vectors.
shz_vec4_t shz_vec4_init(float x, float y, float z, float w) noexcept
Returns a 4D vector with the given x, y, z, and w coordinates.
shz_vec2_t shz_vec2_fill(float v) noexcept
Returns a 2D vector with the value of each component equal to v.
shz_vec3_t shz_vec3_refract(shz_vec3_t incidence, shz_vec3_t normal, float eta) noexcept
Refracts the given 3D incidence vector against a surface with the given normal using the given refrac...
float shz_vec4_min(shz_vec4_t vec) noexcept
Returns the minimum value of the given vector's 4 components.
shz_vec4_t shz_vec4_reflect(shz_vec4_t incidence, shz_vec4_t normal) noexcept
Reflects the given 4D incidence vector against a surface with the given normal, returning the result.
shz_vec3_t shz_vec3_mul(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns a 3D vector whose component values are those of vec1 times vec2.
shz_vec3_t shz_vec3_inv(shz_vec3_t vec) noexcept
Returns the 3D vector whose components have been inverted or reciprocated.
shz_vec2_t shz_vec2_sub(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns a 2D vector whose components are equal to the values of vec1 minus vec2.
float shz_vec2_distance(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns the distance between the two given 2D vectors.
shz_vec3_t shz_vec3_ceil(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the ceil of the given vector's components.
shz_vec4_t shz_vec2_vec4(shz_vec2_t vec, float z, float w) noexcept
Extends a 2D vector to 4D, using z and w as the values of the Z and W components.
shz_vec2_t shz_vec3_dot2(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2) noexcept
Returns the two dot products taken between the 3D vector l and 3D vectors r1 and r2.
shz_vec2_t shz_vec2_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) noexcept
Returns a 2D vector whose elements are equal to the source vector's values at the given indices.
float shz_vec2_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns the angle formed between the given 2D vectors in radians.
shz_vec4_t shz_vec4_round(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the rounded values of the given vector's components.
shz_vec4_t shz_vec4_floor(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the floor of the given vector's components.
shz_vec3_t shz_vec3_smoothstep_safe(shz_vec3_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
shz_vec4_t shz_vec4_scale(shz_vec4_t vec, float factor) noexcept
Returns a 4D vector whose component values are those of the given vector multiplied by a factor.
shz_vec3_t shz_vec4_dot3(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2, shz_vec4_t r3) noexcept
Returns the three dot products taken between the 4D vector l and 4D vectors r1, r2,...
float shz_vec4_magnitude_sqr(shz_vec4_t vec) noexcept
Returns the squared magnitude of the given 4D vector.
shz_vec2_t shz_vec2_div(shz_vec2_t vec1, shz_vec2_t vec2) noexcept
Returns a 2D vector whose component values are those of vec1 divided by vec2.
shz_vec3_t shz_vec2_dot3(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2, shz_vec2_t r3) noexcept
Returns the three dot products taken between the 2D vector l and 2D vectors r1, r2,...
shz_vec2_t shz_vec2_rotate(shz_vec2_t vec, float radians) noexcept
Rotates the given 2D vector about the Z axis by the given angle in radians.
shz_vec3_t shz_vec3_sub(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns a 3D vector whose components are equal to the values of vec1 minus vec2.
float shz_vec4_max(shz_vec4_t vec) noexcept
Returns the maximum value of the given vector's 4 componetns.
shz_vec2_t shz_vec2_abs(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the absolute values of the given vector's components.
shz_vec2_t shz_vec2
Alternate typedef for the shz_vec2 struct for those who hate POSIX-style.
Definition shz_vector.h:49
shz_vec3_t shz_vec3_rotate_z(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the Z axis by the given angle in radians.
shz_vec3_t shz_vec3_minv(shz_vec3_t a, shz_vec3_t b) noexcept
Returns a 3D vector whose components are the pairwise minimums of the two given vectors' components.
shz_vec4_t shz_vec4_clamp(shz_vec4_t vec, float min, float max) noexcept
Clamps the values of the given 4D vec between min and max, returning a new vector.
shz_vec2_t shz_vec2_sign(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec2_t shz_vec2_move(shz_vec2_t vec, shz_vec2_t target, float max_distance) noexcept
Returns the given 2D vector, translated towards the target by the given max_distance.
shz_vec4_t shz_vec4_smoothstep_safe(shz_vec4_t vec, float edge0, float edge1) noexcept
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
shz_vec4_t shz_vec4_add(shz_vec4_t vec1, shz_vec4_t vec2) noexcept
Returns a 4D vector whose components are the sums of the given vectors' components.
shz_vec3_t shz_vec3_clamp(shz_vec3_t vec, float min, float max) noexcept
Clamps the values of the given 3D vec between min and max, returning a new vector.
shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) noexcept
Returns the rejection of the given vector, vec, onto another vector, onto.
shz_vec2_t shz_vec2_floor(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the floor of the given vector's components.
shz_vec3_t shz_vec3_maxv(shz_vec3_t a, shz_vec3_t b) noexcept
Returns a 3D vector whose components are the pairwise maximums of the two given vectors' components.
shz_vec4_t shz_vec4_fract(shz_vec4_t vec) noexcept
Returns a 4D vector whose components are the fractional parts of the given vector's components.
shz_vec4_t shz_vec3_vec4(shz_vec3_t vec, float w) noexcept
Extends a 3D vector to 4D, using w as the value of the W component.
float shz_vec2_magnitude_inv(shz_vec2_t vec) noexcept
Returns the inverse magnitude of the given 2D vector.
shz_vec2_t shz_vec2_stepv(shz_vec2_t vec, shz_vec2_t edge) noexcept
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
bool shz_vec3_equal(shz_vec3_t a, shz_vec3_t b) noexcept
Returns true if the values of each element within the two 3D vectors are approximately equal based on...
shz_vec2_t shz_vec2_clamp(shz_vec2_t vec, float min, float max) noexcept
Clamps the values of the given 2D vec between min and max, returning a new vector.
shz_vec3_t shz_vec3_project_safe(shz_vec3_t vec, shz_vec3_t onto) noexcept
Returns the resulting vector from projecting the given 3D vector along the given (unit) axis.
shz_vec4_t shz_vec4
Alternate typedef for the shz_vec4 struct for those who hate POSIX-style.
Definition shz_vector.h:105
bool shz_vec2_equal(shz_vec2_t a, shz_vec2_t b) noexcept
Returns true if the values of each element within the two 2D vectors are approximately equal based on...
shz_vec3_t shz_vec3_fract(shz_vec3_t vec) noexcept
Returns a 3D vector whose components are the fractional parts of the given vector's components.
shz_vec3_t shz_vec3_project(shz_vec3_t vec, shz_vec3_t onto) noexcept
Returns the resulting vector from projecting the given 3D vector along the given (unit) axis.
float shz_vec2_angle(shz_vec2_t vec) noexcept
Returns the angle formed between the positive X axis and the given 2D vector, in radians.
shz_vec2_t shz_vec2_fract(shz_vec2_t vec) noexcept
Returns a 2D vector whose components are the fractional parts of the given vector's components.
shz_vec2_t shz_vec2_minv(shz_vec2_t a, shz_vec2_t b) noexcept
Returns a 2D vector whose components are the pairwise minimums of the two given vectors' components.
float shz_vec3_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) noexcept
Returns the angle formed between the given 3D vectors in radians.
2D Vector type
Definition shz_vector.h:38
float x
X coordinate.
Definition shz_vector.h:42
float y
Y coordinate.
Definition shz_vector.h:43
float e[2]
<X, Y> coordinates as an array
Definition shz_vector.h:40
3D Vector type
Definition shz_vector.h:57
float y
Y coordinate.
Definition shz_vector.h:64
shz_vec2_t xy
Inner 2D vector containing <X, Y> coords.
Definition shz_vector.h:66
float x
X coordinate.
Definition shz_vector.h:63
float e[3]
<X, Y, Z> coordinates as an array
Definition shz_vector.h:59
float z
Z coordinate.
Definition shz_vector.h:68
4D Vector type
Definition shz_vector.h:82
float z
Z coordinate.
Definition shz_vector.h:90
shz_vec2_t xy
<X, Y> coordinates as a 2D vector
Definition shz_vector.h:97
float w
W coordinate.
Definition shz_vector.h:94
float x
X coordinate.
Definition shz_vector.h:88
float y
Y coordinate.
Definition shz_vector.h:89
shz_vec3_t xyz
<X, Y, Z> coordinates as a 3D vector
Definition shz_vector.h:92
shz_vec2_t zw
<Z, W> coordinates as a 2D vector
Definition shz_vector.h:98