SH4ZAM! 0.1.0
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[4]; //!< <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
327//! @}
328
329/*! \name Arithmetic
330 \brief Routines for basic vector arithmetic operations.
331 @{
332*/
333
334//! Returns a 2D vector whose components are the sums of the given vectors' components.
335SHZ_INLINE shz_vec2_t shz_vec2_add(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
336
337//! Returns a 3D vector whose components are the sums of the given vectors' components.
338SHZ_INLINE shz_vec3_t shz_vec3_add(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
339
340//! Returns a 4D vector whose components are the sums of the given vectors' components.
341SHZ_INLINE shz_vec4_t shz_vec4_add(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
342
343//! Returns a 2D vector whose components are equal to the values of \p vec1 minus \p vec2.
344SHZ_INLINE shz_vec2_t shz_vec2_sub(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
345
346//! Returns a 3D vector whose components are equal to the values of \p vec1 minus \p vec2.
347SHZ_INLINE shz_vec3_t shz_vec3_sub(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
348
349//! Returns a 4D vector whose components are equal to the values of \p vec1 minus \p vec2.
350SHZ_INLINE shz_vec4_t shz_vec4_sub(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
351
352//! Returns a 2D vector whose component values are those of \p vec1 times \p vec2.
353SHZ_INLINE shz_vec2_t shz_vec2_mul(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
354
355//! Returns a 3D vector whose component values are those of \p vec1 times \p vec2.
356SHZ_INLINE shz_vec3_t shz_vec3_mul(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
357
358//! Returns a 4D vector whose component values are those of \p vec1 times \p vec2.
359SHZ_INLINE shz_vec4_t shz_vec4_mul(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
360
361//! Returns a 2D vector whose component values are those of \p vec1 divided by \p vec2.
362SHZ_INLINE shz_vec2_t shz_vec2_div(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
363
364//! Returns a 3D vector whose component values are those of \p vec1 divided by \p vec2.
365SHZ_INLINE shz_vec3_t shz_vec3_div(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
366
367//! Returns a 4D vector whose component values are those of \p vec1 divided by \p vec2.
368SHZ_INLINE shz_vec4_t shz_vec4_div(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
369
370//! Returns a 2D vector whose component values are those of the given vector multiplied by a factor.
371SHZ_INLINE shz_vec2_t shz_vec2_scale(shz_vec2_t vec, float factor) SHZ_NOEXCEPT;
372
373//! Returns a 3D vector whose component values are those of the given vector multiplied by a factor.
374SHZ_INLINE shz_vec3_t shz_vec3_scale(shz_vec3_t vec, float factor) SHZ_NOEXCEPT;
375
376//! Returns a 4D vector whose component values are those of the given vector multiplied by a factor.
377SHZ_INLINE shz_vec4_t shz_vec4_scale(shz_vec4_t vec, float factor) SHZ_NOEXCEPT;
378
379//! @}
380
381/*! \name Magnitude
382 \brief Math routines for vector length and normalization.
383 @{
384*/
385
386//! Returns the squared magnitude of the given 2D vector.
387SHZ_INLINE float shz_vec2_magnitude_sqr(shz_vec2_t vec) SHZ_NOEXCEPT;
388
389//! Returns the squared magnitude of the given 4D vector.
390SHZ_INLINE float shz_vec4_magnitude_sqr(shz_vec4_t vec) SHZ_NOEXCEPT;
391
392//! Returns the squared magnitude of the given 3D vector.
393SHZ_INLINE float shz_vec3_magnitude_sqr(shz_vec3_t vec) SHZ_NOEXCEPT;
394
395//! Returns the magnitude of the given 2D vector.
396SHZ_INLINE float shz_vec2_magnitude(shz_vec2_t vec) SHZ_NOEXCEPT;
397
398//! Returns the magnitude of the given 3D vector.
399SHZ_INLINE float shz_vec3_magnitude(shz_vec3_t vec) SHZ_NOEXCEPT;
400
401//! Returns the magnitude of the given 4D vector.
402SHZ_INLINE float shz_vec4_magnitude(shz_vec4_t vec) SHZ_NOEXCEPT;
403
404//! Returns the inverse magnitude of the given 2D vector.
405SHZ_INLINE float shz_vec2_magnitude_inv(shz_vec2_t vec) SHZ_NOEXCEPT;
406
407//! Returns the inverse magnitude of the given 3D vector.
408SHZ_INLINE float shz_vec3_magnitude_inv(shz_vec3_t vec) SHZ_NOEXCEPT;
409
410//! Returns the inverse magnitude of the given 4D vector.
411SHZ_INLINE float shz_vec4_magnitude_inv(shz_vec4_t vec) SHZ_NOEXCEPT;
412
413//! Returns a normalized unit vector from the given 2D vector.
414SHZ_INLINE shz_vec2_t shz_vec2_normalize(shz_vec2_t vec) SHZ_NOEXCEPT;
415
416//! Returns a normalized unit vector from the given 3D vector.
417SHZ_INLINE shz_vec3_t shz_vec3_normalize(shz_vec3_t vec) SHZ_NOEXCEPT;
418
419//! Returns a normalized unit vector from the given 4D vector.
420SHZ_INLINE shz_vec4_t shz_vec4_normalize(shz_vec4_t vec) SHZ_NOEXCEPT;
421
422/*! SAFELY returns a normalized unit vector from the given 2D vector.
423
424 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
425*/
426SHZ_INLINE shz_vec2_t shz_vec2_normalize_safe(shz_vec2_t vec) SHZ_NOEXCEPT;
427
428/*! SAFELY returns a normalized unit vector from the given 3D vector.
429
430 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
431*/
432SHZ_INLINE shz_vec3_t shz_vec3_normalize_safe(shz_vec3_t vec) SHZ_NOEXCEPT;
433
434/*! SAFELY returns a normalized unit vector from the given 4D vector.
435
436 If the vector's magnitude is not `> 0.0f`, safely returns a zero vector.
437*/
438SHZ_INLINE shz_vec4_t shz_vec4_normalize_safe(shz_vec4_t vec) SHZ_NOEXCEPT;
439
440//! @}
441
442/*! \name Binary Operations
443 \brief Linear algebra operations performed with multiple vectors.
444 @{
445*/
446
447//! Returns the dot product between the two given 2D vectors.
448SHZ_INLINE float shz_vec2_dot(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
449
450//! Returns the two dot products taken between the 2D vector \p l and 2D vectors \p r1 and \p r2.
451SHZ_INLINE shz_vec2_t shz_vec2_dot2(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2) SHZ_NOEXCEPT;
452
453//! Returns the three dot products taken between the 2D vector \p l and 2D vectors \p r1, \p r2, and \p r3.
454SHZ_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;
455
456//! Returns the dot product between the two given 3D vectors.
457SHZ_INLINE float shz_vec3_dot(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
458
459//! Returns the two dot products taken between the 3D vector \p l and 3D vectors \p r1 and \p r2.
460SHZ_INLINE shz_vec2_t shz_vec3_dot2(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2) SHZ_NOEXCEPT;
461
462//! Returns the three dot products taken between the 3D vector \p l and 3D vectors \p r1, \p r2, and \p r3.
463SHZ_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;
464
465//! Returns the dot product between the two given 4D vectors.
466SHZ_INLINE float shz_vec4_dot(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
467
468//! Returns the two dot products taken between the 4D vector \p l and 4D vectors \p r1 and \p r2.
469SHZ_INLINE shz_vec2_t shz_vec4_dot2(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2) SHZ_NOEXCEPT;
470
471//! Returns the three dot products taken between the 4D vector \p l and 4D vectors \p r1, \p r2, and \p r3.
472SHZ_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;
473
474//! Returns the distance between the two given 2D vectors.
475SHZ_INLINE float shz_vec2_distance(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
476
477//! Returns the distance between the two given 3D vectors.
478SHZ_INLINE float shz_vec3_distance(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
479
480//! Returns the distance between the two given 4D vectors.
481SHZ_INLINE float shz_vec4_distance(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
482
483//! Returns the squared-distance between the two given 2D vectors.
484SHZ_INLINE float shz_vec2_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
485
486//! Returns the squared-distance between the two given 3D vectors.
487SHZ_INLINE float shz_vec3_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
488
489//! Returns the squared-distance between the two given 4D vectors.
490SHZ_INLINE float shz_vec4_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT;
491
492//! Returns the given 2D vector, translated towards the \p target by the given \p max_distance.
493SHZ_INLINE shz_vec2_t shz_vec2_move(shz_vec2_t vec, shz_vec2_t target, float max_distance) SHZ_NOEXCEPT;
494
495//! Returns the given 3D vector, translated towards the \p target by the given \p max_distance.
496SHZ_INLINE shz_vec3_t shz_vec3_move(shz_vec3_t vec, shz_vec3_t target, float max_distance) SHZ_NOEXCEPT;
497
498//! Returns the given 4D vector, translated towards the \p target by the given \p max_distance.
499SHZ_INLINE shz_vec4_t shz_vec4_move(shz_vec4_t vec, shz_vec4_t target, float max_distance) SHZ_NOEXCEPT;
500
501//! Returns a 2D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
502SHZ_INLINE shz_vec2_t shz_vec2_lerp(shz_vec2_t a, shz_vec2_t b, float t) SHZ_NOEXCEPT;
503
504//! Returns a 3D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
505SHZ_INLINE shz_vec3_t shz_vec3_lerp(shz_vec3_t a, shz_vec3_t b, float t) SHZ_NOEXCEPT;
506
507//! Returns a 4D vector that is linearly interpolated from \p a to \p b by the given `0.0f-1.0f` factor, \p t.
508SHZ_INLINE shz_vec4_t shz_vec4_lerp(shz_vec4_t a, shz_vec4_t b, float t) SHZ_NOEXCEPT;
509
510//! Reflects the given 2D \p incidence vector against a surface with the given \p normal, returning the result.
511SHZ_INLINE shz_vec2_t shz_vec2_reflect(shz_vec2_t incidence, shz_vec2_t normal) SHZ_NOEXCEPT;
512
513//! Reflects the given 3D \p incidence vector against a surface with the given \p normal, returning the result.
514SHZ_INLINE shz_vec3_t shz_vec3_reflect(shz_vec3_t incidence, shz_vec3_t normal) SHZ_NOEXCEPT;
515
516//! Reflects the given 4D \p incidence vector against a surface with the given \p normal, returning the result.
517SHZ_INLINE shz_vec4_t shz_vec4_reflect(shz_vec4_t incidence, shz_vec4_t normal) SHZ_NOEXCEPT;
518
519//! Refracts the given 2D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
520SHZ_INLINE shz_vec2_t shz_vec2_refract(shz_vec2_t incidence, shz_vec2_t normal, float eta) SHZ_NOEXCEPT;
521
522//! Refracts the given 3D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
523SHZ_INLINE shz_vec3_t shz_vec3_refract(shz_vec3_t incidence, shz_vec3_t normal, float eta) SHZ_NOEXCEPT;
524
525//! Refracts the given 4D \p incidence vector against a surface with the given \p normal using the given refraction index ratio, \p eta.
526SHZ_INLINE shz_vec4_t shz_vec4_refract(shz_vec4_t incidence, shz_vec4_t normal, float eta) SHZ_NOEXCEPT;
527
528/*! Returns the cross product, as a scalar, between two 2D vectors.
529
530 \note
531 The definition of the cross-product is ambiguous in 2D space, but the geometric
532 interpretation here is that the result is the magnitude of the orthogonal vector
533 created from the given two along the Z-axis.
534*/
535SHZ_INLINE float shz_vec2_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
536
537//! Returns the vector produced by taking the cross-product of the two given 3D vectors.
538SHZ_INLINE shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
539
540//! Returns the resulting vector from projecting the given 2D vector along the given (unit) axis
541SHZ_INLINE shz_vec2_t shz_vec2_project(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT;
542
543//! Returns the resulting vector from projecting the given 3D vector along the given (unit) axis
544SHZ_INLINE shz_vec3_t shz_vec3_project(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
545
546//! Returns the resulting vector from projecting the given 4D vector along the given (unit) axis
547SHZ_INLINE shz_vec4_t shz_vec4_project(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT;
548
549/*! Returns the resulting vector from projecting the given 2D vector along the given (unit) axis
550
551 \note
552 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
553*/
554SHZ_INLINE shz_vec2_t shz_vec2_project_safe(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT;
555
556/*! Returns the resulting vector from projecting the given 3D vector along the given (unit) axis
557
558 \note
559 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
560*/
561SHZ_INLINE shz_vec3_t shz_vec3_project_safe(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
562
563/*! Returns the resulting vector from projecting the given 4D vector along the given (unit) axis
564
565 \note
566 This routine should safely return the zero vector when \p vec has a magnitude of 0.0f.
567*/
568SHZ_INLINE shz_vec4_t shz_vec4_project_safe(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT;
569
570//! Returns the rejection of the given vector, \p vec, onto another vector, \p onto.
571SHZ_INLINE shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT;
572
573//! @}
574
575/*! \name Miscellaneous
576 \brief Other specialized vector routines.
577 @{
578*/
579
580//! Returns the 3D vector "triple product" between vector's \p a, \p b, and \p c.
581SHZ_INLINE float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT;
582
583//! Returns a vector which is perpendicular to the given vector.
584SHZ_INLINE shz_vec3_t shz_vec3_perp(shz_vec3_t vec) SHZ_NOEXCEPT;
585
586//! Computes barycentric coordinates `<u, v, w>` for point p, within the plane of the triangle with vertices \p a, \p b, and \p c.
587SHZ_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;
588
589//! Returns 2 3D vectors which are normalized and orthogonal to the two input vectors.
590SHZ_INLINE void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t* out1, shz_vec3_t* out2) SHZ_NOEXCEPT;
591
592//! Calculates the cubic hermite interpolation between two vectors and their tangents.
593SHZ_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;
594
595//! @}
596
597/*! \name Angles
598 \brief Routines for working with vectors and angles.
599 @{
600*/
601
602//! Returns the angle formed between the given 2D vectors in radians.
603SHZ_INLINE float shz_vec2_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT;
604
605//! Returns the angle formed between the given 3D vectors in radians.
606SHZ_INLINE float shz_vec3_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT;
607
608//! Returns the angle formed between the positive X axis and the given 2D vector, in radians.
609SHZ_INLINE float shz_vec2_angle(shz_vec2_t vec) SHZ_NOEXCEPT;
610
611//! Returns the angles formed between the positive X axis and the given 3D vector, in radians.
612SHZ_INLINE shz_vec3_t shz_vec3_angles(shz_vec3_t vec) SHZ_NOEXCEPT;
613
614//! Returns the 2D unit vector representing a rotation from the positive X axis.
615SHZ_INLINE shz_vec2_t shz_vec2_from_sincos(shz_sincos_t sincos) SHZ_NOEXCEPT;
616
617//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis.
618SHZ_INLINE shz_vec3_t shz_vec3_from_sincos(shz_sincos_t azimuth, shz_sincos_t elevation) SHZ_NOEXCEPT;
619
620//! Returns the 2D unit vector representing a rotation from the positive X axis in radians.
621SHZ_INLINE shz_vec2_t shz_vec2_from_angle(float radians) SHZ_NOEXCEPT;
622
623//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in radians.
624SHZ_INLINE shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) SHZ_NOEXCEPT;
625
626//! Returns the 2D unit vector representing a rotation from the positive X axis in degrees.
627SHZ_INLINE shz_vec2_t shz_vec2_from_angle_deg(float degrees) SHZ_NOEXCEPT;
628
629//! Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in degrees.
630SHZ_INLINE shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) SHZ_NOEXCEPT;
631
632//! Rotates the given 2D vector about the Z axis by the given angle in radians.
633SHZ_INLINE shz_vec2_t shz_vec2_rotate(shz_vec2_t vec, float radians) SHZ_NOEXCEPT;
634
635//! @}
636
637/*! \name Extending
638 \brief Routines for extending vectors into other dimensions.
639 @{
640 */
641
642//! Extends a 2D vector to 3D, using \p z as the value of the Z component.
643SHZ_INLINE shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) SHZ_NOEXCEPT;
644
645//! Extends a 2D vector to 4D, using \p z and \p w as the values of the Z and W components.
646SHZ_INLINE shz_vec4_t shz_vec2_vec4(shz_vec2_t vec, float z, float w) SHZ_NOEXCEPT;
647
648//! Extends a 3D vector to 4D, using \p w as the value of the W component.
649SHZ_INLINE shz_vec4_t shz_vec3_vec4(shz_vec3_t vec, float w) SHZ_NOEXCEPT;
650
651//! @}
652
653/*! \name Swizzling
654 \brief Routines for swizzling the order of a vector's components.
655 @{
656 */
657
658 //! Returns a 2D vector whose elements are equal to the source vector's values at the given indices.
659 SHZ_INLINE shz_vec2_t shz_vec2_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) SHZ_NOEXCEPT;
660
661 //! Returns a 3D vector whose elements are equal to the source vector's values at the given indices.
662 SHZ_INLINE shz_vec3_t shz_vec3_swizzle(shz_vec3_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx) SHZ_NOEXCEPT;
663
664 //! Returns a new 2D vector whose elements are equal to the source vector's values at the given indices.
665 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;
666
667 //! @}
668
669SHZ_DECLS_END
670
671/*! \name Adapters
672 \brief Macros for converting between SH4ZAM and other compatible formats.
673 @{
674*/
675
676//! Dereferences the given pointer to a sequence of 2 floats as a shz_vec2_t.
677#define shz_vec2_deref(ptr) (*((SHZ_ALIASING shz_vec2_t*)(ptr)))
678
679//! Dereferences the given pointer to a sequence of 3 floats as a shz_vec3_t.
680#define shz_vec3_deref(ptr) (*((SHZ_ALIASING shz_vec3_t*)(ptr)))
681
682//! Dereferences the given pointer to a sequence of 4 floats as a shz_vec4_t.
683#define shz_vec4_deref(ptr) (*((SHZ_ALIASING shz_vec4_t*)(ptr)))
684
685//! Converts the given \p value or expression to the equivalent 2D SH4ZAM vector value.
686#define shz_vec2_from(value) SHZ_CONVERT(shz_vec2_t, value)
687
688//! Converts the given \p value or expression to the equivalent 3D SH4ZAM vector value.
689#define shz_vec3_from(value) SHZ_CONVERT(shz_vec3_t, value)
690
691//! Converts the given \p value or expression to the equivalent 4D SH4ZAM vector value.
692#define shz_vec4_from(value) SHZ_CONVERT(shz_vec4_t, value)
693
694//! Converts the given 2D \p vector into a value of the given \p type.
695#define shz_vec2_to(type, vector) SHZ_CONVERT(type, vector)
696
697//! Converts the given 3D \p vector into a value of the given \p type.
698#define shz_vec3_to(type, vector) SHZ_CONVERT(type, vector)
699
700//! Converts the given 4D \p vector into a value of the given \p type.
701#define shz_vec4_to(type, vector) SHZ_CONVERT(type, vector)
702
703//! @}
704
705/*! \name Type-Generic Routines
706 \brief Generalized vector routines for C and C++.
707 @{
708*/
709
710#ifndef __cplusplus
711
712 //! C type-generic vector absolute value.
713# define shz_vec_abs(vec)
714 _Generic((vec),
715 shz_vec2_t: shz_vec2_abs,
716 shz_vec3_t: shz_vec3_abs,
717 shz_vec4_t: shz_vec4_abs)(vec)
718
719 //! C type-generic vector negation.
720# define shz_vec_neg(vec)
721 _Generic((vec),
722 shz_vec2_t: shz_vec2_neg,
723 shz_vec3_t: shz_vec3_neg,
724 shz_vec4_t: shz_vec4_neg)(vec)
725
726 //! C type-generic vector inversion.
727# define shz_vec_inv(vec)
728 _Generic((vec),
729 shz_vec2_t: shz_vec2_inv,
730 shz_vec3_t: shz_vec3_inv,
731 shz_vec4_t: shz_vec4_inv)(vec)
732
733 //! C type-generic vector maximum value.
734# define shz_vec_max(vec)
735 _Generic((vec),
736 shz_vec2_t: shz_vec2_max,
737 shz_vec3_t: shz_vec3_max,
738 shz_vec4_t: shz_vec4_max)(vec)
739
740 //! C type-generic vector minimum value.
741# define shz_vec_min(vec)
742 _Generic((vec),
743 shz_vec2_t: shz_vec2_min,
744 shz_vec3_t: shz_vec3_min,
745 shz_vec4_t: shz_vec4_min)(vec)
746
747 //! C type-generic vector minimum value.
748# define shz_vec_clamp(vec, min, max)
749 _Generic((vec),
750 shz_vec2_t: shz_vec2_clamp,
751 shz_vec3_t: shz_vec3_clamp,
752 shz_vec4_t: shz_vec4_clamp)(vec, min, max)
753
754 //! C type-generic vector equals.
755# define shz_vec_equal(vec1, vec2)
756 _Generic((vec1),
757 shz_vec2_t: shz_vec2_equal,
758 shz_vec3_t: shz_vec3_equal,
759 shz_vec4_t: shz_vec4_equal)(vec1, vec2)
760
761 //! C type-generic vector addition.
762# define shz_vec_add(vec1, vec2)
763 _Generic((vec1),
764 shz_vec2_t: shz_vec2_add,
765 shz_vec3_t: shz_vec3_add,
766 shz_vec4_t: shz_vec4_add)(vec1, vec2)
767
768 //! C type-generic vector subtraction.
769# define shz_vec_sub(vec1, vec2)
770 _Generic((vec1),
771 shz_vec2_t: shz_vec2_sub,
772 shz_vec3_t: shz_vec3_sub,
773 shz_vec4_t: shz_vec4_sub)(vec1, vec2)
774
775 //! C type-generic vector multiplication.
776# define shz_vec_mul(vec1, vec2)
777 _Generic((vec1),
778 shz_vec2_t: shz_vec2_mul,
779 shz_vec3_t: shz_vec3_mul,
780 shz_vec4_t: shz_vec4_mul)(vec1, vec2)
781
782 //! C type-generic vector division.
783# define shz_vec_div(vec1, vec2)
784 _Generic((vec1),
785 shz_vec2_t: shz_vec2_div,
786 shz_vec3_t: shz_vec3_div,
787 shz_vec4_t: shz_vec4_div)(vec1, vec2)
788
789 //! C type-generic vector scaling.
790# define shz_vec_scale(vec, factor)
791 _Generic((vec),
792 shz_vec2_t: shz_vec2_scale,
793 shz_vec3_t: shz_vec3_scale,
794 shz_vec4_t: shz_vec4_scale)(vec, factor)
795
796 //! C type-generic vector dot product.
797# define shz_vec_dot(vec1, vec2)
798 _Generic((vec1),
799 shz_vec2_t: shz_vec2_dot,
800 shz_vec3_t: shz_vec3_dot,
801 shz_vec4_t: shz_vec4_dot)(vec1, vec2)
802
803 //! C type-generic vector chained double dot product.
804# define shz_vec_dot2(l, r1, r2)
805 _Generic((l),
806 shz_vec2_t: shz_vec2_dot2,
807 shz_vec3_t: shz_vec3_dot2,
808 shz_vec4_t: shz_vec4_dot2)(l, r1, r2)
809
810 //! C type-generic vector chained triple dot product.
811# define shz_vec_dot3(l, r1, r2, r3)
812 _Generic((l),
813 shz_vec2_t: shz_vec2_dot3,
814 shz_vec3_t: shz_vec3_dot3,
815 shz_vec4_t: shz_vec4_dot3)(l, r1, r2, r3)
816
817 //! C type-generic vector squared magnitude.
818# define shz_vec_magnitude_sqr(vec)
819 _Generic((vec),
820 shz_vec2_t: shz_vec2_magnitude_sqr,
821 shz_vec3_t: shz_vec3_magnitude_sqr,
822 shz_vec4_t: shz_vec4_magnitude_sqr)(vec)
823
824 //! C type-generic vector magnitude.
825# define shz_vec_magnitude(vec)
826 _Generic((vec),
827 shz_vec2_t: shz_vec2_magnitude,
828 shz_vec3_t: shz_vec3_magnitude,
829 shz_vec4_t: shz_vec4_magnitude)(vec)
830
831 //! C type-generic vector inverse magnitude.
832# define shz_vec_magnitude_inv(vec)
833 _Generic((vec),
834 shz_vec2_t: shz_vec2_magnitude_inv,
835 shz_vec3_t: shz_vec3_magnitude_inv,
836 shz_vec4_t: shz_vec4_magnitude_inv)(vec)
837
838 //! C type-generic vector normalization.
839# define shz_vec_normalize(vec)
840 _Generic((vec),
841 shz_vec2_t: shz_vec2_normalize,
842 shz_vec3_t: shz_vec3_normalize,
843 shz_vec4_t: shz_vec4_normalize)(vec)
844
845 //! C type-generic safe vector normalization.
846# define shz_vec_normalize_safe(vec)
847 _Generic((vec),
848 shz_vec2_t: shz_vec2_normalize_safe,
849 shz_vec3_t: shz_vec3_normalize_safe,
850 shz_vec4_t: shz_vec4_normalize_safe)(vec)
851
852 //! C type-generic vector distance.
853# define shz_vec_distance(vec1, vec2)
854 _Generic((vec1),
855 shz_vec2_t: shz_vec2_distance,
856 shz_vec3_t: shz_vec3_distance,
857 shz_vec4_t: shz_vec4_distance)(vec1, vec2)
858
859 //! C type-generic vector move.
860# define shz_vec_move(vec, target, maxdist)
861 _Generic((vec),
862 shz_vec2_t: shz_vec2_move,
863 shz_vec3_t: shz_vec3_move,
864 shz_vec4_t: shz_vec4_move)(vec, target, maxdist)
865
866 //! C type-generic vector squared distance.
867# define shz_vec_distance_sqr(vec1, vec2)
868 _Generic((vec1),
869 shz_vec2_t: shz_vec2_distance_sqr,
870 shz_vec3_t: shz_vec3_distance_sqr,
871 shz_vec4_t: shz_vec4_distance_sqr)(vec1, vec2)
872
873 //! C type-generic linear interpolation between two vectors.
874# define shz_vec_lerp(vec1, vec2, t)
875 _Generic((vec1),
876 shz_vec2_t: shz_vec2_lerp,
877 shz_vec3_t: shz_vec3_lerp,
878 shz_vec4_t: shz_vec4_lerp)(vec1, vec2, t)
879
880 //! C type-generic vector reflection.
881# define shz_vec_reflect(incidence, normal)
882 _Generic((incidence),
883 shz_vec2_t: shz_vec2_reflect,
884 shz_vec3_t: shz_vec3_reflect,
885 shz_vec4_t: shz_vec4_reflect)(incidence, normal)
886
887 //! C type-generic vector refraction.
888# define shz_vec_refract(incidence, normal, eta)
889 _Generic((incidence),
890 shz_vec2_t: shz_vec2_refract,
891 shz_vec3_t: shz_vec3_refract,
892 shz_vec4_t: shz_vec4_refract)(incidence, normal, eta)
893
894 //! C type-generic vector cross-product.
895# define shz_vec_cross(vec1, vec2)
896 _Generic((vec1),
897 shz_vec2_t: shz_vec2_cross,
898 shz_vec3_t: shz_vec3_cross)(vec1, vec2)
899
900 //! C type-generic vector projection.
901# define shz_vec_project(vec1, vec2)
902 _Generic((vec1),
903 shz_vec2_t: shz_vec2_project,
904 shz_vec3_t: shz_vec3_project,
905 shz_vec4_t: shz_vec4_project)(vec1, vec2)
906
907 //! C type-generic safe vector projection.
908# define shz_vec_project_safe(vec1, vec2)
909 _Generic((vec1),
910 shz_vec2_t: shz_vec2_project_safe,
911 shz_vec3_t: shz_vec3_project_safe,
912 shz_vec4_t: shz_vec4_project_safe)(vec1, vec2)
913
914 //! C type-generic angle-from-vector extraction.
915# define shz_vec_angles(vec)
916 _Generic((vec),
917 shz_vec2_t: shz_vec2_angle,
918 shz_vec3_t: shz_vec3_angles)(vec)
919
920 //! C type-generic angle between two vectors.
921# define shz_vec_angle_between(vec1, vec2)
922 _Generic((vec1),
923 shz_vec2_t: shz_vec2_angle_between,
924 shz_vec3_t: shz_vec3_angle_between)(vec1, vec2)
925
926 //! C type-generic vector swizzling.
927# define shz_vec_swizzle(vec, ...)
928 _Generic((vec),
929 shz_vec2_t: shz_vec2_swizzle,
930 shz_vec3_t: shz_vec3_swizzle,
931 shz_vec4_t: shz_vec4_swizzle)(vec, __VA_ARGS__)
932
933 //! C type-generic component-wise floor.
934# define shz_vec_floor(vec)
935 _Generic((vec),
936 shz_vec2_t: shz_vec2_floor,
937 shz_vec3_t: shz_vec3_floor,
938 shz_vec4_t: shz_vec4_floor)(vec)
939
940 //! C type-generic component-wise ceil.
941# define shz_vec_ceil(vec)
942 _Generic((vec),
943 shz_vec2_t: shz_vec2_ceil,
944 shz_vec3_t: shz_vec3_ceil,
945 shz_vec4_t: shz_vec4_ceil)(vec)
946
947 //! C type-generic component-wise round.
948# define shz_vec_round(vec)
949 _Generic((vec),
950 shz_vec2_t: shz_vec2_round,
951 shz_vec3_t: shz_vec3_round,
952 shz_vec4_t: shz_vec4_round)(vec)
953
954 //! C type-generic component-wise fract.
955# define shz_vec_fract(vec)
956 _Generic((vec),
957 shz_vec2_t: shz_vec2_fract,
958 shz_vec3_t: shz_vec3_fract,
959 shz_vec4_t: shz_vec4_fract)(vec)
960
961 //! C type-generic component-wise sign.
962# define shz_vec_sign(vec)
963 _Generic((vec),
964 shz_vec2_t: shz_vec2_sign,
965 shz_vec3_t: shz_vec3_sign,
966 shz_vec4_t: shz_vec4_sign)(vec)
967
968 //! C type-generic component-wise saturate.
969# define shz_vec_saturate(vec)
970 _Generic((vec),
971 shz_vec2_t: shz_vec2_saturate,
972 shz_vec3_t: shz_vec3_saturate,
973 shz_vec4_t: shz_vec4_saturate)(vec)
974
975 //! C type-generic pairwise minimum.
976# define shz_vec_minv(a, b)
977 _Generic((a),
978 shz_vec2_t: shz_vec2_minv,
979 shz_vec3_t: shz_vec3_minv,
980 shz_vec4_t: shz_vec4_minv)(a, b)
981
982 //! C type-generic pairwise maximum.
983# define shz_vec_maxv(a, b)
984 _Generic((a),
985 shz_vec2_t: shz_vec2_maxv,
986 shz_vec3_t: shz_vec3_maxv,
987 shz_vec4_t: shz_vec4_maxv)(a, b)
988
989 //! C type-generic component-wise step
990# define shz_vec_stepv(vec, edge)
991 _Generic((vec),
992 shz_vec2_t: shz_vec2_stepv,
993 shz_vec3_t: shz_vec3_stepv,
994 shz_vec4_t: shz_vec4_stepv)(vec, edge)
995
996 //! C type-generic step
997# define shz_vec_step(vec, edge)
998 _Generic((vec),
999 shz_vec2_t: shz_vec2_step,
1000 shz_vec3_t: shz_vec3_step,
1001 shz_vec4_t: shz_vec4_step)(vec, edge)
1002
1003 //! C type-generic component-wise smoothstep
1004# define shz_vec_smoothstepv(vec, edge0, edge1)
1005 _Generic((vec),
1006 shz_vec2_t: shz_vec2_smoothstepv,
1007 shz_vec3_t: shz_vec3_smoothstepv,
1008 shz_vec4_t: shz_vec4_smoothstepv)(vec, edge0, edge1)
1009
1010 //! C type-generic smoothstep
1011# define shz_vec_smoothstep(vec, edge0, edge1)
1012 _Generic((vec),
1013 shz_vec2_t: shz_vec2_smoothstep,
1014 shz_vec3_t: shz_vec3_smoothstep,
1015 shz_vec4_t: shz_vec4_smoothstep)(vec, edge0, edge1)
1016
1017 //! C type-generic component-wise smoothstep_safe
1018# define shz_vec_smoothstepv_safe(vec, edge0, edge1)
1019 _Generic((vec),
1020 shz_vec2_t: shz_vec2_smoothstepv_safe,
1021 shz_vec3_t: shz_vec3_smoothstepv_safe,
1022 shz_vec4_t: shz_vec4_smoothstepv_safe)(vec, edge0, edge1)
1023
1024 //! C type-generic smoothstep_safe
1025# define shz_vec_smoothstep_safe(vec, edge0, edge1)
1026 _Generic((vec),
1027 shz_vec2_t: shz_vec2_smoothstep_safe,
1028 shz_vec3_t: shz_vec3_smoothstep_safe,
1029 shz_vec4_t: shz_vec4_smoothstep_safe)(vec, edge0, edge1)
1030
1031#else // C++ generics (because it's too dumb to support _Generic()).
1032
1033 //! C++ type-generic vector absolute value.
1034 SHZ_INLINE shz_vec2_t shz_vec_abs(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_abs(vec); }
1035 SHZ_INLINE shz_vec3_t shz_vec_abs(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_abs(vec); }
1036 SHZ_INLINE shz_vec4_t shz_vec_abs(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_abs(vec); }
1037
1038 //! C++ type-generic vector negation.
1039 SHZ_INLINE shz_vec2_t shz_vec_neg(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_neg(vec); }
1040 SHZ_INLINE shz_vec3_t shz_vec_neg(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_neg(vec); }
1041 SHZ_INLINE shz_vec4_t shz_vec_neg(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_neg(vec); }
1042
1043 //! C++ type-generic vector inversion.
1044 SHZ_INLINE shz_vec2_t shz_vec_inv(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_inv(vec); }
1045 SHZ_INLINE shz_vec3_t shz_vec_inv(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_inv(vec); }
1046 SHZ_INLINE shz_vec4_t shz_vec_inv(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_inv(vec); }
1047
1048 //! C++ type-generic vector maximum value.
1049 SHZ_INLINE float shz_vec_max(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_max(vec); }
1050 SHZ_INLINE float shz_vec_max(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_max(vec); }
1051 SHZ_INLINE float shz_vec_max(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_max(vec); }
1052
1053 //! C++ type-generic vector minimum value.
1054 SHZ_INLINE float shz_vec_min(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_min(vec); }
1055 SHZ_INLINE float shz_vec_min(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_min(vec); }
1056 SHZ_INLINE float shz_vec_min(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_min(vec); }
1057
1058 //! C++ type-generic vector clamp.
1059 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); }
1060 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); }
1061 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); }
1062
1063 //! C++ type-generic vector equality.
1064 SHZ_INLINE bool shz_vec_equal(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_equal(vec1, vec2); }
1065 SHZ_INLINE bool shz_vec_equal(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_equal(vec1, vec2); }
1066 SHZ_INLINE bool shz_vec_equal(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_equal(vec1, vec2); }
1067
1068 //! C++ type-generic vector addition.
1069 SHZ_INLINE shz_vec2_t shz_vec_add(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_add(vec1, vec2); }
1070 SHZ_INLINE shz_vec3_t shz_vec_add(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_add(vec1, vec2); }
1071 SHZ_INLINE shz_vec4_t shz_vec_add(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_add(vec1, vec2); }
1072
1073 //! C++ type-generic vector subtraction.
1074 SHZ_INLINE shz_vec2_t shz_vec_sub(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_sub(vec1, vec2); }
1075 SHZ_INLINE shz_vec3_t shz_vec_sub(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_sub(vec1, vec2); }
1076 SHZ_INLINE shz_vec4_t shz_vec_sub(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_sub(vec1, vec2); }
1077
1078 //! C++ type-generic component-wise multiplication.
1079 SHZ_INLINE shz_vec2_t shz_vec_mul(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_mul(vec1, vec2); }
1080 SHZ_INLINE shz_vec3_t shz_vec_mul(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_mul(vec1, vec2); }
1081 SHZ_INLINE shz_vec4_t shz_vec_mul(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_mul(vec1, vec2); }
1082
1083 //! C++ type-generic component-wise division.
1084 SHZ_INLINE shz_vec2_t shz_vec_div(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_div(vec1, vec2); }
1085 SHZ_INLINE shz_vec3_t shz_vec_div(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_div(vec1, vec2); }
1086 SHZ_INLINE shz_vec4_t shz_vec_div(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_div(vec1, vec2); }
1087
1088 //! C++ type-generic uniform scaling.
1089 SHZ_INLINE shz_vec2_t shz_vec_scale(shz_vec2_t vec, float factor) SHZ_NOEXCEPT { return shz_vec2_scale(vec, factor); }
1090 SHZ_INLINE shz_vec3_t shz_vec_scale(shz_vec3_t vec, float factor) SHZ_NOEXCEPT { return shz_vec3_scale(vec, factor); }
1091 SHZ_INLINE shz_vec4_t shz_vec_scale(shz_vec4_t vec, float factor) SHZ_NOEXCEPT { return shz_vec4_scale(vec, factor); }
1092
1093 //! C++ type-generic dot product.
1094 SHZ_INLINE float shz_vec_dot(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_dot(vec1, vec2); }
1095 SHZ_INLINE float shz_vec_dot(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_dot(vec1, vec2); }
1096 SHZ_INLINE float shz_vec_dot(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_dot(vec1, vec2); }
1097
1098 //! C++ type-generic dual dot product.
1099 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); }
1100 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); }
1101 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); }
1102
1103 //! C++ type-generic triple dot product.
1104 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); }
1105 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); }
1106 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); }
1107
1108 //! C++ type-generic squared magnitude.
1109 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude_sqr(vec); }
1110 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude_sqr(vec); }
1111 SHZ_INLINE float shz_vec_magnitude_sqr(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude_sqr(vec); }
1112
1113 //! C++ type-generic magnitude.
1114 SHZ_INLINE float shz_vec_magnitude(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude(vec); }
1115 SHZ_INLINE float shz_vec_magnitude(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude(vec); }
1116 SHZ_INLINE float shz_vec_magnitude(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude(vec); }
1117
1118 //! C++ type-generic inverse magnitude.
1119 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_magnitude_inv(vec); }
1120 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_magnitude_inv(vec); }
1121 SHZ_INLINE float shz_vec_magnitude_inv(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_magnitude_inv(vec); }
1122
1123 //! C++ type-generic vector normalization.
1124 SHZ_INLINE shz_vec2_t shz_vec_normalize(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_normalize(vec); }
1125 SHZ_INLINE shz_vec3_t shz_vec_normalize(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_normalize(vec); }
1126 SHZ_INLINE shz_vec4_t shz_vec_normalize(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_normalize(vec); }
1127
1128 //! C++ type-generic safe vector normalization, avoids divide-by-zero.
1129 SHZ_INLINE shz_vec2_t shz_vec_normalize_safe(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_normalize_safe(vec); }
1130 SHZ_INLINE shz_vec3_t shz_vec_normalize_safe(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_normalize_safe(vec); }
1131 SHZ_INLINE shz_vec4_t shz_vec_normalize_safe(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_normalize_safe(vec); }
1132
1133 //! C++ type-generic distance between two points.
1134 SHZ_INLINE float shz_vec_distance(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_distance(vec1, vec2); }
1135 SHZ_INLINE float shz_vec_distance(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_distance(vec1, vec2); }
1136 SHZ_INLINE float shz_vec_distance(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_distance(vec1, vec2); }
1137
1138 //! C++ type-generic squared distance between two points.
1139 SHZ_INLINE float shz_vec_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_distance_sqr(vec1, vec2); }
1140 SHZ_INLINE float shz_vec_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_distance_sqr(vec1, vec2); }
1141 SHZ_INLINE float shz_vec_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_distance_sqr(vec1, vec2); }
1142
1143 //! C++ type-generic moving of one vector towards another.
1144 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); }
1145 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); }
1146 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); }
1147
1148 //! C++ type-generic linear interpolation between two vectors.
1149 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); }
1150 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); }
1151 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); }
1152
1153 //! C++ type-generic reflection of a vector over a surface normal.
1154 SHZ_INLINE shz_vec2_t shz_vec_reflect(shz_vec2_t incidence, shz_vec2_t normal) SHZ_NOEXCEPT { return shz_vec2_reflect(incidence, normal); }
1155 SHZ_INLINE shz_vec3_t shz_vec_reflect(shz_vec3_t incidence, shz_vec3_t normal) SHZ_NOEXCEPT { return shz_vec3_reflect(incidence, normal); }
1156 SHZ_INLINE shz_vec4_t shz_vec_reflect(shz_vec4_t incidence, shz_vec4_t normal) SHZ_NOEXCEPT { return shz_vec4_reflect(incidence, normal); }
1157
1158 //! C++ type-generic refraction of a vector over a surface normal.
1159 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); }
1160 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); }
1161 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); }
1162
1163 //! C++ type-generic cross product (2D returns scalar, 3D returns vector).
1164 SHZ_INLINE float shz_vec_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_cross(vec1, vec2); }
1165 SHZ_INLINE shz_vec3_t shz_vec_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_cross(vec1, vec2); }
1166
1167 //! C++ type-generic projection of the first vector onto the second.
1168 SHZ_INLINE shz_vec2_t shz_vec_project(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_project(vec1, vec2); }
1169 SHZ_INLINE shz_vec3_t shz_vec_project(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_project(vec1, vec2); }
1170 SHZ_INLINE shz_vec4_t shz_vec_project(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT { return shz_vec4_project(vec1, vec2); }
1171
1172 //! C++ type-generic safe projection, avoiding division-by-zero.
1173 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); }
1174 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); }
1175 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); }
1176
1177 //! C++ type-generic angles from the +X axis (2D returns float, 3D returns vec2).
1178 SHZ_INLINE float shz_vec_angles(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_angle(vec); }
1179 SHZ_INLINE shz_vec3_t shz_vec_angles(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_angles(vec); }
1180
1181 //! C++ type-generic angle between two vectors.
1182 SHZ_INLINE float shz_vec_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT { return shz_vec2_angle_between(vec1, vec2); }
1183 SHZ_INLINE float shz_vec_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT { return shz_vec3_angle_between(vec1, vec2); }
1184
1185 //! C++ type-generic swizzle.
1186 SHZ_INLINE shz_vec2_t shz_vec_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) SHZ_NOEXCEPT {
1187 return shz_vec2_swizzle(vec, x_idx, y_idx);
1188 }
1189 SHZ_INLINE shz_vec3_t shz_vec_swizzle(shz_vec3_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx) SHZ_NOEXCEPT {
1190 return shz_vec3_swizzle(vec, x_idx, y_idx, z_idx);
1191 }
1192 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 {
1193 return shz_vec4_swizzle(vec, x_idx, y_idx, z_idx, w_idx);
1194 }
1195
1196 //! C++ type-generic component-wise floor.
1197 SHZ_INLINE shz_vec2_t shz_vec_floor(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_floor(vec); }
1198 SHZ_INLINE shz_vec3_t shz_vec_floor(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_floor(vec); }
1199 SHZ_INLINE shz_vec4_t shz_vec_floor(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_floor(vec); }
1200
1201 //! C++ type-generic component-wise ceil.
1202 SHZ_INLINE shz_vec2_t shz_vec_ceil(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_ceil(vec); }
1203 SHZ_INLINE shz_vec3_t shz_vec_ceil(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_ceil(vec); }
1204 SHZ_INLINE shz_vec4_t shz_vec_ceil(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_ceil(vec); }
1205
1206 //! C++ type-generic component-wise round.
1207 SHZ_INLINE shz_vec2_t shz_vec_round(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_round(vec); }
1208 SHZ_INLINE shz_vec3_t shz_vec_round(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_round(vec); }
1209 SHZ_INLINE shz_vec4_t shz_vec_round(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_round(vec); }
1210
1211 //! C++ type-generic component-wise fract.
1212 SHZ_INLINE shz_vec2_t shz_vec_fract(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_fract(vec); }
1213 SHZ_INLINE shz_vec3_t shz_vec_fract(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_fract(vec); }
1214 SHZ_INLINE shz_vec4_t shz_vec_fract(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_fract(vec); }
1215
1216 //! C++ type-generic component-wise sign.
1217 SHZ_INLINE shz_vec2_t shz_vec_sign(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_sign(vec); }
1218 SHZ_INLINE shz_vec3_t shz_vec_sign(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_sign(vec); }
1219 SHZ_INLINE shz_vec4_t shz_vec_sign(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_sign(vec); }
1220
1221 //! C++ type-generic component-wise saturate.
1222 SHZ_INLINE shz_vec2_t shz_vec_saturate(shz_vec2_t vec) SHZ_NOEXCEPT { return shz_vec2_saturate(vec); }
1223 SHZ_INLINE shz_vec3_t shz_vec_saturate(shz_vec3_t vec) SHZ_NOEXCEPT { return shz_vec3_saturate(vec); }
1224 SHZ_INLINE shz_vec4_t shz_vec_saturate(shz_vec4_t vec) SHZ_NOEXCEPT { return shz_vec4_saturate(vec); }
1225
1226 //! C++ type-generic component-wise minimum.
1227 SHZ_INLINE shz_vec2_t shz_vec_minv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT { return shz_vec2_minv(a, b); }
1228 SHZ_INLINE shz_vec3_t shz_vec_minv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT { return shz_vec3_minv(a, b); }
1229 SHZ_INLINE shz_vec4_t shz_vec_minv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT { return shz_vec4_minv(a, b); }
1230
1231 //! C++ type-generic component-wise maximum.
1232 SHZ_INLINE shz_vec2_t shz_vec_maxv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT { return shz_vec2_maxv(a, b); }
1233 SHZ_INLINE shz_vec3_t shz_vec_maxv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT { return shz_vec3_maxv(a, b); }
1234 SHZ_INLINE shz_vec4_t shz_vec_maxv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT { return shz_vec4_maxv(a, b); }
1235
1236 //! C++ type-generic step: 0 per component if vec[i] < edge, else 1.
1237 SHZ_INLINE shz_vec2_t shz_vec_step(shz_vec2_t vec, float edge) SHZ_NOEXCEPT { return shz_vec2_step (vec, edge); }
1238 SHZ_INLINE shz_vec2_t shz_vec_step(shz_vec2_t vec, shz_vec2_t edge) SHZ_NOEXCEPT { return shz_vec2_stepv(vec, edge); }
1239 SHZ_INLINE shz_vec3_t shz_vec_step(shz_vec3_t vec, float edge) SHZ_NOEXCEPT { return shz_vec3_step (vec, edge); }
1240 SHZ_INLINE shz_vec3_t shz_vec_step(shz_vec3_t vec, shz_vec3_t edge) SHZ_NOEXCEPT { return shz_vec3_stepv(vec, edge); }
1241 SHZ_INLINE shz_vec4_t shz_vec_step(shz_vec4_t vec, float edge) SHZ_NOEXCEPT { return shz_vec4_step (vec, edge); }
1242 SHZ_INLINE shz_vec4_t shz_vec_step(shz_vec4_t vec, shz_vec4_t edge) SHZ_NOEXCEPT { return shz_vec4_stepv(vec, edge); }
1243
1244 //! C++ type-generic smoothstep: 0 at/below edge0, 1 at/above edge1, smooth in-between. Undefined for edge0 > edge1.
1245 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); }
1246 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); }
1247 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); }
1248 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); }
1249 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); }
1250 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); }
1251
1252 //! C++ type-generic smoothstep with safe edge ordering (accepts edge0 > edge1).
1253 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); }
1254 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); }
1255 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); }
1256 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); }
1257 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); }
1258 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); }
1259
1260#endif
1261
1262#include "inline/shz_vector.inl.h"
1263
1264//! @}
1265
1266#endif // SHZ_VECTOR_H
float shz_vec3_magnitude(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the magnitude of the given 3D vector.
shz_vec4_t shz_vec4_sign(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec3_t shz_vec3_mul(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns a 3D vector whose component values are those of vec1 times vec2.
shz_vec4_t shz_vec4_minv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT
Returns a 4D vector whose components are the pairwise minimums of the two given vectors' components.
shz_vec3_t shz_vec3_project_safe(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 3D vector along the given (unit) axis.
shz_vec4_t shz_vec4_sub(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns a 4D vector whose components are equal to the values of vec1 minus vec2.
shz_vec4_t shz_vec4_smoothstep_safe(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
bool shz_vec4_equal(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT
Returns true if the values of each element within the two 4D vectors are approximately equal based on...
shz_vec3_t shz_vec3_angles(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the angles formed between the positive X axis and the given 3D vector, in radians.
shz_vec3_t shz_vec3_smoothstep_safe(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
shz_vec3_t shz_vec3_smoothstep(shz_vec3_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
shz_vec2_t shz_vec2_saturate(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec2_t shz_vec2_from_angle(float radians) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis in radians.
shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) SHZ_NOEXCEPT
Extends a 2D vector to 3D, using z as the value of the Z component.
shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the vector produced by taking the cross-product of the two given 3D vectors.
shz_vec2_t shz_vec2_div(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns a 2D vector whose component values are those of vec1 divided by vec2.
float shz_vec3_dot(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the dot product between the two given 3D vectors.
shz_vec2_t shz_vec2_smoothstep_safe(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between....
shz_vec4_t shz_vec4_init(float x, float y, float z, float w) SHZ_NOEXCEPT
Returns a 4D vector with the given x, y, z, and w coordinates.
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_saturate(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec3_t shz_vec3_sub(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns a 3D vector whose components are equal to the values of vec1 minus vec2.
shz_vec2_t shz_vec2_smoothstepv(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-betwe...
float shz_vec3_magnitude_sqr(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the squared magnitude of the given 3D vector.
shz_vec4_t shz_vec4_floor(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the floor of the given vector's components.
shz_vec2_t shz_vec2_abs(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the absolute values of the given vector's components.
float shz_vec2_min(shz_vec2_t vec) SHZ_NOEXCEPT
Retuns the minimum value of both of the given vector's components.
float shz_vec4_min(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the minimum value of the given vector's 4 components.
shz_vec2_t shz_vec2_normalize_safe(shz_vec2_t vec) SHZ_NOEXCEPT
SAFELY returns a normalized unit vector from the given 2D vector.
shz_vec3_t shz_vec3_fill(float v) SHZ_NOEXCEPT
Returns a 3D vector with the value of each compoonent equal to v.
shz_vec2_t shz_vec4_dot2(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2) SHZ_NOEXCEPT
Returns the two dot products taken between the 4D vector l and 4D vectors r1 and r2.
shz_vec2_t shz_vec2_add(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns a 2D vector whose components are the sums of the given vectors' components.
shz_vec4_t shz_vec4_round(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the rounded values of the given vector's components.
shz_vec3_t shz_vec3_dot3(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2, shz_vec3_t r3) SHZ_NOEXCEPT
Returns the three dot products taken between the 3D vector l and 3D vectors r1, r2,...
shz_vec4_t shz_vec4_stepv(shz_vec4_t vec, shz_vec4_t edge) SHZ_NOEXCEPT
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
shz_vec3_t shz_vec3_smoothstepv_safe(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_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_vec3_dot2(shz_vec3_t l, shz_vec3_t r1, shz_vec3_t r2) SHZ_NOEXCEPT
Returns the two dot products taken between the 3D vector l and 3D vectors r1 and r2.
shz_vec2_t shz_vec2_rotate(shz_vec2_t vec, float radians) SHZ_NOEXCEPT
Rotates the given 2D vector about the Z axis by the given angle in radians.
shz_vec4_t shz_vec4_maxv(shz_vec4_t a, shz_vec4_t b) SHZ_NOEXCEPT
Returns a 4D vector whose components are the pairwise maximums of the two given vectors' components.
shz_vec3_t shz_vec3_normalize_safe(shz_vec3_t vec) SHZ_NOEXCEPT
SAFELY returns a normalized unit vector from the given 3D vector.
shz_vec4_t shz_vec4_swizzle(shz_vec4_t vec, unsigned x_idx, unsigned y_idx, unsigned z_idx, unsigned w_idx) SHZ_NOEXCEPT
Returns a new 2D vector whose elements are equal to the source vector's values at the given indices.
float shz_vec3_distance_sqr(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the squared-distance between the two given 3D vectors.
shz_vec4_t shz_vec4_smoothstepv(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_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_from_angle_deg(float degrees) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis in degrees.
shz_vec4_t shz_vec4_smoothstep(shz_vec4_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
shz_vec3_t shz_vec3_round(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the rounded values of the given vector's components.
float shz_vec4_max(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the maximum value of the given vector's 4 componetns.
shz_vec2_t shz_vec2_neg(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the negative values of the given vector's components.
shz_vec3_t shz_vec4_dot3(shz_vec4_t l, shz_vec4_t r1, shz_vec4_t r2, shz_vec4_t r3) SHZ_NOEXCEPT
Returns the three dot products taken between the 4D vector l and 4D vectors r1, r2,...
shz_vec4_t shz_vec4_refract(shz_vec4_t incidence, shz_vec4_t normal, float eta) SHZ_NOEXCEPT
Refracts the given 4D incidence vector against a surface with the given normal using the given refrac...
float shz_vec3_distance(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the distance between the two given 3D vectors.
float shz_vec4_magnitude(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the magnitude of the given 4D vector.
shz_vec2_t shz_vec2_from_sincos(shz_sincos_t sincos) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis.
shz_vec4_t shz_vec4_mul(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns a 4D vector whose component values are those of vec1 times vec2.
shz_vec3_t shz_vec3_floor(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the floor of the given vector's components.
shz_vec3_t shz_vec3_neg(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the negative values of the given vector's components.
shz_vec3_t shz_vec3_normalize(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a normalized unit vector from the given 3D vector.
float shz_vec4_dot(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns the dot product between the two given 4D vectors.
shz_vec3_t shz_vec3_maxv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT
Returns a 3D vector whose components are the pairwise maximums of the two given vectors' components.
shz_vec4_t shz_vec4_step(shz_vec4_t vec, float edge) SHZ_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) SHZ_NOEXCEPT
Returns a 3D vector whose elements are equal to the source vector's values at the given indices.
float shz_vec4_distance(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns the distance between the two given 4D vectors.
shz_vec4_t shz_vec4_abs(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the absolute values of the given vector's components.
shz_vec2_t shz_vec2_scale(shz_vec2_t vec, float factor) SHZ_NOEXCEPT
Returns a 2D vector whose component values are those of the given vector multiplied by a factor.
float shz_vec2_angle(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the angle formed between the positive X axis and the given 2D vector, in radians.
float shz_vec2_max(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the maximum value of both of the given vector's components.
shz_vec4_t shz_vec4_normalize_safe(shz_vec4_t vec) SHZ_NOEXCEPT
SAFELY returns a normalized unit vector from the given 4D vector.
shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...
shz_vec2_t shz_vec2_round(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the rounded values of the given vector's components.
shz_vec4_t shz_vec4_smoothstepv_safe(shz_vec4_t vec, shz_vec4_t edge0, shz_vec4_t edge1) SHZ_NOEXCEPT
For each component i: returns 0.0f at/below edge0[i], 1.0f at/above edge1[i], smoothly varying in-bet...
shz_vec3_t shz_vec3_add(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns a 3D vector whose components are the sums of the given vectors' components.
shz_vec3_t shz_vec3_smoothstepv(shz_vec3_t vec, shz_vec3_t edge0, shz_vec3_t edge1) SHZ_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_fract(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the fractional parts of the given vector's components.
shz_vec2_t shz_vec2_maxv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT
Returns a 2D vector whose components are the pairwise maximums of the two given vectors' components.
shz_vec2_t shz_vec2_move(shz_vec2_t vec, shz_vec2_t target, float max_distance) SHZ_NOEXCEPT
Returns the given 2D vector, translated towards the target by the given max_distance.
shz_vec2_t shz_vec2_inv(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the 2D vector whose components have been inverted or reciprocated.
shz_vec4_t shz_vec4_inv(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the 4D vector whose components have been inverted or reciprocated.
shz_vec3_t shz_vec3_barycenter(shz_vec3_t p, shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT
Computes barycentric coordinates <u, v, w> for point p, within the plane of the triangle with vertice...
shz_vec2_t shz_vec2_clamp(shz_vec2_t vec, float min, float max) SHZ_NOEXCEPT
Clamps the values of the given 2D vec between min and max, returning a new vector.
shz_vec4_t shz_vec4_saturate(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are saturated (clamped to [0, 1]) values of the given vector's c...
shz_vec2_t shz_vec2_step(shz_vec2_t vec, float edge) SHZ_NOEXCEPT
For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f.
shz_vec2_t shz_vec2_floor(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the floor of the given vector's components.
float shz_vec2_angle_between(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the angle formed between the given 2D vectors in radians.
shz_vec4_t shz_vec4_div(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns a 4D vector whose component values are those of vec1 divided by vec2.
shz_vec2_t shz_vec2_project_safe(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 2D vector along the given (unit) axis.
shz_vec2_t shz_vec2_normalize(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a normalized unit vector from the given 2D vector.
shz_vec4_t shz_vec4_lerp(shz_vec4_t a, shz_vec4_t b, float t) SHZ_NOEXCEPT
Returns a 4D vector that is linearly interpolated from a to b by the given 0.0f-1....
shz_vec4_t shz_vec4_project_safe(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 4D vector along the given (unit) axis.
shz_vec4_t shz_vec4_move(shz_vec4_t vec, shz_vec4_t target, float max_distance) SHZ_NOEXCEPT
Returns the given 4D vector, translated towards the target by the given max_distance.
shz_vec4_t shz_vec4_fract(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the fractional parts of the given vector's components.
shz_vec2_t shz_vec2_fill(float v) SHZ_NOEXCEPT
Returns a 2D vector with the value of each component equal to v.
float shz_vec3_magnitude_inv(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the inverse magnitude of the given 3D vector.
float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT
Returns the 3D vector "triple product" between vector's a, b, and c.
shz_vec3_t shz_vec3_init(float x, float y, float z) SHZ_NOEXCEPT
Returns a 3D vector with the given x, y, and z coordinates.
float shz_vec3_min(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the minimum value of the given vector's 3 components.
bool shz_vec2_equal(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT
Returns true if the values of each element within the two 2D vectors are approximately equal based on...
shz_vec4_t shz_vec4_reflect(shz_vec4_t incidence, shz_vec4_t normal) SHZ_NOEXCEPT
Reflects the given 4D incidence vector against a surface with the given normal, returning the result.
void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t *out1, shz_vec3_t *out2) SHZ_NOEXCEPT
Returns 2 3D vectors which are normalized and orthogonal to the two input vectors.
float shz_vec2_magnitude_inv(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the inverse magnitude of the given 2D vector.
float shz_vec4_magnitude_sqr(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the squared magnitude of the given 4D vector.
shz_vec3_t shz_vec3_lerp(shz_vec3_t a, shz_vec3_t b, float t) SHZ_NOEXCEPT
Returns a 3D vector that is linearly interpolated from a to b by the given 0.0f-1....
float shz_vec2_distance(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the distance between the two given 2D vectors.
shz_vec3_t shz_vec2_dot3(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2, shz_vec2_t r3) SHZ_NOEXCEPT
Returns the three dot products taken between the 2D vector l and 2D vectors r1, r2,...
shz_vec3_t shz_vec3_from_sincos(shz_sincos_t azimuth, shz_sincos_t elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis.
shz_vec2_t shz_vec2_minv(shz_vec2_t a, shz_vec2_t b) SHZ_NOEXCEPT
Returns a 2D vector whose components are the pairwise minimums of the two given vectors' components.
shz_vec3_t shz_vec3_stepv(shz_vec3_t vec, shz_vec3_t edge) SHZ_NOEXCEPT
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
shz_vec3_t shz_vec3_ceil(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the ceil of the given vector's components.
bool shz_vec3_equal(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT
Returns true if the values of each element within the two 3D vectors are approximately equal based on...
shz_vec2_t shz_vec2_reflect(shz_vec2_t incidence, shz_vec2_t normal) SHZ_NOEXCEPT
Reflects the given 2D incidence vector against a surface with the given normal, returning the result.
shz_vec3_t shz_vec3_sign(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec3_t shz_vec3_step(shz_vec3_t vec, float edge) SHZ_NOEXCEPT
For each component: returns 0.0f if vec[i] < edge, otherwise 1.0f.
float shz_vec2_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the cross product, as a scalar, between two 2D vectors.
float shz_vec4_distance_sqr(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns the squared-distance between the two given 4D vectors.
shz_vec2_t shz_vec2_smoothstepv_safe(shz_vec2_t vec, shz_vec2_t edge0, shz_vec2_t edge1) SHZ_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_fill(float v) SHZ_NOEXCEPT
Returns a 4D vector with the value of each component equal to v.
shz_vec2_t shz_vec2_lerp(shz_vec2_t a, shz_vec2_t b, float t) SHZ_NOEXCEPT
Returns a 2D vector that is linearly interpolated from a to b by the given 0.0f-1....
shz_vec3_t shz_vec3_perp(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a vector which is perpendicular to the given vector.
shz_vec4_t shz_vec4_scale(shz_vec4_t vec, float factor) SHZ_NOEXCEPT
Returns a 4D vector whose component values are those of the given vector multiplied by a factor.
shz_vec3_t shz_vec3_project(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 3D vector along the given (unit) axis.
shz_vec4_t shz_vec2_vec4(shz_vec2_t vec, float z, float w) SHZ_NOEXCEPT
Extends a 2D vector to 4D, using z and w as the values of the Z and W components.
shz_vec2_t shz_vec2_stepv(shz_vec2_t vec, shz_vec2_t edge) SHZ_NOEXCEPT
For each component: returns 0.0f if vec[i] < edge[i], otherwise 1.0f.
shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT
Returns the rejection of the given vector, vec, onto another vector, onto.
shz_vec4_t shz_vec4_project(shz_vec4_t vec, shz_vec4_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 4D vector along the given (unit) axis.
float shz_vec4_magnitude_inv(shz_vec4_t vec) SHZ_NOEXCEPT
Returns the inverse magnitude of the given 4D vector.
shz_vec3_t shz_vec3_scale(shz_vec3_t vec, float factor) SHZ_NOEXCEPT
Returns a 3D vector whose component values are those of the given vector multiplied by a factor.
shz_vec4_t shz_vec3_vec4(shz_vec3_t vec, float w) SHZ_NOEXCEPT
Extends a 3D vector to 4D, using w as the value of the W component.
shz_vec2_t shz_vec2_mul(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns a 2D vector whose component values are those of vec1 times vec2.
float shz_vec2_distance_sqr(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the squared-distance between the two given 2D vectors.
shz_vec3_t shz_vec3_move(shz_vec3_t vec, shz_vec3_t target, float max_distance) SHZ_NOEXCEPT
Returns the given 3D vector, translated towards the target by the given max_distance.
shz_vec3_t shz_vec3_refract(shz_vec3_t incidence, shz_vec3_t normal, float eta) SHZ_NOEXCEPT
Refracts the given 3D incidence vector against a surface with the given normal using the given refrac...
shz_vec4_t shz_vec4_neg(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the negative values of the given vector's components.
shz_vec2_t shz_vec2_swizzle(shz_vec2_t vec, unsigned x_idx, unsigned y_idx) SHZ_NOEXCEPT
Returns a 2D vector whose elements are equal to the source vector's values at the given indices.
float shz_vec3_angle_between(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the angle formed between the given 3D vectors in radians.
shz_vec3_t shz_vec3_inv(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the 3D vector whose components have been inverted or reciprocated.
shz_vec3_t shz_vec3_reflect(shz_vec3_t incidence, shz_vec3_t normal) SHZ_NOEXCEPT
Reflects the given 3D incidence vector against a surface with the given normal, returning the result.
shz_vec2_t shz_vec2_refract(shz_vec2_t incidence, shz_vec2_t normal, float eta) SHZ_NOEXCEPT
Refracts the given 2D incidence vector against a surface with the given normal using the given refrac...
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_abs(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the absolute values of the given vector's components.
float shz_vec2_magnitude(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the magnitude of the given 2D vector.
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
Calculates the cubic hermite interpolation between two vectors and their tangents.
float shz_vec2_dot(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the dot product between the two given 2D vectors.
float shz_vec3_max(shz_vec3_t vec) SHZ_NOEXCEPT
Returns the maximum value of the given vector's 3 components.
shz_vec4_t shz_vec4_normalize(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a normalized unit vector from the given 4D vector.
shz_vec2_t shz_vec2_ceil(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the ceil of the given vector's components.
shz_vec3_t shz_vec3_clamp(shz_vec3_t vec, float min, float max) SHZ_NOEXCEPT
Clamps the values of the given 3D vec between min and max, returning a new vector.
shz_vec3_t shz_vec3_div(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns a 3D vector whose component values are those of vec1 divided by vec2.
shz_vec3_t shz_vec3_minv(shz_vec3_t a, shz_vec3_t b) SHZ_NOEXCEPT
Returns a 3D vector whose components are the pairwise minimums of the two given vectors' components.
shz_vec2_t shz_vec2_dot2(shz_vec2_t l, shz_vec2_t r1, shz_vec2_t r2) SHZ_NOEXCEPT
Returns the two dot products taken between the 2D vector l and 2D vectors r1 and r2.
shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...
shz_vec4_t shz_vec4
Alternate typedef for the shz_vec4 struct for those who hate POSIX-style.
Definition shz_vector.h:105
shz_vec2_t shz_vec2_sign(shz_vec2_t vec) SHZ_NOEXCEPT
Returns a 2D vector whose components are the signs (-1, 0, or 1) of the given vector's components.
shz_vec4_t shz_vec4_ceil(shz_vec4_t vec) SHZ_NOEXCEPT
Returns a 4D vector whose components are the ceil of the given vector's components.
shz_vec2_t shz_vec2_sub(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns a 2D vector whose components are equal to the values of vec1 minus vec2.
shz_vec3_t shz_vec3_fract(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a 3D vector whose components are the fractional parts of the given vector's components.
shz_vec2_t shz_vec2_smoothstep(shz_vec2_t vec, float edge0, float edge1) SHZ_NOEXCEPT
For each component: returns 0.0f at/below edge0, 1.0f at/above edge1, smoothly varying in-between.
float shz_vec2_magnitude_sqr(shz_vec2_t vec) SHZ_NOEXCEPT
Returns the squared magnitude of the given 2D vector.
shz_vec2_t shz_vec2_init(float x, float y) SHZ_NOEXCEPT
Returns a 2D vector with the given x, and y coordinates.
shz_vec2_t shz_vec2_project(shz_vec2_t vec, shz_vec2_t onto) SHZ_NOEXCEPT
Returns the resulting vector from projecting the given 2D vector along the given (unit) axis.
shz_vec4_t shz_vec4_add(shz_vec4_t vec1, shz_vec4_t vec2) SHZ_NOEXCEPT
Returns a 4D vector whose components are the sums of the given vectors' components.
shz_vec4_t shz_vec4_clamp(shz_vec4_t vec, float min, float max) SHZ_NOEXCEPT
Clamps the values of the given 4D vec between min and max, returning a new vector.
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 e[4]
<X, Y, Z, W> coordinates as an array.
Definition shz_vector.h:84
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