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_mat3x3_t
struct  bj_mat3x2_t
struct  bj_mat4x4_t
struct  bj_mat4x3_t
struct  bj_rect_t
struct  bj_vec2_t
struct  bj_vec3_t
struct  bj_vec4_t

Macros

#define BJ_M3(c, r)
#define BJ_M32(c, r)
#define BJ_M4(c, r)
#define BJ_M43(c, r)
#define BJ_VEC2_ZERO   ((bj_vec2){BJ_FZERO, BJ_FZERO})
#define BJ_VEC3_ZERO   ((bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO})
#define BJ_VEC4_ZERO   ((bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO})

Typedefs

typedef struct bj_mat3x3_t bj_mat3x3
typedef struct bj_mat3x3_t bj_mat3
typedef struct bj_mat3x2_t bj_mat3x2
typedef struct bj_mat4x4_t bj_mat4x4
typedef struct bj_mat4x4_t bj_mat4
typedef struct bj_mat4x3_t bj_mat4x3
typedef struct bj_vec4_t bj_quat
typedef struct bj_rect_t bj_rect
typedef struct bj_vec2_t bj_vec2
typedef struct bj_vec3_t bj_vec3
typedef struct bj_vec4_t bj_vec4

Functions

static void bj_mat3_set_identity (bj_mat3 *restrict M)
static void bj_mat3_copy (bj_mat3 *restrict dst, const bj_mat3 *restrict src)
static bj_vec3 bj_mat3_row (const bj_mat3 *restrict M, int r)
static bj_vec3 bj_mat3_col (const bj_mat3 *restrict M, int c)
static void bj_mat3_transpose (bj_mat3 *restrict out, const bj_mat3 *restrict A)
static void bj_mat3_add (bj_mat3 *restrict out, const bj_mat3 *restrict A, const bj_mat3 *restrict B)
static void bj_mat3_sub (bj_mat3 *restrict out, const bj_mat3 *restrict A, const bj_mat3 *restrict B)
static void bj_mat3_mul_scalar (bj_mat3 *restrict out, const bj_mat3 *restrict A, bj_real k)
static void bj_mat3_mul (bj_mat3 *restrict out, const bj_mat3 *restrict A, const bj_mat3 *restrict B)
static bj_vec3 bj_mat3_transform_vec3 (const bj_mat3 *restrict M, bj_vec3 v)
static bj_vec2 bj_mat3_transform_point (const bj_mat3 *restrict M, bj_vec2 p)
static void bj_mat3_set_translation (bj_mat3 *restrict M, bj_real tx, bj_real ty)
static void bj_mat3_translate (bj_mat3 *restrict M, bj_real tx, bj_real ty)
static void bj_mat3_set_scaling_xy (bj_mat3 *restrict M, bj_real sx, bj_real sy)
static void bj_mat3_set_shear_xy (bj_mat3 *restrict M, bj_real shx, bj_real shy)
static void bj_mat3_set_rotation_z (bj_mat3 *restrict M, bj_real angle)
static bj_real bj_mat3_determinant (const bj_mat3 *restrict A)
static bj_bool bj_mat3_invert (bj_mat3 *restrict out, const bj_mat3 *restrict A)
static void bj_mat3_invert_unsafe (bj_mat3 *restrict out, const bj_mat3 *restrict A)
static void bj_mat3_set_ortho (bj_mat3 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t)
static void bj_mat3_set_viewport (bj_mat3 *restrict M, bj_real x, bj_real y, bj_real w, bj_real h)
static void bj_mat3x2_set_identity (bj_mat3x2 *restrict M)
static void bj_mat3x2_set_translation (bj_mat3x2 *restrict M, bj_real tx, bj_real ty)
static void bj_mat3x2_set_scaling_xy (bj_mat3x2 *restrict M, bj_real sx, bj_real sy)
static void bj_mat3x2_set_rotation_z (bj_mat3x2 *restrict M, bj_real angle)
static void bj_mat3x2_mul (bj_mat3x2 *restrict out, const bj_mat3x2 *restrict A, const bj_mat3x2 *restrict B)
static bj_vec2 bj_mat3x2_transform_point (const bj_mat3x2 *restrict M, bj_vec2 p)
static bj_vec2 bj_mat3x2_transform_dir (const bj_mat3x2 *restrict M, bj_vec2 v)
static void bj_mat3_from_mat3x2 (bj_mat3 *restrict M, const bj_mat3x2 *restrict A)
static void bj_mat3x2_from_mat3 (bj_mat3x2 *restrict M, const bj_mat3 *restrict A)
static void bj_mat4_set_identity (bj_mat4 *restrict M)
static void bj_mat4_copy (bj_mat4 *restrict dst, const bj_mat4 *restrict src)
static bj_vec4 bj_mat4_row (const bj_mat4 *restrict M, int r)
static bj_vec4 bj_mat4_col (const bj_mat4 *restrict M, int c)
static void bj_mat4_transpose (bj_mat4 *restrict out, const bj_mat4 *restrict A)
static void bj_mat4_add (bj_mat4 *restrict out, const bj_mat4 *restrict A, const bj_mat4 *restrict B)
static void bj_mat4_sub (bj_mat4 *restrict out, const bj_mat4 *restrict A, const bj_mat4 *restrict B)
static void bj_mat4_mul_scalar (bj_mat4 *restrict out, const bj_mat4 *restrict A, bj_real k)
static void bj_mat4_scale_axes (bj_mat4 *restrict out, const bj_mat4 *restrict A, bj_real sx, bj_real sy, bj_real sz)
static void bj_mat4_mul (bj_mat4 *restrict out, const bj_mat4 *restrict A, const bj_mat4 *restrict B)
static bj_vec4 bj_mat4_transform_vec4 (const bj_mat4 *restrict M, bj_vec4 v)
static void bj_mat4_set_translation (bj_mat4 *restrict M, bj_real x, bj_real y, bj_real z)
static void bj_mat4_translate (bj_mat4 *restrict M, bj_real x, bj_real y, bj_real z)
static void bj_mat4_set_outer_product (bj_mat4 *restrict out, bj_vec3 a, bj_vec3 b)
static void bj_mat4_rotate_axis_andle (bj_mat4 *restrict out, const bj_mat4 *restrict M, bj_vec3 axis, bj_real angle)
static void bj_mat4_rotate_x (bj_mat4 *restrict out, const bj_mat4 *restrict M, bj_real a)
static void bj_mat4_rotate_y (bj_mat4 *restrict out, const bj_mat4 *restrict M, bj_real a)
static void bj_mat4_rotate_z (bj_mat4 *restrict out, const bj_mat4 *restrict M, bj_real a)
static void bj_mat4_rotate_arcball (bj_mat4 *restrict R, const bj_mat4 *restrict M, bj_vec2 a, bj_vec2 b, bj_real s)
static bj_bool bj_mat4_invert (bj_mat4 *restrict out, const bj_mat4 *restrict M)
static void bj_mat4_invert_unsafe (bj_mat4 *restrict out, const bj_mat4 *restrict M)
static void bj_mat4_orthonormalize (bj_mat4 *restrict out, const bj_mat4 *restrict A)
static void bj_mat4_set_frustum (bj_mat4 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f)
static void bj_mat4_set_ortho (bj_mat4 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f)
static void bj_mat4_set_perspective (bj_mat4 *restrict M, bj_real y_fov, bj_real aspect, bj_real n, bj_real f)
static void bj_mat4_set_viewport (bj_mat4 *restrict M, bj_real x, bj_real y, bj_real w, bj_real h)
static void bj_mat4_set_lookat (bj_mat4 *restrict M, bj_vec3 eye, bj_vec3 center, bj_vec3 up)
static void bj_mat4x3_set_identity (bj_mat4x3 *restrict M)
static void bj_mat4x3_set_translation (bj_mat4x3 *restrict M, bj_real tx, bj_real ty, bj_real tz)
static void bj_mat4x3_set_scaling_xyz (bj_mat4x3 *restrict M, bj_real sx, bj_real sy, bj_real sz)
static void bj_mat4x3_set_rotation_x (bj_mat4x3 *restrict M, bj_real a)
static void bj_mat4x3_set_rotation_y (bj_mat4x3 *restrict M, bj_real a)
static void bj_mat4x3_set_rotation_z (bj_mat4x3 *restrict M, bj_real a)
static void bj_mat4x3_mul (bj_mat4x3 *restrict out, const bj_mat4x3 *restrict A, const bj_mat4x3 *restrict B)
static bj_vec3 bj_mat4x3_transform_point (const bj_mat4x3 *restrict M, bj_vec3 p)
static bj_vec3 bj_mat4x3_transform_dir (const bj_mat4x3 *restrict M, bj_vec3 v)
static void bj_mat4_from_mat4x3 (bj_mat4 *restrict M, const bj_mat4x3 *restrict A)
static void bj_mat4x3_from_mat4 (bj_mat4x3 *restrict M, const bj_mat4 *restrict A)
static bj_quat bj_quat_identity (void)
static bj_real bj_quat_dot (bj_quat a, bj_quat b)
static bj_real bj_quat_norm2 (bj_quat q)
static bj_real bj_quat_norm (bj_quat q)
static bj_quat bj_quat_normalize (bj_quat q)
static bj_quat bj_quat_conjugate (bj_quat q)
static bj_quat bj_quat_inverse (bj_quat q)
static bj_quat bj_quat_mul (bj_quat p, bj_quat q)
static bj_quat bj_quat_slerp (bj_quat a, bj_quat b, bj_real t)
static bj_quat bj_quat_from_axis_angle (bj_vec3 axis, bj_real angle_rad)
static bj_vec3 bj_quat_rotate_vec3 (bj_quat q, bj_vec3 v)
static bj_vec4 bj_quat_rotate_vec4 (bj_quat q, bj_vec4 v)
static void bj_quat_to_mat4 (bj_mat4 *restrict M, bj_quat q)
static bj_quat bj_quat_from_mat4 (const bj_mat4 *restrict M)
bj_bool bj_rect_intersection (const bj_rect *p_rect_a, const bj_rect *p_rect_b, bj_rect *p_result)
static bj_vec2 bj_vec2_map (bj_vec2 a, bj_real(*f)(bj_real))
static bj_vec2 bj_vec2_add (bj_vec2 lhs, bj_vec2 rhs)
static bj_vec2 bj_vec2_add_scaled (bj_vec2 lhs, bj_vec2 rhs, bj_real s)
static bj_vec2 bj_vec2_sub (const bj_vec2 lhs, const bj_vec2 rhs)
static bj_vec2 bj_vec2_scale (bj_vec2 v, bj_real s)
static bj_vec2 bj_vec2_mul_comp (const bj_vec2 v, const bj_vec2 s)
static bj_real bj_vec2_dot (bj_vec2 a, bj_vec2 b)
static bj_real bj_vec2_perp_dot (bj_vec2 a, bj_vec2 b)
static bj_real bj_vec2_len (bj_vec2 v)
static bj_vec2 bj_vec2_scale_to_len (bj_vec2 v, bj_real L)
static bj_real bj_vec2_distance_sq (bj_vec2 a, bj_vec2 b)
static bj_real bj_vec2_distance (const bj_vec2 a, const bj_vec2 b)
static bj_vec2 bj_vec2_normalize (bj_vec2 v)
static bj_vec2 bj_vec2_normalize_unsafe (bj_vec2 v)
static bj_vec2 bj_vec2_min (bj_vec2 a, bj_vec2 b)
static bj_vec2 bj_vec2_max (bj_vec2 a, bj_vec2 b)
static bj_vec3 bj_vec3_map (bj_vec3 a, bj_real(*f)(bj_real))
static bj_vec3 bj_vec3_add (bj_vec3 lhs, bj_vec3 rhs)
static bj_vec3 bj_vec3_add_scaled (bj_vec3 lhs, bj_vec3 rhs, bj_real s)
static bj_vec3 bj_vec3_sub (bj_vec3 lhs, bj_vec3 rhs)
static bj_vec3 bj_vec3_scale (bj_vec3 v, bj_real s)
static bj_real bj_vec3_dot (bj_vec3 a, bj_vec3 b)
static bj_real bj_vec3_len (bj_vec3 v)
static bj_vec3 bj_vec3_scale_to_len (bj_vec3 v, bj_real L)
static bj_real bj_vec3_distance_sq (bj_vec3 a, bj_vec3 b)
static bj_real bj_vec3_distance (bj_vec3 a, bj_vec3 b)
static bj_vec3 bj_vec3_normalize (bj_vec3 v)
static bj_vec3 bj_vec3_normalize_unsafe (bj_vec3 v)
static bj_vec3 bj_vec3_min (bj_vec3 a, bj_vec3 b)
static bj_vec3 bj_vec3_max (bj_vec3 a, bj_vec3 b)
static bj_vec3 bj_vec3_cross (bj_vec3 l, bj_vec3 r)
static bj_vec3 bj_vec3_reflect (bj_vec3 v, bj_vec3 n)
static bj_vec4 bj_vec4_map (bj_vec4 a, bj_real(*f)(bj_real))
static bj_vec4 bj_vec4_add (bj_vec4 lhs, bj_vec4 rhs)
static bj_vec4 bj_vec4_add_scaled (bj_vec4 lhs, bj_vec4 rhs, bj_real s)
static bj_vec4 bj_vec4_sub (bj_vec4 lhs, bj_vec4 rhs)
static bj_vec4 bj_vec4_scale (bj_vec4 v, bj_real s)
static bj_real bj_vec4_dot (bj_vec4 a, bj_vec4 b)
static bj_real bj_vec4_len (bj_vec4 v)
static bj_vec4 bj_vec4_normalize (bj_vec4 v)
static bj_vec4 bj_vec4_normalize_unsafe (bj_vec4 v)
static bj_vec4 bj_vec4_min (bj_vec4 a, bj_vec4 b)
static bj_vec4 bj_vec4_max (bj_vec4 a, bj_vec4 b)
static bj_vec4 bj_vec4_cross_xyz (bj_vec4 l, bj_vec4 r)
static bj_vec4 bj_vec4_reflect (bj_vec4 v, 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_mat3x3_t

struct bj_mat3x3_t
Data Fields
bj_real m[9]

◆ bj_mat3x2_t

struct bj_mat3x2_t

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.

Data Fields
bj_real m[6]

◆ bj_mat4x4_t

struct bj_mat4x4_t

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

Columns are arrays of 4 components.

Data Fields
bj_real m[16]

◆ bj_mat4x3_t

struct bj_mat4x3_t

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.

Data Fields
bj_real m[12]

◆ 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.

◆ bj_vec2_t

struct bj_vec2_t

bj_vec2: 2D vector of bj_real values.

Intended for lightweight math operations and POD interop.

Data Fields
bj_real x
bj_real y

◆ bj_vec3_t

struct bj_vec3_t

bj_vec3: 3D vector of bj_real values.

Intended for lightweight math operations and POD interop.

Data Fields
bj_real x
bj_real y
bj_real z

◆ bj_vec4_t

struct bj_vec4_t

bj_vec4: 4D vector of bj_real values.

Intended for lightweight math operations and POD interop.

Data Fields
bj_real w
bj_real x
bj_real y
bj_real z

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_M3

#define BJ_M3 ( c,
r )
Value:
((c)*3 + (r)) /* 0<=c,r<3 */

