50 res[0] = a; res[1] = b;
71 res[0] = lhs[0] + rhs[0];
72 res[1] = lhs[1] + rhs[1];
89 res[0] = a[0] + b[0] * s;
90 res[1] = a[1] + b[1] * s;
100 res[0] = lhs[0] - rhs[0];
101 res[1] = lhs[1] - rhs[1];
122 res[0] = v[0] * s[0];
123 res[1] = v[1] * s[1];
133 return a[0] * b[0] + a[1] * b[1];
141 return a[0]*b[1] - a[1]*b[0];
150 return bj_sqrt(v[0] * v[0] + v[1] * v[1]);
163 bj_real scale = target_len / len;
175 const bj_real dx = a[0] - b[0];
176 const bj_real dy = a[1] - b[1];
177 return dx * dx + dy * dy;
199 res[0] = v[0] * inv_len;
200 res[1] = v[1] * inv_len;
210 res[0] = a[0] < b[0] ? a[0] : b[0];
211 res[1] = a[1] < b[1] ? a[1] : b[1];
221 res[0] = a[0] > b[0] ? a[0] : b[0];
222 res[1] = a[1] > b[1] ? a[1] : b[1];
243 res[0] = a; res[1] = b; res[2] = c;
247 res[0] = res[1] = res[2] =
BJ_FZERO;
264 res[0] = lhs[0] + rhs[0];
265 res[1] = lhs[1] + rhs[1];
266 res[2] = lhs[2] + rhs[2];
277 res[0] = a[0] + b[0] * s;
278 res[1] = a[1] + b[1] * s;
279 res[2] = a[2] + b[2] * s;
290 res[0] = lhs[0] - rhs[0];
291 res[1] = lhs[1] - rhs[1];
292 res[2] = lhs[2] - rhs[2];
314 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
323 return bj_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
336 bj_real scale = target_len / len;
348 const bj_real dx = a[0] - b[0];
349 const bj_real dy = a[1] - b[1];
350 const bj_real dz = a[2] - b[2];
351 return dx * dx + dy * dy + dz * dz;
374 res[0] = v[0] * inv_len;
375 res[1] = v[1] * inv_len;
376 res[2] = v[2] * inv_len;
386 res[0] = a[0] < b[0] ? a[0] : b[0];
387 res[1] = a[1] < b[1] ? a[1] : b[1];
388 res[2] = a[2] < b[2] ? a[2] : b[2];
398 res[0] = a[0] > b[0] ? a[0] : b[0];
399 res[1] = a[1] > b[1] ? a[1] : b[1];
400 res[2] = a[2] > b[2] ? a[2] : b[2];
422 res[0] = l[1] * r[2] - l[2] * r[1];
423 res[1] = l[2] * r[0] - l[0] * r[2];
424 res[2] = l[0] * r[1] - l[1] * r[0];
437 for (
int i = 0; i < 3; ++i) {
438 res[i] = v[i] - p * n[i];
452 res[0] = a; res[1] = b; res[2] = c; res[3] = d;
469 res[0] = lhs[0] + rhs[0];
470 res[1] = lhs[1] + rhs[1];
471 res[2] = lhs[2] + rhs[2];
472 res[3] = lhs[3] + rhs[3];
483 res[0] = a[0] + b[0] * s;
484 res[1] = a[1] + b[1] * s;
485 res[2] = a[2] + b[2] * s;
486 res[3] = a[3] + b[3] * s;
496 res[0] = lhs[0] - rhs[0];
497 res[1] = lhs[1] - rhs[1];
498 res[2] = lhs[2] - rhs[2];
499 res[3] = lhs[3] - rhs[3];
522 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
531 return bj_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
541 bj_real inv_len =
BJ_F(1.0) /
bj_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
542 res[0] = v[0] * inv_len;
543 res[1] = v[1] * inv_len;
544 res[2] = v[2] * inv_len;
545 res[3] = v[3] * inv_len;
555 res[0] = a[0] < b[0] ? a[0] : b[0];
556 res[1] = a[1] < b[1] ? a[1] : b[1];
557 res[2] = a[2] < b[2] ? a[2] : b[2];
558 res[3] = a[3] < b[3] ? a[3] : b[3];
568 res[0] = a[0] > b[0] ? a[0] : b[0];
569 res[1] = a[1] > b[1] ? a[1] : b[1];
570 res[2] = a[2] > b[2] ? a[2] : b[2];
571 res[3] = a[3] > b[3] ? a[3] : b[3];
595 res[0] = l[1] * r[2] - l[2] * r[1];
596 res[1] = l[2] * r[0] - l[0] * r[2];
597 res[2] = l[0] * r[1] - l[1] * r[0];
611 for (
int i = 0; i < 4; ++i) {
612 res[i] = v[i] - p * n[i];
General-purpose definitions for Banjo API.
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:260
bj_real bj_vec3[3]
bj_vec3: 3D vector of bj_real values.
Definition vec.h:34
static void bj_vec4_reflect(bj_vec4 res, const bj_vec4 v, const bj_vec4 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:608
static void bj_vec2_scale_each(bj_vec2 res, const bj_vec2 v, const bj_vec2 s)
Per-component scaling: res[i] = v[i] * s[i].
Definition vec.h:121
bj_real bj_vec2[2]
bj_vec2: 2D vector of bj_real values.
Definition vec.h:27
static void bj_vec3_add(bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
Component-wise addition of two 3D vectors: res = lhs + rhs.
Definition vec.h:263
static void bj_vec2_scale(bj_vec2 res, const bj_vec2 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:110
static void bj_vec2_set_len(bj_vec2 res, const bj_vec2 v, bj_real target_len)
Scale a 2D vector to a given length.
Definition vec.h:161
static bj_real bj_vec2_dist(const bj_vec2 a, const bj_vec2 b)
Euclidean distance between two 2D vectors.
Definition vec.h:187
static bj_real bj_vec3_dist(const bj_vec3 a, const bj_vec3 b)
Euclidean distance between two 3D vectors.
Definition vec.h:361
static bj_real bj_vec3_dist_squared(const bj_vec3 a, const bj_vec3 b)
Squared Euclidean distance between two 3D vectors.
Definition vec.h:347
static void bj_vec2_zero(bj_vec2 res)
Definition vec.h:53
static void bj_vec2_add(bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
Component-wise addition of two 2D vectors: res = lhs + rhs.
Definition vec.h:70
static bj_real bj_vec2_len(const bj_vec2 v)
Euclidean length (L2 norm) of a 2D vector.
Definition vec.h:149
bj_real bj_vec4[4]
bj_vec4: 4D vector of bj_real values.
Definition vec.h:41
static void bj_vec3_add_scaled(bj_vec3 res, const bj_vec3 a, const bj_vec3 b, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:276
static void bj_vec3_scale(bj_vec3 res, const bj_vec3 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:301
static void bj_vec2_min(bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
Component-wise minimum of two 2D vectors.
Definition vec.h:209
static void bj_vec3_max(bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
Component-wise maximum of two 3D vectors.
Definition vec.h:397
static bj_real bj_vec3_dot(const bj_vec3 a, const bj_vec3 b)
Dot product of two 3D vectors.
Definition vec.h:313
static void bj_vec2_set(bj_vec2 res, bj_real a, bj_real b)
Set a 2D vector from components (x, y).
Definition vec.h:49
static void bj_vec2_add_scaled(bj_vec2 res, const bj_vec2 a, const bj_vec2 b, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:83
static void bj_vec2_apply(bj_vec2 res, const bj_vec2 a, bj_real(*f)(bj_real))
Definition vec.h:57
static void bj_vec3_set_len(bj_vec3 res, const bj_vec3 v, bj_real target_len)
Scale a 3D vector to a given length.
Definition vec.h:334
static bj_real bj_vec4_len(const bj_vec4 v)
Euclidean length (L2 norm) of a 4D vector.
Definition vec.h:530
static void bj_vec3_min(bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
Component-wise minimum of two 3D vectors.
Definition vec.h:385
static void bj_vec4_sub(bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
Component-wise subtraction of two 4D vectors: res = lhs - rhs.
Definition vec.h:495
static void bj_vec2_sub(bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
Component-wise subtraction of two 2D vectors: res = lhs - rhs.
Definition vec.h:99
static bj_real bj_vec3_len(const bj_vec3 v)
Euclidean length (L2 norm) of a 3D vector.
Definition vec.h:322
static void bj_vec4_cross(bj_vec4 res, const bj_vec4 l, const bj_vec4 r)
Cross product using xyz components; w is set to 1.
Definition vec.h:593
static void bj_vec3_zero(bj_vec3 res)
Definition vec.h:246
static void bj_vec4_copy(bj_vec4 res, const bj_vec4 src)
Copy a 4D vector.
Definition vec.h:579
static void bj_vec4_max(bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
Component-wise maximum of two 4D vectors.
Definition vec.h:567
static void bj_vec4_set(bj_vec4 res, bj_real a, bj_real b, bj_real c, bj_real d)
Set a 4D vector from components (x, y, z, w).
Definition vec.h:451
static void bj_vec2_normalize(bj_vec2 res, const bj_vec2 v)
Normalize a 2D vector to unit length.
Definition vec.h:197
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
static void bj_vec4_add_scaled(bj_vec4 res, const bj_vec4 a, const bj_vec4 b, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:482
static bj_real bj_vec2_dist_squared(const bj_vec2 a, const bj_vec2 b)
Squared Euclidean distance between two 2D vectors.
Definition vec.h:174
static void bj_vec3_set(bj_vec3 res, bj_real a, bj_real b, bj_real c)
Set a 3D vector from components (x, y, z).
Definition vec.h:242
static void bj_vec3_apply(bj_vec3 res, const bj_vec3 a, bj_real(*f)(bj_real))
Definition vec.h:250
static void bj_vec2_copy(bj_vec2 res, const bj_vec2 src)
Copy a 2D vector.
Definition vec.h:230
static void bj_vec2_max(bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
Component-wise maximum of two 2D vectors.
Definition vec.h:220
static bj_real bj_vec2_dot(const bj_vec2 a, const bj_vec2 b)
Dot product of two 2D vectors.
Definition vec.h:132
static void bj_vec4_normalize(bj_vec4 res, const bj_vec4 v)
Normalize a 4D vector to unit length.
Definition vec.h:540
static void bj_vec4_add(bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
Component-wise addition of two 4D vectors: res = lhs + rhs.
Definition vec.h:468
static bj_real bj_vec2_cross(const bj_vec2 a, const bj_vec2 b)
2D "cross product" (perp dot): returns scalar a.x*b.y - a.y*b.x.
Definition vec.h:140
static void bj_vec4_scale(bj_vec4 res, const bj_vec4 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:508
static void bj_vec3_copy(bj_vec3 res, const bj_vec3 src)
Copy a 3D vector.
Definition vec.h:408
static void bj_vec3_reflect(bj_vec3 res, const bj_vec3 v, const bj_vec3 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:434
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
static void bj_vec4_min(bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
Component-wise minimum of two 4D vectors.
Definition vec.h:554
#define bj_sqrt
Square root.
Definition math.h:222
float bj_real
Selected real type for float configuration.
Definition math.h:51
static void bj_vec3_sub(bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
Component-wise subtraction of two 3D vectors: res = lhs - rhs.
Definition vec.h:289
static bj_real bj_vec4_dot(const bj_vec4 a, const bj_vec4 b)
Dot product of two 4D vectors.
Definition vec.h:521
static void bj_vec4_apply(bj_vec4 res, const bj_vec4 a, bj_real(*f)(bj_real))
Definition vec.h:455
static void bj_vec3_cross(bj_vec3 res, const bj_vec3 l, const bj_vec3 r)
3D cross product: res = l × r (right-hand rule).
Definition vec.h:420
static void bj_vec3_normalize(bj_vec3 res, const bj_vec3 v)
Normalize a 3D vector to unit length.
Definition vec.h:372
C99 math shim with bj_real precision type and scalar utilities.