57#define BJ_VEC2_ZERO ((struct bj_vec2){BJ_FZERO, BJ_FZERO})
71#define BJ_VEC3_ZERO ((struct bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO})
87#define BJ_VEC4_ZERO ((struct bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO})
105 return (
struct bj_vec2){ .x = f(a.x), .y = f(a.y), };
116 return (
struct bj_vec2){ .x = lhs.x + rhs.x, .y = lhs.y + rhs.y, };
136 return (
struct bj_vec2){ .x = lhs.x + rhs.x * s, .y = lhs.y + rhs.y * s, };
150 return (
struct bj_vec2){ .x = lhs.x - rhs.x, .y = lhs.y - rhs.y, };
161 return (
struct bj_vec2){ .x = v.x * s, .y = v.y * s, };
179 return (
struct bj_vec2){ .x = v.x * s.x, .y = v.y * s.y, };
190 return a.
x * b.
x + a.
y * b.
y;
210 return a.
x*b.
y - a.
y*b.
x;
258 return dx * dx + dy * dy;
287 const bj_real l2 = v.x * v.x + v.y * v.y;
292 return (
struct bj_vec2){ v.x * inv, v.y * inv };
312 return (
struct bj_vec2){ v.x * inv, v.y * inv };
323 return (
struct bj_vec2){a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, };
334 return (
struct bj_vec2){a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, };
348 return (
struct bj_vec3){ .x = f(a.x), .y = f(a.y), .z = f(a.z), };
380 .x = lhs.x + rhs.x * s,
381 .y = lhs.y + rhs.y * s,
382 .z = lhs.z + rhs.z * s,
427 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z;
475 return dx * dx + dy * dy + dz * dz;
503 const bj_real l2 = v.x * v.x + v.y * v.y + v.z * v.z;
508 return (
struct bj_vec3){ v.x * inv, v.y * inv, v.z * inv };
526 return (
struct bj_vec3){ v.x * inv, v.y * inv, v.z * inv };
538 a.x < b.x ? a.x : b.x,
539 a.y < b.y ? a.y : b.y,
540 a.z < b.z ? a.z : b.z,
552 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,};
570 .x = l.y * r.z - l.z * r.y,
571 .y = l.z * r.x - l.x * r.z,
572 .z = l.x * r.y - l.y * r.x,
609 return (
struct bj_vec4){ .x = f(a.x), .y = f(a.y), .z = f(a.z), .w = f(a.w), };
642 .x = lhs.x + rhs.x * s,
643 .y = lhs.y + rhs.y * s,
644 .z = lhs.z + rhs.z * s,
645 .w = lhs.w + rhs.w * s,
692 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
719 const bj_real len2 = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w;
724 return (
struct bj_vec4){ v.x * inv, v.y * inv, v.z * inv, v.w * inv };
742 return (
struct bj_vec4){ v.x * inv, v.y * inv, v.z * inv, v.w * inv };
754 a.x < b.x ? a.x : b.x,
755 a.y < b.y ? a.y : b.y,
756 a.z < b.z ? a.z : b.z,
757 a.w < b.w ? a.w : b.w,
770 a.x > b.x ? a.x : b.x,
771 a.y > b.y ? a.y : b.y,
772 a.z > b.z ? a.z : b.z,
773 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.
bj_real w
W component (scalar part for quaternions).
static struct bj_vec3 bj_vec3_map(struct bj_vec3 a, bj_real(*f)(bj_real))
Apply a scalar function component-wise: (f(x), f(y), f(z)).
static struct bj_vec4 bj_vec4_sub(struct bj_vec4 lhs, struct bj_vec4 rhs)
Component-wise subtraction: lhs - rhs.
static bj_real bj_vec2_len(struct bj_vec2 v)
Euclidean length: sqrt(x^2 + y^2).
static struct bj_vec2 bj_vec2_max(struct bj_vec2 a, struct bj_vec2 b)
Component-wise maximum: (max(a.x,b.x), max(a.y,b.y)).
static struct bj_vec3 bj_vec3_scale(struct bj_vec3 v, bj_real s)
Uniform scaling by a scalar: v * s.
static struct bj_vec3 bj_vec3_sub(struct bj_vec3 lhs, struct bj_vec3 rhs)
Component-wise subtraction: lhs - rhs.
static struct bj_vec2 bj_vec2_add(struct bj_vec2 lhs, struct bj_vec2 rhs)
Component-wise addition: lhs + rhs.
static struct bj_vec2 bj_vec2_map(struct bj_vec2 a, bj_real(*f)(bj_real))
Apply a scalar function component-wise: (f(x), f(y)).
static struct bj_vec3 bj_vec3_max(struct bj_vec3 a, struct bj_vec3 b)
Component-wise maximum.
static bj_real bj_vec2_dot(struct bj_vec2 a, struct bj_vec2 b)
Dot product: a.x*b.x + a.y*b.y.
static struct bj_vec4 bj_vec4_map(struct bj_vec4 a, bj_real(*f)(bj_real))
Apply a scalar function component-wise to all four components.
static bj_real bj_vec4_dot(struct bj_vec4 a, struct bj_vec4 b)
Dot product over all four components.
static struct bj_vec2 bj_vec2_min(struct bj_vec2 a, struct bj_vec2 b)
Component-wise minimum: (min(a.x,b.x), min(a.y,b.y)).
static bj_real bj_vec3_distance_sq(struct bj_vec3 a, struct bj_vec3 b)
Squared Euclidean distance: ||a - b||^2.
static bj_real bj_vec2_perp_dot(struct bj_vec2 a, struct bj_vec2 b)
2D perp-dot product (signed scalar): a.x*b.y - a.y*b.x.
static struct bj_vec4 bj_vec4_normalize_unsafe(struct bj_vec4 v)
Normalise to unit length (unsafe).
static bj_real bj_vec3_len(struct bj_vec3 v)
Euclidean length: sqrt(x^2 + y^2 + z^2).
static struct bj_vec2 bj_vec2_sub(const struct bj_vec2 lhs, const struct bj_vec2 rhs)
Component-wise subtraction: lhs - rhs.
static struct bj_vec4 bj_vec4_cross_xyz(struct bj_vec4 l, struct bj_vec4 r)
Cross product of the XYZ components, with w = 0.
static struct bj_vec2 bj_vec2_add_scaled(struct bj_vec2 lhs, struct bj_vec2 rhs, bj_real s)
Fused scaled add: lhs + s * rhs.
static struct bj_vec4 bj_vec4_max(struct bj_vec4 a, struct bj_vec4 b)
Component-wise maximum across all four components.
static struct bj_vec4 bj_vec4_scale(struct bj_vec4 v, bj_real s)
Uniform scaling by a scalar: v * s.
static struct bj_vec3 bj_vec3_normalize_unsafe(struct bj_vec3 v)
Normalise to unit length (unsafe).
static struct bj_vec2 bj_vec2_mul_comp(const struct bj_vec2 v, const struct bj_vec2 s)
Component-wise (Hadamard) product: (v.x*s.x, v.y*s.y).
static struct bj_vec4 bj_vec4_add(struct bj_vec4 lhs, struct bj_vec4 rhs)
Component-wise addition: lhs + rhs.
static struct bj_vec4 bj_vec4_reflect(struct bj_vec4 v, struct bj_vec4 n)
Reflect a vector about a surface normal: v - 2*dot(v, n)*n.
static struct bj_vec4 bj_vec4_min(struct bj_vec4 a, struct bj_vec4 b)
Component-wise minimum across all four components.
static struct bj_vec3 bj_vec3_reflect(struct bj_vec3 v, struct bj_vec3 n)
Reflect a vector about a surface normal: v - 2*dot(v, n)*n.
#define BJ_FZERO
Zero constant in bj_real.
static bj_real bj_vec3_dot(struct bj_vec3 a, struct bj_vec3 b)
Dot product: a.x*b.x + a.y*b.y + a.z*b.z.
static struct bj_vec3 bj_vec3_add(struct bj_vec3 lhs, struct bj_vec3 rhs)
Component-wise addition: lhs + rhs.
static struct bj_vec2 bj_vec2_normalize(struct bj_vec2 v)
Normalise to unit length (safe).
static bj_real bj_vec2_distance_sq(struct bj_vec2 a, struct bj_vec2 b)
Squared Euclidean distance: ||a - b||^2.
static int bj_real_is_zero(bj_real x)
Absolute-zero test.
static bj_real bj_vec2_distance(const struct bj_vec2 a, const struct bj_vec2 b)
Euclidean distance: ||a - b||.
static struct bj_vec4 bj_vec4_normalize(struct bj_vec4 v)
Normalise to unit length (safe).
static struct bj_vec3 bj_vec3_cross(struct bj_vec3 l, struct bj_vec3 r)
3D cross product: l × r (right-hand rule).
static struct bj_vec2 bj_vec2_scale_to_len(struct bj_vec2 v, bj_real L)
Rescale a vector to a chosen length.
static struct bj_vec2 bj_vec2_scale(struct bj_vec2 v, bj_real s)
Uniform scaling by a scalar: v * s.
static struct bj_vec3 bj_vec3_add_scaled(struct bj_vec3 lhs, struct bj_vec3 rhs, bj_real s)
Fused scaled add: lhs + s * rhs.
static struct bj_vec3 bj_vec3_scale_to_len(struct bj_vec3 v, bj_real L)
Rescale a vector to a chosen length.
static bj_real bj_vec4_len(struct bj_vec4 v)
Euclidean length: sqrt(x^2 + y^2 + z^2 + w^2).
static struct bj_vec4 bj_vec4_add_scaled(struct bj_vec4 lhs, struct bj_vec4 rhs, bj_real s)
Fused scaled add: lhs + s * rhs.
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
static struct bj_vec3 bj_vec3_normalize(struct bj_vec3 v)
Normalise to unit length (safe).
static struct bj_vec3 bj_vec3_min(struct bj_vec3 a, struct bj_vec3 b)
Component-wise minimum.
#define bj_sqrt
Square root.
float bj_real
Selected real type for float configuration.
static bj_real bj_vec3_distance(struct bj_vec3 a, struct bj_vec3 b)
Euclidean distance: ||a - b||.
static struct bj_vec2 bj_vec2_normalize_unsafe(struct bj_vec2 v)
Normalise to unit length (unsafe).
2D vector of bj_real components.
3D vector of bj_real components.
4D vector of bj_real components.
C99 math shim with bj_real precision type and scalar utilities.