◆ BJ_M32

#define BJ_M32 ( c,
r )
Value:
((c)*2 + (r)) /* 0<=c<3, 0<=r<2 */

◆ BJ_M4

#define BJ_M4 ( c,
r )
Value:
((c)*4 + (r)) /* 0<=c,r<4) */

◆ BJ_M43

#define BJ_M43 ( c,
r )
Value:
((c)*3 + (r)) /* 0<=c<4, 0<=r<3 */

◆ 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_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).

◆ BJ_VEC2_ZERO

#define BJ_VEC2_ZERO   ((bj_vec2){BJ_FZERO, BJ_FZERO})

◆ BJ_VEC3_ZERO

#define BJ_VEC3_ZERO   ((bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO})

◆ BJ_VEC4_ZERO

#define BJ_VEC4_ZERO   ((bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO})

Typedef Documentation

◆ bj_mat3

typedef struct bj_mat3x3_t bj_mat3

◆ bj_mat3x2

typedef struct bj_mat3x2_t bj_mat3x2

◆ bj_mat3x3

typedef struct bj_mat3x3_t bj_mat3x3

◆ bj_mat4

typedef struct bj_mat4x4_t bj_mat4

◆ bj_mat4x3

typedef struct bj_mat4x3_t bj_mat4x3

◆ bj_mat4x4

