32#define BJ_VEC2_ZERO ((bj_vec2){BJ_FZERO, BJ_FZERO})
45#define BJ_VEC3_ZERO ((bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO})
59#define BJ_VEC4_ZERO ((bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO})
65 return (
bj_vec2){ .x = f(a.
x), .y = f(a.
y), };
77 return (
bj_vec2){ .x = lhs.
x + rhs.
x, .y = lhs.
y + rhs.
y, };
92 return (
bj_vec2){ .x = lhs.
x + rhs.
x * s, .y = lhs.
y + rhs.
y * s, };
105 return (
bj_vec2){ .x = lhs.
x - rhs.
x, .y = lhs.
y - rhs.
y, };
115 return (
bj_vec2){ .x = v.
x * s, .y = v.
y * s, };
128 return (
bj_vec2){ .x = v.
x * s.
x, .y = v.
y * s.
y, };
138 return a.
x * b.
x + a.
y * b.
y;
146 return a.
x*b.
y - a.
y*b.
x;
182 return dx * dx + dy * dy;
214 return (
bj_vec2){ v.
x * inv, v.
y * inv };
232 return (
bj_vec2){ v.
x * inv, v.
y * inv };
260 return (
bj_vec3){ .x = f(a.
x), .y = f(a.
y), .z = f(a.
z), };
290 .x = lhs.
x + rhs.
x * s,
291 .y = lhs.
y + rhs.
y * s,
292 .z = lhs.
z + rhs.
z * s,
335 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
372 return dx * dx + dy * dy + dz * dz;
403 return (
bj_vec3){ v.
x * inv, v.
y * inv, v.
z * inv };
420 return (
bj_vec3){ v.
x * inv, v.
y * inv, v.
z * inv };
431 a.
x < b.
x ? a.
x : b.
x,
432 a.
y < b.
y ? a.
y : b.
y,
433 a.
z < b.
z ? a.
z : b.
z,
456 .x = l.
y * r.
z - l.
z * r.
y,
457 .y = l.
z * r.
x - l.
x * r.
z,
458 .z = l.
x * r.
y - l.
y * r.
x,
483 return (
bj_vec4){ .x = f(a.
x), .y = f(a.
y), .z = f(a.
z), .w = f(a.
w), };
514 .x = lhs.
x + rhs.
x * s,
515 .y = lhs.
y + rhs.
y * s,
516 .z = lhs.
z + rhs.
z * s,
517 .w = lhs.
w + rhs.
w * s,
561 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
591 return (
bj_vec4){ v.
x * inv, v.
y * inv, v.
z * inv, v.
w * inv };
608 return (
bj_vec4){ v.
x * inv, v.
y * inv, v.
z * inv, v.
w * inv };
619 a.
x < b.
x ? a.
x : b.
x,
620 a.
y < b.
y ? a.
y : b.
y,
621 a.
z < b.
z ? a.
z : b.
z,
622 a.
w < b.
w ? a.
w : b.
w,
634 a.
x > b.
x ? a.
x : b.
x,
635 a.
y > b.
y ? a.
y : b.
y,
636 a.
z > b.
z ? a.
z : b.
z,
637 a.
w > b.
w ? a.
w : b.
w,
General-purpose definitions for Banjo API.
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:217
bj_real y
Definition vec.h:40
bj_real z
Definition vec.h:54
bj_real x
Definition vec.h:52
bj_real y
Definition vec.h:28
bj_real y
Definition vec.h:53
bj_real x
Definition vec.h:39
bj_real z
Definition vec.h:41
bj_real x
Definition vec.h:27
bj_real w
Definition vec.h:55
struct bj_vec3_t bj_vec3
Definition vec.h:43
static bj_vec3 bj_vec3_max(bj_vec3 a, bj_vec3 b)
Component-wise maximum of two 3D vectors.
Definition vec.h:443
static bj_vec4 bj_vec4_normalize_unsafe(bj_vec4 v)
Normalize a 4D vector to unit length (unsafe).
Definition vec.h:606
static bj_vec4 bj_vec4_min(bj_vec4 a, bj_vec4 b)
Component-wise minimum of two 4D vectors.
Definition vec.h:617
static bj_vec3 bj_vec3_sub(bj_vec3 lhs, bj_vec3 rhs)
Component-wise subtraction of two 3D vectors: res = lhs - rhs.
Definition vec.h:303
static bj_vec3 bj_vec3_min(bj_vec3 a, bj_vec3 b)
Component-wise minimum of two 3D vectors.
Definition vec.h:429
static bj_real bj_vec2_len(bj_vec2 v)
Euclidean length (L2 norm) of a 2D vector.
Definition vec.h:154
static bj_vec2 bj_vec2_normalize_unsafe(bj_vec2 v)
Normalize a 2D vector to unit length (unsafe).
Definition vec.h:230
static bj_real bj_vec2_distance_sq(bj_vec2 a, bj_vec2 b)
Squared Euclidean distance between two 2D vectors.
Definition vec.h:179
static bj_vec2 bj_vec2_min(bj_vec2 a, bj_vec2 b)
Component-wise minimum of two 2D vectors.
Definition vec.h:242
static bj_real bj_vec3_len(bj_vec3 v)
Euclidean length (L2 norm) of a 3D vector.
Definition vec.h:343
static bj_real bj_vec3_distance(bj_vec3 a, bj_vec3 b)
Euclidean distance between two 3D vectors.
Definition vec.h:381
static bj_vec3 bj_vec3_reflect(bj_vec3 v, bj_vec3 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:469
static bj_vec2 bj_vec2_max(bj_vec2 a, bj_vec2 b)
Component-wise maximum of two 2D vectors.
Definition vec.h:252
static bj_vec3 bj_vec3_normalize_unsafe(bj_vec3 v)
Normalize a 3D vector to unit length (unsafe).
Definition vec.h:418
static bj_vec2 bj_vec2_scale_to_len(bj_vec2 v, bj_real L)
Scale a 2D vector to a given length.
Definition vec.h:165
struct bj_vec2_t bj_vec2
Definition vec.h:30
static bj_real bj_vec2_perp_dot(bj_vec2 a, bj_vec2 b)
2D "cross product" (perp dot): returns scalar a.x*b.y - a.y*b.x.
Definition vec.h:145
struct bj_vec4_t bj_vec4
Definition vec.h:57
static bj_vec2 bj_vec2_add(bj_vec2 lhs, bj_vec2 rhs)
Component-wise addition of two 2D vectors: res = lhs + rhs.
Definition vec.h:76
static bj_real bj_vec4_dot(bj_vec4 a, bj_vec4 b)
Dot product of two 4D vectors.
Definition vec.h:560
static bj_vec2 bj_vec2_add_scaled(bj_vec2 lhs, bj_vec2 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:87
static bj_vec4 bj_vec4_add(bj_vec4 lhs, bj_vec4 rhs)
Component-wise addition of two 4D vectors: res = lhs + rhs.
Definition vec.h:492
static bj_vec4 bj_vec4_normalize(bj_vec4 v)
Normalize a 4D vector to unit length (safe).
Definition vec.h:585
static bj_vec2 bj_vec2_map(bj_vec2 a, bj_real(*f)(bj_real))
Definition vec.h:61
static bj_vec3 bj_vec3_normalize(bj_vec3 v)
Normalize a 3D vector to unit length (safe).
Definition vec.h:397
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
static bj_vec2 bj_vec2_normalize(bj_vec2 v)
Normalize a 2D vector to unit length (safe).
Definition vec.h:208
static int bj_real_is_zero(bj_real x)
Absolute-zero test.
Definition math.h:441
static bj_vec4 bj_vec4_cross_xyz(bj_vec4 l, bj_vec4 r)
Cross product using xyz components; w is set to 1.
Definition vec.h:648
static bj_real bj_vec2_dot(bj_vec2 a, bj_vec2 b)
Dot product of two 2D vectors.
Definition vec.h:137
static bj_vec3 bj_vec3_cross(bj_vec3 l, bj_vec3 r)
3D cross product: res = l × r (right-hand rule).
Definition vec.h:453
static bj_vec2 bj_vec2_sub(const bj_vec2 lhs, const bj_vec2 rhs)
Component-wise subtraction of two 2D vectors: res = lhs - rhs.
Definition vec.h:101
static bj_real bj_vec2_distance(const bj_vec2 a, const bj_vec2 b)
Euclidean distance between two 2D vectors.
Definition vec.h:191
static bj_vec4 bj_vec4_add_scaled(bj_vec4 lhs, bj_vec4 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:508
static bj_vec4 bj_vec4_map(bj_vec4 a, bj_real(*f)(bj_real))
Definition vec.h:479
static bj_vec3 bj_vec3_map(bj_vec3 a, bj_real(*f)(bj_real))
Definition vec.h:256
static bj_vec3 bj_vec3_add_scaled(bj_vec3 lhs, bj_vec3 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:284
static bj_vec4 bj_vec4_max(bj_vec4 a, bj_vec4 b)
Component-wise maximum of two 4D vectors.
Definition vec.h:632
static bj_real bj_vec3_dot(bj_vec3 a, bj_vec3 b)
Dot product of two 3D vectors.
Definition vec.h:334
static bj_vec3 bj_vec3_scale_to_len(bj_vec3 v, bj_real L)
Scale a 3D vector to a given length.
Definition vec.h:354
static bj_real bj_vec3_distance_sq(bj_vec3 a, bj_vec3 b)
Squared Euclidean distance between two 3D vectors.
Definition vec.h:368
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
static bj_vec2 bj_vec2_mul_comp(const bj_vec2 v, const bj_vec2 s)
Per-component scaling: res[i] = v[i] * s[i].
Definition vec.h:124
static bj_real bj_vec4_len(bj_vec4 v)
Euclidean length (L2 norm) of a 4D vector.
Definition vec.h:569
static bj_vec4 bj_vec4_scale(bj_vec4 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:545
#define bj_sqrt
Square root.
Definition math.h:222
float bj_real
Selected real type for float configuration.
Definition math.h:51
static bj_vec4 bj_vec4_reflect(bj_vec4 v, bj_vec4 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:664
static bj_vec3 bj_vec3_add(bj_vec3 lhs, bj_vec3 rhs)
Component-wise addition of two 3D vectors: res = lhs + rhs.
Definition vec.h:269
static bj_vec3 bj_vec3_scale(bj_vec3 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:320
static bj_vec2 bj_vec2_scale(bj_vec2 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:114
static bj_vec4 bj_vec4_sub(bj_vec4 lhs, bj_vec4 rhs)
Component-wise subtraction of two 4D vectors: res = lhs - rhs.
Definition vec.h:527
bj_vec2: 2D vector of bj_real values.
Definition vec.h:26
bj_vec3: 3D vector of bj_real values.
Definition vec.h:38
bj_vec4: 4D vector of bj_real values.
Definition vec.h:51
C99 math shim with bj_real precision type and scalar utilities.