32#define BJ_VEC2_ZERO ((struct bj_vec2){BJ_FZERO, BJ_FZERO})
45#define BJ_VEC3_ZERO ((struct bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO})
59#define BJ_VEC4_ZERO ((struct bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO})
65 return (
struct bj_vec2){ .x = f(a.x), .y = f(a.y), };
77 return (
struct bj_vec2){ .x = lhs.x + rhs.x, .y = lhs.y + rhs.y, };
92 return (
struct bj_vec2){ .x = lhs.x + rhs.x * s, .y = lhs.y + rhs.y * s, };
105 return (
struct bj_vec2){ .x = lhs.x - rhs.x, .y = lhs.y - rhs.y, };
115 return (
struct bj_vec2){ .x = v.x * s, .y = v.y * s, };
128 return (
struct 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;
181 return dx * dx + dy * dy;
208 const bj_real l2 = v.x * v.x + v.y * v.y;
213 return (
struct bj_vec2){ v.x * inv, v.y * inv };
231 return (
struct bj_vec2){ v.x * inv, v.y * inv };
241 return (
struct bj_vec2){a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, };
250 return (
struct bj_vec2){a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, };
257 return (
struct bj_vec3){ .x = f(a.x), .y = f(a.y), .z = f(a.z), };
286 .x = lhs.x + rhs.x * s,
287 .y = lhs.y + rhs.y * s,
288 .z = lhs.z + rhs.z * s,
331 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
367 return dx * dx + dy * dy + dz * dz;
393 const bj_real l2 = v.x * v.x + v.y * v.y + v.z * v.z;
398 return (
struct bj_vec3){ v.x * inv, v.y * inv, v.z * inv };
415 return (
struct bj_vec3){ v.x * inv, v.y * inv, v.z * inv };
425 a.x < b.x ? a.x : b.x,
426 a.y < b.y ? a.y : b.y,
427 a.z < b.z ? a.z : b.z,
437 return (
struct bj_vec3){a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z,};
449 .x = l.y * r.z - l.z * r.y,
450 .y = l.z * r.x - l.x * r.z,
451 .z = l.x * r.y - l.y * r.x,
476 return (
struct bj_vec4){ .x = f(a.x), .y = f(a.y), .z = f(a.z), .w = f(a.w), };
507 .x = lhs.x + rhs.x * s,
508 .y = lhs.y + rhs.y * s,
509 .z = lhs.z + rhs.z * s,
510 .w = lhs.w + rhs.w * s,
554 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
579 const bj_real len2 = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w;
584 return (
struct bj_vec4){ v.x * inv, v.y * inv, v.z * inv, v.w * inv };
601 return (
struct bj_vec4){ v.x * inv, v.y * inv, v.z * inv, v.w * inv };
611 a.x < b.x ? a.x : b.x,
612 a.y < b.y ? a.y : b.y,
613 a.z < b.z ? a.z : b.z,
614 a.w < b.w ? a.w : b.w,
625 a.x > b.x ? a.x : b.x,
626 a.y > b.y ? a.y : b.y,
627 a.z > b.z ? a.z : b.z,
628 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:233
bj_real z
Definition vec.h:54
bj_real x
Definition vec.h:27
bj_real x
Definition vec.h:39
bj_real y
Definition vec.h:28
bj_real w
Definition vec.h:55
bj_real z
Definition vec.h:41
bj_real x
Definition vec.h:52
bj_real y
Definition vec.h:40
bj_real y
Definition vec.h:53
static struct bj_vec3 bj_vec3_map(struct bj_vec3 a, bj_real(*f)(bj_real))
Definition vec.h:253
static struct bj_vec4 bj_vec4_sub(struct bj_vec4 lhs, struct bj_vec4 rhs)
Component-wise subtraction of two 4D vectors: res = lhs - rhs.
Definition vec.h:520
static bj_real bj_vec2_len(struct bj_vec2 v)
Euclidean length (L2 norm) of a 2D vector.
Definition vec.h:154
static struct bj_vec2 bj_vec2_max(struct bj_vec2 a, struct bj_vec2 b)
Component-wise maximum of two 2D vectors.
Definition vec.h:249
static struct bj_vec3 bj_vec3_scale(struct bj_vec3 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:316
static struct bj_vec3 bj_vec3_sub(struct bj_vec3 lhs, struct bj_vec3 rhs)
Component-wise subtraction of two 3D vectors: res = lhs - rhs.
Definition vec.h:299
static struct bj_vec2 bj_vec2_add(struct bj_vec2 lhs, struct bj_vec2 rhs)
Component-wise addition of two 2D vectors: res = lhs + rhs.
Definition vec.h:76
static struct bj_vec2 bj_vec2_map(struct bj_vec2 a, bj_real(*f)(bj_real))
Definition vec.h:61
static struct bj_vec3 bj_vec3_max(struct bj_vec3 a, struct bj_vec3 b)
Component-wise maximum of two 3D vectors.
Definition vec.h:436
static bj_real bj_vec2_dot(struct bj_vec2 a, struct bj_vec2 b)
Dot product of two 2D vectors.
Definition vec.h:137
static struct bj_vec4 bj_vec4_map(struct bj_vec4 a, bj_real(*f)(bj_real))
Definition vec.h:472
static bj_real bj_vec4_dot(struct bj_vec4 a, struct bj_vec4 b)
Dot product of two 4D vectors.
Definition vec.h:553
static struct bj_vec2 bj_vec2_min(struct bj_vec2 a, struct bj_vec2 b)
Component-wise minimum of two 2D vectors.
Definition vec.h:240
static bj_real bj_vec3_distance_sq(struct bj_vec3 a, struct bj_vec3 b)
Squared Euclidean distance between two 3D vectors.
Definition vec.h:363
static bj_real bj_vec2_perp_dot(struct bj_vec2 a, struct bj_vec2 b)
2D "cross product" (perp dot): returns scalar a.x*b.y - a.y*b.x.
Definition vec.h:145
static struct bj_vec4 bj_vec4_normalize_unsafe(struct bj_vec4 v)
Normalize a 4D vector to unit length (unsafe).
Definition vec.h:599
static bj_real bj_vec3_len(struct bj_vec3 v)
Euclidean length (L2 norm) of a 3D vector.
Definition vec.h:339
static struct bj_vec2 bj_vec2_sub(const struct bj_vec2 lhs, const struct bj_vec2 rhs)
Component-wise subtraction of two 2D vectors: res = lhs - rhs.
Definition vec.h:101
static struct bj_vec4 bj_vec4_cross_xyz(struct bj_vec4 l, struct bj_vec4 r)
Cross product using xyz components; w is set to 1.
Definition vec.h:638
static struct bj_vec2 bj_vec2_add_scaled(struct bj_vec2 lhs, struct bj_vec2 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:87
static struct bj_vec4 bj_vec4_max(struct bj_vec4 a, struct bj_vec4 b)
Component-wise maximum of two 4D vectors.
Definition vec.h:623
static struct bj_vec4 bj_vec4_scale(struct bj_vec4 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:538
static struct bj_vec3 bj_vec3_normalize_unsafe(struct bj_vec3 v)
Normalize a 3D vector to unit length (unsafe).
Definition vec.h:413
static struct bj_vec2 bj_vec2_mul_comp(const struct bj_vec2 v, const struct bj_vec2 s)
Per-component scaling: res[i] = v[i] * s[i].
Definition vec.h:124
static struct bj_vec4 bj_vec4_add(struct bj_vec4 lhs, struct bj_vec4 rhs)
Component-wise addition of two 4D vectors: res = lhs + rhs.
Definition vec.h:485
static struct bj_vec4 bj_vec4_reflect(struct bj_vec4 v, struct bj_vec4 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:653
static struct bj_vec4 bj_vec4_min(struct bj_vec4 a, struct bj_vec4 b)
Component-wise minimum of two 4D vectors.
Definition vec.h:609
static struct bj_vec3 bj_vec3_reflect(struct bj_vec3 v, struct bj_vec3 n)
Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
Definition vec.h:462
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
static bj_real bj_vec3_dot(struct bj_vec3 a, struct bj_vec3 b)
Dot product of two 3D vectors.
Definition vec.h:330
static struct bj_vec3 bj_vec3_add(struct bj_vec3 lhs, struct bj_vec3 rhs)
Component-wise addition of two 3D vectors: res = lhs + rhs.
Definition vec.h:265
static struct bj_vec2 bj_vec2_normalize(struct bj_vec2 v)
Normalize a 2D vector to unit length (safe).
Definition vec.h:207
static bj_real bj_vec2_distance_sq(struct bj_vec2 a, struct bj_vec2 b)
Squared Euclidean distance between two 2D vectors.
Definition vec.h:178
static int bj_real_is_zero(bj_real x)
Absolute-zero test.
Definition math.h:441
static bj_real bj_vec2_distance(const struct bj_vec2 a, const struct bj_vec2 b)
Euclidean distance between two 2D vectors.
Definition vec.h:190
static struct bj_vec4 bj_vec4_normalize(struct bj_vec4 v)
Normalize a 4D vector to unit length (safe).
Definition vec.h:578
static struct bj_vec3 bj_vec3_cross(struct bj_vec3 l, struct bj_vec3 r)
3D cross product: res = l × r (right-hand rule).
Definition vec.h:446
static struct bj_vec2 bj_vec2_scale_to_len(struct bj_vec2 v, bj_real L)
Scale a 2D vector to a given length.
Definition vec.h:164
static struct bj_vec2 bj_vec2_scale(struct bj_vec2 v, bj_real s)
Uniform scaling by scalar: res = v * s.
Definition vec.h:114
static struct bj_vec3 bj_vec3_add_scaled(struct bj_vec3 lhs, struct bj_vec3 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:280
static struct bj_vec3 bj_vec3_scale_to_len(struct bj_vec3 v, bj_real L)
Scale a 3D vector to a given length.
Definition vec.h:349
static bj_real bj_vec4_len(struct bj_vec4 v)
Euclidean length (L2 norm) of a 4D vector.
Definition vec.h:562
static struct bj_vec4 bj_vec4_add_scaled(struct bj_vec4 lhs, struct bj_vec4 rhs, bj_real s)
Add a scaled vector: res = a + s * b.
Definition vec.h:501
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
static struct bj_vec3 bj_vec3_normalize(struct bj_vec3 v)
Normalize a 3D vector to unit length (safe).
Definition vec.h:392
static struct bj_vec3 bj_vec3_min(struct bj_vec3 a, struct bj_vec3 b)
Component-wise minimum of two 3D vectors.
Definition vec.h:423
#define bj_sqrt
Square root.
Definition math.h:222
float bj_real
Selected real type for float configuration.
Definition math.h:51
static bj_real bj_vec3_distance(struct bj_vec3 a, struct bj_vec3 b)
Euclidean distance between two 3D vectors.
Definition vec.h:376
static struct bj_vec2 bj_vec2_normalize_unsafe(struct bj_vec2 v)
Normalize a 2D vector to unit length (unsafe).
Definition vec.h:229
struct bj_vec2: 2D vector of bj_real values.
Definition vec.h:26
struct bj_vec3: 3D vector of bj_real values.
Definition vec.h:38
struct bj_vec4: 4D vector of bj_real values.
Definition vec.h:51
C99 math shim with bj_real precision type and scalar utilities.