typedef struct bj_mat4x4_t bj_mat4x4

◆ bj_quat

typedef struct bj_vec4_t bj_quat

Quaternion type alias based on the 4D vector struct.

The layout matches bj_vec4_t fields:

q.x, q.y, q.z // vector part
q.w // scalar part

The alias preserves binary compatibility with bj_vec4_t and allows using quaternion values wherever a 4D vector is accepted, when meaningful.

◆ 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 struct bj_vec2_t bj_vec2

◆ bj_vec3

typedef struct bj_vec3_t bj_vec3

◆ bj_vec4

typedef struct bj_vec4_t bj_vec4

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_mat3 *restrict out,
const bj_mat3 *restrict A,
const bj_mat3 *restrict B )
inlinestatic

Component-wise addition: out = A + B.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.
BInput 3×3 matrix.

◆ bj_mat3_col()

bj_vec3 bj_mat3_col ( const bj_mat3 *restrict M,
int c )
inlinestatic

Extract a matrix column as a vector.

Parameters
MInput 3×3 matrix.
cindex (0-based).
Returns
3D vector result.

◆ bj_mat3_copy()

void bj_mat3_copy ( bj_mat3 *restrict dst,
const bj_mat3 *restrict src )
inlinestatic

Copy a matrix.

Parameters
dstOutput 3×3 matrix.
srcInput 3×3 matrix.

◆ bj_mat3_determinant()

bj_real bj_mat3_determinant ( const bj_mat3 *restrict A)
inlinestatic

Determinant of a 3×3 matrix.

Parameters
AInput 3×3 matrix.
Returns
bj_real.

◆ bj_mat3_from_mat3x2()

void bj_mat3_from_mat3x2 ( bj_mat3 *restrict M,
const bj_mat3x2 *restrict A )
inlinestatic

Promote a 3×2 affine matrix to 3×3.

Parameters
MOutput 3×3 matrix.
AInput 3×2 matrix.

◆ bj_mat3_invert()

bj_bool bj_mat3_invert ( bj_mat3 *restrict out,
const bj_mat3 *restrict A )
inlinestatic

Invert a 3×3 matrix (safe, adjugate).

Computes A^{-1} = adj(A) / det(A). If det(A) is zero by bj_real_is_zero, returns 0 and leaves out unspecified.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.
Returns
BJ_TRUE on success, BJ_FALSE if singular or near-singular by bj_real_is_zero(det).
Warning
Adj/Det method is numerically unstable for ill-conditioned A.
See also
bj_mat3_invert_unsafe

◆ bj_mat3_invert_unsafe()

void bj_mat3_invert_unsafe ( bj_mat3 *restrict out,
const bj_mat3 *restrict A )
inlinestatic

Invert a 3×3 matrix (unsafe, adjugate).

Same as bj_mat3_invert but skips the singularity check and divides by det(A) unconditionally. Faster when invertibility is guaranteed.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix (must be nonsingular).
Precondition
det(A) != 0 and A is well-conditioned for numerical stability.
Warning
Division by zero if det(A) == 0. Consider bj_mat3_invert instead.

◆ bj_mat3_mul()

void bj_mat3_mul ( bj_mat3 *restrict out,
const bj_mat3 *restrict A,
const bj_mat3 *restrict B )
inlinestatic

Matrix product: out = A * B.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.
BInput 3×3 matrix.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat3_mul_scalar()

void bj_mat3_mul_scalar ( bj_mat3 *restrict out,
const bj_mat3 *restrict A,
bj_real k )
inlinestatic

Scalar multiply: out = A * k.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.
kUniform scale factor.

◆ bj_mat3_row()

bj_vec3 bj_mat3_row ( const bj_mat3 *restrict M,
int r )
inlinestatic

