Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
Math
Collaboration diagram for Math:

Topics

 Geometry 2D

Data Structures

struct  bj_rect_t

Macros

#define bj_quat_add   bj_vec4_add
#define bj_quat_sub   bj_vec4_sub
#define bj_quat_norm   bj_vec4_normalize
#define bj_quat_scale   bj_vec4_scale
#define bj_quat_dot   bj_vec4_dot

Typedefs

typedef bj_vec3 bj_mat3x3[3]
typedef bj_mat3x3 bj_mat3
typedef bj_vec2 bj_mat3x2[3]
typedef bj_vec4 bj_mat4x4[4]
typedef bj_mat4x4 bj_mat4
typedef bj_vec3 bj_mat4x3[4]
typedef bj_real bj_quat[4]
typedef struct bj_rect_t bj_rect
typedef bj_real bj_vec2[2]
typedef bj_real bj_vec3[3]
typedef bj_real bj_vec4[4]

Functions

static void bj_mat3_identity (bj_mat3x3 m)
static void bj_mat3_copy (bj_mat3x3 to, const bj_mat3x3 from)
static void bj_mat3_row (bj_vec3 res, const bj_mat3x3 m, int r)
static void bj_mat3_col (bj_vec3 res, const bj_mat3x3 m, int c)
static void bj_mat3_transpose (bj_mat3x3 res, const bj_mat3x3 m)
static void bj_mat3_add (bj_mat3x3 res, const bj_mat3x3 a, const bj_mat3x3 b)
static void bj_mat3_sub (bj_mat3x3 res, const bj_mat3x3 a, const bj_mat3x3 b)
static void bj_mat3_scale (bj_mat3x3 res, const bj_mat3x3 m, bj_real k)
static void bj_mat3_mul (bj_real res[restrict static(3)][3], const bj_real lhs[restrict static(3)][3], const bj_real rhs[restrict static(3)][3])
static void bj_mat3_mul_vec3 (bj_real res[restrict static(3)], const bj_real m[restrict static(3)][3], const bj_real v[restrict static(3)])
static void bj_mat3_mul_point (bj_vec2 res, const bj_mat3x3 m, const bj_vec2 p)
static void bj_mat3_mul_vector2 (bj_vec2 res, const bj_mat3x3 m, const bj_vec2 v2)
static void bj_mat3_translation (bj_mat3x3 res, bj_real tx, bj_real ty)
static void bj_mat3_translation_inplace (bj_mat3x3 M, bj_real tx, bj_real ty)
static void bj_mat3_scale_xy (bj_mat3x3 res, bj_real sx, bj_real sy)
static void bj_mat3_shear (bj_mat3x3 res, bj_real shx, bj_real shy)
static void bj_mat3_rotate (bj_mat3x3 res, bj_real angle)
static void bj_mat3_inverse (bj_mat3x3 res, const bj_mat3x3 m)
static void bj_mat3_ortho (bj_real omat[restrict static(3)][3], bj_real l, bj_real r, bj_real b, bj_real t)
static void bj_mat3_viewport (bj_real vpmat[restrict static(3)][3], bj_real x, bj_real y, bj_real w, bj_real h)
static void bj_mat3x2_identity (bj_real m[restrict static(3)][2])
static void bj_mat3x2_translate (bj_real m[restrict static(3)][2], bj_real tx, bj_real ty)
static void bj_mat3x2_scale (bj_real m[restrict static(3)][2], bj_real sx, bj_real sy)
static void bj_mat3x2_rotate (bj_real m[restrict static(3)][2], bj_real angle)
static void bj_mat3x2_mul (bj_real res[restrict static(3)][2], const bj_real A[restrict static(3)][2], const bj_real B[restrict static(3)][2])
static void bj_mat3x2_mul_point (bj_real r[restrict static(2)], const bj_real m[restrict static(3)][2], const bj_real p[restrict static(2)])
static void bj_mat3x2_mul_dir (bj_real r[restrict static(2)], const bj_real m[restrict static(3)][2], const bj_real v[restrict static(2)])
static void bj_mat3_from_mat3x2 (bj_real out3x3[restrict static(3)][3], const bj_real a[restrict static(3)][2])
static void bj_mat3x2_from_mat3 (bj_real out3x2[restrict static(3)][2], const bj_real m[restrict static(3)][3])
static void bj_mat4_identity (bj_mat4x4 mat)
static void bj_mat4_copy (bj_mat4x4 to, const bj_mat4x4 from)
static void bj_mat4_row (bj_vec4 res, const bj_mat4x4 mat, int r)
static void bj_mat4_col (bj_vec4 res, const bj_mat4x4 mat, int c)
static void bj_mat4_transpose (bj_mat4x4 res, const bj_mat4x4 mat)
static void bj_mat4_add (bj_mat4x4 res, const bj_mat4x4 lhs, const bj_mat4x4 rhs)
static void bj_mat4_sub (bj_mat4x4 res, const bj_mat4x4 lhs, const bj_mat4x4 rhs)
static void bj_mat4_scale (bj_mat4x4 res, const bj_mat4x4 lhs, bj_real k)
static void bj_mat4_scale_xyz (bj_mat4x4 res, const bj_mat4x4 mat, bj_real x, bj_real y, bj_real z)
static void bj_mat4_mul (bj_real res[restrict static(4)][4], const bj_real lhs[restrict static(4)][4], const bj_real rhs[restrict static(4)][4])
static void bj_mat4_mul_vec4 (bj_real res[restrict static(4)], const bj_real mat[restrict static(4)][4], const bj_real v[restrict static(4)])
static void bj_mat4_translation (bj_mat4x4 res, bj_real x, bj_real y, bj_real z)
static void bj_mat4_translation_inplace (bj_mat4x4 M, bj_real x, bj_real y, bj_real z)
static void bj_mat4_mul_outer (bj_mat4x4 res, const bj_vec3 a, const bj_vec3 b)
static void bj_mat4_rotate (bj_mat4x4 res, const bj_mat4x4 mat, bj_real x, bj_real y, bj_real z, bj_real angle)
static void bj_mat4_rotate_x (bj_mat4x4 res, const bj_mat4x4 mat, bj_real angle)
static void bj_mat4_rotate_y (bj_mat4x4 res, const bj_mat4x4 mat, bj_real angle)
static void bj_mat4_rotate_z (bj_mat4x4 res, const bj_mat4x4 mat, bj_real angle)
static void bj_mat4_rotate_arcball (bj_mat4x4 R, const bj_mat4x4 M, bj_vec2 const _a, bj_vec2 const _b, bj_real s)
static void bj_mat4_inverse (bj_mat4x4 res, const bj_mat4x4 mat)
static void bj_mat4_orthonormalize (bj_mat4x4 res, const bj_mat4x4 mat)
static void bj_mat4_frustum (bj_real fmat[restrict static(4)][4], bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f)
static void bj_mat4_ortho (bj_real omat[restrict static(4)][4], bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f)
static void bj_mat4_perspective (bj_real pmat[restrict static(4)][4], bj_real y_fov, bj_real aspect, bj_real n, bj_real f)
static void bj_mat4_viewport (bj_real vpmat[restrict static(4)][4], bj_real x, bj_real y, bj_real w, bj_real h)
static void bj_mat4_lookat (bj_real m[restrict static(4)][4], const bj_vec3 eye, const bj_vec3 center, const bj_vec3 up)
static void bj_mat4x3_identity (bj_real m[restrict static(4)][3])
static void bj_mat4x3_translate (bj_real m[restrict static(4)][3], bj_real tx, bj_real ty, bj_real tz)
static void bj_mat4x3_scale (bj_real m[restrict static(4)][3], bj_real sx, bj_real sy, bj_real sz)
static void bj_mat4x3_rotate_x (bj_real m[restrict static(4)][3], bj_real angle)
static void bj_mat4x3_rotate_y (bj_real m[restrict static(4)][3], bj_real angle)
static void bj_mat4x3_rotate_z (bj_real m[restrict static(4)][3], bj_real angle)
static void bj_mat4x3_mul (bj_real res[restrict static(4)][3], const bj_real A[restrict static(4)][3], const bj_real B[restrict static(4)][3])
static void bj_mat4x3_mul_point (bj_real r[restrict static(3)], const bj_real m[restrict static(4)][3], const bj_real p[restrict static(3)])
static void bj_mat4x3_mul_dir (bj_real r[restrict static(3)], const bj_real m[restrict static(4)][3], const bj_real v[restrict static(3)])
static void bj_mat4_from_mat4x3 (bj_mat4x4 out, const bj_real a[restrict static(4)][3])
static void bj_mat4x3_from_mat4 (bj_real out43[restrict static(4)][3], const bj_mat4x4 m)
static void bj_mat4x3_lookat (bj_real m[restrict static(4)][3], const bj_real eye[restrict static(3)], const bj_real center[restrict static(3)], const bj_real up[restrict static(3)])
static void bj_quat_identity (bj_quat q)
static void bj_quat_mul (bj_quat res, const bj_quat p, const bj_quat q)
static void bj_quat_conjugate (bj_quat res, const bj_quat q)
static void bj_quat_rotation (bj_quat res, bj_real angle, const bj_vec3 axis)
static void bj_quat_mul_vec3 (bj_vec3 res, const bj_quat q, const bj_vec3 v)
static void bj_mat4_from_quat (bj_mat4 res, const bj_quat q)
static void bj_mat4_rotate_from_quat (bj_mat4 R, const bj_mat4 M, const bj_quat q)
static void bj_quat_from_mat4 (bj_quat q, const bj_mat4 M)
bj_bool bj_rect_intersection (const bj_rect *p_rect_a, const bj_rect *p_rect_b, bj_rect *p_result)
static void bj_vec2_set (bj_vec2 res, bj_real a, bj_real b)
static void bj_vec2_zero (bj_vec2 res)
static void bj_vec2_apply (bj_vec2 res, const bj_vec2 a, bj_real(*f)(bj_real))
static void bj_vec2_add (bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
static void bj_vec2_add_scaled (bj_vec2 res, const bj_vec2 a, const bj_vec2 b, bj_real s)
static void bj_vec2_sub (bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
static void bj_vec2_scale (bj_vec2 res, const bj_vec2 v, bj_real s)
static void bj_vec2_scale_each (bj_vec2 res, const bj_vec2 v, const bj_vec2 s)
static bj_real bj_vec2_dot (const bj_vec2 a, const bj_vec2 b)
static bj_real bj_vec2_cross (const bj_vec2 a, const bj_vec2 b)
static bj_real bj_vec2_len (const bj_vec2 v)
static void bj_vec2_set_len (bj_vec2 res, const bj_vec2 v, bj_real target_len)
static bj_real bj_vec2_dist_squared (const bj_vec2 a, const bj_vec2 b)
static bj_real bj_vec2_dist (const bj_vec2 a, const bj_vec2 b)
static void bj_vec2_normalize (bj_vec2 res, const bj_vec2 v)
static void bj_vec2_min (bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
static void bj_vec2_max (bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
static void bj_vec2_copy (bj_vec2 res, const bj_vec2 src)
static void bj_vec3_set (bj_vec3 res, bj_real a, bj_real b, bj_real c)
static void bj_vec3_zero (bj_vec3 res)
static void bj_vec3_apply (bj_vec3 res, const bj_vec3 a, bj_real(*f)(bj_real))
static void bj_vec3_add (bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
static void bj_vec3_add_scaled (bj_vec3 res, const bj_vec3 a, const bj_vec3 b, bj_real s)
static void bj_vec3_sub (bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
static void bj_vec3_scale (bj_vec3 res, const bj_vec3 v, bj_real s)
static bj_real bj_vec3_dot (const bj_vec3 a, const bj_vec3 b)
static bj_real bj_vec3_len (const bj_vec3 v)
static void bj_vec3_set_len (bj_vec3 res, const bj_vec3 v, bj_real target_len)
static bj_real bj_vec3_dist_squared (const bj_vec3 a, const bj_vec3 b)
static bj_real bj_vec3_dist (const bj_vec3 a, const bj_vec3 b)
static void bj_vec3_normalize (bj_vec3 res, const bj_vec3 v)
static void bj_vec3_min (bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
static void bj_vec3_max (bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
static void bj_vec3_copy (bj_vec3 res, const bj_vec3 src)
static void bj_vec3_cross (bj_vec3 res, const bj_vec3 l, const bj_vec3 r)
static void bj_vec3_reflect (bj_vec3 res, const bj_vec3 v, const bj_vec3 n)
static void bj_vec4_set (bj_vec4 res, bj_real a, bj_real b, bj_real c, bj_real d)
static void bj_vec4_apply (bj_vec4 res, const bj_vec4 a, bj_real(*f)(bj_real))
static void bj_vec4_add (bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
static void bj_vec4_add_scaled (bj_vec4 res, const bj_vec4 a, const bj_vec4 b, bj_real s)
static void bj_vec4_sub (bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
static void bj_vec4_scale (bj_vec4 res, const bj_vec4 v, bj_real s)
static bj_real bj_vec4_dot (const bj_vec4 a, const bj_vec4 b)
static bj_real bj_vec4_len (const bj_vec4 v)
static void bj_vec4_normalize (bj_vec4 res, const bj_vec4 v)
static void bj_vec4_min (bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
static void bj_vec4_max (bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
static void bj_vec4_copy (bj_vec4 res, const bj_vec4 src)
static void bj_vec4_cross (bj_vec4 res, const bj_vec4 l, const bj_vec4 r)
static void bj_vec4_reflect (bj_vec4 res, const bj_vec4 v, const bj_vec4 n)

Real type selection and helpers

typedef float bj_real
#define BJ_F(x)
#define BJ_EPSILON   (FLT_EPSILON)
#define BJ_FI(x)
#define BJ_FZERO   (BJ_F(0.0))

Scalar utilities

Generic scalar helpers.

All arguments and results are bj_real.

static bj_real bj_clamp (bj_real x, bj_real lo, bj_real hi)
static bj_real bj_step (bj_real edge, bj_real x)
static bj_real bj_smoothstep (bj_real e0, bj_real e1, bj_real x)
static bj_real bj_fract (bj_real x)
static bj_real bj_mod (bj_real x, bj_real y)

Absolute-epsilon comparisons

Comparisons using BJ_EPSILON as an absolute tolerance.

static int bj_real_eq (bj_real a, bj_real b)
static int bj_real_neq (bj_real a, bj_real b)
static int bj_real_lt (bj_real a, bj_real b)
static int bj_real_gt (bj_real a, bj_real b)
static int bj_real_lte (bj_real a, bj_real b)
static int bj_real_gte (bj_real a, bj_real b)
static int bj_real_cmp (bj_real a, bj_real b)

Relative-epsilon comparisons

Comparisons using a scale-dependent tolerance.

static bj_real bj_real_relative_scale (bj_real a, bj_real b)
static int bj_real_eq_rel (bj_real a, bj_real b)
static int bj_real_neq_rel (bj_real a, bj_real b)
static int bj_real_lt_rel (bj_real a, bj_real b)
static int bj_real_gt_rel (bj_real a, bj_real b)
static int bj_real_lte_rel (bj_real a, bj_real b)
static int bj_real_gte_rel (bj_real a, bj_real b)
static int bj_real_cmp_rel (bj_real a, bj_real b)

Zero tests and helpers

Utilities for zero checks and safe normalization.

static int bj_real_is_zero (bj_real x)
static int bj_real_is_zero_scaled (bj_real x, bj_real scale)
static bj_real bj_real_snap_zero (bj_real x)
static bj_real bj_real_snorm_safe (bj_real x, bj_real len)

Circle constants

#define BJ_PI_F   (3.14159265358979323846f)
#define BJ_TAU_F   (6.28318530717958647692f)
#define BJ_PI_D   (3.14159265358979323846264338327950288)
#define BJ_TAU_D   (6.28318530717958647692528676655900576)
#define BJ_PI_L   (3.141592653589793238462643383279502884L)
#define BJ_TAU_L   (6.283185307179586476925286766559005768L)
#define BJ_PI   (BJ_F(3.141592653589793238462643383279502884))
#define BJ_TAU   (BJ_F(6.283185307179586476925286766559005768))

Typed wrappers (float)

Thin aliases to <math.h> float functions.

#define bj_absf   fabsf
#define bj_acosf   acosf
#define bj_atan2f   atan2f
#define bj_copysignf   copysignf
#define bj_cosf   cosf
#define bj_expf   expf
#define bj_floorf   floorf
#define bj_fmodf   fmodf
#define bj_logf   logf
#define bj_maxf   fmaxf
#define bj_minf   fminf
#define bj_powf   powf
#define bj_roundf   roundf
#define bj_sinf   sinf
#define bj_sqrtf   sqrtf
#define bj_tanf   tanf

Typed wrappers (double)

Thin aliases to <math.h> double functions.

#define bj_absd   fabs
#define bj_acosd   acos
#define bj_atan2d   atan2
#define bj_copysignd   copysign
#define bj_cosd   cos
#define bj_expd   exp
#define bj_floord   floor
#define bj_fmodd   fmod
#define bj_logd   log
#define bj_maxd   fmax
#define bj_mind   fmin
#define bj_powd   pow
#define bj_roundd   round
#define bj_sind   sin
#define bj_sqrtd   sqrt
#define bj_tand   tan

Typed wrappers (long double)

Thin aliases to <math.h> long double functions.

#define bj_absl   fabsl
#define bj_acosl   acosl
#define bj_atan2l   atan2l
#define bj_copysignl   copysignl
#define bj_cosl   cosl
#define bj_expl   expl
#define bj_floorl   floorl
#define bj_fmodl   fmodl
#define bj_logl   logl
#define bj_maxl   fmaxl
#define bj_minl   fminl
#define bj_powl   powl
#define bj_roundl   roundl
#define bj_sinl   sinl
#define bj_sqrtl   sqrtl
#define bj_tanl   tanl

Precision-dispatch to match bj_real

Map generic bj_* names to the active precision.

#define bj_abs   bj_absf
#define bj_acos   bj_acosf
#define bj_atan2   bj_atan2f
#define bj_copysign   bj_copysignf
#define bj_cos   bj_cosf
#define bj_exp   bj_expf
#define bj_floor   bj_floorf
#define bj_fmod   bj_fmodf
#define bj_log   bj_logf
#define bj_max   bj_maxf
#define bj_min   bj_minf
#define bj_pow   bj_powf
#define bj_round   bj_roundf
#define bj_sin   bj_sinf
#define bj_sqrt   bj_sqrtf
#define bj_tan   bj_tanf

Detailed Description

Math utilities (precision abstraction, constants, scalar functions).

This header provides:

  • Compile-time selection of real precision (bj_real).
  • Constants such as PI and TAU in multiple precisions.
  • Typed wrappers for C math functions.
  • Generic bj_* math macros mapped to the selected bj_real type.
  • Scalar helpers: clamp, step, smoothstep, fract, modulus.
  • Floating-point comparison utilities (absolute and relative epsilon).
  • Zero tests and safe normalization.

All functions are thin wrappers around <math.h> with consistent naming and precision handling. They are dimensionless utilities: values are treated as pure scalars without physical units.


Data Structure Documentation

◆ bj_rect_t

struct bj_rect_t

Represents a rectangle with position and dimensions.

Data Fields
uint16_t h The height of the rectangle.
uint16_t w The width of the rectangle.
int16_t x The x-coordinate of the rectangle's top-left corner.
int16_t y The y-coordinate of the rectangle's top-left corner.

Macro Definition Documentation

◆ bj_abs

#define bj_abs   bj_absf

Absolute value.

◆ bj_absd

#define bj_absd   fabs

Absolute value (double)

◆ bj_absf

#define bj_absf   fabsf

Absolute value (float)

◆ bj_absl

#define bj_absl   fabsl

Absolute value (long double)

◆ bj_acos

#define bj_acos   bj_acosf

Arc cosine.

◆ bj_acosd

#define bj_acosd   acos

Arc cosine (double)

◆ bj_acosf

#define bj_acosf   acosf

Arc cosine (float)

◆ bj_acosl

#define bj_acosl   acosl

Arc cosine (long double)

◆ bj_atan2

#define bj_atan2   bj_atan2f

Arc tangent.

◆ bj_atan2d

#define bj_atan2d   atan2

Arc tangent (float)

◆ bj_atan2f

#define bj_atan2f   atan2f

Arc tangent (float)

◆ bj_atan2l

#define bj_atan2l   atan2l

Arc tangent (float)

◆ bj_copysign

#define bj_copysign   bj_copysignf

Copy sign.

◆ bj_copysignd

#define bj_copysignd   copysign

Copy sign (double)

◆ bj_copysignf

#define bj_copysignf   copysignf

Copy sign (float)

◆ bj_copysignl

#define bj_copysignl   copysignl

Copy sign (long double)

◆ bj_cos

#define bj_cos   bj_cosf

Cosine.

◆ bj_cosd

#define bj_cosd   cos

Cosine (double)

◆ bj_cosf

#define bj_cosf   cosf

Cosine (float)

◆ bj_cosl

#define bj_cosl   cosl

Cosine (long double)

◆ BJ_EPSILON

#define BJ_EPSILON   (FLT_EPSILON)

Machine epsilon for bj_real when float is selected.

◆ bj_exp

#define bj_exp   bj_expf

Exponential.

◆ bj_expd

#define bj_expd   exp

Exponential (double)

◆ bj_expf

#define bj_expf   expf

Exponential (float)

◆ bj_expl

#define bj_expl   expl

Exponential (long double)

◆ BJ_F

#define BJ_F ( x)
Value:
x##f

Literal suffix helper for bj_real when float is selected.

◆ BJ_FI

#define BJ_FI ( x)
Value:
BJ_F(1.0) / BJ_F(x)
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53

Convenience reciprocal literal generator.

Parameters
xPositive scalar literal
Returns
1.0 / x in bj_real

◆ bj_floor

#define bj_floor   bj_floorf

Floor.

◆ bj_floord

#define bj_floord   floor

Floor (double)

◆ bj_floorf

#define bj_floorf   floorf

Floor (float)

◆ bj_floorl

#define bj_floorl   floorl

Floor (long double)

◆ bj_fmod

#define bj_fmod   bj_fmodf

Floating modulus.

◆ bj_fmodd

#define bj_fmodd   fmod

Floating modulus (double)

◆ bj_fmodf

#define bj_fmodf   fmodf

Floating modulus (float)

◆ bj_fmodl

#define bj_fmodl   fmodl

Floating modulus (long double)

◆ BJ_FZERO

#define BJ_FZERO   (BJ_F(0.0))

Zero constant in bj_real.

◆ bj_log

#define bj_log   bj_logf

Natural logarithm.

◆ bj_logd

#define bj_logd   log

Natural log (double)

◆ bj_logf

#define bj_logf   logf

Natural log (float)

◆ bj_logl

#define bj_logl   logl

Natural log (long double)

◆ bj_max

#define bj_max   bj_maxf

Maximum of two floats.

◆ bj_maxd

#define bj_maxd   fmax

Maximum of two doubles.

◆ bj_maxf

#define bj_maxf   fmaxf

Maximum of two floats.

◆ bj_maxl

#define bj_maxl   fmaxl

Maximum of two long doubles.

◆ bj_min

#define bj_min   bj_minf

Minimum of two floats.

◆ bj_mind

#define bj_mind   fmin

Minimum of two doubles.

◆ bj_minf

#define bj_minf   fminf

Minimum of two floats.

◆ bj_minl

#define bj_minl   fminl

Minimum of two long doubles.

◆ BJ_PI

#define BJ_PI   (BJ_F(3.141592653589793238462643383279502884))

PI in the selected bj_real precision.

◆ BJ_PI_D

#define BJ_PI_D   (3.14159265358979323846264338327950288)

Double-precision PI.

◆ BJ_PI_F

#define BJ_PI_F   (3.14159265358979323846f)

Single-precision PI.

◆ BJ_PI_L

#define BJ_PI_L   (3.141592653589793238462643383279502884L)

Long-double PI.

◆ bj_pow

#define bj_pow   bj_powf

Power.

◆ bj_powd

#define bj_powd   pow

Power (double)

◆ bj_powf

#define bj_powf   powf

Power (float)

◆ bj_powl

#define bj_powl   powl

Power (long double)

◆ bj_quat_add

#define bj_quat_add   bj_vec4_add

Alias to vector add (component-wise).

See also
bj_vec4_add

◆ bj_quat_dot

#define bj_quat_dot   bj_vec4_dot

Alias to 4D dot product.

See also
bj_vec4_dot

◆ bj_quat_norm

#define bj_quat_norm   bj_vec4_normalize

Alias to normalize quaternion (scales to unit length).

See also
bj_vec4_normalize

◆ bj_quat_scale

#define bj_quat_scale   bj_vec4_scale

Alias to uniform scale all four components.

See also
bj_vec4_scale

◆ bj_quat_sub

#define bj_quat_sub   bj_vec4_sub

Alias to vector subtract (component-wise).

See also
bj_vec4_sub

◆ bj_round

#define bj_round   bj_roundf

Round to nearest integer.

◆ bj_roundd

#define bj_roundd   round

Round to nearest (double)

◆ bj_roundf

#define bj_roundf   roundf

Round to nearest (float)

◆ bj_roundl

#define bj_roundl   roundl

Round to nearest (long double)

◆ bj_sin

#define bj_sin   bj_sinf

Sine.

◆ bj_sind

#define bj_sind   sin

Sine (double)

◆ bj_sinf

#define bj_sinf   sinf

Sine (float)

◆ bj_sinl

#define bj_sinl   sinl

Sine (long double)

◆ bj_sqrt

#define bj_sqrt   bj_sqrtf

Square root.

◆ bj_sqrtd

#define bj_sqrtd   sqrt

Square root (double)

◆ bj_sqrtf

#define bj_sqrtf   sqrtf

Square root (float)

◆ bj_sqrtl

#define bj_sqrtl   sqrtl

Square root (long double)

◆ bj_tan

#define bj_tan   bj_tanf

Tangent.

◆ bj_tand

#define bj_tand   tan

Tangent (double)

◆ bj_tanf

#define bj_tanf   tanf

Tangent (float)

◆ bj_tanl

#define bj_tanl   tanl

Tangent (long double)

◆ BJ_TAU

#define BJ_TAU   (BJ_F(6.283185307179586476925286766559005768))

TAU in the selected bj_real precision.

◆ BJ_TAU_D

#define BJ_TAU_D   (6.28318530717958647692528676655900576)

Double-precision TAU (2 * PI).

◆ BJ_TAU_F

#define BJ_TAU_F   (6.28318530717958647692f)

Single-precision TAU (2 * PI).

◆ BJ_TAU_L

#define BJ_TAU_L   (6.283185307179586476925286766559005768L)

Long-double TAU (2 * PI).

Typedef Documentation

◆ bj_mat3

typedef bj_mat3x3 bj_mat3

bj_mat3: Alias for bj_mat3x3

◆ bj_mat3x2

typedef bj_vec2 bj_mat3x2[3]

bj_mat3x2: 3×2 column-major matrix backed by bj_vec2.

(2D affine: 2×2 linear block plus translation column). Columns are arrays of 2 components.

◆ bj_mat3x3

typedef bj_vec3 bj_mat3x3[3]

bj_mat3x3: 3×3 column-major matrix backed by bj_vec3.

Columns are arrays of 3 components.

◆ bj_mat4

typedef bj_mat4x4 bj_mat4

bj_mat4: Alias for bj_mat4x4

◆ bj_mat4x3

typedef bj_vec3 bj_mat4x3[4]

bj_mat4x3: 4×3 column-major matrix backed by bj_vec3.

(3D affine: 3×3 linear block plus translation row). Columns are arrays of 3 components.

◆ bj_mat4x4

typedef bj_vec4 bj_mat4x4[4]

bj_mat4x4: 4×4 column-major matrix backed by bj_vec4.

Columns are arrays of 4 components.

◆ bj_quat

typedef bj_real bj_quat[4]

bj_quat: Quaternion stored as {x, y, z, w} with bj_real components.

Multiplication composes rotations; unit quaternions represent pure rotations.

◆ bj_real

typedef float bj_real

Selected real type for float configuration.

◆ bj_rect

typedef struct bj_rect_t bj_rect

Typedef for bj_rect_t.

◆ bj_vec2

typedef bj_real bj_vec2[2]

bj_vec2: 2D vector of bj_real values.

Intended for lightweight math operations and POD interop. Components are indexed as 0..1.

◆ bj_vec3

typedef bj_real bj_vec3[3]

bj_vec3: 3D vector of bj_real values.

Intended for lightweight math operations and POD interop. Components are indexed as 0..2.

◆ bj_vec4

typedef bj_real bj_vec4[4]

bj_vec4: 4D vector of bj_real values.

Intended for lightweight math operations and POD interop. Components are indexed as 0..3.

Function Documentation

◆ bj_clamp()

bj_real bj_clamp ( bj_real x,
bj_real lo,
bj_real hi )
inlinestatic

Clamp x to the closed interval [lo, hi].

Parameters
xInput value
loLower bound
hiUpper bound
Returns
lo if x < lo, hi if x > hi, else x

◆ bj_fract()

bj_real bj_fract ( bj_real x)
inlinestatic

Fractional part of x.

Parameters
xInput value
Returns
x - floor(x)

◆ bj_mat3_add()

void bj_mat3_add ( bj_mat3x3 res,
const bj_mat3x3 a,
const bj_mat3x3 b )
inlinestatic

Component-wise addition: res = a + b.

◆ bj_mat3_col()

void bj_mat3_col ( bj_vec3 res,
const bj_mat3x3 m,
int c )
inlinestatic

Extract a column as a vector (column index into first subscript).

Parameters
resOutput vector.
mInput matrix.
cColumn index.

◆ bj_mat3_copy()

void bj_mat3_copy ( bj_mat3x3 to,
const bj_mat3x3 from )
inlinestatic

Copy matrix contents.

Parameters
toOutput matrix.
fromInput matrix.

◆ bj_mat3_from_mat3x2()

void bj_mat3_from_mat3x2 ( bj_real out3x3[restrict static(3)][3],
const bj_real a[restrict static(3)][2] )
inlinestatic

Promote 3×2 to 3×3 homogeneous.

◆ bj_mat3_identity()

void bj_mat3_identity ( bj_mat3x3 m)
inlinestatic

Set to identity matrix.

Parameters
mOutput buffer.

◆ bj_mat3_inverse()

void bj_mat3_inverse ( bj_mat3x3 res,
const bj_mat3x3 m )
inlinestatic

Invert a 3×3.

◆ bj_mat3_mul()

void bj_mat3_mul ( bj_real res[restrict static(3)][3],
const bj_real lhs[restrict static(3)][3],
const bj_real rhs[restrict static(3)][3] )
inlinestatic

Matrix multiplication: res = lhs * rhs (column-major).

Note
Column-major convention: res = lhs * rhs.

◆ bj_mat3_mul_point()

void bj_mat3_mul_point ( bj_vec2 res,
const bj_mat3x3 m,
const bj_vec2 p )
inlinestatic

Transform a point (homogeneous w=1).

Note
Column-major convention: res = m * p.

◆ bj_mat3_mul_vec3()

void bj_mat3_mul_vec3 ( bj_real res[restrict static(3)],
const bj_real m[restrict static(3)][3],
const bj_real v[restrict static(3)] )
inlinestatic

Multiply 3×3 matrix by a 3D column vector: res = M * v.

Note
Column-major convention: res = lhs * rhs.

◆ bj_mat3_mul_vector2()

void bj_mat3_mul_vector2 ( bj_vec2 res,
const bj_mat3x3 m,
const bj_vec2 v2 )
inlinestatic

Transform a direction (w=0; ignores translation).

Note
Column-major convention: res = m * v2.

◆ bj_mat3_ortho()

void bj_mat3_ortho ( bj_real omat[restrict static(3)][3],
bj_real l,
bj_real r,
bj_real b,
bj_real t )
inlinestatic

Orthographic projection matrix (3×3).

◆ bj_mat3_rotate()

void bj_mat3_rotate ( bj_mat3x3 res,
bj_real angle )
inlinestatic

Rotate 2D about Z.

◆ bj_mat3_row()

void bj_mat3_row ( bj_vec3 res,
const bj_mat3x3 m,
int r )
inlinestatic

Extract a row as a vector (row index into second subscript).

Parameters
resOutput vector.
mInput matrix.
rRow index.

◆ bj_mat3_scale()

void bj_mat3_scale ( bj_mat3x3 res,
const bj_mat3x3 m,
bj_real k )
inlinestatic

Uniformly scale all elements by scalar k.

◆ bj_mat3_scale_xy()

void bj_mat3_scale_xy ( bj_mat3x3 res,
bj_real sx,
bj_real sy )
inlinestatic

Create 2D scaling matrix with independent X/Y scales.

◆ bj_mat3_shear()

void bj_mat3_shear ( bj_mat3x3 res,
bj_real shx,
bj_real shy )
inlinestatic

Create 2D shear matrix.

◆ bj_mat3_sub()

void bj_mat3_sub ( bj_mat3x3 res,
const bj_mat3x3 a,
const bj_mat3x3 b )
inlinestatic

Component-wise subtraction: res = a - b.

◆ bj_mat3_translation()

void bj_mat3_translation ( bj_mat3x3 res,
bj_real tx,
bj_real ty )
inlinestatic

Create a translation matrix.

◆ bj_mat3_translation_inplace()

void bj_mat3_translation_inplace ( bj_mat3x3 M,
bj_real tx,
bj_real ty )
inlinestatic

Apply a translation in-place.

◆ bj_mat3_transpose()

void bj_mat3_transpose ( bj_mat3x3 res,
const bj_mat3x3 m )
inlinestatic

Transpose the matrix.

Parameters
resOutput matrix.
mInput matrix.

◆ bj_mat3_viewport()

void bj_mat3_viewport ( bj_real vpmat[restrict static(3)][3],
bj_real x,
bj_real y,
bj_real w,
bj_real h )
inlinestatic

Viewport transform matrix (3×3).

◆ bj_mat3x2_from_mat3()

void bj_mat3x2_from_mat3 ( bj_real out3x2[restrict static(3)][2],
const bj_real m[restrict static(3)][3] )
inlinestatic

Extract 3×2 from 3×3.

◆ bj_mat3x2_identity()

void bj_mat3x2_identity ( bj_real m[restrict static(3)][2])
inlinestatic

Set 3×2 to identity.

◆ bj_mat3x2_mul()

void bj_mat3x2_mul ( bj_real res[restrict static(3)][2],
const bj_real A[restrict static(3)][2],
const bj_real B[restrict static(3)][2] )
inlinestatic

3×2 multiplication: res = A * B.

◆ bj_mat3x2_mul_dir()

void bj_mat3x2_mul_dir ( bj_real r[restrict static(2)],
const bj_real m[restrict static(3)][2],
const bj_real v[restrict static(2)] )
inlinestatic

3×2 transform direction (no translation).

◆ bj_mat3x2_mul_point()

void bj_mat3x2_mul_point ( bj_real r[restrict static(2)],
const bj_real m[restrict static(3)][2],
const bj_real p[restrict static(2)] )
inlinestatic

3×2 transform point.

◆ bj_mat3x2_rotate()

void bj_mat3x2_rotate ( bj_real m[restrict static(3)][2],
bj_real angle )
inlinestatic

Build 3×2 rotation.

◆ bj_mat3x2_scale()

void bj_mat3x2_scale ( bj_real m[restrict static(3)][2],
bj_real sx,
bj_real sy )
inlinestatic

Build 3×2 scale.

◆ bj_mat3x2_translate()

void bj_mat3x2_translate ( bj_real m[restrict static(3)][2],
bj_real tx,
bj_real ty )
inlinestatic

Build 3×2 translation.

◆ bj_mat4_add()

void bj_mat4_add ( bj_mat4x4 res,
const bj_mat4x4 lhs,
const bj_mat4x4 rhs )
inlinestatic

Add 4×4.

◆ bj_mat4_col()

void bj_mat4_col ( bj_vec4 res,
const bj_mat4x4 mat,
int c )
inlinestatic

Extract 4×4 column.

◆ bj_mat4_copy()

void bj_mat4_copy ( bj_mat4x4 to,
const bj_mat4x4 from )
inlinestatic

Copy 4×4.

◆ bj_mat4_from_mat4x3()

void bj_mat4_from_mat4x3 ( bj_mat4x4 out,
const bj_real a[restrict static(4)][3] )
inlinestatic

Promote 4×3 to 4×4 homogeneous.

◆ bj_mat4_from_quat()

void bj_mat4_from_quat ( bj_mat4 res,
const bj_quat q )
inlinestatic

Convert unit quaternion to a 4×4 rotation matrix.

Parameters
resOutput quaternion.
qInput quaternion.
Note
Assumes unit-length quaternions for pure rotations.

◆ bj_mat4_frustum()

void bj_mat4_frustum ( bj_real fmat[restrict static(4)][4],
bj_real l,
bj_real r,
bj_real b,
bj_real t,
bj_real n,
bj_real f )
inlinestatic

Off-center perspective frustum (4×4).

◆ bj_mat4_identity()

void bj_mat4_identity ( bj_mat4x4 mat)
inlinestatic

Set 4×4 to identity.

◆ bj_mat4_inverse()

void bj_mat4_inverse ( bj_mat4x4 res,
const bj_mat4x4 mat )
inlinestatic

Invert 4×4.

◆ bj_mat4_lookat()

void bj_mat4_lookat ( bj_real m[restrict static(4)][4],
const bj_vec3 eye,
const bj_vec3 center,
const bj_vec3 up )
inlinestatic

Look-at view matrix builder (4×4).

◆ bj_mat4_mul()

void bj_mat4_mul ( bj_real res[restrict static(4)][4],
const bj_real lhs[restrict static(4)][4],
const bj_real rhs[restrict static(4)][4] )
inlinestatic

4×4 multiplication: res = lhs * rhs.

◆ bj_mat4_mul_outer()

void bj_mat4_mul_outer ( bj_mat4x4 res,
const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Outer product to upper-left 3×3 block of 4×4.

◆ bj_mat4_mul_vec4()

void bj_mat4_mul_vec4 ( bj_real res[restrict static(4)],
const bj_real mat[restrict static(4)][4],
const bj_real v[restrict static(4)] )
inlinestatic

4×4 multiply by vec4.

◆ bj_mat4_ortho()

void bj_mat4_ortho ( bj_real omat[restrict static(4)][4],
bj_real l,
bj_real r,
bj_real b,
bj_real t,
bj_real n,
bj_real f )
inlinestatic

Orthographic projection (4×4).

◆ bj_mat4_orthonormalize()

void bj_mat4_orthonormalize ( bj_mat4x4 res,
const bj_mat4x4 mat )
inlinestatic

Orthonormalize upper-left 3×3 of 4×4.

◆ bj_mat4_perspective()

void bj_mat4_perspective ( bj_real pmat[restrict static(4)][4],
bj_real y_fov,
bj_real aspect,
bj_real n,
bj_real f )
inlinestatic

Symmetric perspective from FOV+aspect (4×4).

◆ bj_mat4_rotate()

void bj_mat4_rotate ( bj_mat4x4 res,
const bj_mat4x4 mat,
bj_real x,
bj_real y,
bj_real z,
bj_real angle )
inlinestatic

Rotate about axis, post-multiply.

◆ bj_mat4_rotate_arcball()

void bj_mat4_rotate_arcball ( bj_mat4x4 R,
const bj_mat4x4 M,
bj_vec2 const _a,
bj_vec2 const _b,
bj_real s )
inlinestatic

Arcball rotation.

◆ bj_mat4_rotate_from_quat()

void bj_mat4_rotate_from_quat ( bj_mat4 R,
const bj_mat4 M,
const bj_quat q )
inlinestatic

Post-multiply matrix by rotation from quaternion: R = M * rot(q).

Parameters
ROutput matrix.
MInput 4×4 matrix.
qInput quaternion.
Note
Assumes unit-length quaternions for pure rotations.

◆ bj_mat4_rotate_x()

void bj_mat4_rotate_x ( bj_mat4x4 res,
const bj_mat4x4 mat,
bj_real angle )
inlinestatic

Rotate about X/Y/Z, post-multiply.

◆ bj_mat4_rotate_y()

void bj_mat4_rotate_y ( bj_mat4x4 res,
const bj_mat4x4 mat,
bj_real angle )
inlinestatic

◆ bj_mat4_rotate_z()

void bj_mat4_rotate_z ( bj_mat4x4 res,
const bj_mat4x4 mat,
bj_real angle )
inlinestatic

◆ bj_mat4_row()

void bj_mat4_row ( bj_vec4 res,
const bj_mat4x4 mat,
int r )
inlinestatic

Extract 4×4 row.

◆ bj_mat4_scale()

void bj_mat4_scale ( bj_mat4x4 res,
const bj_mat4x4 lhs,
bj_real k )
inlinestatic

Scale 4×4 by k.

◆ bj_mat4_scale_xyz()

void bj_mat4_scale_xyz ( bj_mat4x4 res,
const bj_mat4x4 mat,
bj_real x,
bj_real y,
bj_real z )
inlinestatic

Scale basis vectors.

◆ bj_mat4_sub()

void bj_mat4_sub ( bj_mat4x4 res,
const bj_mat4x4 lhs,
const bj_mat4x4 rhs )
inlinestatic

Sub 4×4.

◆ bj_mat4_translation()

void bj_mat4_translation ( bj_mat4x4 res,
bj_real x,
bj_real y,
bj_real z )
inlinestatic

Create 4×4 translation matrix.

◆ bj_mat4_translation_inplace()

void bj_mat4_translation_inplace ( bj_mat4x4 M,
bj_real x,
bj_real y,
bj_real z )
inlinestatic

Apply 4×4 translation in-place.

◆ bj_mat4_transpose()

void bj_mat4_transpose ( bj_mat4x4 res,
const bj_mat4x4 mat )
inlinestatic

Transpose 4×4.

◆ bj_mat4_viewport()

void bj_mat4_viewport ( bj_real vpmat[restrict static(4)][4],
bj_real x,
bj_real y,
bj_real w,
bj_real h )
inlinestatic

Viewport transform (4×4).

◆ bj_mat4x3_from_mat4()

void bj_mat4x3_from_mat4 ( bj_real out43[restrict static(4)][3],
const bj_mat4x4 m )
inlinestatic

Extract 4×3 from 4×4.

◆ bj_mat4x3_identity()

void bj_mat4x3_identity ( bj_real m[restrict static(4)][3])
inlinestatic

Set 4×3 to identity.

◆ bj_mat4x3_lookat()

void bj_mat4x3_lookat ( bj_real m[restrict static(4)][3],
const bj_real eye[restrict static(3)],
const bj_real center[restrict static(3)],
const bj_real up[restrict static(3)] )
inlinestatic

Look-at builder for 4×3.

◆ bj_mat4x3_mul()

void bj_mat4x3_mul ( bj_real res[restrict static(4)][3],
const bj_real A[restrict static(4)][3],
const bj_real B[restrict static(4)][3] )
inlinestatic

4×3 multiplication: res = A * B.

◆ bj_mat4x3_mul_dir()

void bj_mat4x3_mul_dir ( bj_real r[restrict static(3)],
const bj_real m[restrict static(4)][3],
const bj_real v[restrict static(3)] )
inlinestatic

4×3 transform direction (no translation).

◆ bj_mat4x3_mul_point()

void bj_mat4x3_mul_point ( bj_real r[restrict static(3)],
const bj_real m[restrict static(4)][3],
const bj_real p[restrict static(3)] )
inlinestatic

4×3 transform point.

◆ bj_mat4x3_rotate_x()

void bj_mat4x3_rotate_x ( bj_real m[restrict static(4)][3],
bj_real angle )
inlinestatic

4×3 rotate X/Y/Z.

◆ bj_mat4x3_rotate_y()

void bj_mat4x3_rotate_y ( bj_real m[restrict static(4)][3],
bj_real angle )
inlinestatic

◆ bj_mat4x3_rotate_z()

void bj_mat4x3_rotate_z ( bj_real m[restrict static(4)][3],
bj_real angle )
inlinestatic

◆ bj_mat4x3_scale()

void bj_mat4x3_scale ( bj_real m[restrict static(4)][3],
bj_real sx,
bj_real sy,
bj_real sz )
inlinestatic

4×3 scale.

◆ bj_mat4x3_translate()

void bj_mat4x3_translate ( bj_real m[restrict static(4)][3],
bj_real tx,
bj_real ty,
bj_real tz )
inlinestatic

4×3 translation.

◆ bj_mod()

bj_real bj_mod ( bj_real x,
bj_real y )
inlinestatic

Positive modulus with non-negative result magnitude.

Parameters
xDividend
yDivisor (must be non-zero)
Returns
Remainder in [0, |y|) with the sign of y
Precondition
y != 0

◆ bj_quat_conjugate()

void bj_quat_conjugate ( bj_quat res,
const bj_quat q )
inlinestatic

Conjugate quaternion: (x,y,z,w) -> (-x,-y,-z,w).

Parameters
resOutput quaternion.
qInput quaternion.

◆ bj_quat_from_mat4()

void bj_quat_from_mat4 ( bj_quat q,
const bj_mat4 M )
inlinestatic

Extract a unit quaternion from a 4×4 rotation matrix.

Parameters
qInput quaternion.
MInput 4×4 matrix.
Note
Assumes unit-length quaternions for pure rotations.
Uses a numerically stable branch based on the dominant diagonal term.

◆ bj_quat_identity()

void bj_quat_identity ( bj_quat q)
inlinestatic

Set quaternion to identity (no rotation).

Parameters
qInput quaternion.

◆ bj_quat_mul()

void bj_quat_mul ( bj_quat res,
const bj_quat p,
const bj_quat q )
inlinestatic

Hamilton product: res = p * q.

Parameters
resOutput quaternion.
pInput quaternion.
qInput quaternion.
Note
Assumes unit-length quaternions for pure rotations.

◆ bj_quat_mul_vec3()

void bj_quat_mul_vec3 ( bj_vec3 res,
const bj_quat q,
const bj_vec3 v )
inlinestatic

Rotate a 3D vector by a unit quaternion.

Parameters
resOutput quaternion.
qInput quaternion.
v3D vector.
Note
Assumes unit-length quaternions for pure rotations.

◆ bj_quat_rotation()

void bj_quat_rotation ( bj_quat res,
bj_real angle,
const bj_vec3 axis )
inlinestatic

Build a unit quaternion from axis-angle.

Parameters
resOutput quaternion.
angleRotation angle in radians.
axis3D vector.
Note
Assumes unit-length quaternions for pure rotations.
Warning
If axis is near zero length, the result is implementation-defined.

◆ bj_real_cmp()

int bj_real_cmp ( bj_real a,
bj_real b )
inlinestatic

Three-way compare using absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
-1 if a < b, 1 if a > b, 0 otherwise

◆ bj_real_cmp_rel()

int bj_real_cmp_rel ( bj_real a,
bj_real b )
inlinestatic

Three-way compare using relative epsilon.

Parameters
aFirst value
bSecond value
Returns
-1 if a < b, 1 if a > b, 0 otherwise

◆ bj_real_eq()

int bj_real_eq ( bj_real a,
bj_real b )
inlinestatic

Equality within absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if |a - b| <= BJ_EPSILON

◆ bj_real_eq_rel()

int bj_real_eq_rel ( bj_real a,
bj_real b )
inlinestatic

Equality within relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if |a - b| <= BJ_EPSILON * max(1, |a|, |b|)

◆ bj_real_gt()

int bj_real_gt ( bj_real a,
bj_real b )
inlinestatic

a > b by more than absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if (a - b) > BJ_EPSILON

◆ bj_real_gt_rel()

int bj_real_gt_rel ( bj_real a,
bj_real b )
inlinestatic

a > b by more than relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if (a - b) > BJ_EPSILON * max(1, |a|, |b|)

◆ bj_real_gte()

int bj_real_gte ( bj_real a,
bj_real b )
inlinestatic

a >= b within absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if a >= b within tolerance

◆ bj_real_gte_rel()

int bj_real_gte_rel ( bj_real a,
bj_real b )
inlinestatic

a >= b within relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if a >= b within tolerance

◆ bj_real_is_zero()

int bj_real_is_zero ( bj_real x)
inlinestatic

Absolute-zero test.

Parameters
xInput value
Returns
Non-zero if |x| <= BJ_EPSILON

◆ bj_real_is_zero_scaled()

int bj_real_is_zero_scaled ( bj_real x,
bj_real scale )
inlinestatic

Scaled zero test using max(1, |scale|).

Parameters
xInput value
scaleScale reference
Returns
Non-zero if |x| <= BJ_EPSILON * max(1, |scale|)

◆ bj_real_lt()

int bj_real_lt ( bj_real a,
bj_real b )
inlinestatic

a < b by more than absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if (b - a) > BJ_EPSILON

◆ bj_real_lt_rel()

int bj_real_lt_rel ( bj_real a,
bj_real b )
inlinestatic

a < b by more than relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if (b - a) > BJ_EPSILON * max(1, |a|, |b|)

◆ bj_real_lte()

int bj_real_lte ( bj_real a,
bj_real b )
inlinestatic

a <= b within absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if a <= b within tolerance

◆ bj_real_lte_rel()

int bj_real_lte_rel ( bj_real a,
bj_real b )
inlinestatic

a <= b within relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if a <= b within tolerance

◆ bj_real_neq()

int bj_real_neq ( bj_real a,
bj_real b )
inlinestatic

Inequality within absolute epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if not equal within absolute epsilon

◆ bj_real_neq_rel()

int bj_real_neq_rel ( bj_real a,
bj_real b )
inlinestatic

Inequality within relative epsilon.

Parameters
aFirst value
bSecond value
Returns
Non-zero if not equal within relative epsilon

◆ bj_real_relative_scale()

bj_real bj_real_relative_scale ( bj_real a,
bj_real b )
inlinestatic

Internal scale helper max(1, |a|, |b|).

Parameters
aFirst value
bSecond value
Returns
Scale factor s >= 1

◆ bj_real_snap_zero()

bj_real bj_real_snap_zero ( bj_real x)
inlinestatic

Snap to exact zero under absolute epsilon.

Parameters
xInput value
Returns
0 if |x| <= BJ_EPSILON, else x

◆ bj_real_snorm_safe()

bj_real bj_real_snorm_safe ( bj_real x,
bj_real len )
inlinestatic

Safe scalar normalization.

Parameters
xNumerator
lenDenominator magnitude
Returns
0 if len is zero, else x / len

◆ bj_rect_intersection()

bj_bool bj_rect_intersection ( const bj_rect * p_rect_a,
const bj_rect * p_rect_b,
bj_rect * p_result )

Computes the intersection of two bj_rect.

Parameters
p_rect_aPointer to the first rectangle. Must not be 0.
p_rect_bPointer to the second rectangle. Must not be 0.
p_resultPointer to the rectangle where the result will be stored. Can be 0 if only checking intersection presence.
Returns
BJ_TRUE if the rectangles intersect and neither input is 0, BJ_FALSE.
Note
Both input rectangles must be valid and properly initialized. If either p_rect_a or p_rect_b is 0, the function returns 0. If p_result is 0, the function only checks for intersection presence and does not compute the intersection rectangle.

Example usage:

bj_rect rect_a = {0, 0, 10, 10};
bj_rect rect_b = {5, 5, 15, 15};
bj_rect result;
if (bj_rect_intersection(&rect_a, &rect_b, 0)) {
// There is an intersection between rect_a and rect_b.
}
struct bj_rect_t bj_rect
Typedef for bj_rect_t.
Definition rect.h:15
bj_bool bj_rect_intersection(const bj_rect *p_rect_a, const bj_rect *p_rect_b, bj_rect *p_result)
Computes the intersection of two bj_rect.

◆ bj_smoothstep()

bj_real bj_smoothstep ( bj_real e0,
bj_real e1,
bj_real x )
inlinestatic

Smooth Hermite step between e0 and e1.

Clamps t to [0,1].

Parameters
e0Start edge
e1End edge
xInput value
Returns
Interpolant in [0,1]

◆ bj_step()

bj_real bj_step ( bj_real edge,
bj_real x )
inlinestatic

Step function.

Parameters
edgeThreshold edge
xInput value
Returns
0 if x < edge, else 1

◆ bj_vec2_add()

void bj_vec2_add ( bj_vec2 res,
const bj_vec2 lhs,
const bj_vec2 rhs )
inlinestatic

Component-wise addition of two 2D vectors: res = lhs + rhs.

Parameters
resOutput 2D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.

◆ bj_vec2_add_scaled()

void bj_vec2_add_scaled ( bj_vec2 res,
const bj_vec2 a,
const bj_vec2 b,
bj_real s )
inlinestatic

Add a scaled vector: res = a + s * b.

Parameters
resOutput 2D vector.
aInput component or vector a.
bInput component or vector b.
sScalar factor.

◆ bj_vec2_apply()

void bj_vec2_apply ( bj_vec2 res,
const bj_vec2 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec2_copy()

void bj_vec2_copy ( bj_vec2 res,
const bj_vec2 src )
inlinestatic

Copy a 2D vector.

Parameters
resOutput 2D vector.
srcSource vector to copy from.

◆ bj_vec2_cross()

bj_real bj_vec2_cross ( const bj_vec2 a,
const bj_vec2 b )
inlinestatic

2D "cross product" (perp dot): returns scalar a.x*b.y - a.y*b.x.

Useful for orientation tests, signed area, segment intersection.

◆ bj_vec2_dist()

bj_real bj_vec2_dist ( const bj_vec2 a,
const bj_vec2 b )
inlinestatic

Euclidean distance between two 2D vectors.

Parameters
aInput vector a.
bInput vector b.
Returns
The Euclidean distance ||a - b||.

◆ bj_vec2_dist_squared()

bj_real bj_vec2_dist_squared ( const bj_vec2 a,
const bj_vec2 b )
inlinestatic

Squared Euclidean distance between two 2D vectors.

Parameters
aInput vector a.
bInput vector b.
Returns
The squared distance ||a - b||^2.

◆ bj_vec2_dot()

bj_real bj_vec2_dot ( const bj_vec2 a,
const bj_vec2 b )
inlinestatic

Dot product of two 2D vectors.

Parameters
aInput component or vector a.
bInput component or vector b.
Returns
The scalar dot product.

◆ bj_vec2_len()

bj_real bj_vec2_len ( const bj_vec2 v)
inlinestatic

Euclidean length (L2 norm) of a 2D vector.

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec2_max()

void bj_vec2_max ( bj_vec2 res,
const bj_vec2 a,
const bj_vec2 b )
inlinestatic

Component-wise maximum of two 2D vectors.

Parameters
resOutput 2D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec2_min()

void bj_vec2_min ( bj_vec2 res,
const bj_vec2 a,
const bj_vec2 b )
inlinestatic

Component-wise minimum of two 2D vectors.

Parameters
resOutput 2D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec2_normalize()

void bj_vec2_normalize ( bj_vec2 res,
const bj_vec2 v )
inlinestatic

Normalize a 2D vector to unit length.

Parameters
resOutput 2D vector.
vInput vector.
Warning
Undefined if the input vector has zero length.

◆ bj_vec2_scale()

void bj_vec2_scale ( bj_vec2 res,
const bj_vec2 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
resOutput 2D vector.
vInput vector.
sScalar factor.

◆ bj_vec2_scale_each()

void bj_vec2_scale_each ( bj_vec2 res,
const bj_vec2 v,
const bj_vec2 s )
inlinestatic

Per-component scaling: res[i] = v[i] * s[i].

Parameters
resOutput 2D vector.
vInput vector.
sScalar factor.

◆ bj_vec2_set()

void bj_vec2_set ( bj_vec2 res,
bj_real a,
bj_real b )
inlinestatic

Set a 2D vector from components (x, y).

Parameters
resOutput 2D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec2_set_len()

void bj_vec2_set_len ( bj_vec2 res,
const bj_vec2 v,
bj_real target_len )
inlinestatic

Scale a 2D vector to a given length.

Parameters
resOutput 2D vector.
vInput vector.
target_lenDesired length of the result.
Warning
Undefined if the input vector has zero length.

◆ bj_vec2_sub()

void bj_vec2_sub ( bj_vec2 res,
const bj_vec2 lhs,
const bj_vec2 rhs )
inlinestatic

Component-wise subtraction of two 2D vectors: res = lhs - rhs.

Parameters
resOutput 2D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.

◆ bj_vec2_zero()

void bj_vec2_zero ( bj_vec2 res)
inlinestatic

◆ bj_vec3_add()

void bj_vec3_add ( bj_vec3 res,
const bj_vec3 lhs,
const bj_vec3 rhs )
inlinestatic

Component-wise addition of two 3D vectors: res = lhs + rhs.

Parameters
resOutput 3D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.

◆ bj_vec3_add_scaled()

void bj_vec3_add_scaled ( bj_vec3 res,
const bj_vec3 a,
const bj_vec3 b,
bj_real s )
inlinestatic

Add a scaled vector: res = a + s * b.

Parameters
resOutput 3D vector.
aInput component or vector a.
bInput component or vector b.
sScalar factor.

◆ bj_vec3_apply()

void bj_vec3_apply ( bj_vec3 res,
const bj_vec3 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec3_copy()

void bj_vec3_copy ( bj_vec3 res,
const bj_vec3 src )
inlinestatic

Copy a 3D vector.

Parameters
resOutput 3D vector.
srcSource vector to copy from.

◆ bj_vec3_cross()

void bj_vec3_cross ( bj_vec3 res,
const bj_vec3 l,
const bj_vec3 r )
inlinestatic

3D cross product: res = l × r (right-hand rule).

Parameters
resOutput 3D vector.
lLeft-hand input vector.
rRight-hand input vector.

◆ bj_vec3_dist()

bj_real bj_vec3_dist ( const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Euclidean distance between two 3D vectors.

Parameters
aInput vector a.
bInput vector b.
Returns
The Euclidean distance ||a - b||.

◆ bj_vec3_dist_squared()

bj_real bj_vec3_dist_squared ( const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Squared Euclidean distance between two 3D vectors.

Parameters
aInput vector a.
bInput vector b.
Returns
The squared distance ||a - b||^2.

◆ bj_vec3_dot()

bj_real bj_vec3_dot ( const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Dot product of two 3D vectors.

Parameters
aInput component or vector a.
bInput component or vector b.
Returns
The scalar dot product.

◆ bj_vec3_len()

bj_real bj_vec3_len ( const bj_vec3 v)
inlinestatic

Euclidean length (L2 norm) of a 3D vector.

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec3_max()

void bj_vec3_max ( bj_vec3 res,
const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Component-wise maximum of two 3D vectors.

Parameters
resOutput 3D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec3_min()

void bj_vec3_min ( bj_vec3 res,
const bj_vec3 a,
const bj_vec3 b )
inlinestatic

Component-wise minimum of two 3D vectors.

Parameters
resOutput 3D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec3_normalize()

void bj_vec3_normalize ( bj_vec3 res,
const bj_vec3 v )
inlinestatic

Normalize a 3D vector to unit length.

Parameters
resOutput 3D vector.
vInput vector.
Warning
Undefined if the input vector has zero length.

◆ bj_vec3_reflect()

void bj_vec3_reflect ( bj_vec3 res,
const bj_vec3 v,
const bj_vec3 n )
inlinestatic

Reflect a vector about a normal: res = v - 2*dot(v, n)*n.

Parameters
resOutput 3D vector.
vInput vector.
nSurface normal (expected normalized).
Note
The normal n should be normalized for a true reflection.

◆ bj_vec3_scale()

void bj_vec3_scale ( bj_vec3 res,
const bj_vec3 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
resOutput 3D vector.
vInput vector.
sScalar factor.

◆ bj_vec3_set()

void bj_vec3_set ( bj_vec3 res,
bj_real a,
bj_real b,
bj_real c )
inlinestatic

Set a 3D vector from components (x, y, z).

Parameters
resOutput 3D vector.
aInput component or vector a.
bInput component or vector b.
cInput component or vector c.

◆ bj_vec3_set_len()

void bj_vec3_set_len ( bj_vec3 res,
const bj_vec3 v,
bj_real target_len )
inlinestatic

Scale a 3D vector to a given length.

Parameters
resOutput 3D vector.
vInput vector.
target_lenDesired length of the result.
Warning
Undefined if the input vector has zero length.

◆ bj_vec3_sub()

void bj_vec3_sub ( bj_vec3 res,
const bj_vec3 lhs,
const bj_vec3 rhs )
inlinestatic

Component-wise subtraction of two 3D vectors: res = lhs - rhs.

Parameters
resOutput 3D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.

◆ bj_vec3_zero()

void bj_vec3_zero ( bj_vec3 res)
inlinestatic

◆ bj_vec4_add()

void bj_vec4_add ( bj_vec4 res,
const bj_vec4 lhs,
const bj_vec4 rhs )
inlinestatic

Component-wise addition of two 4D vectors: res = lhs + rhs.

Parameters
resOutput 4D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.

◆ bj_vec4_add_scaled()

void bj_vec4_add_scaled ( bj_vec4 res,
const bj_vec4 a,
const bj_vec4 b,
bj_real s )
inlinestatic

Add a scaled vector: res = a + s * b.

Parameters
resOutput 4D vector.
aInput component or vector a.
bInput component or vector b.
sScalar factor.

◆ bj_vec4_apply()

void bj_vec4_apply ( bj_vec4 res,
const bj_vec4 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec4_copy()

void bj_vec4_copy ( bj_vec4 res,
const bj_vec4 src )
inlinestatic

Copy a 4D vector.

Parameters
resOutput 4D vector.
srcSource vector to copy from.

◆ bj_vec4_cross()

void bj_vec4_cross ( bj_vec4 res,
const bj_vec4 l,
const bj_vec4 r )
inlinestatic

Cross product using xyz components; w is set to 1.

Parameters
resOutput 4D vector.
lLeft-hand input vector.
rRight-hand input vector.
Note
Uses only xyz components; the result w component is set to 1.0.

◆ bj_vec4_dot()

bj_real bj_vec4_dot ( const bj_vec4 a,
const bj_vec4 b )
inlinestatic

Dot product of two 4D vectors.

Parameters
aInput component or vector a.
bInput component or vector b.
Returns
The scalar dot product.

◆ bj_vec4_len()

bj_real bj_vec4_len ( const bj_vec4 v)
inlinestatic

Euclidean length (L2 norm) of a 4D vector.

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec4_max()

void bj_vec4_max ( bj_vec4 res,
const bj_vec4 a,
const bj_vec4 b )
inlinestatic

Component-wise maximum of two 4D vectors.

Parameters
resOutput 4D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec4_min()

void bj_vec4_min ( bj_vec4 res,
const bj_vec4 a,
const bj_vec4 b )
inlinestatic

Component-wise minimum of two 4D vectors.

Parameters
resOutput 4D vector.
aInput component or vector a.
bInput component or vector b.

◆ bj_vec4_normalize()

void bj_vec4_normalize ( bj_vec4 res,
const bj_vec4 v )
inlinestatic

Normalize a 4D vector to unit length.

Parameters
resOutput 4D vector.
vInput vector.
Warning
Undefined if the input vector has zero length.

◆ bj_vec4_reflect()

void bj_vec4_reflect ( bj_vec4 res,
const bj_vec4 v,
const bj_vec4 n )
inlinestatic

Reflect a vector about a normal: res = v - 2*dot(v, n)*n.

Parameters
resOutput 4D vector.
vInput vector.
nSurface normal (expected normalized).
Note
The normal n should be normalized for a true reflection.

◆ bj_vec4_scale()

void bj_vec4_scale ( bj_vec4 res,
const bj_vec4 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
resOutput 4D vector.
vInput vector.
sScalar factor.

◆ bj_vec4_set()

void bj_vec4_set ( bj_vec4 res,
bj_real a,
bj_real b,
bj_real c,
bj_real d )
inlinestatic

Set a 4D vector from components (x, y, z, w).

Parameters
resOutput 4D vector.
aInput component or vector a.
bInput component or vector b.
cInput component or vector c.
dInput component or vector d.

◆ bj_vec4_sub()

void bj_vec4_sub ( bj_vec4 res,
const bj_vec4 lhs,
const bj_vec4 rhs )
inlinestatic

Component-wise subtraction of two 4D vectors: res = lhs - rhs.

Parameters
resOutput 4D vector.
lhsLeft-hand input vector.
rhsRight-hand input vector.