Extract a matrix row as a vector.

Parameters
MInput 3×3 matrix.
rindex (0-based).
Returns
3D vector result.

◆ bj_mat3_set_identity()

void bj_mat3_set_identity ( bj_mat3 *restrict M)
inlinestatic

Set a 3×3 matrix to identity.

Parameters
MOutput 3×3 matrix.

◆ bj_mat3_set_ortho()

void bj_mat3_set_ortho ( bj_mat3 *restrict M,
bj_real l,
bj_real r,
bj_real b,
bj_real t )
inlinestatic

Build a 2D orthographic projection into a 3×3 matrix.

Parameters
MOutput 3×3 matrix.
lInput scalar.
rscalar (0-based).
bInput scalar.
tInput scalar.

◆ bj_mat3_set_rotation_z()

void bj_mat3_set_rotation_z ( bj_mat3 *restrict M,
bj_real angle )
inlinestatic

Matrix operation.

Parameters
MOutput 3×3 matrix.
angleRotation angle in radians.

◆ bj_mat3_set_scaling_xy()

void bj_mat3_set_scaling_xy ( bj_mat3 *restrict M,
bj_real sx,
bj_real sy )
inlinestatic

Apply non-uniform XY scale to a 3×3 matrix.

Parameters
MOutput 3×3 matrix.
sxScale on x.
syScale on y.

◆ bj_mat3_set_shear_xy()

void bj_mat3_set_shear_xy ( bj_mat3 *restrict M,
bj_real shx,
bj_real shy )
inlinestatic

Build an XY shear into a 3×3 matrix.

Parameters
MOutput 3×3 matrix.
shxInput scalar.
shyInput scalar.

◆ bj_mat3_set_translation()

void bj_mat3_set_translation ( bj_mat3 *restrict M,
bj_real tx,
bj_real ty )
inlinestatic

Build a 3×3 translation matrix.

Parameters
MOutput 3×3 matrix.
txTranslation along x.
tyTranslation along y.

◆ bj_mat3_set_viewport()

void bj_mat3_set_viewport ( bj_mat3 *restrict M,
bj_real x,
bj_real y,
bj_real w,
bj_real h )
inlinestatic

Build a 2D viewport transform into a 3×3 matrix.

Parameters
MOutput 3×3 matrix.
xViewport X origin in pixels.
yViewport Y origin in pixels.
wViewport width in pixels.
hViewport height in pixels.

◆ bj_mat3_sub()

void bj_mat3_sub ( bj_mat3 *restrict out,
const bj_mat3 *restrict A,
const bj_mat3 *restrict B )
inlinestatic

Component-wise subtraction: out = A - B.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.
BInput 3×3 matrix.

◆ bj_mat3_transform_point()

bj_vec2 bj_mat3_transform_point ( const bj_mat3 *restrict M,
bj_vec2 p )
inlinestatic

Transform a 2D point by a 3×3 homogeneous transform.

Parameters
MInput 3×3 matrix.
pInput point.
Returns
2D vector result.
Note
Homogeneous 2D. Applies projective divide if w ≠ 0.

◆ bj_mat3_transform_vec3()

bj_vec3 bj_mat3_transform_vec3 ( const bj_mat3 *restrict M,
bj_vec3 v )
inlinestatic

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

Parameters
MInput 3×3 matrix.
vInput vector.
Returns
3D vector result.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat3_translate()

void bj_mat3_translate ( bj_mat3 *restrict M,
bj_real tx,
bj_real ty )
inlinestatic

Right-multiply by a translation: M = M * T(tx,ty).

Parameters
MOutput 3×3 matrix.
txTranslation along x.
tyTranslation along y.
Note
Right-multiply in place.

◆ bj_mat3_transpose()

void bj_mat3_transpose ( bj_mat3 *restrict out,
const bj_mat3 *restrict A )
inlinestatic

Transpose a matrix.

Parameters
outOutput 3×3 matrix.
AInput 3×3 matrix.

◆ bj_mat3x2_from_mat3()

void bj_mat3x2_from_mat3 ( bj_mat3x2 *restrict M,
const bj_mat3 *restrict A )
inlinestatic

Demote a 3×3 matrix to 3×2 (drop projective terms).

Parameters
MOutput 3×2 matrix.
AInput 3×3 matrix.

◆ bj_mat3x2_mul()

void bj_mat3x2_mul ( bj_mat3x2 *restrict out,
const bj_mat3x2 *restrict A,
const bj_mat3x2 *restrict B )
inlinestatic

Matrix product: out = A * B.

Parameters
outOutput 3×2 matrix.
AInput 3×2 matrix.
BInput 3×2 matrix.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat3x2_set_identity()

void bj_mat3x2_set_identity ( bj_mat3x2 *restrict M)
inlinestatic

Set a 3×2 affine matrix to identity.

Parameters
MOutput 3×2 matrix.

◆ bj_mat3x2_set_rotation_z()

void bj_mat3x2_set_rotation_z ( bj_mat3x2 *restrict M,
bj_real angle )
inlinestatic

Matrix operation.

Parameters
MOutput 3×2 matrix.
angleRotation angle in radians.

◆ bj_mat3x2_set_scaling_xy()

void bj_mat3x2_set_scaling_xy ( bj_mat3x2 *restrict M,
bj_real sx,
bj_real sy )
inlinestatic

Scalar multiply: M = sx * k.

Parameters
MOutput 3×2 matrix.
sxScale on x.
syScale on y.

◆ bj_mat3x2_set_translation()

void bj_mat3x2_set_translation ( bj_mat3x2 *restrict M,
bj_real tx,
bj_real ty )
inlinestatic

Matrix operation.

Parameters
MOutput 3×2 matrix.
txTranslation along x.
tyTranslation along y.

◆ bj_mat3x2_transform_dir()

bj_vec2 bj_mat3x2_transform_dir ( const bj_mat3x2 *restrict M,
bj_vec2 v )
inlinestatic

Transform a direction vector (ignoring translation).

Parameters
MInput 3×2 matrix.
vInput vector.
Returns
2D vector result.
Note
Homogeneous 2D. Applies projective divide if w ≠ 0.

◆ bj_mat3x2_transform_point()

bj_vec2 bj_mat3x2_transform_point ( const bj_mat3x2 *restrict M,
bj_vec2 p )
inlinestatic

Transform a 2D point by a 3×2 affine matrix.

Parameters
MInput 3×2 matrix.
pInput point.
Returns
2D vector result.
Note
Homogeneous 2D. Applies projective divide if w ≠ 0.

◆ bj_mat4_add()

void bj_mat4_add ( bj_mat4 *restrict out,
const bj_mat4 *restrict A,
const bj_mat4 *restrict B )
inlinestatic

Component-wise addition: out = A + B.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
BInput 4×4 matrix.

◆ bj_mat4_col()

bj_vec4 bj_mat4_col ( const bj_mat4 *restrict M,
int c )
inlinestatic

Extract a matrix column as a vector.

Parameters
MInput 4×4 matrix.
cindex (0-based).
Returns
4D vector result.

◆ bj_mat4_copy()

void bj_mat4_copy ( bj_mat4 *restrict dst,
const bj_mat4 *restrict src )
inlinestatic

Copy a matrix.

Parameters
dstOutput 4×4 matrix.
srcInput 4×4 matrix.

◆ bj_mat4_from_mat4x3()

void bj_mat4_from_mat4x3 ( bj_mat4 *restrict M,
const bj_mat4x3 *restrict A )
inlinestatic

Promote a 4×3 affine matrix to 4×4.

Parameters
MOutput 4×4 matrix.
AInput 4×3 matrix.

◆ bj_mat4_invert()

bj_bool bj_mat4_invert ( bj_mat4 *restrict out,
const bj_mat4 *restrict M )
inlinestatic

Invert a 4×4 matrix (safe).

Computes A^{-1} via cofactors. If det(A) is zero by bj_real_is_zero, returns 0 and leaves out unspecified.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix.
Returns
BJ_TRUE on success, BJ_FALSE if singular or near-singular by bj_real_is_zero(det).
Warning
Cofactor-based inversion is costly and can be unstable for ill-conditioned matrices. Prefer affine/orthonormal specializations when possible.
See also
bj_mat4_invert_unsafe

◆ bj_mat4_invert_unsafe()

void bj_mat4_invert_unsafe ( bj_mat4 *restrict out,
const bj_mat4 *restrict M )
inlinestatic

Invert a 4×4 matrix (unsafe).

Same as bj_mat4_invert but skips the singularity check and divides by det(A) unconditionally.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix (must be nonsingular).
Precondition
det(M) != 0 and M is well-conditioned for numerical stability.
Warning
Division by zero if det(M) == 0. Consider bj_mat4_invert instead.

◆ bj_mat4_mul()

void bj_mat4_mul ( bj_mat4 *restrict out,
const bj_mat4 *restrict A,
const bj_mat4 *restrict B )
inlinestatic

Matrix product: out = A * B.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
BInput 4×4 matrix.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat4_mul_scalar()

void bj_mat4_mul_scalar ( bj_mat4 *restrict out,
const bj_mat4 *restrict A,
bj_real k )
inlinestatic

Scalar multiply: out = A * k.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
kUniform scale factor.

◆ bj_mat4_orthonormalize()

void bj_mat4_orthonormalize ( bj_mat4 *restrict out,
const bj_mat4 *restrict A )
inlinestatic

Orthonormalize the 3×3 linear part of a 4×4 matrix.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
Warning
If the 3×3 block is degenerate the result may contain NaNs.

◆ bj_mat4_rotate_arcball()

void bj_mat4_rotate_arcball ( bj_mat4 *restrict R,
const bj_mat4 *restrict M,
bj_vec2 a,
bj_vec2 b,
bj_real s )
inlinestatic

Build a 4×4 rotation from two unit vectors (arcball).

Parameters
ROutput 4×4 matrix.
MInput 4×4 matrix.
aInput 2D vector.
bInput 2D vector.
sScale factors as a vector.

◆ bj_mat4_rotate_axis_andle()

void bj_mat4_rotate_axis_andle ( bj_mat4 *restrict out,
const bj_mat4 *restrict M,
bj_vec3 axis,
bj_real angle )
inlinestatic

Right-multiply a 4×4 by a rotation around an arbitrary axis.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix.
axisUnit axis of rotation.
angleRotation angle in radians.

◆ bj_mat4_rotate_x()

void bj_mat4_rotate_x ( bj_mat4 *restrict out,
const bj_mat4 *restrict M,
bj_real a )
inlinestatic

Right-multiply by an X-axis rotation.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix.
aInput scalar.

◆ bj_mat4_rotate_y()

void bj_mat4_rotate_y ( bj_mat4 *restrict out,
const bj_mat4 *restrict M,
bj_real a )
inlinestatic

Right-multiply by a Y-axis rotation.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix.
aInput scalar.

◆ bj_mat4_rotate_z()

void bj_mat4_rotate_z ( bj_mat4 *restrict out,
const bj_mat4 *restrict M,
bj_real a )
inlinestatic

Right-multiply by a Z-axis rotation.

Parameters
outOutput 4×4 matrix.
MInput 4×4 matrix.
aInput scalar.

◆ bj_mat4_row()

bj_vec4 bj_mat4_row ( const bj_mat4 *restrict M,
int r )
inlinestatic

Extract a matrix row as a vector.

Parameters
MInput 4×4 matrix.
rindex (0-based).
Returns
4D vector result.

◆ bj_mat4_scale_axes()

void bj_mat4_scale_axes ( bj_mat4 *restrict out,
const bj_mat4 *restrict A,
bj_real sx,
bj_real sy,
bj_real sz )
inlinestatic

Scale basis vectors of a 4×4 matrix by per-axis factors.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
sxScale on x.
syScale on y.
szScale on z.

◆ bj_mat4_set_frustum()

void bj_mat4_set_frustum ( bj_mat4 *restrict M,
bj_real l,
bj_real r,
bj_real b,
bj_real t,
bj_real n,
bj_real f )
inlinestatic

Build a perspective frustum into a 4×4 matrix.

Parameters
MOutput 4×4 matrix.
lInput scalar.
rscalar (0-based).
bInput scalar.
tInput scalar.
nNear plane distance.
fFar plane distance.
Warning
Requires r>l, t>b, f>n. Depth maps to [0,1]. Y is inverted.

◆ bj_mat4_set_identity()

void bj_mat4_set_identity ( bj_mat4 *restrict M)
inlinestatic

Set a 4×4 matrix to identity.

Parameters
MOutput 4×4 matrix.

◆ bj_mat4_set_lookat()

void bj_mat4_set_lookat ( bj_mat4 *restrict M,
bj_vec3 eye,
bj_vec3 center,
bj_vec3 up )
inlinestatic

Build a right-handed look-at view matrix.

Parameters
MOutput 4×4 matrix.
eyeCamera position.
centerTarget point the camera looks at.
upApproximate up direction.
Note
Right-handed view: +Z looks from eye to center.

◆ bj_mat4_set_ortho()

void bj_mat4_set_ortho ( bj_mat4 *restrict M,
bj_real l,
bj_real r,
bj_real b,
bj_real t,
bj_real n,
bj_real f )
inlinestatic

Build a 3D orthographic projection into a 4×4 matrix.

Parameters
MOutput 4×4 matrix.
lInput scalar.
rscalar (0-based).
bInput scalar.
tInput scalar.
nNear plane distance.
fFar plane distance.
Warning
Requires r!=l, t!=b, f!=n. Depth maps to [0,1]. Y is inverted.

◆ bj_mat4_set_outer_product()

void bj_mat4_set_outer_product ( bj_mat4 *restrict out,
bj_vec3 a,
bj_vec3 b )
inlinestatic

Add outer product r += s * v^T to a 4×4 matrix.

Parameters
outOutput 4×4 matrix.
aInput 3D vector.
bInput 3D vector.

◆ bj_mat4_set_perspective()

void bj_mat4_set_perspective ( bj_mat4 *restrict M,
bj_real y_fov,
bj_real aspect,
bj_real n,
bj_real f )
inlinestatic

Build a 4×4 perspective projection from vertical FOV.

Parameters
MOutput 4×4 matrix.
y_fovVertical field of view in radians.
aspectAspect ratio width/height.
nNear plane distance.
fFar plane distance.
Warning
Requires f > n and aspect > 0. Depth maps to [0,1]. Y is inverted.

◆ bj_mat4_set_translation()

void bj_mat4_set_translation ( bj_mat4 *restrict M,
bj_real x,
bj_real y,
bj_real z )
inlinestatic

Build a 4×4 translation matrix.

Parameters
MOutput 4×4 matrix.
xViewport X origin in pixels.
yViewport Y origin in pixels.
zInput scalar.

◆ bj_mat4_set_viewport()

void bj_mat4_set_viewport ( bj_mat4 *restrict M,
bj_real x,
bj_real y,
bj_real w,
bj_real h )
inlinestatic

Build a 3D viewport transform into a 4×4 matrix.

Parameters
MOutput 4×4 matrix.
xViewport X origin in pixels.
yViewport Y origin in pixels.
wViewport width in pixels.
hViewport height in pixels.
Note
Maps NDC x,y ∈ [-1,1] and z ∈ [0,1] to window coordinates.

◆ bj_mat4_sub()

void bj_mat4_sub ( bj_mat4 *restrict out,
const bj_mat4 *restrict A,
const bj_mat4 *restrict B )
inlinestatic

Component-wise subtraction: out = A - B.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.
BInput 4×4 matrix.

◆ bj_mat4_transform_vec4()

bj_vec4 bj_mat4_transform_vec4 ( const bj_mat4 *restrict M,
bj_vec4 v )
inlinestatic

Multiply a 4×4 matrix by a 4D vector: r = M * v.

Parameters
MInput 4×4 matrix.
vInput vector.
Returns
4D vector result.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat4_translate()

void bj_mat4_translate ( bj_mat4 *restrict M,
bj_real x,
bj_real y,
bj_real z )
inlinestatic

Right-multiply by a translation: M = M * T(tx,ty,tz).

Parameters
MOutput 4×4 matrix.
xViewport X origin in pixels.
yViewport Y origin in pixels.
zInput scalar.
Note
Right-multiply in place.

◆ bj_mat4_transpose()

void bj_mat4_transpose ( bj_mat4 *restrict out,
const bj_mat4 *restrict A )
inlinestatic

Transpose a matrix.

Parameters
outOutput 4×4 matrix.
AInput 4×4 matrix.

◆ bj_mat4x3_from_mat4()

void bj_mat4x3_from_mat4 ( bj_mat4x3 *restrict M,
const bj_mat4 *restrict A )
inlinestatic

Demote a 4×4 matrix to 4×3 (drop projective terms).

Parameters
MOutput 4×3 matrix.
AInput 4×4 matrix.

◆ bj_mat4x3_mul()

void bj_mat4x3_mul ( bj_mat4x3 *restrict out,
const bj_mat4x3 *restrict A,
const bj_mat4x3 *restrict B )
inlinestatic

Matrix product: out = A * B.

Parameters
outOutput 4×3 matrix.
AInput 4×3 matrix.
BInput 4×3 matrix.
Note
Column-major storage. Vectors are columns. Right-multiply: r = M * v.

◆ bj_mat4x3_set_identity()

void bj_mat4x3_set_identity ( bj_mat4x3 *restrict M)
inlinestatic

Set a 4×3 affine matrix to identity.

Parameters
MOutput 4×3 matrix.

◆ bj_mat4x3_set_rotation_x()

void bj_mat4x3_set_rotation_x ( bj_mat4x3 *restrict M,
bj_real a )
inlinestatic

Right-multiply by an X-axis rotation.

Parameters
MOutput 4×3 matrix.
aInput scalar.

◆ bj_mat4x3_set_rotation_y()

void bj_mat4x3_set_rotation_y ( bj_mat4x3 *restrict M,
bj_real a )
inlinestatic

Right-multiply by a Y-axis rotation.

Parameters
MOutput 4×3 matrix.
aInput scalar.

◆ bj_mat4x3_set_rotation_z()

void bj_mat4x3_set_rotation_z ( bj_mat4x3 *restrict M,
bj_real a )
inlinestatic

Right-multiply by a Z-axis rotation.

Parameters
MOutput 4×3 matrix.
aInput scalar.

◆ bj_mat4x3_set_scaling_xyz()

void bj_mat4x3_set_scaling_xyz ( bj_mat4x3 *restrict M,
bj_real sx,
bj_real sy,
bj_real sz )
inlinestatic

Scalar multiply: M = sx * k.

Parameters
MOutput 4×3 matrix.
sxScale on x.
syScale on y.
szScale on z.

◆ bj_mat4x3_set_translation()

void bj_mat4x3_set_translation ( bj_mat4x3 *restrict M,
bj_real tx,
bj_real ty,
bj_real tz )
inlinestatic

Matrix operation.

Parameters
MOutput 4×3 matrix.
txTranslation along x.
tyTranslation along y.
tzTranslation along z.

◆ bj_mat4x3_transform_dir()

bj_vec3 bj_mat4x3_transform_dir ( const bj_mat4x3 *restrict M,
bj_vec3 v )
inlinestatic

Transform a direction vector (ignoring translation).

Parameters
MInput 4×3 matrix.
vInput vector.
Returns
3D vector result.
Note
Affine 3D. Ignores projective terms; no divide.

◆ bj_mat4x3_transform_point()

bj_vec3 bj_mat4x3_transform_point ( const bj_mat4x3 *restrict M,
bj_vec3 p )
inlinestatic

Transform a 3D point by a 4×3 affine matrix.

Parameters
MInput 4×3 matrix.
pInput point.
Returns
3D vector result.
Note
Affine 3D. Ignores projective terms; no divide.

◆ 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()

bj_quat bj_quat_conjugate ( bj_quat q)
inlinestatic

Conjugate of a quaternion.

Negates the vector part and keeps the scalar part: conj(q) = {-x,-y,-z,w}.

Parameters
qQuaternion.
Returns
Conjugated quaternion.
See also
bj_quat_inverse

◆ bj_quat_dot()

bj_real bj_quat_dot ( bj_quat a,
bj_quat b )
inlinestatic

4D dot product between two quaternions.

Parameters
aFirst quaternion.
bSecond quaternion.
Returns
a·b.
Note
For unit quaternions this equals cos(theta) where theta is the half-angle between orientations used by bj_quat_slerp.

◆ bj_quat_from_axis_angle()

bj_quat bj_quat_from_axis_angle ( bj_vec3 axis,
bj_real angle_rad )
inlinestatic

Build a quaternion from a rotation axis and angle.

Parameters
axisRotation axis. Need not be unit length.
angle_radRotation angle in radians.
Returns
Quaternion representing the rotation.
Note
Identity is returned if the axis length is near zero.

◆ bj_quat_from_mat4()

bj_quat bj_quat_from_mat4 ( const bj_mat4 *restrict M)
inlinestatic

Build a quaternion from a 4×4 rotation matrix.

Only the upper-left 3×3 block is used. Assumes it encodes a proper rotation. The result is normalized.

Parameters
MSource 4×4 matrix (column-major).
Returns
Quaternion representing the rotation.

◆ bj_quat_identity()

bj_quat bj_quat_identity ( void )
inlinestatic

Return the identity quaternion.

Represents a no-rotation. Equivalent to {0,0,0,1}.

Returns
Identity quaternion.
See also
bj_quat_normalize

◆ bj_quat_inverse()

bj_quat bj_quat_inverse ( bj_quat q)
inlinestatic

Multiplicative inverse of a quaternion.

Returns identity if the squared norm is near zero (<= BJ_EPSILON). Otherwise q^{-1} = conj(q) / ||q||^2.

Parameters
qQuaternion.
Returns
Inverse quaternion.
See also
bj_quat_conjugate, bj_quat_normalize

◆ bj_quat_mul()

bj_quat bj_quat_mul ( bj_quat p,
bj_quat q )
inlinestatic

Hamilton product p * q.

Composition order follows standard Hamilton convention. When used to rotate vectors via v' = q * v * q^{-1}, apply q on the left.

Parameters
pLeft quaternion.
qRight quaternion.
Returns
Product p*q.

◆ bj_quat_norm()

bj_real bj_quat_norm ( bj_quat q)
inlinestatic

Euclidean norm (length).

Parameters
qQuaternion.
Returns
||q||.

◆ bj_quat_norm2()

bj_real bj_quat_norm2 ( bj_quat q)
inlinestatic

Squared Euclidean norm.

Parameters
qQuaternion.
Returns
||q||^2.
See also
bj_quat_norm, bj_quat_normalize

◆ bj_quat_normalize()

bj_quat bj_quat_normalize ( bj_quat q)
inlinestatic

Normalize a quaternion.

Returns identity if the input length is near zero (<= BJ_EPSILON).

Parameters
qQuaternion.
Returns
Unit-length quaternion.

◆ bj_quat_rotate_vec3()

bj_vec3 bj_quat_rotate_vec3 ( bj_quat q,
bj_vec3 v )
inlinestatic

Rotate a 3D vector by a quaternion.

Parameters
qRotation quaternion. Expected to be unit length for pure rotation.
vVector to rotate.
Returns
Rotated vector.
Note
For performance, q is not normalized inside the function. Call bj_quat_normalize beforehand if needed.

◆ bj_quat_rotate_vec4()

bj_vec4 bj_quat_rotate_vec4 ( bj_quat q,
bj_vec4 v )
inlinestatic

Rotate a 4D vector by a quaternion, preserving w.

Parameters
qRotation quaternion. Expected to be unit length for pure rotation.
vVector to rotate. Its w component is passed through unchanged.
Returns
Rotated vector with original w.

◆ bj_quat_slerp()

bj_quat bj_quat_slerp ( bj_quat a,
bj_quat b,
bj_real t )
inlinestatic

Spherical linear interpolation between two orientations.

Interpolates along the shortest arc on S^3. If inputs are nearly parallel, falls back to normalized linear interpolation to avoid divide-by-zero.

Parameters
aStart quaternion.
bEnd quaternion.
tInterpolation factor in [0,1].
Returns
Interpolated quaternion.
Note
Inputs need not be normalized; the result is normalized.

◆ bj_quat_to_mat4()

void bj_quat_to_mat4 ( bj_mat4 *restrict M,
bj_quat q )
inlinestatic

Fill a 4×4 rotation matrix from a quaternion.

Parameters
[out]MDestination matrix (column-major).
[in]qInput quaternion. It is normalized internally.
Note
The resulting matrix has the last row and column set to form a proper rigid transform rotation block with bottom-right element equal to 1.

◆ 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()

bj_vec2 bj_vec2_add ( bj_vec2 lhs,
bj_vec2 rhs )
inlinestatic

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

Parameters
lhsLeft-hand input vector.
rhsRight-hand input vector.
Returns
Sum of lhs and rhs.

◆ bj_vec2_add_scaled()

bj_vec2 bj_vec2_add_scaled ( bj_vec2 lhs,
bj_vec2 rhs,
bj_real s )
inlinestatic

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

Parameters
lhsInput component or vector a.
rhsInput component or vector b.
sScalar factor.
Returns
Sum of lhs and rhs * s.

◆ bj_vec2_distance()

bj_real bj_vec2_distance ( 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_distance_sq()

bj_real bj_vec2_distance_sq ( bj_vec2 a,
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 ( bj_vec2 a,
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 ( bj_vec2 v)
inlinestatic

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

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec2_map()

bj_vec2 bj_vec2_map ( bj_vec2 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec2_max()

bj_vec2 bj_vec2_max ( bj_vec2 a,
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()

bj_vec2 bj_vec2_min ( bj_vec2 a,
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_mul_comp()

bj_vec2 bj_vec2_mul_comp ( const bj_vec2 v,
const bj_vec2 s )
inlinestatic

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

Parameters
vInput vector.
sScalar factor.
Returns
The result of v * s

◆ bj_vec2_normalize()

bj_vec2 bj_vec2_normalize ( bj_vec2 v)
inlinestatic

Normalize a 2D vector to unit length (safe).

Computes v / ||v||. If the squared length is zero according to bj_real_is_zero, returns the zero vector to avoid division by zero. Uses a single square root.

Parameters
vInput vector.
Returns
Unit-length copy of v, or {0,0} if ||v|| == 0 by bj_real_is_zero.
Warning
Zero-detection follows bj_real_is_zero semantics and tolerance.
See also
bj_vec2_normalize_unsafe, bj_real_is_zero

◆ bj_vec2_normalize_unsafe()

bj_vec2 bj_vec2_normalize_unsafe ( bj_vec2 v)
inlinestatic

Normalize a 2D vector to unit length (unsafe).

Computes v / ||v|| without any zero-length check. Faster on hot paths where nonzero length is guaranteed.

Parameters
vInput vector (must be nonzero).
Returns
Unit-length copy of v.
Precondition
||v|| > 0 (caller guarantees).
Warning
Undefined results if ||v|| == 0. Consider bj_vec2_normalize instead.
See also
bj_vec2_normalize

◆ bj_vec2_perp_dot()

bj_real bj_vec2_perp_dot ( bj_vec2 a,
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_scale()

bj_vec2 bj_vec2_scale ( bj_vec2 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
vInput vector.
sScalar factor.
Returns
The result of v * s

◆ bj_vec2_scale_to_len()

bj_vec2 bj_vec2_scale_to_len ( bj_vec2 v,
bj_real L )
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()

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

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

Parameters
lhsLeft-hand input vector.
rhsRight-hand input vector.
Returns
lhs - rhs

◆ bj_vec3_add()

bj_vec3 bj_vec3_add ( bj_vec3 lhs,
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()

bj_vec3 bj_vec3_add_scaled ( bj_vec3 lhs,
bj_vec3 rhs,
bj_real s )
inlinestatic

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

Parameters
lhsInput component or vector a.
rhsInput component or vector b.
sScalar factor.
Returns
Sum of lhs and rhs * s.

◆ bj_vec3_cross()

bj_vec3 bj_vec3_cross ( bj_vec3 l,
bj_vec3 r )
inlinestatic

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

Parameters
lLeft-hand input vector.
rRight-hand input vector.
Returns
Resulting cross product.

◆ bj_vec3_distance()

bj_real bj_vec3_distance ( bj_vec3 a,
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_distance_sq()

bj_real bj_vec3_distance_sq ( bj_vec3 a,
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 ( bj_vec3 a,
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 ( bj_vec3 v)
inlinestatic

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

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec3_map()

bj_vec3 bj_vec3_map ( bj_vec3 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec3_max()

bj_vec3 bj_vec3_max ( bj_vec3 a,
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()

bj_vec3 bj_vec3_min ( bj_vec3 a,
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()

bj_vec3 bj_vec3_normalize ( bj_vec3 v)
inlinestatic

Normalize a 3D vector to unit length (safe).

Computes v / ||v||. Returns {0,0,0} if ||v|| is zero by bj_real_is_zero. Uses one square root.

Parameters
vInput vector.
Returns
Unit-length copy of v, or {0,0,0} if ||v|| == 0 by bj_real_is_zero.
Warning
Zero-detection follows bj_real_is_zero semantics and tolerance.
See also
bj_vec3_normalize_unsafe, bj_real_is_zero

◆ bj_vec3_normalize_unsafe()

bj_vec3 bj_vec3_normalize_unsafe ( bj_vec3 v)
inlinestatic

Normalize a 3D vector to unit length (unsafe).

Computes v / ||v|| without any zero-length check.

Parameters
vInput vector (must be nonzero).
Returns
Unit-length copy of v.
Precondition
||v|| > 0 (caller guarantees).
Warning
Undefined results if ||v|| == 0. Consider bj_vec3_normalize instead.
See also
bj_vec3_normalize

◆ bj_vec3_reflect()

bj_vec3 bj_vec3_reflect ( bj_vec3 v,
bj_vec3 n )
inlinestatic

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

Parameters
vInput vector.
nSurface normal (expected normalized). \reutrn Resulting reflect vector.
Note
The normal n should be normalized for a true reflection.

◆ bj_vec3_scale()

bj_vec3 bj_vec3_scale ( bj_vec3 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
vInput vector.
sScalar factor.
Returns
The result of v * s

◆ bj_vec3_scale_to_len()

bj_vec3 bj_vec3_scale_to_len ( bj_vec3 v,
bj_real L )
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()

bj_vec3 bj_vec3_sub ( bj_vec3 lhs,
bj_vec3 rhs )
inlinestatic

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

Parameters
lhsLeft-hand input vector.
rhsRight-hand input vector.
Returns
lhs - rhs

◆ bj_vec4_add()

bj_vec4 bj_vec4_add ( bj_vec4 lhs,
bj_vec4 rhs )
inlinestatic

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

Parameters
lhsLeft-hand input vector.
rhsRight-hand input vector.
Returns
Result of lhs + rhs

◆ bj_vec4_add_scaled()

bj_vec4 bj_vec4_add_scaled ( bj_vec4 lhs,
bj_vec4 rhs,
bj_real s )
inlinestatic

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

Parameters
lhsInput component or vector a.
rhsInput component or vector b.
sScalar factor.
Returns
Sum of lhs and rhs * s.

◆ bj_vec4_cross_xyz()

bj_vec4 bj_vec4_cross_xyz ( bj_vec4 l,
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 ( bj_vec4 a,
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 ( bj_vec4 v)
inlinestatic

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

Parameters
vInput vector.
Returns
The Euclidean norm.

◆ bj_vec4_map()

bj_vec4 bj_vec4_map ( bj_vec4 a,
bj_real(* )(bj_real) )
inlinestatic

◆ bj_vec4_max()

bj_vec4 bj_vec4_max ( bj_vec4 a,
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()

bj_vec4 bj_vec4_min ( bj_vec4 a,
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()

bj_vec4 bj_vec4_normalize ( bj_vec4 v)
inlinestatic

Normalize a 4D vector to unit length (safe).

Computes v / ||v||. Returns {0,0,0,0} if ||v|| is zero by bj_real_is_zero. Uses one square root.

Parameters
vInput vector.
Returns
Unit-length copy of v, or {0,0,0,0} if ||v|| == 0 by bj_real_is_zero.
Warning
Zero-detection follows bj_real_is_zero semantics and tolerance.
See also
bj_vec4_normalize_unsafe, bj_real_is_zero

◆ bj_vec4_normalize_unsafe()

bj_vec4 bj_vec4_normalize_unsafe ( bj_vec4 v)
inlinestatic

Normalize a 4D vector to unit length (unsafe).

Computes v / ||v|| without any zero-length check.

Parameters
vInput vector (must be nonzero).
Returns
Unit-length copy of v.
Precondition
||v|| > 0 (caller guarantees).
Warning
Undefined results if ||v|| == 0. Consider bj_vec4_normalize instead.
See also
bj_vec4_normalize

◆ bj_vec4_reflect()

bj_vec4 bj_vec4_reflect ( bj_vec4 v,
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()

bj_vec4 bj_vec4_scale ( bj_vec4 v,
bj_real s )
inlinestatic

Uniform scaling by scalar: res = v * s.

Parameters
vInput vector.
sScalar factor.
Returns
The result of v * s

◆ bj_vec4_sub()

bj_vec4 bj_vec4_sub ( bj_vec4 lhs,
bj_vec4 rhs )
inlinestatic

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

Parameters
lhsLeft-hand input vector.
rhsRight-hand input vector.
Returns
lhs - rhs