include/vecmat.h file

Classes

struct vector2
2-D floating-point vector (x, y).
struct vector3
3-D floating-point vector (x, y, z).
struct vector4
4-D floating-point vector (x, y, z, w).
struct vector2i
2-D integer vector (x, y).
struct vector3i
3-D integer vector (x, y, z).
struct vector4i
4-D integer vector (x, y, z, w).
struct matrix2
2x2 column-major floating-point matrix.
struct matrix3
3x3 column-major floating-point matrix.
struct matrix4
4x4 column-major floating-point matrix.
struct matrix2i
2x2 column-major integer matrix.
struct matrix3i
3x3 column-major integer matrix.
struct matrix4i
4x4 column-major integer matrix.
struct quaternion
Rotation quaternion (vector part x,y,z, scalar part w).
struct vm_mat
Heap dense matrix used by LU / QR / SVD / Cholesky / det / inverse.
struct vm_spmat
Heap sparse matrix in compressed sparse row (CSR) form.
struct vm_ksp_info
Iteration stats from vm_cg / vm_bicgstab.
struct vm_grid3
Uniform Cartesian grid.

Enums

enum vm_clip_t { VM_CLIP_RH_NO = 0, VM_CLIP_RH_ZO, VM_CLIP_LH_ZO, VM_CLIP_LH_NO }
Clip-space handedness and depth range for projection / look-at matrices.
enum vm_layout_t { VM_LAYOUT_COL_MAJOR = 0, VM_LAYOUT_ROW_MAJOR = 1 }
Memory layout for dense panels passed to vm_gemm and vm_mat.
enum (anonymous) { VM_GEMM_OP_NONE = 0, VM_GEMM_OP_BIAS = 1, VM_GEMM_OP_RELU = 2, VM_GEMM_OP_BIAS_RELU = 3 }
Optional GEMM epilogue.
enum vm_ksp_prec_t { VM_KSP_PREC_NONE = 0, VM_KSP_PREC_JACOBI = 1, VM_KSP_PREC_SSOR = 2, VM_KSP_PREC_IC0 = 3 }
Left preconditioner for the Krylov solvers.
enum vm_bc_t { VM_BC_DIRICHLET = 0, VM_BC_NEUMANN = 1 }
Boundary condition for assembled grid operators.
enum (anonymous) { VM_CPU_SCALAR = 1u << 0, VM_CPU_AVX2 = 1u << 1, VM_CPU_SVE = 1u << 2, VM_CPU_AVX512 = 1u << 3, VM_CPU_SVE2 = 1u << 4, VM_CPU_AVX = 1u << 5 }

Typedefs

using vm_float_t = double
using vm_int_t = int8_t
using vm_ode_fn = void(*)(const vm_float_t*y, vm_float_t*ydot, void*ctx)
First-order ODE right-hand side ydot = f(y).
using vm_acc_fn = void(*)(const vm_float_t*x, vm_float_t*a, void*ctx)
Acceleration callback a = acc(x) for velocity Verlet.
using vm_cpu_features_t = uint32_t
Bit mask of compiled or detected CPU ISA features.

Functions

auto vm_cpu_compiled_features(void) -> vm_cpu_features_t
ISA bits compiled into this binary.
auto vm_cpu_runtime_features(void) -> vm_cpu_features_t
ISA bits detected on this CPU (cached).
auto vm_cpu_selected_features(void) -> vm_cpu_features_t
Highest-priority ISA that is both compiled and present.
auto vm_cpu_name(vm_cpu_features_t features) -> const char*
Short name of the highest bit set in features.
void vm_cpu_init(void)
One-time runtime dispatch bind (thread-safe).
auto vec2_add(vector2 a, vector2 b) -> vector2
Adds two vectors component-wise.
auto vec2_sub(vector2 a, vector2 b) -> vector2
Subtracts the second vector from the first component-wise.
auto vec2_mul_scalar(vector2 v, vm_float_t s) -> vector2
Multiplies a vector by a scalar component-wise.
auto vec2_div_scalar(vector2 v, vm_float_t s) -> vector2
Divides a vector by a scalar component-wise.
auto vec2_mul(vector2 a, vector2 b) -> vector2
Multiplies two vectors component-wise (Hadamard product).
auto vec2_neg(vector2 v) -> vector2
Negates the vector (multiplies each component by -1.0f).
auto vec2_abs(vector2 v) -> vector2
Returns the absolute values of each component.
auto vec2_zero(void) -> vector2
Returns a vector2 with both components set to 0.0f.
auto vec2_one(void) -> vector2
Returns a vector2 with both components set to 1.0f.
auto vec2_x_axis(vm_float_t x) -> vector2
Returns a vector2 along the x-axis (y = 0.0f).
auto vec2_y_axis(vm_float_t y) -> vector2
Returns a vector2 along the y-axis (x = 0.0f).
auto vec2_x_scale(vm_float_t x) -> vector2
Returns a vector2 representing x-axis scaling (y = 1.0f).
auto vec2_y_scale(vm_float_t y) -> vector2
Returns a vector2 representing y-axis scaling (x = 1.0f).
auto vec2_scale(vector2 v, vm_float_t s) -> vector2
Scales a vector by a scalar component-wise.
auto vec2_cross(vector2 a, vector2 b) -> vector2
Computes the 2D cross-product as a vector.
auto vec2_normalize(vector2 v) -> vector2
Normalizes the vector to unit length.
auto vec2_min(vector2 a, vector2 b) -> vector2
Returns the component-wise minimum of two vectors.
auto vec2_max(vector2 a, vector2 b) -> vector2
Returns the component-wise maximum of two vectors.
auto vec2_sign(vector2 v) -> vector2
Returns the sign of each component (+1.0f, -1.0f, or 0.0f).
auto vec2_floor(vector2 v) -> vector2
Applies floor to each component.
auto vec2_ceil(vector2 v) -> vector2
Applies ceil to each component.
auto vec2_round(vector2 v) -> vector2
Applies round to each component.
auto vec2_perpendicular(vector2 v) -> vector2
Returns the perpendicular vector (90 degrees counterclockwise).
auto vec2_reflect(vector2 v, vector2 normal) -> vector2
Reflects vector v across the normal, storing the result in res.
auto vec2_project(vector2 a, vector2 b) -> vector2
Projects the first vector onto the second.
auto vec2_tangent(vector2 v) -> vector2
Returns the tangent vector perpendicular to the input (90 degrees clockwise).
auto vec2_rotate(vector2 v, vm_float_t radians) -> vector2
Rotates the input vector counterclockwise by the given angle (radians).
auto vec2_rotate_deg(vector2 v, vm_float_t degrees) -> vector2
Rotates a vector2 by the given angle in degrees.
auto vec2_slide(vector2 v, vector2 normal) -> vector2
Slides the input vector tangent to the normal (removes normal component).
auto vec2_clamp(vector2 v, vector2 min, vector2 max) -> vector2
Clamps vector v component-wise between min and max.
auto vec2_lerp(vector2 a, vector2 b, vm_float_t t) -> vector2
Linearly interpolates from a to b by t.
auto vec2_div(vector2 a, vector2 b) -> vector2
Divides two vectors component-wise.
auto vec2_add_scalar(vector2 v, vm_float_t s) -> vector2
Adds a scalar to each component.
auto vec2_sub_scalar(vector2 v, vm_float_t s) -> vector2
Subtracts a scalar from each component.
auto vec2_clamp_scalar(vector2 v, vm_float_t min, vm_float_t max) -> vector2
Clamps each component to the scalar range [min, max].
auto vec2_saturate(vector2 v) -> vector2
Clamps each component to the range [0, 1].
auto vec2_fract(vector2 v) -> vector2
Returns the fractional part of each component.
auto vec2_refract(vector2 incident, vector2 normal, vm_float_t eta) -> vector2
Computes the refraction of incident across normal with ratio eta.
auto vec2_reject(vector2 a, vector2 b) -> vector2
Returns the component of a orthogonal to b.
auto vec2_splat(vm_float_t s) -> vector2
Returns a vector with every component set to s.
auto vec2_from_angle(vm_float_t radians) -> vector2
Returns the unit vector at the given angle in radians.
auto vec2_from_angle_deg(vm_float_t degrees) -> vector2
Creates a vector2 from an angle given in degrees.
auto vec2_rotate_around(vector2 v, vector2 pivot, vm_float_t radians) -> vector2
Rotates v around pivot by angle radians.
auto vec2_rotate_around_deg(vector2 v, vector2 pivot, vm_float_t degrees) -> vector2
Rotates a vector2 around a pivot point by the given angle in degrees.
auto vec2_move_toward(vector2 current, vector2 target, vm_float_t max_delta) -> vector2
Moves current toward target by at most max_delta.
auto vec2_limit_length(vector2 v, vm_float_t max_len) -> vector2
Clamps the vector length to max_len.
auto vec2_to_vec3(vector2 v, vm_float_t z) -> vector3
Converts a vector2 to a vector3 using z.
auto vec2_dot(vector2 a, vector2 b) -> vm_float_t
Computes the dot product of two vectors.
auto vec2_length(vector2 v) -> vm_float_t
Computes the length (magnitude) of the vector.
auto vec2_length_squared(vector2 v) -> vm_float_t
Returns the squared Euclidean length.
auto vec2_length_manhattan(vector2 v) -> vm_float_t
Returns the Manhattan (L1) length.
auto vec2_length_chebyshev(vector2 v) -> vm_float_t
Returns the Chebyshev (L-inf) length.
auto vec2_aspect_ratio(vector2 v) -> vm_float_t
Computes the aspect ratio of the vector (x / y).
auto vec2_distance(vector2 a, vector2 b) -> vm_float_t
Computes the Euclidean distance between two vectors (treated as points).
auto vec2_distance_squared(vector2 a, vector2 b) -> vm_float_t
Returns the squared Euclidean distance between a and b.
auto vec2_angle(vector2 a, vector2 b) -> vm_float_t
Computes the angle between two vectors (in radians, range [0, PI]).
auto vec2_cross_scalar(vector2 a, vector2 b) -> vm_float_t
Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).
auto vec2_heading(vector2 v) -> vm_float_t
Returns the heading angle of the vector in radians.
auto vec2_heading_deg(vector2 v) -> vm_float_t
Returns the heading angle of the vector in degrees.
auto vec2_min_component(vector2 v) -> vm_float_t
Returns the smallest component.
auto vec2_max_component(vector2 v) -> vm_float_t
Returns the largest component.
auto vec2_sum(vector2 v) -> vm_float_t
Returns the sum of all components.
auto vec2_is_zero(vector2 v) -> bool
Returns true if every component is zero.
auto vec2_is_normalized(vector2 v) -> bool
Returns true if the vector has unit length.
auto vec2_near(vector2 a, vector2 b, vm_float_t eps) -> bool
Returns true if a and b are within eps of each other.
auto vec3_add(vector3 a, vector3 b) -> vector3
Component-wise addition of two vectors.
auto vec3_sub(vector3 a, vector3 b) -> vector3
Component-wise subtraction of two vectors.
auto vec3_mul_scalar(vector3 v, vm_float_t s) -> vector3
Component-wise multiplication of vector by scalar.
auto vec3_div_scalar(vector3 v, vm_float_t s) -> vector3
Component-wise division of vector by scalar.
auto vec3_mul(vector3 a, vector3 b) -> vector3
Component-wise multiplication of two vectors.
auto vec3_neg(vector3 v) -> vector3
Negation of a vector.
auto vec3_abs(vector3 v) -> vector3
Computes the absolute value per component of a vector3.
auto vec3_zero(void) -> vector3
Returns a zero-initialized vector3.
auto vec3_one(void) -> vector3
Returns a vector3 with all components set to 1.0f.
auto vec3_x_axis(vm_float_t x) -> vector3
Returns a vector3 along the x-axis.
auto vec3_y_axis(vm_float_t y) -> vector3
Returns a vector3 along the y-axis.
auto vec3_z_axis(vm_float_t z) -> vector3
Returns a vector3 along the z-axis.
auto vec3_x_scale(vm_float_t x) -> vector3
Returns a vector3 for scaling along the x-axis.
auto vec3_y_scale(vm_float_t y) -> vector3
Returns a vector3 for scaling along the y-axis.
auto vec3_z_scale(vm_float_t z) -> vector3
Returns a vector3 for scaling along the z-axis.
auto vec3_cross(vector3 a, vector3 b) -> vector3
Computes the cross-product of two vector3.
auto vec3_normalize(vector3 v) -> vector3
Normalizes a vector3 to unit length.
auto vec3_min(vector3 a, vector3 b) -> vector3
Computes the component-wise minimum of two vector3.
auto vec3_max(vector3 a, vector3 b) -> vector3
Computes the component-wise maximum of two vector3.
auto vec3_sign(vector3 v) -> vector3
Computes the sign per component of a vector3 (-1, 0, or 1).
auto vec3_floor(vector3 v) -> vector3
Applies the floor per component to a vector3.
auto vec3_ceil(vector3 v) -> vector3
Applies ceil per component to a vector3.
auto vec3_round(vector3 v) -> vector3
Applies round per component to a vector3.
auto vec3_reflect(vector3 incident, vector3 normal) -> vector3
Reflects an incident vector over normal.
auto vec3_refract(vector3 incident, vector3 normal, vm_float_t eta) -> vector3
Refracts an incident vector across an interface with a given normal and ratio of refraction eta.
auto vec3_lerp(vector3 a, vector3 b, vm_float_t t) -> vector3
Linearly interpolates between two vector3.
auto vec3_clamp(vector3 v, vector3 min, vector3 max) -> vector3
Clamps a vector3 between min and max per component.
auto vec3_scale(vector3 v, vm_float_t s) -> vector3
Scales the vector by a scalar.
auto vec3_div(vector3 a, vector3 b) -> vector3
Divides two vectors component-wise.
auto vec3_add_scalar(vector3 v, vm_float_t s) -> vector3
Adds a scalar to each component.
auto vec3_sub_scalar(vector3 v, vm_float_t s) -> vector3
Subtracts a scalar from each component.
auto vec3_clamp_scalar(vector3 v, vm_float_t min, vm_float_t max) -> vector3
Clamps each component to the scalar range [min, max].
auto vec3_saturate(vector3 v) -> vector3
Clamps each component to the range [0, 1].
auto vec3_fract(vector3 v) -> vector3
Returns the fractional part of each component.
auto vec3_project(vector3 a, vector3 b) -> vector3
Projects a onto b.
auto vec3_slide(vector3 v, vector3 normal) -> vector3
Removes the component of v along normal.
auto vec3_reject(vector3 a, vector3 b) -> vector3
Returns the component of a orthogonal to b.
auto vec3_rotate_axis(vector3 v, vector3 axis, vm_float_t radians) -> vector3
Rotates v around axis by angle radians.
auto vec3_rotate_axis_deg(vector3 v, vector3 axis, vm_float_t degrees) -> vector3
Rotates a vector around an arbitrary axis by a given angle in degrees.
auto vec3_splat(vm_float_t s) -> vector3
Returns a vector with every component set to s.
auto vec3_from_vec2(vector2 v, vm_float_t z) -> vector3
Builds a vector3 from a vector2 and z.
auto vec3_move_toward(vector3 current, vector3 target, vm_float_t max_delta) -> vector3
Moves current toward target by at most max_delta.
auto vec3_limit_length(vector3 v, vm_float_t max_len) -> vector3
Clamps the vector length to max_len.
auto vec3_xy(vector3 v) -> vector2
Returns the x and y components as a 2D vector.
void vec3_orthonormal_basis(vector3 n, vector3* t, vector3* b)
Builds a tangent and bitangent orthonormal to n.
auto vec3_dot(vector3 a, vector3 b) -> vm_float_t
Computes the dot product of two vector3.
auto vec3_length(vector3 v) -> vm_float_t
Computes the length (magnitude) of a vector3.
auto vec3_length_squared(vector3 v) -> vm_float_t
Returns the squared Euclidean length.
auto vec3_length_manhattan(vector3 v) -> vm_float_t
Returns the Manhattan (L1) length.
auto vec3_length_chebyshev(vector3 v) -> vm_float_t
Returns the Chebyshev (L-inf) length.
auto vec3_distance(vector3 a, vector3 b) -> vm_float_t
Computes the Euclidean distance between two vector3.
auto vec3_distance_squared(vector3 a, vector3 b) -> vm_float_t
Returns the squared Euclidean distance between a and b.
auto vec3_angle(vector3 a, vector3 b) -> vm_float_t
Computes the angle between two non-zero vector3 in radians.
auto vec3_signed_angle(vector3 a, vector3 b, vector3 axis) -> vm_float_t
Returns the signed angle from a to b around axis.
auto vec3_min_component(vector3 v) -> vm_float_t
Returns the smallest component.
auto vec3_max_component(vector3 v) -> vm_float_t
Returns the largest component.
auto vec3_sum(vector3 v) -> vm_float_t
Returns the sum of all components.
auto vec3_is_zero(vector3 v) -> bool
Returns true if every component is zero.
auto vec3_is_normalized(vector3 v) -> bool
Returns true if the vector has unit length.
auto vec3_near(vector3 a, vector3 b, vm_float_t eps) -> bool
Returns true if a and b are within eps of each other.
auto vec4_add(vector4 a, vector4 b) -> vector4
Component-wise addition of two vectors.
auto vec4_sub(vector4 a, vector4 b) -> vector4
Component-wise subtraction of two vectors.
auto vec4_mul_scalar(vector4 v, vm_float_t s) -> vector4
Component-wise multiplication of vector by scalar.
auto vec4_div_scalar(vector4 v, vm_float_t s) -> vector4
Component-wise division of vector by scalar.
auto vec4_mul(vector4 a, vector4 b) -> vector4
Component-wise multiplication of two vectors.
auto vec4_neg(vector4 v) -> vector4
Negation of a vector.
auto vec4_abs(vector4 v) -> vector4
Computes the absolute value per component of a vector4.
auto vec4_zero(void) -> vector4
Returns a zero-initialized vector4.
auto vec4_one(void) -> vector4
Returns a vector4 with all components set to 1.0f.
auto vec4_x_axis(vm_float_t x) -> vector4
Returns a vector4 along the x-axis.
auto vec4_y_axis(vm_float_t y) -> vector4
Returns a vector4 along the y-axis.
auto vec4_z_axis(vm_float_t z) -> vector4
Returns a vector4 along the z-axis.
auto vec4_w_axis(vm_float_t w) -> vector4
Returns a vector4 along the w-axis.
auto vec4_x_scale(vm_float_t x) -> vector4
Returns avector4 for scaling along the x-axis.
auto vec4_y_scale(vm_float_t y) -> vector4
Returns a vector4 for scaling along the y-axis.
auto vec4_z_scale(vm_float_t z) -> vector4
Returns a vector4for scaling along the z-axis.
auto vec4_w_scale(vm_float_t w) -> vector4
Returns a vector4 for scaling along the w-axis.
auto vec4_normalize(vector4 v) -> vector4
Normalizes a vector4 to unit length.
auto vec4_min(vector4 a, vector4 b) -> vector4
Computes the component-wise minimum of two vector4.
auto vec4_max(vector4 a, vector4 b) -> vector4
Computes the component-wise maximum of two vector4.
auto vec4_sign(vector4 v) -> vector4
Computes the sign per component of a vector4 (-1, 0, or 1).
auto vec4_floor(vector4 v) -> vector4
Applies the floor per component to a vector4.
auto vec4_ceil(vector4 v) -> vector4
Applies ceil per component to a vector4.
auto vec4_round(vector4 v) -> vector4
Applies round per component to a vector4.
auto vec4_lerp(vector4 a, vector4 b, vm_float_t t) -> vector4
Linearly interpolates between two vector4.
auto vec4_clamp(vector4 v, vector4 min, vector4 max) -> vector4
Clamps a vector4 between min and max per component.
auto vec4_homogenize(vector4 v) -> vector4
Homogenizes a vector4 (divides x, y, z by w).
auto vec4_div(vector4 a, vector4 b) -> vector4
Divides two vectors component-wise.
auto vec4_add_scalar(vector4 v, vm_float_t s) -> vector4
Adds a scalar to each component.
auto vec4_sub_scalar(vector4 v, vm_float_t s) -> vector4
Subtracts a scalar from each component.
auto vec4_clamp_scalar(vector4 v, vm_float_t min, vm_float_t max) -> vector4
Clamps each component to the scalar range [min, max].
auto vec4_saturate(vector4 v) -> vector4
Clamps each component to the range [0, 1].
auto vec4_fract(vector4 v) -> vector4
Returns the fractional part of each component.
auto vec4_project(vector4 a, vector4 b) -> vector4
Projects a onto b.
auto vec4_reject(vector4 a, vector4 b) -> vector4
Returns the component of a orthogonal to b.
auto vec4_slide(vector4 v, vector4 normal) -> vector4
Removes the component of v along normal.
auto vec4_splat(vm_float_t s) -> vector4
Returns a vector with every component set to s.
auto vec4_to_vec3(vector4 v) -> vector3
Converts a vector4 to a vector3 (discards the w component).
auto vec4_dot(vector4 a, vector4 b) -> vm_float_t
Computes the dot product of two vector4.
auto vec4_length(vector4 v) -> vm_float_t
Computes the length (magnitude) of a vector4.
auto vec4_length_squared(vector4 v) -> vm_float_t
Returns the squared Euclidean length.
auto vec4_distance(vector4 a, vector4 b) -> vm_float_t
Computes the Euclidean distance between two vector4.
auto vec4_distance_squared(vector4 a, vector4 b) -> vm_float_t
Returns the squared Euclidean distance between a and b.
auto vec4_is_zero(vector4 v) -> bool
Returns true if every component is zero.
auto vec4_is_normalized(vector4 v) -> bool
Returns true if the vector has unit length.
auto vec4_near(vector4 a, vector4 b, vm_float_t eps) -> bool
Returns true if a and b are within eps of each other.
void vec2_add_ptr(vector2* res, const vector2* a, const vector2* b)
Adds vectors a and b component-wise, storing the result in res.
void vec2_sub_ptr(vector2* res, const vector2* a, const vector2* b)
Subtracts vector b from vector a component-wise, storing the result in res.
void vec2_mul_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)
Multiplies vector v by scalar s component-wise, storing the result in res.
void vec2_div_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)
Divides vector v by scalar s component-wise, storing the result in res.
void vec2_mul_ptr(vector2* res, const vector2* a, const vector2* b)
Multiplies vectors a and b component-wise, storing the result in res.
void vec2_neg_ptr(vector2* res, const vector2* v)
Negates the components of vector v, storing the result in res.
void vec2_abs_ptr(vector2* res, const vector2* v)
Computes the absolute values of the components of vector v, storing the result in res.
void vec2_normalize_ptr(vector2* res, const vector2* v)
Normalizes vector v to unit length, storing the result in res.
void vec2_min_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the component-wise minimum of vectors a and b, storing the result in res.
void vec2_max_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the component-wise maximum of vectors a and b, storing the result in res.
void vec2_sign_ptr(vector2* res, const vector2* v)
Sets each component of res to the sign of the corresponding component in v (+1, -1).
void vec2_floor_ptr(vector2* res, const vector2* v)
Applies the floor function to each component of vector v, storing the result in res.
void vec2_ceil_ptr(vector2* res, const vector2* v)
Applies the ceil function to each component of vector v, storing the result in res.
void vec2_round_ptr(vector2* res, const vector2* v)
Applies the round function to each component of vector v, storing the result in res.
void vec2_perpendicular_ptr(vector2* res, const vector2* v)
Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.
void vec2_scale_ptr(vector2* res, const vector2* v, vm_float_t s)
Scales a vector by a scalar component-wise, storing the result in res.
void vec2_cross_ptr(vector2* res, const vector2* a, const vector2* b)
Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.
void vec2_reflect_ptr(vector2* res, const vector2* v, const vector2* normal)
Reflects vector v across the normal, storing the result in res.
void vec2_project_ptr(vector2* res, const vector2* a, const vector2* b)
Projects vector a onto vector b (scalar projection scaled by b).
void vec2_tangent_ptr(vector2* res, const vector2* v)
Computes a tangent vector perpendicular to the input (90 degrees clockwise).
void vec2_rotate_ptr(vector2* result, const vector2* v, vm_float_t radians)
Rotates the input vector counterclockwise by the given angle (radians).
void vec2_rotate_deg_ptr(vector2* result, const vector2* v, vm_float_t degrees)
Rotates vector v by the given angle in degrees, storing the result in result.
void vec2_slide_ptr(vector2* result, const vector2* v, const vector2* normal)
Slides the input vector tangent to the normal (removes normal component).
void vec2_clamp_ptr(vector2* res, const vector2* v, const vector2* min, const vector2* max)
Clamps vector v component-wise between min and max.
void vec2_lerp_ptr(vector2* res, const vector2* a, const vector2* b, vm_float_t t)
Linearly interpolates from a to b by t.
void vec2_div_ptr(vector2* res, const vector2* a, const vector2* b)
Divides two vectors component-wise.
void vec2_add_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)
Adds a scalar to each component.
void vec2_sub_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)
Subtracts a scalar from each component.
void vec2_clamp_scalar_ptr(vector2* res, const vector2* v, vm_float_t min, vm_float_t max)
Clamps each component to the scalar range [min, max].
void vec2_saturate_ptr(vector2* res, const vector2* v)
Clamps each component to the range [0, 1].
void vec2_fract_ptr(vector2* res, const vector2* v)
Returns the fractional part of each component.
void vec2_refract_ptr(vector2* res, const vector2* incident, const vector2* normal, vm_float_t eta)
Computes the refraction of incident across normal with ratio eta.
void vec2_reject_ptr(vector2* res, const vector2* a, const vector2* b)
Returns the component of a orthogonal to b.
void vec2_rotate_around_ptr(vector2* res, const vector2* v, const vector2* pivot, vm_float_t radians)
Rotates v around pivot by angle radians.
void vec2_rotate_around_deg_ptr(vector2* res, const vector2* v, const vector2* pivot, vm_float_t degrees)
Rotates vector v around the given pivot point by the specified angle in degrees.
void vec2_move_toward_ptr(vector2* res, const vector2* current, const vector2* target, vm_float_t max_delta)
Moves current toward target by at most max_delta.
void vec2_limit_length_ptr(vector2* res, const vector2* v, vm_float_t max_len)
Clamps the vector length to max_len.
void vec2_to_vec3_ptr(vector3* res, const vector2* v, vm_float_t z)
Converts a vector2 to a vector3 with the given z.
void vec3_add_ptr(vector3* res, const vector3* a, const vector3* b)
Component-wise addition of two vectors.
void vec3_sub_ptr(vector3* res, const vector3* a, const vector3* b)
Component-wise subtraction of two vectors.
void vec3_mul_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)
Component-wise multiplication of vector by scalar.
void vec3_div_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)
Component-wise division of vector by scalar.
void vec3_mul_ptr(vector3* res, const vector3* a, const vector3* b)
Component-wise multiplication of two vectors.
void vec3_neg_ptr(vector3* res, const vector3* v)
Negation of a vector.
void vec3_abs_ptr(vector3* res, const vector3* v)
Computes the absolute value per component of a vector3.
void vec3_normalize_ptr(vector3* res, const vector3* v)
Normalize a vector to unit length.
void vec3_cross_ptr(vector3* res, const vector3* a, const vector3* b)
Compute cross-product of two vectors.
void vec3_min_ptr(vector3* res, const vector3* a, const vector3* b)
Component-wise minimum of two vectors.
void vec3_max_ptr(vector3* res, const vector3* a, const vector3* b)
Component-wise maximum of two vectors.
void vec3_sign_ptr(vector3* res, const vector3* v)
Component-wise sign of a vector.
void vec3_floor_ptr(vector3* res, const vector3* v)
Component-wise floor of a vector.
void vec3_ceil_ptr(vector3* res, const vector3* v)
Component-wise ceil of a vector.
void vec3_round_ptr(vector3* res, const vector3* v)
Component-wise round of a vector.
void vec3_reflect_ptr(vector3* res, const vector3* incident, const vector3* normal)
Compute reflection of the incident vector over normal.
void vec3_refract_ptr(vector3* res, const vector3* incident, const vector3* normal, vm_float_t eta)
Compute refraction of the incident vector through normal with eta.
void vec3_lerp_ptr(vector3* res, const vector3* a, const vector3* b, vm_float_t t)
Linear interpolation between two vectors.
void vec3_clamp_ptr(vector3* res, const vector3* v, const vector3* min, const vector3* max)
Clamp vector components between min and max.
void vec3_scale_ptr(vector3* res, const vector3* v, vm_float_t s)
Scales the vector by a scalar.
void vec3_div_ptr(vector3* res, const vector3* a, const vector3* b)
Divides two vectors component-wise.
void vec3_add_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)
Adds a scalar to each component.
void vec3_sub_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)
Subtracts a scalar from each component.
void vec3_clamp_scalar_ptr(vector3* res, const vector3* v, vm_float_t min, vm_float_t max)
Clamps each component to the scalar range [min, max].
void vec3_saturate_ptr(vector3* res, const vector3* v)
Clamps each component to the range [0, 1].
void vec3_fract_ptr(vector3* res, const vector3* v)
Returns the fractional part of each component.
void vec3_project_ptr(vector3* res, const vector3* a, const vector3* b)
Projects a onto b.
void vec3_slide_ptr(vector3* res, const vector3* v, const vector3* normal)
Removes the component of v along normal.
void vec3_reject_ptr(vector3* res, const vector3* a, const vector3* b)
Returns the component of a orthogonal to b.
void vec3_rotate_axis_ptr(vector3* res, const vector3* v, const vector3* axis, vm_float_t radians)
Rotates v around axis by angle radians.
void vec3_rotate_axis_deg_ptr(vector3* res, const vector3* v, const vector3* axis, vm_float_t degrees)
Component-wise rotation of a vector around an axis by a given angle in degrees.
void vec3_from_vec2_ptr(vector3* res, const vector2* v, vm_float_t z)
Builds a higher-dimension vector from a vector2.
void vec3_xy_ptr(vector2* res, const vector3* v)
Returns the x and y components as a 2D vector.
void vec3_move_toward_ptr(vector3* res, const vector3* current, const vector3* target, vm_float_t max_delta)
Moves current toward target by at most max_delta.
void vec3_limit_length_ptr(vector3* res, const vector3* v, vm_float_t max_len)
Clamps the vector length to max_len.
void vec3_orthonormal_basis_ptr(const vector3* n, vector3* t, vector3* b)
Builds a tangent and bitangent orthonormal to n.
void vec4_add_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise addition (dispatched).
void vec4_sub_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise subtraction (dispatched).
void vec4_mul_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)
Multiplies a vector by a scalar (dispatched).
void vec4_div_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)
Divides a vector by a scalar (dispatched).
void vec4_mul_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise multiplication (dispatched).
void vec4_neg_ptr(vector4* res, const vector4* v)
Negates a vector (dispatched).
void vec4_abs_ptr(vector4* res, const vector4* v)
Component-wise absolute value (dispatched).
void vec4_normalize_ptr(vector4* res, const vector4* v)
Normalizes a vector (dispatched).
void vec4_min_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise minimum (dispatched).
void vec4_max_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise maximum (dispatched).
void vec4_sign_ptr(vector4* res, const vector4* v)
Component-wise sign (dispatched).
void vec4_floor_ptr(vector4* res, const vector4* v)
Component-wise floor (dispatched).
void vec4_ceil_ptr(vector4* res, const vector4* v)
Component-wise ceil (dispatched).
void vec4_round_ptr(vector4* res, const vector4* v)
Component-wise round (dispatched).
void vec4_lerp_ptr(vector4* res, const vector4* a, const vector4* b, vm_float_t t)
Linear interpolation (dispatched).
void vec4_clamp_ptr(vector4* res, const vector4* v, const vector4* min, const vector4* max)
Component-wise clamp (dispatched).
void vec4_homogenize_ptr(vector4* res, const vector4* v)
Divides xyz by w (dispatched).
void vec4_div_ptr(vector4* res, const vector4* a, const vector4* b)
Component-wise division (dispatched).
void vec4_add_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)
Adds a scalar to each component (dispatched).
void vec4_sub_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)
Subtracts a scalar from each component (dispatched).
void vec4_clamp_scalar_ptr(vector4* res, const vector4* v, vm_float_t min, vm_float_t max)
Clamps each component to a scalar range (dispatched).
void vec4_saturate_ptr(vector4* res, const vector4* v)
Clamps each component to [0, 1] (dispatched).
void vec4_fract_ptr(vector4* res, const vector4* v)
Component-wise fractional part (dispatched).
void vec4_project_ptr(vector4* res, const vector4* a, const vector4* b)
Projects a onto b.
void vec4_reject_ptr(vector4* res, const vector4* a, const vector4* b)
Returns the component of a orthogonal to b.
void vec4_slide_ptr(vector4* res, const vector4* v, const vector4* normal)
Removes the component of v along normal.
void vec4_to_vec3_ptr(vector3* res, const vector4* v)
Copies the x, y, z components from a vector4 to a vector3.
auto vec2i_add(vector2i a, vector2i b) -> vector2i
Adds two vectors component-wise.
auto vec2i_sub(vector2i a, vector2i b) -> vector2i
Subtracts the second vector from the first component-wise.
auto vec2i_mul_scalar(vector2i v, vm_int_t s) -> vector2i
Multiplies a vector by a scalar component-wise.
auto vec2i_div_scalar(vector2i v, vm_int_t s) -> vector2i
Divides a vector by a scalar component-wise (float division, truncated to int).
auto vec2i_mul(vector2i a, vector2i b) -> vector2i
Multiplies two vectors component-wise (Hadamard product).
auto vec2i_neg(vector2i v) -> vector2i
Negates the vector (multiplies each component by -1).
auto vec2i_abs(vector2i v) -> vector2i
Returns the absolute values of each component.
auto vec2i_zero(void) -> vector2i
Returns a vector2i with both components set to 0.
auto vec2i_one(void) -> vector2i
Returns a vector2i with both components set to 1.
auto vec2i_x_axis(vm_int_t x) -> vector2i
Returns a vector2i along the x-axis (y = 0).
auto vec2i_y_axis(vm_int_t y) -> vector2i
Returns a vector2i along the y-axis (x = 0).
auto vec2i_x_scale(vm_int_t x) -> vector2i
Returns a vector2i representing x-axis scaling (y = 1).
auto vec2i_y_scale(vm_int_t y) -> vector2i
Returns a vector2i representing y-axis scaling (x = 1).
auto vec2i_cross(vector2i a, vector2i b) -> vector2i
Computes the 2D cross-product as a vector.
auto vec2i_normalize(vector2i v) -> vector2i
Normalizes the vector to approximate unit length (float length, truncated to int).
auto vec2i_min(vector2i a, vector2i b) -> vector2i
Returns the component-wise minimum of two vectors.
auto vec2i_max(vector2i a, vector2i b) -> vector2i
Returns the component-wise maximum of two vectors.
auto vec2i_sign(vector2i v) -> vector2i
Returns the sign of each component (+1, -1, or 0).
auto vec2i_perpendicular(vector2i v) -> vector2i
Returns the perpendicular vector (90 degrees counterclockwise).
auto vec2i_lerp(vector2i a, vector2i b, vm_float_t t) -> vector2i
Linearly interpolates from a to b by t.
auto vec2i_clamp(vector2i v, vector2i min, vector2i max) -> vector2i
Clamps each component between min and max.
auto vec2i_div(vector2i a, vector2i b) -> vector2i
Divides two vectors component-wise.
auto vec2i_add_scalar(vector2i v, vm_int_t s) -> vector2i
Adds a scalar to each component.
auto vec2i_sub_scalar(vector2i v, vm_int_t s) -> vector2i
Subtracts a scalar from each component.
auto vec2i_mod(vector2i a, vector2i b) -> vector2i
Component-wise floor modulo of a by b.
auto vec2i_div_floor(vector2i a, vector2i b) -> vector2i
Component-wise floored division of a by b.
auto vec2i_wrap(vector2i v, vector2i period) -> vector2i
Wraps each component of v into [0, period).
auto vec2i_splat(vm_int_t s) -> vector2i
Returns a vector with every component set to s.
auto vec2i_to_vec3i(vector2i v, vm_int_t z) -> vector3i
Converts a vector2i to a vector3i using z.
auto vec2i_normalize_to_vec2(vector2i v) -> vector2
Converts to a unit-length vector2.
auto vec2i_dot(vector2i a, vector2i b) -> vm_int_t
Computes the dot product of two vectors.
auto vec2i_cross_scalar(vector2i a, vector2i b) -> vm_int_t
Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).
auto vec2i_length_squared(vector2i v) -> vm_int_t
Returns the squared Euclidean length.
auto vec2i_distance_squared(vector2i a, vector2i b) -> vm_int_t
Returns the squared Euclidean distance between a and b.
auto vec2i_length_manhattan(vector2i v) -> vm_int_t
Returns the Manhattan (L1) length.
auto vec2i_length_chebyshev(vector2i v) -> vm_int_t
Returns the Chebyshev (L-inf) length.
auto vec2i_min_component(vector2i v) -> vm_int_t
Returns the smallest component.
auto vec2i_max_component(vector2i v) -> vm_int_t
Returns the largest component.
auto vec2i_sum(vector2i v) -> vm_int_t
Returns the sum of all components.
auto vec2i_length(vector2i v) -> vm_float_t
Computes the length (magnitude) of the vector.
auto vec2i_distance(vector2i a, vector2i b) -> vm_float_t
Computes the Euclidean distance between two vectors (treated as points).
auto vec2i_angle(vector2i a, vector2i b) -> vm_float_t
Computes the signed angle between two vectors (in radians, range [-PI, PI]) using atan2(cross, dot).
auto vec2i_aspect_ratio(vector2i v) -> vm_float_t
Computes the aspect ratio of the vector (x / y).
auto vec2i_is_zero(vector2i v) -> bool
Returns true if every component is zero.
auto vec3i_add(vector3i a, vector3i b) -> vector3i
Component-wise addition of two vectors.
auto vec3i_sub(vector3i a, vector3i b) -> vector3i
Component-wise subtraction of two vectors.
auto vec3i_mul_scalar(vector3i v, vm_int_t s) -> vector3i
Component-wise multiplication of vector by scalar.
auto vec3i_div_scalar(vector3i v, vm_int_t s) -> vector3i
Component-wise division of vector by scalar.
auto vec3i_mul(vector3i a, vector3i b) -> vector3i
Component-wise multiplication of two vectors.
auto vec3i_neg(vector3i v) -> vector3i
Negation of a vector.
auto vec3i_abs(vector3i v) -> vector3i
Computes the absolute value per component of a vector3i.
auto vec3i_zero(void) -> vector3i
Returns a zero-initialized vector3i.
auto vec3i_one(void) -> vector3i
Returns a vector3i with all components set to 1.
auto vec3i_x_axis(vm_int_t x) -> vector3i
Returns a vector3i along the x-axis.
auto vec3i_y_axis(vm_int_t y) -> vector3i
Returns a vector3i along the y-axis.
auto vec3i_z_axis(vm_int_t z) -> vector3i
Returns a vector3i along the z-axis.
auto vec3i_x_scale(vm_int_t x) -> vector3i
Returns a vector3i for scaling along the x-axis.
auto vec3i_y_scale(vm_int_t y) -> vector3i
Returns a vector3i for scaling along the y-axis.
auto vec3i_z_scale(vm_int_t z) -> vector3i
Returns a vector3i for scaling along the z-axis.
auto vec3i_cross(vector3i a, vector3i b) -> vector3i
Computes the cross-product of two vector3i.
auto vec3i_normalize(vector3i v) -> vector3i
Normalizes a vector3i to unit length.
auto vec3i_min(vector3i a, vector3i b) -> vector3i
Computes the component-wise minimum of two vector3i.
auto vec3i_max(vector3i a, vector3i b) -> vector3i
Computes the component-wise maximum of two vector3i.
auto vec3i_sign(vector3i v) -> vector3i
Computes the sign per component of a vector3i (-1, 0, or 1).
auto vec3i_lerp(vector3i a, vector3i b, vm_float_t t) -> vector3i
Linearly interpolates between two vector3i.
auto vec3i_clamp(vector3i v, vector3i min, vector3i max) -> vector3i
Clamps a vector3i between min and max per component.
auto vec3i_div(vector3i a, vector3i b) -> vector3i
Divides two vectors component-wise.
auto vec3i_add_scalar(vector3i v, vm_int_t s) -> vector3i
Adds a scalar to each component.
auto vec3i_sub_scalar(vector3i v, vm_int_t s) -> vector3i
Subtracts a scalar from each component.
auto vec3i_mod(vector3i a, vector3i b) -> vector3i
Component-wise floor modulo of a by b.
auto vec3i_div_floor(vector3i a, vector3i b) -> vector3i
Component-wise floored division of a by b.
auto vec3i_wrap(vector3i v, vector3i period) -> vector3i
Wraps each component of v into [0, period).
auto vec3i_splat(vm_int_t s) -> vector3i
Returns a vector with every component set to s.
auto vec3i_from_vec2i(vector2i v, vm_int_t z) -> vector3i
Builds a vector3i from a vector2i and z.
auto vec3i_xy(vector3i v) -> vector2i
Returns the x and y components as a 2D vector.
auto vec3i_normalize_to_vec3(vector3i v) -> vector3
Converts to a unit-length vector3.
auto vec3i_dot(vector3i a, vector3i b) -> vm_int_t
Computes the dot product of two vector3i.
auto vec3i_length_squared(vector3i v) -> vm_int_t
Returns the squared Euclidean length.
auto vec3i_distance_squared(vector3i a, vector3i b) -> vm_int_t
Returns the squared Euclidean distance between a and b.
auto vec3i_length_manhattan(vector3i v) -> vm_int_t
Returns the Manhattan (L1) length.
auto vec3i_length_chebyshev(vector3i v) -> vm_int_t
Returns the Chebyshev (L-inf) length.
auto vec3i_min_component(vector3i v) -> vm_int_t
Returns the smallest component.
auto vec3i_max_component(vector3i v) -> vm_int_t
Returns the largest component.
auto vec3i_sum(vector3i v) -> vm_int_t
Returns the sum of all components.
auto vec3i_length(vector3i v) -> vm_float_t
Computes the length (magnitude) of a vector3i.
auto vec3i_distance(vector3i a, vector3i b) -> vm_float_t
Computes the Euclidean distance between two vector3i.
auto vec3i_angle(vector3i a, vector3i b) -> vm_float_t
Computes the angle between two non-zero vector3i in radians.
auto vec3i_is_zero(vector3i v) -> bool
Returns true if every component is zero.
auto vec4i_add(vector4i a, vector4i b) -> vector4i
Component-wise addition of two vectors.
auto vec4i_sub(vector4i a, vector4i b) -> vector4i
Component-wise subtraction of two vectors.
auto vec4i_mul_scalar(vector4i v, vm_int_t s) -> vector4i
Component-wise multiplication of vector by scalar.
auto vec4i_div_scalar(vector4i v, vm_int_t s) -> vector4i
Component-wise division of vector by scalar.
auto vec4i_mul(vector4i a, vector4i b) -> vector4i
Component-wise multiplication of two vectors.
auto vec4i_neg(vector4i v) -> vector4i
Negation of a vector.
auto vec4i_abs(vector4i v) -> vector4i
Computes the absolute value per component of a vector4i.
auto vec4i_zero(void) -> vector4i
Returns a zero-initialized vector4i.
auto vec4i_one(void) -> vector4i
Returns a vector4i with all components set to 1.
auto vec4i_x_axis(vm_int_t x) -> vector4i
Returns a vector4i along the x-axis.
auto vec4i_y_axis(vm_int_t y) -> vector4i
Returns a vector4i along the y-axis.
auto vec4i_z_axis(vm_int_t z) -> vector4i
Returns a vector4i along the z-axis.
auto vec4i_w_axis(vm_int_t w) -> vector4i
Returns a vector4i along the w-axis.
auto vec4i_x_scale(vm_int_t x) -> vector4i
Returns a vector4i for scaling along the x-axis.
auto vec4i_y_scale(vm_int_t y) -> vector4i
Returns a vector4i for scaling along the y-axis.
auto vec4i_z_scale(vm_int_t z) -> vector4i
Returns a vector4i for scaling along the z-axis.
auto vec4i_w_scale(vm_int_t w) -> vector4i
Returns a vector4i for scaling along the w-axis.
auto vec4i_normalize(vector4i v) -> vector4i
Normalizes a vector4i to unit length.
auto vec4i_min(vector4i a, vector4i b) -> vector4i
Computes the component-wise minimum of two vector4i.
auto vec4i_max(vector4i a, vector4i b) -> vector4i
Computes the component-wise maximum of two vector4i.
auto vec4i_sign(vector4i v) -> vector4i
Computes the sign per component of a vector4i (-1, 0, or 1).
auto vec4i_lerp(vector4i a, vector4i b, vm_float_t t) -> vector4i
Linearly interpolates between two vector4i.
auto vec4i_clamp(vector4i v, vector4i min, vector4i max) -> vector4i
Clamps each component of the input vector to the range defined by the minimum and maximum vectors.
auto vec4i_div(vector4i a, vector4i b) -> vector4i
Divides two vectors component-wise.
auto vec4i_add_scalar(vector4i v, vm_int_t s) -> vector4i
Adds a scalar to each component.
auto vec4i_sub_scalar(vector4i v, vm_int_t s) -> vector4i
Subtracts a scalar from each component.
auto vec4i_mod(vector4i a, vector4i b) -> vector4i
Component-wise floor modulo of a by b.
auto vec4i_div_floor(vector4i a, vector4i b) -> vector4i
Component-wise floored division of a by b.
auto vec4i_wrap(vector4i v, vector4i period) -> vector4i
Wraps each component of v into [0, period).
auto vec4i_splat(vm_int_t s) -> vector4i
Returns a vector with every component set to s.
auto vec4i_to_vec3i(vector4i v) -> vector3i
Converts a vector4i to a vector3i (discards the w component).
auto vec4i_dot(vector4i a, vector4i b) -> vm_int_t
Computes the dot product of two vector4i.
auto vec4i_length_squared(vector4i v) -> vm_int_t
Returns the squared Euclidean length.
auto vec4i_distance_squared(vector4i a, vector4i b) -> vm_int_t
Returns the squared Euclidean distance between a and b.
auto vec4i_length_manhattan(vector4i v) -> vm_int_t
Returns the Manhattan (L1) length.
auto vec4i_length_chebyshev(vector4i v) -> vm_int_t
Returns the Chebyshev (L-inf) length.
auto vec4i_min_component(vector4i v) -> vm_int_t
Returns the smallest component.
auto vec4i_max_component(vector4i v) -> vm_int_t
Returns the largest component.
auto vec4i_sum(vector4i v) -> vm_int_t
Returns the sum of all components.
auto vec4i_length(vector4i v) -> vm_float_t
Computes the length (magnitude) of a vector4i.
auto vec4i_distance(vector4i a, vector4i b) -> vm_float_t
Computes the Euclidean distance between two vector4i.
auto vec4i_is_zero(vector4i v) -> bool
Returns true if every component is zero.
void vec2i_add_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Adds vectors a and b component-wise, storing the result in res.
void vec2i_sub_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Subtracts vector b from vector a component-wise, storing the result in res.
void vec2i_mul_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)
Multiplies vector v by scalar s component-wise, storing the result in res.
void vec2i_div_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)
Divides vector v by scalar s component-wise (float division, truncated to int), storing the result in res.
void vec2i_mul_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Multiplies vectors a and b component-wise (Hadamard product), storing the result in res.
void vec2i_neg_ptr(vector2i* res, const vector2i* v)
Negates the components of vector v, storing the result in res.
void vec2i_abs_ptr(vector2i* res, const vector2i* v)
Computes the absolute values of the components of vector v (using int abs), storing the result in res.
void vec2i_normalize_ptr(vector2i* res, const vector2i* v)
Normalizes vector v to approximate unit length (float length computation, truncated to int), storing the result in res.
void vec2i_min_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Computes the component-wise minimum of vectors a and b, storing the result in res.
void vec2i_max_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Computes the component-wise maximum of vectors a and b, storing the result in res.
void vec2i_sign_ptr(vector2i* res, const vector2i* v)
Sets each component of res to the sign of the corresponding component in v (+1, -1, or 0).
void vec2i_perpendicular_ptr(vector2i* res, const vector2i* v)
Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.
void vec2i_cross_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.
void vec2i_lerp_ptr(vector2i* res, const vector2i* a, const vector2i* b, vm_float_t t)
Linearly interpolates from a to b by t.
void vec2i_clamp_ptr(vector2i* res, const vector2i* v, const vector2i* min, const vector2i* max)
Clamps each component between min and max.
void vec2i_div_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Divides two vectors component-wise.
void vec2i_add_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)
Adds a scalar to each component.
void vec2i_sub_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)
Subtracts a scalar from each component.
void vec2i_mod_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Component-wise floor modulo of a by b.
void vec2i_div_floor_ptr(vector2i* res, const vector2i* a, const vector2i* b)
Component-wise floored division of a by b.
void vec2i_wrap_ptr(vector2i* res, const vector2i* v, const vector2i* period)
Wraps each component of v into [0, period).
void vec2i_to_vec3i_ptr(vector3i* res, const vector2i* v, vm_int_t z)
Converts a vector4i to a vector3i by dropping w.
void vec2i_normalize_to_vec2_ptr(vector2* res, const vector2i* v)
Converts to a unit-length vector2.
void vec3i_add_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the component-wise sum of two vector3i.
void vec3i_sub_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the component-wise difference of two vector3i (a minus b).
void vec3i_mul_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)
Scales a vector3i by an integer scalar.
void vec3i_div_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)
Scales a vector3i by the inverse of an integer scalar.
void vec3i_mul_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the component-wise product (Hadamard) of two vector3i.
void vec3i_neg_ptr(vector3i* res, const vector3i* v)
Negates a vector3i (multiplies by -1).
void vec3i_abs_ptr(vector3i* res, const vector3i* v)
Computes the absolute value of each component of a vector3i.
void vec3i_normalize_ptr(vector3i* res, const vector3i* v)
Normalizes a vector3i to approximate unit length.
void vec3i_cross_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the cross-product of two vector3i.
void vec3i_min_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the component-wise minimum of two vector3i.
void vec3i_max_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Computes the component-wise maximum of two vector3i.
void vec3i_sign_ptr(vector3i* res, const vector3i* v)
Computes the sign of each component of a vector3i (-1, 0, or 1).
void vec3i_lerp_ptr(vector3i* res, const vector3i* a, const vector3i* b, vm_float_t t)
Performs linear interpolation between two vector3i.
void vec3i_clamp_ptr(vector3i* res, const vector3i* v, const vector3i* min, const vector3i* max)
Clamps each component of a vector3i between corresponding min and max values.
void vec3i_div_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Divides two vectors component-wise.
void vec3i_add_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)
Adds a scalar to each component.
void vec3i_sub_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)
Subtracts a scalar from each component.
void vec3i_mod_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Component-wise floor modulo of a by b.
void vec3i_div_floor_ptr(vector3i* res, const vector3i* a, const vector3i* b)
Component-wise floored division of a by b.
void vec3i_wrap_ptr(vector3i* res, const vector3i* v, const vector3i* period)
Wraps each component of v into [0, period).
void vec3i_from_vec2i_ptr(vector3i* res, const vector2i* v, vm_int_t z)
Builds a vector3i from a vector2i and z.
void vec3i_xy_ptr(vector2i* res, const vector3i* v)
Returns the x and y components as a 2D vector.
void vec3i_normalize_to_vec3_ptr(vector3* res, const vector3i* v)
Converts to a unit-length vector3.
void vec4i_add_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Adds the components of two vector4i and stores the result in res.
void vec4i_sub_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Subtracts the components of the second vector from the first vector4i and stores the result in res.
void vec4i_mul_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)
Multiplies the components of a vector4i by a scalar and stores the result in res.
void vec4i_div_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)
Divides the components of a vector4i by a scalar and stores the result in res.
void vec4i_mul_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Multiplies the components of two vector4i and stores the result in res.
void vec4i_neg_ptr(vector4i* res, const vector4i* v)
Negates the components of a vector4i and stores the result in res.
void vec4i_abs_ptr(vector4i* res, const vector4i* v)
Computes the absolute value of each component of a vector4i and stores the result in res.
void vec4i_normalize_ptr(vector4i* res, const vector4i* v)
Normalizes a vector4i by dividing its components by the vector length and stores the result in res.
void vec4i_min_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Takes the component-wise minimum of two vector4i and stores the result in res.
void vec4i_max_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Computes the component-wise maximum of two vector4i and stores the result in res.
void vec4i_sign_ptr(vector4i* res, const vector4i* v)
Computes the sign (-1, 0, or 1) of each component of a vector4i and stores the result in res.
void vec4i_lerp_ptr(vector4i* res, const vector4i* a, const vector4i* b, vm_float_t t)
Linearly interpolates between two vector4i using an interpolation factor t (clamped to [0,1]) and stores the result in res.
void vec4i_clamp_ptr(vector4i* res, const vector4i* v, const vector4i* min, const vector4i* max)
Clamps the components of a vector4i to the range [min, max] and stores the result in res.
void vec4i_div_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Divides two vectors component-wise.
void vec4i_add_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)
Adds a scalar to each component.
void vec4i_sub_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)
Subtracts a scalar from each component.
void vec4i_mod_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Component-wise floor modulo of a by b.
void vec4i_div_floor_ptr(vector4i* res, const vector4i* a, const vector4i* b)
Component-wise floored division of a by b.
void vec4i_wrap_ptr(vector4i* res, const vector4i* v, const vector4i* period)
Wraps each component of v into [0, period).
void vec4i_to_vec3i_ptr(vector3i* res, const vector4i* v)
Copies the x, y, z components of a vector4i and stores the result in a vector3i.
auto mat2_identity(void) -> matrix2
Constructs the 2x2 identity matrix.
auto mat2_mul(matrix2 a, matrix2 b) -> matrix2
Multiplies two 2x2 matrices (a * b).
auto mat2_transpose(matrix2 m) -> matrix2
Computes the transpose of a 2x2 matrix.
auto mat2_inverse(matrix2 m) -> matrix2
Computes the inverse of a 2x2 matrix.
auto mat2_rotation_z(vm_float_t radians) -> matrix2
Constructs a 2x2 rotation matrix around the Z axis.
auto mat2_rotation_z_deg(vm_float_t degrees) -> matrix2
Constructs a 2x2 rotation matrix from an angle in degrees around the Z axis.
auto mat2_scale(vector2 s) -> matrix2
Builds a 2x2 scaling matrix from a vector2.
auto mat2_from_mat3(matrix3 m) -> matrix2
Copies the upper-left 2x2 of a matrix3.
auto mat2_mul_vec2(matrix2 m, vector2 v) -> vector2
Multiplies a 2x2 matrix by a vector2.
auto mat2_determinant(matrix2 m) -> vm_float_t
Calculates the determinant of the given 2x2 matrix.
auto mat3_identity(void) -> matrix3
Constructs the 3x3 identity matrix.
auto mat3_mul(matrix3 a, matrix3 b) -> matrix3
Multiplies two 3x3 matrices.
auto mat3_transpose(matrix3 m) -> matrix3
Computes the transpose of a 3x3 matrix.
auto mat3_inverse(matrix3 m) -> matrix3
Computes the inverse of a 3x3 matrix.
auto mat3_rotation_x(vm_float_t radians) -> matrix3
Constructs a 3x3 rotation matrix around the X axis.
auto mat3_rotation_y(vm_float_t radians) -> matrix3
Constructs a 3x3 rotation matrix around the Y axis.
auto mat3_rotation_z(vm_float_t radians) -> matrix3
Constructs a 3x3 rotation matrix around the Z axis.
auto mat3_rotation_x_deg(vm_float_t degrees) -> matrix3
Constructs a 3x3 rotation matrix around the X axis.
auto mat3_rotation_y_deg(vm_float_t degrees) -> matrix3
3x3 rotation about Y from an angle in degrees.
auto mat3_rotation_z_deg(vm_float_t degrees) -> matrix3
Constructs a 3x3 rotation matrix around the Z axis.
auto mat3_translate(vector2 t) -> matrix3
Builds a 3x3 2D translation matrix.
auto mat3_scale(vector2 s) -> matrix3
Builds a 3x3 2D scaling matrix.
auto mat3_normal(matrix3 m) -> matrix3
Inverse-transpose of a 3x3 (normal matrix).
auto mat3_from_mat4(matrix4 m) -> matrix3
Copies the upper-left 3x3 of a matrix4.
auto mat3_mul_vec3(matrix3 m, vector3 v) -> vector3
Multiplies a 3x3 matrix by a vector3.
auto mat3_sym_eigen(matrix3 m, matrix3* axes) -> vector3
Symmetric 3x3 eigensolve (Jacobi).
auto mat3_mul_vec2(matrix3 m, vector2 v) -> vector2
Applies a 3x3 affine transform to a vector2.
auto mat3_determinant(matrix3 m) -> vm_float_t
Computes the determinant of a 3x3 matrix.
auto mat4_identity(void) -> matrix4
Constructs the 4x4 identity matrix.
auto mat4_mul(matrix4 a, matrix4 b) -> matrix4
Multiplies two 4x4 matrices (a * b).
auto mat4_transpose(matrix4 m) -> matrix4
Computes the transpose of a 4x4 matrix.
auto mat4_inverse(matrix4 m) -> matrix4
Computes the inverse of a 4x4 matrix.
auto mat4_inverse_affine(matrix4 m) -> matrix4
Inverse of an affine matrix [R t; 0 1].
auto mat4_translate(vector3 v) -> matrix4
Constructs a translation matrix from the given vector.
auto mat4_scale(vector3 v) -> matrix4
Constructs a scaling matrix from the given scale vector.
auto mat4_normal(matrix4 m) -> matrix4
Inverse-transpose of the upper 3x3, embedded in a matrix4.
auto mat4_rotation(vector3 axis, vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix.
auto mat4_rotation_x(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the X axis.
auto mat4_rotation_y(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the Y axis.
auto mat4_rotation_z(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the Z axis.
auto mat4_rotation_deg(vector3 axis, vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix from an axis and angle in degrees.
auto mat4_rotation_x_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the X axis.
auto mat4_rotation_y_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the Y axis.
auto mat4_rotation_z_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the Z axis from an angle in degrees.
auto mat4_trs(vector3 translation, quaternion rotation, vector3 scale) -> matrix4
Builds a 4x4 TRS matrix from translation, rotation, and scale.
auto mat4_from_mat3(matrix3 m) -> matrix4
Embeds a matrix3 into the upper-left of a matrix4.
auto mat4_ortho(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Constructs an orthographic projection matrix.
auto mat4_look_at(vector3 position, vector3 target, vector3 up) -> matrix4
Constructs a view matrix from eye position, target, and up vector.
auto mat4_perspective(vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Constructs a perspective projection matrix.
auto mat4_perspective_fov(vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f) -> matrix4
Constructs a perspective projection matrix using FOV, width, and height.
auto mat4_perspective_infinite(vm_float_t fov_y, vm_float_t aspect, vm_float_t n) -> matrix4
Constructs an infinite far-plane perspective projection matrix.
auto mat4_perspective_infinite_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite-far perspective with an explicit clip convention.
auto mat4_infinite_reverse_z(vm_float_t fov_y, vm_float_t aspect, vm_float_t n) -> matrix4
Infinite reverse-Z perspective (RH + ZO by default).
auto mat4_infinite_reverse_z_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite reverse-Z perspective with an explicit clip convention.
auto mat4_perspective_deg(vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.
auto mat4_perspective_fov_deg(vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f) -> matrix4
Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.
auto mat4_perspective_infinite_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n) -> matrix4
Constructs a 4x4 infinite perspective projection matrix using vertical field of view in degrees.
auto mat4_perspective_infinite_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite-far perspective from a FOV in degrees.
auto mat4_infinite_reverse_z_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n) -> matrix4
Infinite reverse-Z perspective from a FOV in degrees.
auto mat4_infinite_reverse_z_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite reverse-Z perspective (degrees + clip convention).
auto mat4_perspective_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Constructs a 4x4 perspective projection matrix.
auto mat4_perspective_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Perspective projection from a vertical FOV in degrees.
auto mat4_perspective_rh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH perspective, clip z in [-1, 1].
auto mat4_perspective_rh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH perspective, clip z in [0, 1].
auto mat4_perspective_lh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH perspective, clip z in [0, 1].
auto mat4_perspective_lh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Left-handed perspective, clip z in [-1, 1].
auto mat4_perspective_rh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH perspective from a FOV in degrees.
auto mat4_perspective_rh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH perspective from a FOV in degrees.
auto mat4_perspective_lh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH perspective from a FOV in degrees.
auto mat4_perspective_lh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Left-handed NO perspective from a FOV in degrees.
auto mat4_ortho_clip(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Orthographic projection with an explicit clip convention.
auto mat4_ortho_rh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH orthographic projection.
auto mat4_ortho_rh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH orthographic projection.
auto mat4_ortho_lh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH orthographic projection.
auto mat4_ortho_lh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Left-handed NO orthographic projection.
auto mat4_look_at_clip(vector3 position, vector3 target, vector3 up, vm_clip_t clip) -> matrix4
Look-at view matrix with an explicit clip convention.
auto mat4_look_at_rh(vector3 position, vector3 target, vector3 up) -> matrix4
Right-handed look-at view matrix.
auto mat4_look_at_lh(vector3 position, vector3 target, vector3 up) -> matrix4
Left-handed look-at view matrix.
auto mat4_look_from_dir(vector3 position, vector3 direction, vector3 up) -> matrix4
View matrix from eye position and a look direction.
auto mat4_look_from_dir_clip(vector3 position, vector3 direction, vector3 up, vm_clip_t clip) -> matrix4
Look-from-direction view matrix with an explicit clip convention.
auto mat4_look_from_dir_rh(vector3 position, vector3 direction, vector3 up) -> matrix4
Right-handed look-from-direction view matrix.
auto mat4_look_from_dir_lh(vector3 position, vector3 direction, vector3 up) -> matrix4
Left-handed look-from-direction view matrix.
auto mat4_viewport(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height) -> matrix4
Pixel-box viewport matrix (NDC xy/z [-1,1] to window + depth [0,1]).
auto mat4_viewport_depth(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f) -> matrix4
Viewport matrix with an explicit depth range.
auto mat4_determinant(matrix4 m) -> vm_float_t
Calculates the determinant of the given 4x4 matrix.
auto mat4_extract_translation(matrix4 m) -> vector3
Extracts the translation vector from a matrix4.
auto mat4_extract_scale(matrix4 m) -> vector3
Extracts the scale vector from a matrix4.
auto mat4_mul_vec3(matrix4 m, vector3 v, vm_float_t w) -> vector3
Transforms a vector3 by a 4x4 matrix using homogeneous w.
auto mat4_mul_vec4(matrix4 m, vector4 v) -> vector4
Multiplies a 4x4 matrix by a vector4.
auto mat4_extract_rotation(matrix4 m) -> quaternion
Extracts the rotation quaternion from a matrix4.
auto vec3_world_to_window(vector3 world, matrix4 model, matrix4 projection, vector4 viewport) -> vector3
Projects a world space point to window coordinates.
auto vec3_window_to_world(vector3 window, matrix4 model, matrix4 projection, vector4 viewport) -> vector3
Un-projects a window coordinate back to world space.
auto vec3_world_to_window_clip(vector3 world, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip) -> vector3
Projects a world-space point into window coordinates using model, projection and viewport.
auto vec3_window_to_world_clip(vector3 window, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip) -> vector3
Un-projects a window coordinate using model, projection, viewport and clip space.
void mat2_identity_ptr(matrix2* res)
Initializes the 2x2 matrix to identity (diagonal 1.0, others 0.0).
void mat2_mul_ptr(matrix2* res, const matrix2* a, const matrix2* b)
Multiplies two 2x2 matrices (a * b) in column-major / column-vector convention.
void mat2_transpose_ptr(matrix2* res, const matrix2* m)
Computes the transpose of the input 2x2 matrix and stores in res.
void mat2_inverse_ptr(matrix2* res, const matrix2* m)
Computes the inverse of the input 2x2 matrix using determinant and stores in res.
void mat2_rotation_z_ptr(matrix2* res, vm_float_t radians)
Sets the 2x2 matrix to a Z-axis (counter-clockwise) rotation.
void mat2_rotation_z_deg_ptr(matrix2* res, vm_float_t degrees)
Initializes the 2x2 matrix to a rotation around Z axis (counter-clockwise).
void mat2_scale_ptr(matrix2* res, const vector2* s)
Builds a 2x2 scaling matrix from a vector2.
void mat2_from_mat3_ptr(matrix2* res, const matrix3* m)
Copies the upper-left 2x2 of a matrix3.
void mat2_mul_vec2_ptr(vector2* res, const matrix2* m, const vector2* v)
Multiplies a 2x2 matrix by a vector2.
void mat3_identity_ptr(matrix3* res)
Initializes the 3x3 matrix to identity (diagonal 1.0, others 0.0).
void mat3_mul_ptr(matrix3* res, const matrix3* a, const matrix3* b)
Multiplies two 3x3 matrices (a * b) in column-major / column-vector convention.
void mat3_transpose_ptr(matrix3* res, const matrix3* m)
Computes the transpose of the input 3x3 matrix and stores in res.
void mat3_inverse_ptr(matrix3* res, const matrix3* m)
Computes the inverse of the input 3x3 matrix using the adjugate method and stores in res.
void mat3_rotation_x_ptr(matrix3* res, vm_float_t radians)
Sets the 3x3 matrix to a rotation around the X axis.
void mat3_rotation_y_ptr(matrix3* res, vm_float_t radians)
Sets the 3x3 matrix to a rotation around the Y axis.
void mat3_rotation_z_ptr(matrix3* res, vm_float_t radians)
Sets the 3x3 matrix to a Z-axis rotation by the given angle in radians.
void mat3_rotation_x_deg_ptr(matrix3* res, vm_float_t degrees)
Initializes the 3x3 matrix to a rotation around the X axis.
void mat3_rotation_y_deg_ptr(matrix3* res, vm_float_t degrees)
Initializes the 3x3 matrix to a rotation around the Y axis.
void mat3_rotation_z_deg_ptr(matrix3* res, vm_float_t degrees)
Initializes the 3x3 matrix to a rotation around the Z axis.
void mat3_translate_ptr(matrix3* res, const vector2* t)
Builds a 3x3 2D translation matrix.
void mat3_scale_ptr(matrix3* res, const vector2* s)
Builds a 3x3 2D scaling matrix.
void mat3_from_mat4_ptr(matrix3* res, const matrix4* m)
Copies the upper-left 3x3 of a matrix4.
void mat3_normal_ptr(matrix3* res, const matrix3* m)
Inverse-transpose of a 3x3, for transforming normals.
void mat3_mul_vec3_ptr(vector3* res, const matrix3* m, const vector3* v)
Multiplies a 3x3 matrix by a vector3.
void mat3_mul_vec2_ptr(vector2* res, const matrix3* m, const vector2* v)
Applies a 3x3 affine transform to a vector2.
void mat3_sym_eigen_ptr(vector3* eigenvalues, matrix3* axes, const matrix3* m)
Jacobi eigensolve of a symmetric 3x3 matrix.
void mat4_identity_ptr(matrix4* res)
Sets the matrix to the identity matrix.
void mat4_mul_ptr(matrix4* res, const matrix4* a, const matrix4* b)
Multiplies two 4x4 matrices (dispatched).
void mat4_transpose_ptr(matrix4* res, const matrix4* m)
Transposes a 4x4 matrix (dispatched).
void mat4_inverse_ptr(matrix4* res, const matrix4* m)
Computes the inverse of a 4x4 matrix.
void mat4_inverse_affine_ptr(matrix4* res, const matrix4* m)
Inverse of an affine matrix [R t; 0 1].
void mat4_translate_ptr(matrix4* res, const vector3* v)
Sets the matrix to a translation matrix.
void mat4_scale_ptr(matrix4* res, const vector3* v)
Sets the matrix to a scaling matrix using the provided scale vector.
void mat4_normal_ptr(matrix4* res, const matrix4* m)
Inverse-transpose of the upper-left 3x3, embedded in a matrix4.
void mat4_rotation_ptr(matrix4* res, const vector3* axis, vm_float_t radians)
Sets the matrix to a rotation matrix around the given axis.
void mat4_rotation_x_ptr(matrix4* res, vm_float_t radians)
Builds a 4x4 rotation matrix around the X axis (radians).
void mat4_rotation_y_ptr(matrix4* res, vm_float_t radians)
Sets the matrix to a rotation matrix around the Y axis.
void mat4_rotation_z_ptr(matrix4* res, vm_float_t radians)
Sets the matrix to a rotation around the Z axis.
void mat4_rotation_deg_ptr(matrix4* res, const vector3* axis, vm_float_t degrees)
Sets the matrix to a rotation matrix using an axis and angle in degrees.
void mat4_rotation_x_deg_ptr(matrix4* res, vm_float_t degrees)
Builds a 4x4 rotation matrix around the X axis (degrees).
void mat4_rotation_y_deg_ptr(matrix4* res, vm_float_t degrees)
Builds a 4x4 rotation matrix around the Y axis (degrees).
void mat4_rotation_z_deg_ptr(matrix4* res, vm_float_t degrees)
Builds a 4x4 rotation matrix around the Z axis (degrees).
void mat4_trs_ptr(matrix4* res, const vector3* translation, const quaternion* rotation, const vector3* scale)
Builds a 4x4 TRS matrix from translation, rotation, and scale.
void mat4_from_mat3_ptr(matrix4* res, const matrix3* m)
Embeds a matrix3 into the upper-left of a matrix4.
void mat4_extract_translation_ptr(vector3* res, const matrix4* m)
Extracts the translation vector from a matrix4.
void mat4_extract_scale_ptr(vector3* res, const matrix4* m)
Extracts the scale vector from a matrix4.
void mat4_extract_rotation_ptr(quaternion* res, const matrix4* m)
Extracts the rotation quaternion from a matrix4.
void mat4_ortho_ptr(matrix4* res, vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)
Sets the matrix to an orthographic projection matrix.
void mat4_look_at_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up)
Constructs a view matrix for a camera positioned at the given location, looking towards a target, with a specified up direction.
void mat4_look_from_dir_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up)
View matrix from eye position and a look direction (no target point).
void mat4_look_from_dir_clip_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up, vm_clip_t clip)
Clip-aware look-from-direction view matrix.
void mat4_viewport_ptr(matrix4* res, vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height)
Viewport matrix from origin (x, y) and size (width, height).
void mat4_viewport_depth_ptr(matrix4* res, vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f)
Viewport matrix from origin, size, and depth range [n, f].
void mat4_perspective_ptr(matrix4* res, vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far)
Creates a perspective projection matrix.
void mat4_perspective_fov_ptr(matrix4* res, vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)
Sets the matrix to a perspective projection matrix.
void mat4_perspective_infinite_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n)
Sets the matrix to an infinite perspective projection matrix.
void mat4_perspective_infinite_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)
Infinite perspective matrix for a chosen clip convention.
void mat4_infinite_reverse_z_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n)
Infinite reverse-Z perspective matrix (RH, [0, 1] depth).
void mat4_infinite_reverse_z_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)
Infinite reverse-Z perspective matrix for a chosen clip convention.
void mat4_perspective_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)
Constructs a perspective projection matrix with configurable clip space.
void mat4_perspective_deg_ptr(matrix4* res, vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)
Sets the matrix to a perspective projection matrix using field of view in degrees.
void mat4_perspective_fov_deg_ptr(matrix4* res, vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)
Sets the matrix to a perspective projection matrix using vertical field of view in degrees.
void mat4_perspective_infinite_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)
Sets the matrix to an infinite perspective projection matrix using vertical field of view in degrees.
void mat4_perspective_infinite_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)
Infinite perspective matrix from FOV in degrees and clip space.
void mat4_infinite_reverse_z_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)
Infinite reverse-Z perspective matrix from a vertical FOV in degrees.
void mat4_infinite_reverse_z_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)
Infinite reverse-Z perspective matrix from FOV in degrees and clip space.
void mat4_perspective_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)
Sets a perspective projection matrix using vertical field of view in degrees.
void mat4_ortho_clip_ptr(matrix4* res, vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip)
Sets the matrix to an orthographic projection matrix.
void mat4_look_at_clip_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up, vm_clip_t clip)
Constructs a look-at view matrix with support for different clip space conventions.
void mat4_mul_vec4_ptr(vector4* res, const matrix4* m, const vector4* v)
Transforms a vector4 by a 4x4 matrix (dispatched).
void mat4_mul_vec3_ptr(vector3* res, const matrix4* m, const vector3* v, vm_float_t w)
Transforms a vector3 by a 4x4 matrix using homogeneous w (dispatched).
void vec3_world_to_window_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport)
Projects a world-space point to window coordinates (OpenGL clip).
void vec3_window_to_world_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport)
Un-projects a window-space point to world coordinates using model, projection, and viewport.
void vec3_world_to_window_clip_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport, vm_clip_t clip)
Projects a world-space point into window coordinates using model, projection, viewport, and clip depth range.
void vec3_window_to_world_clip_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport, vm_clip_t clip)
Un-projects a window-space point to world coordinates using model, projection, viewport, and clip depth range.
auto mat2i_identity(void) -> matrix2i
Constructs the 2x2 integer identity matrix.
auto mat2i_mul(matrix2i a, matrix2i b) -> matrix2i
Multiplies two 2x2 integer matrices (a * b).
auto mat2i_transpose(matrix2i m) -> matrix2i
Computes the transpose of a 2x2 integer matrix.
auto mat2i_inverse(matrix2i m) -> matrix2i
Computes the inverse of a 2x2 integer matrix.
auto mat2i_mul_vec2i(matrix2i m, vector2i v) -> vector2i
Multiplies a 2x2 integer matrix by a vector2i.
auto mat2i_determinant(matrix2i m) -> vm_int_t
Calculates the determinant of the given 2x2 integer matrix.
auto mat3i_identity(void) -> matrix3i
Constructs the 3x3 identity matrix.
auto mat3i_mul(matrix3i a, matrix3i b) -> matrix3i
Multiplies two 3x3 integer matrices.
auto mat3i_transpose(matrix3i m) -> matrix3i
Computes the transpose of a 3x3 integer matrix.
auto mat3i_inverse(matrix3i m) -> matrix3i
Computes the inverse of a 3x3 integer matrix.
auto mat3i_mul_vec3i(matrix3i m, vector3i v) -> vector3i
Multiplies a 3x3 integer matrix by a vector3i.
auto mat3i_mul_vec2i(matrix3i m, vector2i v) -> vector2i
Applies a 3x3 integer affine transform to a vector2i.
auto mat3i_determinant(matrix3i m) -> vm_int_t
Computes the determinant of a 3x3 integer matrix.
auto mat4i_identity(void) -> matrix4i
Constructs the 4x4 identity matrix.
auto mat4i_mul(matrix4i a, matrix4i b) -> matrix4i
Multiplies two 4x4 integer matrices.
auto mat4i_transpose(matrix4i m) -> matrix4i
Computes the transpose of a 4x4 integer matrix.
auto mat4i_inverse(matrix4i m) -> matrix4i
Computes the inverse of a 4x4 integer matrix.
auto mat4i_mul_vec4i(matrix4i m, vector4i v) -> vector4i
Multiplies a 4x4 integer matrix by a vector4i.
auto mat4i_mul_vec3i(matrix4i m, vector3i v, vm_int_t w) -> vector3i
Transforms a vector3i by a 4x4 integer matrix using homogeneous w.
auto mat4i_determinant(matrix4i m) -> vm_int_t
Computes the determinant of a 4x4 integer matrix (Laplace expansion along first row).
void mat2i_identity_ptr(matrix2i* res)
Initializes the integer 2x2 matrix to identity (diagonal 1, others 0).
void mat2i_mul_ptr(matrix2i* res, const matrix2i* a, const matrix2i* b)
Multiplies two integer 2x2 matrices (a * b) using explicit loops and stores the result in res.
void mat2i_transpose_ptr(matrix2i* res, const matrix2i* m)
Computes the transpose of the input integer 2x2 matrix and stores in res.
void mat2i_inverse_ptr(matrix2i* res, const matrix2i* m)
Computes the inverse of the input integer 2x2 matrix and stores in res.
void mat2i_mul_vec2i_ptr(vector2i* res, const matrix2i* m, const vector2i* v)
Multiplies a 2x2 integer matrix by a vector2i.
void mat3i_identity_ptr(matrix3i* res)
Fills the given 3x3 integer matrix with the identity matrix.
void mat3i_mul_ptr(matrix3i* res, const matrix3i* a, const matrix3i* b)
Multiplies two 3x3 integer matrices (standard matrix multiplication).
void mat3i_transpose_ptr(matrix3i* res, const matrix3i* m)
Computes the transpose of a 3x3 integer matrix.
void mat3i_inverse_ptr(matrix3i* res, const matrix3i* m)
Computes the inverse of a 3x3 integer matrix using adjugate over determinant.
void mat3i_mul_vec3i_ptr(vector3i* res, const matrix3i* m, const vector3i* v)
Multiplies a 3x3 integer matrix by a vector3i.
void mat3i_mul_vec2i_ptr(vector2i* res, const matrix3i* m, const vector2i* v)
Applies a 3x3 integer affine transform to a vector2i.
void mat4i_identity_ptr(matrix4i* res)
Sets the given 4x4 integer matrix to the identity matrix.
void mat4i_mul_ptr(matrix4i* res, const matrix4i* a, const matrix4i* b)
Performs matrix multiplication of two 4x4 matrices and stores the result.
void mat4i_transpose_ptr(matrix4i* res, const matrix4i* m)
Transposes the given 4x4 integer matrix and stores the result in the provided matrix structure.
void mat4i_inverse_ptr(matrix4i* res, const matrix4i* m)
Computes the inverse of the given 4x4 integer matrix and stores the result in the specified matrix.
void mat4i_mul_vec4i_ptr(vector4i* res, const matrix4i* m, const vector4i* v)
Multiplies a 4x4 integer matrix by a vector4i.
void mat4i_mul_vec3i_ptr(vector3i* res, const matrix4i* m, const vector3i* v, vm_int_t w)
Transforms a vector3i by a 4x4 integer matrix using homogeneous w.
auto quat_identity(void) -> quaternion
Constructs the identity quaternion.
auto quat_mul(quaternion a, quaternion b) -> quaternion
Multiplies two quaternions (a * b).
auto quat_normalize(quaternion q) -> quaternion
Normalizes a quaternion.
auto quat_conjugate(quaternion q) -> quaternion
Returns the conjugate of a quaternion.
auto quat_inverse(quaternion q) -> quaternion
Returns the inverse of a quaternion.
auto quat_from_euler(vector3 euler) -> quaternion
Constructs a quaternion from Euler angles.
auto quat_from_euler_deg(vector3 euler_deg) -> quaternion
Constructs a quaternion from Euler angles in degrees.
auto quat_from_axis_angle(vector3 axis, vm_float_t radians) -> quaternion
Constructs a quaternion from a rotation axis and angle.
auto quat_from_axis_angle_deg(vector3 axis, vm_float_t degrees) -> quaternion
Constructs a quaternion from an axis and an angle in degrees.
auto quat_from_mat3(matrix3 m) -> quaternion
Builds a quaternion from a 3x3 rotation matrix.
auto quat_from_mat4(matrix4 m) -> quaternion
Builds a quaternion from the rotation of a 4x4 matrix.
auto quat_look(vector3 direction, vector3 up) -> quaternion
Constructs a quaternion that rotates from the negative Z axis towards the given direction, with the specified up vector.
auto quat_look_clip(vector3 direction, vector3 up, vm_clip_t clip) -> quaternion
Constructs a quaternion representing a look-at rotation with specified clip space.
auto quat_from_to(vector3 from, vector3 to) -> quaternion
Constructs a quaternion representing the shortest rotation from one vector to another.
auto quat_slerp(quaternion a, quaternion b, vm_float_t t) -> quaternion
Spherical-linearly interpolates from a to b by t.
auto quat_nlerp(quaternion a, quaternion b, vm_float_t t) -> quaternion
Normalized-linearly interpolates from a to b by t.
auto quat_integrate(quaternion q, vector3 omega, vm_float_t dt) -> quaternion
Integrates a quaternion using angular velocity.
auto quat_rotate_vec3(quaternion q, vector3 v) -> vector3
Rotates a vector3 by a quaternion.
auto quat_to_euler(quaternion q) -> vector3
Converts a quaternion to Euler angles in degrees (XYZ).
auto quat_to_euler_deg(quaternion q) -> vector3
Converts a quaternion to Euler angles in degrees.
auto quat_to_axis_angle(quaternion q, vm_float_t* radians) -> vector3
Converts a quaternion to axis-angle representation.
auto quat_to_axis_angle_deg(quaternion q, vm_float_t* degrees) -> vector3
Converts a quaternion to axis-angle representation in degrees.
auto quat_to_mat4(quaternion q) -> matrix4
Converts a quaternion to a 4x4 rotation matrix.
auto quat_to_mat3(quaternion q) -> matrix3
Converts a quaternion to a 3x3 rotation matrix.
auto quat_dot(quaternion a, quaternion b) -> vm_float_t
Returns the dot product of two quaternions.
auto quat_near(quaternion a, quaternion b, vm_float_t eps) -> bool
Returns true if a and b are within eps of each other.
void quat_identity_ptr(quaternion* res)
Sets the quaternion to the identity quaternion (x=0, y=0, z=0, w=1).
void quat_mul_ptr(quaternion* res, const quaternion* a, const quaternion* b)
Hamilton product a * b (dispatched).
void quat_normalize_ptr(quaternion* res, const quaternion* q)
Normalizes a quaternion (dispatched).
void quat_conjugate_ptr(quaternion* res, const quaternion* q)
Writes the conjugate of a quaternion.
void quat_inverse_ptr(quaternion* res, const quaternion* q)
Writes the inverse of a quaternion.
void quat_from_euler_ptr(quaternion* res, const vector3* euler)
Converts Euler angles (in radians) to a normalized quaternion.
void quat_from_euler_deg_ptr(quaternion* res, const vector3* euler_deg)
Converts Euler angles in degrees to a quaternion.
void quat_from_axis_angle_ptr(quaternion* res, const vector3* axis, vm_float_t radians)
Converts an axis-angle rotation to a quaternion.
void quat_from_axis_angle_deg_ptr(quaternion* res, const vector3* axis, vm_float_t degrees)
Converts an axis-angle rotation (in degrees) to a quaternion.
void quat_from_mat3_ptr(quaternion* res, const matrix3* m)
Builds a quaternion from a 3x3 rotation matrix.
void quat_from_mat4_ptr(quaternion* res, const matrix4* m)
Builds a quaternion from the rotation of a 4x4 matrix.
void quat_look_ptr(quaternion* res, const vector3* direction, const vector3* up)
Orientation that aims local -Z along direction (RH / FPS camera).
void quat_look_clip_ptr(quaternion* res, const vector3* direction, const vector3* up, vm_clip_t clip)
Orientation that aims along direction.
void quat_from_to_ptr(quaternion* res, const vector3* from, const vector3* to)
Shortest rotation taking from onto to.
void quat_slerp_ptr(quaternion* res, const quaternion* a, const quaternion* b, vm_float_t t)
Spherical-linearly interpolates from a to b by t.
void quat_nlerp_ptr(quaternion* res, const quaternion* a, const quaternion* b, vm_float_t t)
Normalized-linearly interpolates from a to b by t.
void quat_rotate_vec3_ptr(vector3* res, const quaternion* q, const vector3* v)
Rotates a vector3 by a quaternion.
void quat_to_euler_ptr(vector3* res, const quaternion* q)
Converts a quaternion to Euler angles in degrees (XYZ).
void quat_to_euler_deg_ptr(vector3* res, const quaternion* q)
Converts a quaternion to XYZ Euler angles in degrees.
void quat_to_axis_angle_ptr(vector3* axis, vm_float_t* radians, const quaternion* q)
Converts a quaternion to an axis-angle representation.
void quat_to_axis_angle_deg_ptr(vector3* axis, vm_float_t* degrees, const quaternion* q)
Converts a quaternion to an axis-angle representation, with the angle in degrees.
void quat_to_mat4_ptr(matrix4* res, const quaternion* q)
Converts a unit quaternion to a 4x4 rotation matrix and stores in res.
void quat_to_mat3_ptr(matrix3* res, const quaternion* q)
Converts a quaternion to a 3x3 rotation matrix.
void quat_integrate_ptr(quaternion* res, const quaternion* q, const vector3* omega, vm_float_t dt)
Integrates angular velocity over a time step and applies the resulting rotation to the input quaternion.
auto vec2_from(const vector2i* v) -> vector2
Converts a vector2i to a vector2.
auto vec2i_from(const vector2* v) -> vector2i
Converts a vector2 to a vector2i by truncation.
auto vec2i_from_floored(const vector2* v) -> vector2i
Converts a vector2 to a vector2i by flooring each component.
auto vec2i_from_rounded(const vector2* v) -> vector2i
Converts a vector2 to a vector2i by rounding each component.
auto vec3_from(const vector3i* v) -> vector3
Converts a vector3i to a vector3.
auto vec3i_from(const vector3* v) -> vector3i
Converts a vector3 to a vector3i by truncation.
auto vec3i_from_floored(const vector3* v) -> vector3i
Converts a vector3 to a vector3i by flooring each component.
auto vec3i_from_rounded(const vector3* v) -> vector3i
Converts a vector3 to a vector3i by rounding each component.
auto deg_to_rad(vm_float_t degrees) -> vm_float_t
Converts degrees to radians.
auto rad_to_deg(vm_float_t radians) -> vm_float_t
Converts radians to degrees.
void vm_gemm(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout)
C = alpha * op(A) * op(B) + beta * C for dense float panels.
void vm_gemm_ref(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout)
Triple-loop reference GEMM.
void vm_gemm_batch(vm_float_t*const* C, int ldc, const vm_float_t*const* A, int lda, const vm_float_t*const* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int batch)
Batched GEMM: batch independent GEMMs with shared shape.
void vm_gemm_strided_batch(vm_float_t* C, int ldc, int strideC, const vm_float_t* A, int lda, int strideA, const vm_float_t* B, int ldb, int strideB, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int batch)
Strided batched GEMM: problems live strideX elements apart.
void vm_gemm_ex(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int op, const vm_float_t* bias)
C = alpha * op(A) * op(B) + beta * C with optional fused epilogue.
auto vm_gemm_threads(void) -> int
Resolve the GEMM worker-thread budget.
void vm_gemm_set_threads(int n)
Cap or force the GEMM worker-thread budget.
void vm_im2col(vm_float_t* col, int ld_col, const vm_float_t* img, int n, int c, int h, int w, int kh, int kw, int pad_h, int pad_w, int stride_h, int stride_w, vm_layout_t layout)
NCHW im2col into a GEMM-ready panel.
auto vm_mat_alloc(int rows, int cols) -> vm_mat
Allocates a new matrix with the specified dimensions.
void vm_mat_free(vm_mat* m)
Frees the memory allocated for a matrix and resets its state.
void vm_mat_zero(vm_mat* m)
Sets all elements of the matrix to zero.
auto vm_mat_get(const vm_mat* m, int r, int c) -> vm_float_t
Returns the value of the matrix element at the specified row and column.
void vm_mat_set(vm_mat* m, int r, int c, vm_float_t v)
Sets the element at the specified row and column in the matrix to the given value.
auto vm_mat_copy(vm_mat* dst, const vm_mat* src) -> bool
Copies the contents of one matrix to another.
auto vm_mat_det(const vm_mat* A) -> vm_float_t
Determinant of a square matrix via LU.
auto vm_mat_inverse(vm_mat* out, const vm_mat* A) -> bool
Inverse of a square matrix via LU.
auto vm_lu_factor(vm_mat* A, int* pivot, int* sign) -> bool
In-place LU factorization with partial pivoting.
auto vm_lu_solve(const vm_mat* LU, const int* pivot, const vm_float_t* b, vm_float_t* x) -> bool
Solves A x = b from a factored LU.
auto vm_qr_factor(vm_mat* A, vm_float_t* tau) -> bool
In-place Householder QR.
auto vm_qr_unpack(vm_mat* Q, vm_mat* R, const vm_mat* QR, const vm_float_t* tau) -> bool
Thin factors: Q is m x k, R is k x n, k = min(m, n).
auto vm_qr_solve(const vm_mat* QR, const vm_float_t* tau, const vm_float_t* b, vm_float_t* x) -> bool
Least-squares solve min ||A x - b|| from a factored QR.
auto vm_svd_factor(const vm_mat* A, vm_mat* U, vm_float_t* s, vm_mat* V) -> bool
Thin SVD A = U diag(s) V^T.
auto vm_chol_factor(vm_mat* A) -> bool
In-place dense Cholesky A = L Lᵀ (lower triangle overwritten).
auto vm_chol_solve(const vm_mat* L, const vm_float_t* b, vm_float_t* x) -> bool
Solve L Lᵀ x = b after vm_chol_factor.
void vm_spmat_init(vm_spmat* A)
Initialize a sparse matrix to empty.
void vm_spmat_free(vm_spmat* A)
Free sparse matrix storage and reset it.
auto vm_spmat_from_triplets(vm_spmat* A, int n, int nnz, const int* row, const int* col, const vm_float_t* val) -> bool
Build a square CSR matrix from unsorted (row, col, val) triplets.
void vm_spmv(vm_float_t* y, const vm_spmat* A, const vm_float_t* x)
Sparse matrix–vector product y = A x.
auto vm_spmat_diag(const vm_spmat* A, vm_float_t* d) -> bool
Extract the main diagonal of A into d.
auto vm_cg(const vm_spmat* A, const vm_float_t* b, vm_float_t* x, vm_float_t tol, int max_iter, vm_ksp_prec_t pre_cond, vm_ksp_info* info) -> bool
Conjugate gradient for SPD A x = b.
auto vm_bicgstab(const vm_spmat* A, const vm_float_t* b, vm_float_t* x, vm_float_t tol, int max_iter, vm_ksp_prec_t pre_cond, vm_ksp_info* info) -> bool
BiCGSTAB for general (possibly nonsymmetric) A x = b.
void vm_euler_semi(vm_float_t* x, vm_float_t* v, const vm_float_t* a, int n, vm_float_t dt)
Semi-implicit Euler: v += a dt, then x += v dt.
void vm_verlet(vm_acc_fn acc, vm_float_t* x, vm_float_t* v, vm_float_t* a, int n, vm_float_t dt, void* ctx)
Velocity Verlet with an acceleration callback.
void vm_rk2(vm_ode_fn f, vm_float_t* y, int n, vm_float_t dt, void* ctx)
Explicit midpoint RK2 for y' = f(y).
void vm_rk4(vm_ode_fn f, vm_float_t* y, int n, vm_float_t dt, void* ctx)
Classic RK4 for y' = f(y).
auto vm_cfl_dt(vm_float_t cfl, vm_float_t dx, vm_float_t speed) -> vm_float_t
CFL timestep dt = cfl * dx / (|u| + ε).
auto mat3_chol(matrix3 a, matrix3* L) -> bool
3×3 Cholesky A = L Lᵀ.
auto mat3_spd_solve(matrix3 a, vector3 b, vector3* x) -> bool
Solve the 3×3 SPD system A x = b via Cholesky.
auto vm_inertia_world(matrix3 ib, quaternion q) -> matrix3
World-frame inertia I_w = R I_b Rᵀ from a body tensor and orientation.
auto vm_omega_from_angmom(matrix3 I, vector3 L) -> vector3
Recover ω from angular momentum L = I ω.
auto vm_rigid_energy(vm_float_t mass, vector3 v, matrix3 I, vector3 w) -> vm_float_t
Rigid kinetic energy ½ m |v|² + ½ ω · (I ω).
void vm_rigid_step(vector3* x, vector3* v, quaternion* q, vector3* w, vector3 F, vector3 tau, vm_float_t mass, matrix3 I_body, vm_float_t dt)
One symplectic-Euler rigid step.
void vm_baumgarte_correct(vector3* x, vector3* v, vector3 n, vm_float_t C, vm_float_t beta, vm_float_t gamma, vm_float_t dt)
Single-constraint Baumgarte correction along a unit normal.
auto vm_grid3_make(int nx, int ny, int nz, vm_float_t dx, vm_float_t dy, vm_float_t dz) -> vm_grid3
Build a 3-D grid descriptor.
auto vm_grid_ncells(vm_grid3 g) -> int
Returns the total number of cells in the grid.
auto vm_grid_cell(vm_grid3 g, int i, int j, int k) -> int
Compute linear index of a cell in a 3-D grid stored in row-major order.
auto vm_mac_nu(vm_grid3 g) -> int
Returns the number of u-velocity MAC face values for the grid.
auto vm_mac_nv(vm_grid3 g) -> int
Returns the number of MAC grid v-velocity components.
auto vm_mac_nw(vm_grid3 g) -> int
Returns the number of MAC grid faces in the z (vertical) direction.
auto vm_mac_u(vm_grid3 g, int i, int j, int k) -> int
Compute linear index of u-velocity on MAC grid.
auto vm_mac_v(vm_grid3 g, int i, int j, int k) -> int
Computes the linear index for the v-component of a MAC grid velocity.
auto vm_mac_w(vm_grid3 g, int i, int j, int k) -> int
Compute linear index of MAC grid w-component at cell (i,j,k).
auto vm_grid_laplacian(vm_spmat* A, vm_grid3 g, vm_bc_t bc) -> bool
Assemble the SPD operator -∇² on a cell-centered grid.
void vm_mac_div(vm_float_t* div, const vm_float_t* u, const vm_float_t* v, const vm_float_t* w, vm_grid3 g)
Cell-centered divergence of a MAC velocity field.
void vm_mac_grad(vm_float_t* gu, vm_float_t* gv, vm_float_t* gw, const vm_float_t* p, vm_grid3 g)
MAC face gradient of a cell-centered scalar (pressure).
void vm_mac_curl_z(vm_float_t* cz, const vm_float_t* u, const vm_float_t* v, vm_grid3 g)
Cell-centered z-vorticity (∂v/∂x − ∂u/∂y) from MAC u, v.
auto vec2(vm_float_t x, vm_float_t y) -> vector2
Constructs a vector2 from x and y.
void vec2_assign(vector2* dest, const vector2* src)
Copies src into dest.
void vec2_assign_xy(vector2* dest, vm_float_t x, vm_float_t y)
Assigns x and y to dest.
void vec2_add_assign(vector2* dest, const vector2* src)
Adds src to dest in place.
auto vec3(vm_float_t x, vm_float_t y, vm_float_t z) -> vector3
Constructs a vector3 from x, y, and z.
void vec3_assign(vector3* dest, const vector3* src)
Copies src into dest.
void vec3_assign_xyz(vector3* dest, vm_float_t x, vm_float_t y, vm_float_t z)
Assigns x, y, and z to dest.
void vec3_add_assign(vector3* dest, const vector3* src)
Adds src to dest in place.
auto vec2i(vm_int_t x, vm_int_t y) -> vector2i
Constructs a vector2i from x and y.
void vec2i_assign(vector2i* dest, const vector2i* src)
Copies src into dest.
void vec2i_assign_xy(vector2i* dest, vm_int_t x, vm_int_t y)
Assigns x and y to dest.
void vec2i_add_assign(vector2i* dest, const vector2i* src)
Adds src to dest in place.
auto vec3i(vm_int_t x, vm_int_t y, vm_int_t z) -> vector3i
Constructs a vector3i from x, y, and z.
void vec3i_assign(vector3i* dest, const vector3i* src)
Copies src into dest.
void vec3i_assign_xyz(vector3i* dest, vm_int_t x, vm_int_t y, vm_int_t z)
Assigns x, y, and z to dest.
void vec3i_add_assign(vector3i* dest, const vector3i* src)
Adds src to dest in place.
auto vec2_eq(vector2 a, vector2 b) -> bool
Returns true if two vectors are equal within VECMAT_EPSILON.
auto vec3_eq(vector3 a, vector3 b) -> bool
Returns true if two vectors are equal within VECMAT_EPSILON.
auto vec4_eq(vector4 a, vector4 b) -> bool
Returns true if two vectors are equal within VECMAT_EPSILON.
auto vec2i_eq(vector2i a, vector2i b) -> bool
Returns true if two vectors are exactly equal.
auto vec3i_eq(vector3i a, vector3i b) -> bool
Returns true if two vectors are exactly equal.
auto vec4i_eq(vector4i a, vector4i b) -> bool
Returns true if two vectors are exactly equal.
auto mat2_eq(matrix2 a, matrix2 b) -> bool
Returns true if two matrices are equal within VECMAT_EPSILON.
auto mat3_eq(matrix3 a, matrix3 b) -> bool
Returns true if two matrices are equal within VECMAT_EPSILON.
auto mat4_eq(matrix4 a, matrix4 b) -> bool
Returns true if two matrices are equal within VECMAT_EPSILON.
auto mat2i_eq(matrix2i a, matrix2i b) -> bool
Returns true if two matrices are exactly equal.
auto mat3i_eq(matrix3i a, matrix3i b) -> bool
Returns true if two matrices are exactly equal.
auto mat4i_eq(matrix4i a, matrix4i b) -> bool
Returns true if two matrices are exactly equal.
auto quat_eq(quaternion a, quaternion b) -> bool
Returns true if two quaternions are equal within VECMAT_EPSILON.
auto elastic_oscillation(vm_float_t f, vm_float_t exp_mult, vm_float_t sin_mult, vm_float_t sin_offset, vm_float_t period) -> vm_float_t
Damped sine used by the elastic easing curves.
auto poly_ease_in(vm_float_t f, vm_float_t n) -> vm_float_t
Polynomial ease-in: f^n.
auto poly_ease_out(vm_float_t f, vm_float_t n) -> vm_float_t
Polynomial ease-out: 1 - (1-f)^n.
auto poly_ease_in_out(vm_float_t f, vm_float_t n) -> vm_float_t
Polynomial ease-in-out of degree n.
auto quadratic_ease_out(vm_float_t f) -> vm_float_t
Quadratic ease-out.
auto quadratic_ease_in(vm_float_t f) -> vm_float_t
Quadratic ease-in.
auto quadratic_ease_in_out(vm_float_t f) -> vm_float_t
Quadratic ease-in-out.
auto cubic_ease_out(vm_float_t f) -> vm_float_t
Cubic ease-out.
auto cubic_ease_in(vm_float_t f) -> vm_float_t
Cubic ease-in.
auto cubic_ease_in_out(vm_float_t f) -> vm_float_t
Cubic ease-in-out.
auto quartic_ease_out(vm_float_t f) -> vm_float_t
Quartic ease-out.
auto quartic_ease_in(vm_float_t f) -> vm_float_t
Quartic ease-in.
auto quartic_ease_in_out(vm_float_t f) -> vm_float_t
Quartic ease-in-out.
auto quintic_ease_out(vm_float_t f) -> vm_float_t
Quintic ease-out.
auto quintic_ease_in(vm_float_t f) -> vm_float_t
Quintic ease-in.
auto quintic_ease_in_out(vm_float_t f) -> vm_float_t
Quintic ease-in-out.
auto sine_ease_out(vm_float_t f) -> vm_float_t
Sinusoidal ease-out.
auto sine_ease_in(vm_float_t f) -> vm_float_t
Sinusoidal ease-in.
auto sine_ease_in_out(vm_float_t f) -> vm_float_t
Sinusoidal ease-in-out.
auto circular_ease_out(vm_float_t f) -> vm_float_t
Circular ease-out.
auto circular_ease_in(vm_float_t f) -> vm_float_t
Circular ease-in.
auto circular_ease_in_out(vm_float_t f) -> vm_float_t
Circular ease-in-out.
auto exponential_ease_out(vm_float_t f) -> vm_float_t
Exponential ease-out.
auto exponential_ease_in(vm_float_t f) -> vm_float_t
Exponential ease-in.
auto exponential_ease_in_out(vm_float_t f) -> vm_float_t
Exponential ease-in-out.
auto elastic_ease_out(vm_float_t f) -> vm_float_t
Elastic ease-out.
auto elastic_ease_in(vm_float_t f) -> vm_float_t
Elastic ease-in.
auto elastic_ease_in_out(vm_float_t f) -> vm_float_t
Elastic ease-in-out.
auto back_ease_out(vm_float_t f) -> vm_float_t
Overshooting "back" ease-out.
auto back_ease_in(vm_float_t f) -> vm_float_t
Overshooting "back" ease-in.
auto back_ease_in_out(vm_float_t f) -> vm_float_t
Overshooting "back" ease-in-out.
auto bounce_ease_out(vm_float_t f) -> vm_float_t
Bounce ease-out.
auto bounce_ease_in(vm_float_t f) -> vm_float_t
Bounce ease-in.
auto bounce_ease_in_out(vm_float_t f) -> vm_float_t
Bounce ease-in-out.

Variables

static const float VM_DEG_TO_RAD_F32
static const float VM_RAD_TO_DEG_F32
static const double VM_DEG_TO_RAD_F64
static const double VM_RAD_TO_DEG_F64
static const vm_float_t VM_DEG_TO_RAD
static const vm_float_t VM_RAD_TO_DEG

Defines

#define VECMAT_VERSION_MAJOR
#define VECMAT_VERSION_MINOR
#define VECMAT_VERSION_PATCH
#define VECMAT_STR_HELPER(x)
#define VECMAT_STR(x)
#define VECMAT_VERSION
#define VEC_API
#define M_E
#define M_LOG2E
#define M_LOG10E
#define M_LN2
#define M_LN10
#define M_PI
#define M_PI_2
#define M_PI_4
#define M_1_PI
#define M_2_PI
#define M_2_SQRTPI
#define M_SQRT2
#define M_SQRT1_2
#define VECMAT_EPS_F32
#define VECMAT_EPS_F64
#define VECMAT_FLT_MAX
#define VECMAT_DBL_MAX
#define VECMAT_FLT_MIN
#define VECMAT_DBL_MIN
#define VECMAT_VEC2_SIZE
#define VECMAT_VEC3_SIZE
#define VECMAT_VEC4_SIZE
#define VECMAT_MAT2_SIZE
#define VECMAT_MAT3_SIZE
#define VECMAT_MAT4_SIZE
#define VECMAT_QUAT_SIZE
#define VM_F(x)
#define VM_DEG(d)
Angle literals in the library's native unit (radians).
#define VM_RAD(r)
#define VEC_INT_MAX
#define VEC_INT_MIN
#define VM_CLIP_OPENGL
#define VM_CLIP_VULKAN
#define VM_CLIP_DIRECTX
#define FLOAT_EQ(a, b, eps)
Checks if two floats are approximately equal within tolerance.
#define DOUBLE_EQ(a, b, eps)
Checks if two doubles are approximately equal within tolerance.
#define VECMAT_EPSILON
#define VECMAT_EQ(a, b, eps)
#define VECMAT_FABS(x)
#define VECMAT_SQRT(x)
#define VECMAT_SIN(x)
#define VECMAT_COS(x)
#define VECMAT_TAN(x)
#define VECMAT_ASIN(x)
#define VECMAT_ACOS(x)
#define VECMAT_ATAN(x)
#define VECMAT_ATAN2(y, x)
#define VECMAT_FMIN(a, b)
#define VECMAT_FMAX(a, b)
#define VECMAT_FLOOR(x)
#define VECMAT_CEIL(x)
#define VECMAT_ROUND(x)
#define VECMAT_POW(x, y)
#define VECMAT_COPYSIGN(x, y)

Enum documentation

enum vm_clip_t

Clip-space handedness and depth range for projection / look-at matrices.

Historic mat4_perspective / mat4_look_at / mat4_ortho stay OpenGL right-handed with z in [-1, 1] (VM_CLIP_RH_NO). Perspective FOV and rotation angles are in radians; use the _deg suffix for degrees.

Enumerators
VM_CLIP_RH_NO

OpenGL: right-handed, clip z in [-1, 1].

VM_CLIP_RH_ZO

Vulkan: right-handed, clip z in [0, 1].

VM_CLIP_LH_ZO

Direct3D: left-handed, clip z in [0, 1].

VM_CLIP_LH_NO

Left-handed, clip z in [-1, 1].

enum vm_layout_t

Memory layout for dense panels passed to vm_gemm and vm_mat.

Enumerators
VM_LAYOUT_COL_MAJOR

Element (r, c) at data[r + c * ld].

VM_LAYOUT_ROW_MAJOR

Element (r, c) at data[c + r * ld].

enum (anonymous)

Optional GEMM epilogue.

Flags may be OR-ed.

Bias is length N and broadcasts over rows: C(i, j) += bias[j]. ReLU is max(C, 0) after alpha/beta/bias.

Enumerators
VM_GEMM_OP_NONE

No epilogue.

VM_GEMM_OP_BIAS

Add per-column bias.

VM_GEMM_OP_RELU

Apply ReLU.

VM_GEMM_OP_BIAS_RELU

Bias then ReLU (BIAS | RELU).

enum vm_ksp_prec_t

Left preconditioner for the Krylov solvers.

IC0 is incomplete Cholesky with no fill. On breakdown the solver falls back to Jacobi for that call.

Enumerators
VM_KSP_PREC_NONE

No preconditioning.

VM_KSP_PREC_JACOBI

Diagonal (Jacobi) scaling.

VM_KSP_PREC_SSOR

Symmetric successive over-relaxation.

VM_KSP_PREC_IC0

Incomplete Cholesky, zero fill.

enum vm_bc_t

Boundary condition for assembled grid operators.

Dirichlet rows become the identity (rhs holds the boundary value). Homogeneous Neumann drops the missing neighbour; the 7-point Neumann Laplacian is singular (constant nullspace).

Enumerators
VM_BC_DIRICHLET

Fixed-value boundary (identity rows).

VM_BC_NEUMANN

Homogeneous Neumann (drop missing neighbour).

Function documentation

vm_cpu_features_t vm_cpu_compiled_features(void)

ISA bits compiled into this binary.

Returns Feature mask of enabled backends.

vm_cpu_features_t vm_cpu_runtime_features(void)

ISA bits detected on this CPU (cached).

Returns Feature mask of usable backends.

vm_cpu_features_t vm_cpu_selected_features(void)

Highest-priority ISA that is both compiled and present.

Returns Single selected feature bit (or scalar).

const char* vm_cpu_name(vm_cpu_features_t features)

Short name of the highest bit set in features.

Parameters
features Feature mask.
Returns Stable string such as avx2 or scalar.

vector2 vec2_add(vector2 a, vector2 b)

Adds two vectors component-wise.

Parameters
a The first vector.
b The second vector.
Returns The sum vector2.

vector2 vec2_sub(vector2 a, vector2 b)

Subtracts the second vector from the first component-wise.

Parameters
a The first vector.
b The second vector.
Returns The difference vector2.

vector2 vec2_mul_scalar(vector2 v, vm_float_t s)

Multiplies a vector by a scalar component-wise.

Parameters
v The input vector.
s The scalar multiplier.
Returns The scaled vector2.

vector2 vec2_div_scalar(vector2 v, vm_float_t s)

Divides a vector by a scalar component-wise.

Parameters
v The input vector.
s The scalar divisor (non-zero).
Returns The divided vector2.

vector2 vec2_mul(vector2 a, vector2 b)

Multiplies two vectors component-wise (Hadamard product).

Parameters
a The first vector.
b The second vector.
Returns The product vector2.

vector2 vec2_neg(vector2 v)

Negates the vector (multiplies each component by -1.0f).

Parameters
v The input vector.
Returns The negated vector2.

vector2 vec2_abs(vector2 v)

Returns the absolute values of each component.

Parameters
v The input vector.
Returns The absolute value vector2.

vector2 vec2_zero(void)

Returns a vector2 with both components set to 0.0f.

Returns The zero vector2.

vector2 vec2_one(void)

Returns a vector2 with both components set to 1.0f.

Returns The one vector2.

vector2 vec2_x_axis(vm_float_t x)

Returns a vector2 along the x-axis (y = 0.0f).

Parameters
x The x component value.
Returns The x-axis vector2.

vector2 vec2_y_axis(vm_float_t y)

Returns a vector2 along the y-axis (x = 0.0f).

Parameters
y The y component value.
Returns The y-axis vector2.

vector2 vec2_x_scale(vm_float_t x)

Returns a vector2 representing x-axis scaling (y = 1.0f).

Parameters
x The x scale factor.
Returns The x-scale vector2.

vector2 vec2_y_scale(vm_float_t y)

Returns a vector2 representing y-axis scaling (x = 1.0f).

Parameters
y The y scale factor.
Returns The y-scale vector2.

vector2 vec2_scale(vector2 v, vm_float_t s)

Scales a vector by a scalar component-wise.

Parameters
v The input vector.
s The scalar multiplier.
Returns The scaled vector2.

vector2 vec2_cross(vector2 a, vector2 b)

Computes the 2D cross-product as a vector.

Parameters
a The first vector.
b The second vector.
Returns The cross-product vector2.

vector2 vec2_normalize(vector2 v)

Normalizes the vector to unit length.

Parameters
v The input vector.
Returns The normalized vector2 (unchanged if zero length).

vector2 vec2_min(vector2 a, vector2 b)

Returns the component-wise minimum of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The minimum vector2.

vector2 vec2_max(vector2 a, vector2 b)

Returns the component-wise maximum of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The maximum vector2.

vector2 vec2_sign(vector2 v)

Returns the sign of each component (+1.0f, -1.0f, or 0.0f).

Parameters
v The input vector.
Returns The sign vector2.

vector2 vec2_floor(vector2 v)

Applies floor to each component.

Parameters
v The input vector.
Returns The floored vector2.

vector2 vec2_ceil(vector2 v)

Applies ceil to each component.

Parameters
v The input vector.
Returns The ceiled vector2.

vector2 vec2_round(vector2 v)

Applies round to each component.

Parameters
v The input vector.
Returns The rounded vector2.

vector2 vec2_perpendicular(vector2 v)

Returns the perpendicular vector (90 degrees counterclockwise).

Parameters
v The input vector.
Returns The perpendicular vector2.

vector2 vec2_reflect(vector2 v, vector2 normal)

Reflects vector v across the normal, storing the result in res.

Parameters
v The incident vector.
normal The unit normal vector.
Returns The reflected vector2.

vector2 vec2_project(vector2 a, vector2 b)

Projects the first vector onto the second.

Parameters
a The vector to project.
b The projection direction vector.
Returns The projected vector2.

vector2 vec2_tangent(vector2 v)

Returns the tangent vector perpendicular to the input (90 degrees clockwise).

Parameters
v The input vector.
Returns The tangent vector2.

vector2 vec2_rotate(vector2 v, vm_float_t radians)

Rotates the input vector counterclockwise by the given angle (radians).

Parameters
v The input vector.
radians The rotation angle in radians.
Returns The rotated vector2.

vector2 vec2_rotate_deg(vector2 v, vm_float_t degrees)

Rotates a vector2 by the given angle in degrees.

Parameters
v The vector2 to rotate.
degrees The rotation angle in degrees.
Returns The rotated vector2.

vector2 vec2_slide(vector2 v, vector2 normal)

Slides the input vector tangent to the normal (removes normal component).

Parameters
v The input vector.
normal The unit normal vector.
Returns The slid vector2.

vector2 vec2_clamp(vector2 v, vector2 min, vector2 max)

Clamps vector v component-wise between min and max.

Parameters
v The input vector.
min The minimum bounds vector.
max The maximum bounds vector.
Returns The clamped vector2.

vector2 vec2_lerp(vector2 a, vector2 b, vm_float_t t)

Linearly interpolates from a to b by t.

Parameters
a First input vector.
b Second input vector.
t Interpolation factor.
Returns The resulting vector2.

vector2 vec2_div(vector2 a, vector2 b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector2.

vector2 vec2_add_scalar(vector2 v, vm_float_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector2.

vector2 vec2_sub_scalar(vector2 v, vm_float_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector2.

vector2 vec2_clamp_scalar(vector2 v, vm_float_t min, vm_float_t max)

Clamps each component to the scalar range [min, max].

Parameters
v Input vector.
min Lower bound.
max Upper bound.
Returns The resulting vector2.

vector2 vec2_saturate(vector2 v)

Clamps each component to the range [0, 1].

Parameters
v Input vector.
Returns The resulting vector2.

vector2 vec2_fract(vector2 v)

Returns the fractional part of each component.

Parameters
v Input vector.
Returns The resulting vector2.

vector2 vec2_refract(vector2 incident, vector2 normal, vm_float_t eta)

Computes the refraction of incident across normal with ratio eta.

Parameters
incident Incident vector.
normal Surface normal.
eta Ratio of indices of refraction.
Returns The resulting vector2.

vector2 vec2_reject(vector2 a, vector2 b)

Returns the component of a orthogonal to b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector2.

vector2 vec2_splat(vm_float_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector2.

vector2 vec2_from_angle(vm_float_t radians)

Returns the unit vector at the given angle in radians.

Parameters
radians Angle in radians.
Returns The resulting vector2.

vector2 vec2_from_angle_deg(vm_float_t degrees)

Creates a vector2 from an angle given in degrees.

Parameters
degrees The angle in degrees.
Returns A unit vector2 representing the given angle.

The resulting vector has unit length and points in the direction specified by the angle. The angle is converted to radians internally before computing the cosine and sine.

vector2 vec2_rotate_around(vector2 v, vector2 pivot, vm_float_t radians)

Rotates v around pivot by angle radians.

Parameters
v Input vector.
pivot Rotation pivot.
radians Angle in radians.
Returns The resulting vector2.

vector2 vec2_rotate_around_deg(vector2 v, vector2 pivot, vm_float_t degrees)

Rotates a vector2 around a pivot point by the given angle in degrees.

Parameters
v The vector2 to rotate.
pivot The vector2 to rotate around.
degrees The rotation angle in degrees.
Returns The rotated vector2.

vector2 vec2_move_toward(vector2 current, vector2 target, vm_float_t max_delta)

Moves current toward target by at most max_delta.

Parameters
current Current position.
target Target position.
max_delta Maximum distance to move.
Returns The resulting vector2.

vector2 vec2_limit_length(vector2 v, vm_float_t max_len)

Clamps the vector length to max_len.

Parameters
v Input vector.
max_len Maximum length.
Returns The resulting vector2.

vector3 vec2_to_vec3(vector2 v, vm_float_t z)

Converts a vector2 to a vector3 using z.

Parameters
v Input vector.
z Z component.
Returns The resulting vector3.

vm_float_t vec2_dot(vector2 a, vector2 b)

Computes the dot product of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The dot product scalar.

vm_float_t vec2_length(vector2 v)

Computes the length (magnitude) of the vector.

Parameters
v The input vector.
Returns The length scalar.

vm_float_t vec2_length_squared(vector2 v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_length_manhattan(vector2 v)

Returns the Manhattan (L1) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_length_chebyshev(vector2 v)

Returns the Chebyshev (L-inf) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_aspect_ratio(vector2 v)

Computes the aspect ratio of the vector (x / y).

Parameters
v The input vector.
Returns The aspect ratio scalar.

Returns 0.0f if y == 0.0f.

vm_float_t vec2_distance(vector2 a, vector2 b)

Computes the Euclidean distance between two vectors (treated as points).

Parameters
a The first point.
b The second point.
Returns The distance scalar.

vm_float_t vec2_distance_squared(vector2 a, vector2 b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_float_t vec2_angle(vector2 a, vector2 b)

Computes the angle between two vectors (in radians, range [0, PI]).

Parameters
a The first vector.
b The second vector.
Returns The angle scalar.

Returns 0.0f if either vector has zero length.

vm_float_t vec2_cross_scalar(vector2 a, vector2 b)

Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_float_t vec2_heading(vector2 v)

Returns the heading angle of the vector in radians.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_heading_deg(vector2 v)

Returns the heading angle of the vector in degrees.

Parameters
v The vector2 whose heading is to be calculated.
Returns The heading angle of the vector in degrees.

Computes the angle between the positive x-axis and the vector using atan2, then converts the result from radians to degrees.

vm_float_t vec2_min_component(vector2 v)

Returns the smallest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_max_component(vector2 v)

Returns the largest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2_sum(vector2 v)

Returns the sum of all components.

Parameters
v Input vector.
Returns The resulting scalar.

bool vec2_is_zero(vector2 v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

bool vec2_is_normalized(vector2 v)

Returns true if the vector has unit length.

Parameters
v Input vector.
Returns True if the vector has unit length.

bool vec2_near(vector2 a, vector2 b, vm_float_t eps)

Returns true if a and b are within eps of each other.

Parameters
a First input vector.
b Second input vector.
eps Distance tolerance.
Returns True if a and b are within eps.

vector3 vec3_add(vector3 a, vector3 b)

Component-wise addition of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3 vec3_sub(vector3 a, vector3 b)

Component-wise subtraction of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3 vec3_mul_scalar(vector3 v, vm_float_t s)

Component-wise multiplication of vector by scalar.

Parameters
v The vector.
s The scalar.
Returns Result vector.

vector3 vec3_div_scalar(vector3 v, vm_float_t s)

Component-wise division of vector by scalar.

Parameters
v The vector.
s The scalar (non-zero).
Returns Result vector.

vector3 vec3_mul(vector3 a, vector3 b)

Component-wise multiplication of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3 vec3_neg(vector3 v)

Negation of a vector.

Parameters
v The vector.
Returns The negated vector.

vector3 vec3_abs(vector3 v)

Computes the absolute value per component of a vector3.

Parameters
v The vector.
Returns The absolute vector3.

vector3 vec3_zero(void)

Returns a zero-initialized vector3.

Returns A vector3 with all components set to 0.0f.

vector3 vec3_one(void)

Returns a vector3 with all components set to 1.0f.

Returns A vector3 with all components set to 1.0f.

vector3 vec3_x_axis(vm_float_t x)

Returns a vector3 along the x-axis.

Parameters
x The x component value.
Returns A vector3 with (x, 0.0f, 0.0f).

vector3 vec3_y_axis(vm_float_t y)

Returns a vector3 along the y-axis.

Parameters
y The y component value.
Returns A vector3 with (0.0f, y, 0.0f).

vector3 vec3_z_axis(vm_float_t z)

Returns a vector3 along the z-axis.

Parameters
z The z component value.
Returns A vector3 with (0.0f, 0.0f, z).

vector3 vec3_x_scale(vm_float_t x)

Returns a vector3 for scaling along the x-axis.

Parameters
x The x scale factor.
Returns A vector3 with (x, 1.0f, 1.0f).

vector3 vec3_y_scale(vm_float_t y)

Returns a vector3 for scaling along the y-axis.

Parameters
y The y scale factor.
Returns A vector3 with (1.0f, y, 1.0f).

vector3 vec3_z_scale(vm_float_t z)

Returns a vector3 for scaling along the z-axis.

Parameters
z The z scale factor.
Returns A vector3 with (1.0f, 1.0f, z).

vector3 vec3_cross(vector3 a, vector3 b)

Computes the cross-product of two vector3.

Parameters
a First vector.
b Second vector.
Returns The cross-product (a × b).

vector3 vec3_normalize(vector3 v)

Normalizes a vector3 to unit length.

Parameters
v The vector (non-zero).
Returns The normalized vector.

vector3 vec3_min(vector3 a, vector3 b)

Computes the component-wise minimum of two vector3.

Parameters
a First vector.
b Second vector.
Returns Per-component min(a, b).

vector3 vec3_max(vector3 a, vector3 b)

Computes the component-wise maximum of two vector3.

Parameters
a First vector.
b Second vector.
Returns Per-component max(a, b).

vector3 vec3_sign(vector3 v)

Computes the sign per component of a vector3 (-1, 0, or 1).

Parameters
v The vector.
Returns The sign vector.

vector3 vec3_floor(vector3 v)

Applies the floor per component to a vector3.

Parameters
v The vector.
Returns The floored vector.

vector3 vec3_ceil(vector3 v)

Applies ceil per component to a vector3.

Parameters
v The vector.
Returns The ceiling vector.

vector3 vec3_round(vector3 v)

Applies round per component to a vector3.

Parameters
v The vector.
Returns The rounded vector.

vector3 vec3_reflect(vector3 incident, vector3 normal)

Reflects an incident vector over normal.

Parameters
incident The incident vector.
normal The surface normal.
Returns The reflected vector.

vector3 vec3_refract(vector3 incident, vector3 normal, vm_float_t eta)

Refracts an incident vector across an interface with a given normal and ratio of refraction eta.

Parameters
incident The incident vector.
normal The surface normal.
eta The ratio of refraction (eta = n1 / n2).
Returns The refracted vector, or incident if total internal reflection.

vector3 vec3_lerp(vector3 a, vector3 b, vm_float_t t)

Linearly interpolates between two vector3.

Parameters
a Start vector.
b End vector.
t Interpolation factor [0, 1].
Returns The interpolated vector (a * (1 - t) + b * t).

vector3 vec3_clamp(vector3 v, vector3 min, vector3 max)

Clamps a vector3 between min and max per component.

Parameters
v The vector.
min Minimum bounds.
max Maximum bounds.
Returns The clamped vector.

vector3 vec3_scale(vector3 v, vm_float_t s)

Scales the vector by a scalar.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector3.

vector3 vec3_div(vector3 a, vector3 b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3.

vector3 vec3_add_scalar(vector3 v, vm_float_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector3.

vector3 vec3_sub_scalar(vector3 v, vm_float_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector3.

vector3 vec3_clamp_scalar(vector3 v, vm_float_t min, vm_float_t max)

Clamps each component to the scalar range [min, max].

Parameters
v Input vector.
min Lower bound.
max Upper bound.
Returns The resulting vector3.

vector3 vec3_saturate(vector3 v)

Clamps each component to the range [0, 1].

Parameters
v Input vector.
Returns The resulting vector3.

vector3 vec3_fract(vector3 v)

Returns the fractional part of each component.

Parameters
v Input vector.
Returns The resulting vector3.

vector3 vec3_project(vector3 a, vector3 b)

Projects a onto b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3.

vector3 vec3_slide(vector3 v, vector3 normal)

Removes the component of v along normal.

Parameters
v Input vector.
normal Surface normal.
Returns The resulting vector3.

vector3 vec3_reject(vector3 a, vector3 b)

Returns the component of a orthogonal to b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3.

vector3 vec3_rotate_axis(vector3 v, vector3 axis, vm_float_t radians)

Rotates v around axis by angle radians.

Parameters
v Input vector.
axis Rotation axis.
radians Angle in radians.
Returns The resulting vector3.

vector3 vec3_rotate_axis_deg(vector3 v, vector3 axis, vm_float_t degrees)

Rotates a vector around an arbitrary axis by a given angle in degrees.

Parameters
v The vector to rotate.
axis The axis of rotation. The axis vector is assumed to be normalized.
degrees The rotation angle in degrees.
Returns The rotated vector.

This is a convenience wrapper that converts degrees to radians and delegates to vec3_rotate_axis.

vector3 vec3_splat(vm_float_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector3.

vector3 vec3_from_vec2(vector2 v, vm_float_t z)

Builds a vector3 from a vector2 and z.

Parameters
v Input vector.
z Z component.
Returns The resulting vector3.

vector3 vec3_move_toward(vector3 current, vector3 target, vm_float_t max_delta)

Moves current toward target by at most max_delta.

Parameters
current Current position.
target Target position.
max_delta Maximum distance to move.
Returns The resulting vector3.

vector3 vec3_limit_length(vector3 v, vm_float_t max_len)

Clamps the vector length to max_len.

Parameters
v Input vector.
max_len Maximum length.
Returns The resulting vector3.

vector2 vec3_xy(vector3 v)

Returns the x and y components as a 2D vector.

Parameters
v Input vector.
Returns The resulting vector2.

void vec3_orthonormal_basis(vector3 n, vector3* t, vector3* b)

Builds a tangent and bitangent orthonormal to n.

Parameters
n Unit normal.
t Output tangent.
b Output bitangent.

vm_float_t vec3_dot(vector3 a, vector3 b)

Computes the dot product of two vector3.

Parameters
a First vector.
b Second vector.
Returns The dot product (a.x * b.x + a.y * b.y + a.z * b.z).

vm_float_t vec3_length(vector3 v)

Computes the length (magnitude) of a vector3.

Parameters
v The vector.
Returns The Euclidean length of v.

vm_float_t vec3_length_squared(vector3 v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3_length_manhattan(vector3 v)

Returns the Manhattan (L1) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3_length_chebyshev(vector3 v)

Returns the Chebyshev (L-inf) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3_distance(vector3 a, vector3 b)

Computes the Euclidean distance between two vector3.

Parameters
a First vector.
b Second vector.
Returns The distance between a and b.

vm_float_t vec3_distance_squared(vector3 a, vector3 b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_float_t vec3_angle(vector3 a, vector3 b)

Computes the angle between two non-zero vector3 in radians.

Parameters
a First vector.
b Second vector.
Returns The angle between the directions of a and b.

vm_float_t vec3_signed_angle(vector3 a, vector3 b, vector3 axis)

Returns the signed angle from a to b around axis.

Parameters
a First input vector.
b Second input vector.
axis Rotation axis.
Returns The resulting scalar.

vm_float_t vec3_min_component(vector3 v)

Returns the smallest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3_max_component(vector3 v)

Returns the largest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3_sum(vector3 v)

Returns the sum of all components.

Parameters
v Input vector.
Returns The resulting scalar.

bool vec3_is_zero(vector3 v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

bool vec3_is_normalized(vector3 v)

Returns true if the vector has unit length.

Parameters
v Input vector.
Returns True if the vector has unit length.

bool vec3_near(vector3 a, vector3 b, vm_float_t eps)

Returns true if a and b are within eps of each other.

Parameters
a First input vector.
b Second input vector.
eps Distance tolerance.
Returns True if a and b are within eps.

vector4 vec4_add(vector4 a, vector4 b)

Component-wise addition of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4 vec4_sub(vector4 a, vector4 b)

Component-wise subtraction of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4 vec4_mul_scalar(vector4 v, vm_float_t s)

Component-wise multiplication of vector by scalar.

Parameters
v The vector.
s The scalar.
Returns Result vector.

vector4 vec4_div_scalar(vector4 v, vm_float_t s)

Component-wise division of vector by scalar.

Parameters
v The vector.
s The scalar (non-zero).
Returns Result vector.

vector4 vec4_mul(vector4 a, vector4 b)

Component-wise multiplication of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4 vec4_neg(vector4 v)

Negation of a vector.

Parameters
v The vector.
Returns The negated vector.

vector4 vec4_abs(vector4 v)

Computes the absolute value per component of a vector4.

Parameters
v The vector.
Returns The absolute vector4.

vector4 vec4_zero(void)

Returns a zero-initialized vector4.

Returns A vector4 with all components set to 0.0f.

vector4 vec4_one(void)

Returns a vector4 with all components set to 1.0f.

Returns A vector4 with all components set to 1.0f.

vector4 vec4_x_axis(vm_float_t x)

Returns a vector4 along the x-axis.

Parameters
x The x component value.
Returns A vector4 with (x, 0.0f, 0.0f, 0.0f).

vector4 vec4_y_axis(vm_float_t y)

Returns a vector4 along the y-axis.

Parameters
y The y component value.
Returns A vector4 with (0.0f, y, 0.0f, 0.0f).

vector4 vec4_z_axis(vm_float_t z)

Returns a vector4 along the z-axis.

Parameters
z The z component value.
Returns A vector4 with (0.0f, 0.0f, z, 0.0f).

vector4 vec4_w_axis(vm_float_t w)

Returns a vector4 along the w-axis.

Parameters
w The w component value.
Returns A vector4 with (0.0f, 0.0f, 0.0f, w).

vector4 vec4_x_scale(vm_float_t x)

Returns avector4 for scaling along the x-axis.

Parameters
x The x scale factor.
Returns A vector4 with (x, 1.0f, 1.0f, 1.0f).

vector4 vec4_y_scale(vm_float_t y)

Returns a vector4 for scaling along the y-axis.

Parameters
y The y scale factor.
Returns A vector4 with (1.0f, y, 1.0f, 1.0f).

vector4 vec4_z_scale(vm_float_t z)

Returns a vector4for scaling along the z-axis.

Parameters
z The z scale factor.
Returns A vector4 with (1.0f, 1.0f, z, 1.0f).

vector4 vec4_w_scale(vm_float_t w)

Returns a vector4 for scaling along the w-axis.

Parameters
w The w scale factor.
Returns A vector4 with (1.0f, 1.0f, 1.0f, w).

vector4 vec4_normalize(vector4 v)

Normalizes a vector4 to unit length.

Parameters
v The vector (non-zero).
Returns The normalized vector.

vector4 vec4_min(vector4 a, vector4 b)

Computes the component-wise minimum of two vector4.

Parameters
a First vector.
b Second vector.
Returns Per-component min(a, b).

vector4 vec4_max(vector4 a, vector4 b)

Computes the component-wise maximum of two vector4.

Parameters
a First vector.
b Second vector.
Returns Per-component max(a, b).

vector4 vec4_sign(vector4 v)

Computes the sign per component of a vector4 (-1, 0, or 1).

Parameters
v The vector.
Returns The sign vector.

vector4 vec4_floor(vector4 v)

Applies the floor per component to a vector4.

Parameters
v The vector.
Returns The floored vector.

vector4 vec4_ceil(vector4 v)

Applies ceil per component to a vector4.

Parameters
v The vector.
Returns The ceiling vector.

vector4 vec4_round(vector4 v)

Applies round per component to a vector4.

Parameters
v The vector.
Returns The rounded vector.

vector4 vec4_lerp(vector4 a, vector4 b, vm_float_t t)

Linearly interpolates between two vector4.

Parameters
a Start vector.
b End vector.
t Interpolation factor [0, 1].
Returns The interpolated vector (a * (1 - t) + b * t).

vector4 vec4_clamp(vector4 v, vector4 min, vector4 max)

Clamps a vector4 between min and max per component.

Parameters
v The vector.
min Minimum bounds.
max Maximum bounds.
Returns The clamped vector.

vector4 vec4_homogenize(vector4 v)

Homogenizes a vector4 (divides x, y, z by w).

Parameters
v The homogeneous vector (w != 0.0f).
Returns The normalized cartesian vector4.

vector4 vec4_div(vector4 a, vector4 b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4.

vector4 vec4_add_scalar(vector4 v, vm_float_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector4.

vector4 vec4_sub_scalar(vector4 v, vm_float_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector4.

vector4 vec4_clamp_scalar(vector4 v, vm_float_t min, vm_float_t max)

Clamps each component to the scalar range [min, max].

Parameters
v Input vector.
min Lower bound.
max Upper bound.
Returns The resulting vector4.

vector4 vec4_saturate(vector4 v)

Clamps each component to the range [0, 1].

Parameters
v Input vector.
Returns The resulting vector4.

vector4 vec4_fract(vector4 v)

Returns the fractional part of each component.

Parameters
v Input vector.
Returns The resulting vector4.

vector4 vec4_project(vector4 a, vector4 b)

Projects a onto b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4.

vector4 vec4_reject(vector4 a, vector4 b)

Returns the component of a orthogonal to b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4.

vector4 vec4_slide(vector4 v, vector4 normal)

Removes the component of v along normal.

Parameters
v Input vector.
normal Surface normal.
Returns The resulting vector4.

vector4 vec4_splat(vm_float_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector4.

vector3 vec4_to_vec3(vector4 v)

Converts a vector4 to a vector3 (discards the w component).

Parameters
v The source vector4.
Returns A vector3 {v.x, v.y, v.z}.

vm_float_t vec4_dot(vector4 a, vector4 b)

Computes the dot product of two vector4.

Parameters
a First vector.
b Second vector.
Returns The dot product (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w).

vm_float_t vec4_length(vector4 v)

Computes the length (magnitude) of a vector4.

Parameters
v The vector.
Returns The Euclidean length of v.

vm_float_t vec4_length_squared(vector4 v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec4_distance(vector4 a, vector4 b)

Computes the Euclidean distance between two vector4.

Parameters
a First vector.
b Second vector.
Returns The distance between a and b.

vm_float_t vec4_distance_squared(vector4 a, vector4 b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

bool vec4_is_zero(vector4 v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

bool vec4_is_normalized(vector4 v)

Returns true if the vector has unit length.

Parameters
v Input vector.
Returns True if the vector has unit length.

bool vec4_near(vector4 a, vector4 b, vm_float_t eps)

Returns true if a and b are within eps of each other.

Parameters
a First input vector.
b Second input vector.
eps Distance tolerance.
Returns True if a and b are within eps.

void vec2_add_ptr(vector2* res, const vector2* a, const vector2* b)

Adds vectors a and b component-wise, storing the result in res.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_sub_ptr(vector2* res, const vector2* a, const vector2* b)

Subtracts vector b from vector a component-wise, storing the result in res.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_mul_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)

Multiplies vector v by scalar s component-wise, storing the result in res.

Parameters
res Output vector.
v Input vector.
s Input scalar.

void vec2_div_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)

Divides vector v by scalar s component-wise, storing the result in res.

Parameters
res Output vector.
v Input vector.
s Input scalar.

void vec2_mul_ptr(vector2* res, const vector2* a, const vector2* b)

Multiplies vectors a and b component-wise, storing the result in res.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_neg_ptr(vector2* res, const vector2* v)

Negates the components of vector v, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_abs_ptr(vector2* res, const vector2* v)

Computes the absolute values of the components of vector v, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_normalize_ptr(vector2* res, const vector2* v)

Normalizes vector v to unit length, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_min_ptr(vector2* res, const vector2* a, const vector2* b)

Computes the component-wise minimum of vectors a and b, storing the result in res.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_max_ptr(vector2* res, const vector2* a, const vector2* b)

Computes the component-wise maximum of vectors a and b, storing the result in res.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_sign_ptr(vector2* res, const vector2* v)

Sets each component of res to the sign of the corresponding component in v (+1, -1).

Parameters
res Output vector.
v Input vector.

void vec2_floor_ptr(vector2* res, const vector2* v)

Applies the floor function to each component of vector v, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_ceil_ptr(vector2* res, const vector2* v)

Applies the ceil function to each component of vector v, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_round_ptr(vector2* res, const vector2* v)

Applies the round function to each component of vector v, storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_perpendicular_ptr(vector2* res, const vector2* v)

Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.

Parameters
res Output vector.
v Input vector.

void vec2_scale_ptr(vector2* res, const vector2* v, vm_float_t s)

Scales a vector by a scalar component-wise, storing the result in res.

Parameters
res Output vector.
v Input vector.
s Input scalar.

void vec2_cross_ptr(vector2* res, const vector2* a, const vector2* b)

Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.

Parameters
res Output vector.
a Input vector a.
b Input vector b.

void vec2_reflect_ptr(vector2* res, const vector2* v, const vector2* normal)

Reflects vector v across the normal, storing the result in res.

Parameters
res Output vector.
v Input incident vector.
normal Input surface normal.

void vec2_project_ptr(vector2* res, const vector2* a, const vector2* b)

Projects vector a onto vector b (scalar projection scaled by b).

Parameters
res The output projected vector.
a The vector to project.
b The direction vector (non-zero length recommended).

void vec2_tangent_ptr(vector2* res, const vector2* v)

Computes a tangent vector perpendicular to the input (90 degrees clockwise).

Parameters
res The output tangent vector.
v The input vector.

Equivalent to (v.y, -v.x).

void vec2_rotate_ptr(vector2* result, const vector2* v, vm_float_t radians)

Rotates the input vector counterclockwise by the given angle (radians).

Parameters
result The output rotated vector.
v The input vector.
radians The rotation angle in radians.

Uses standard 2D rotation matrix.

void vec2_rotate_deg_ptr(vector2* result, const vector2* v, vm_float_t degrees)

Rotates vector v by the given angle in degrees, storing the result in result.

Parameters
result Output vector.
v Input vector.
degrees Rotation angle in degrees.

void vec2_slide_ptr(vector2* result, const vector2* v, const vector2* normal)

Slides the input vector tangent to the normal (removes normal component).

Parameters
result The output slid vector.
v The input vector.
normal The unit normal vector.

Formula: v - dot(v, normal) * normal (assumes unit normal).

void vec2_clamp_ptr(vector2* res, const vector2* v, const vector2* min, const vector2* max)

Clamps vector v component-wise between min and max.

Parameters
res Output vector.
v Input vector to clamp.
min Minimum bounds vector.
max Maximum bounds vector.

void vec2_lerp_ptr(vector2* res, const vector2* a, const vector2* b, vm_float_t t)

Linearly interpolates from a to b by t.

Parameters
res Output vector.
a First input vector.
b Second input vector.
t Interpolation factor.

void vec2_div_ptr(vector2* res, const vector2* a, const vector2* b)

Divides two vectors component-wise.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec2_add_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)

Adds a scalar to each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec2_sub_scalar_ptr(vector2* res, const vector2* v, vm_float_t s)

Subtracts a scalar from each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec2_clamp_scalar_ptr(vector2* res, const vector2* v, vm_float_t min, vm_float_t max)

Clamps each component to the scalar range [min, max].

Parameters
res Output vector.
v Input vector.
min Lower bound.
max Upper bound.

void vec2_saturate_ptr(vector2* res, const vector2* v)

Clamps each component to the range [0, 1].

Parameters
res Output vector.
v Input vector.

void vec2_fract_ptr(vector2* res, const vector2* v)

Returns the fractional part of each component.

Parameters
res Output vector.
v Input vector.

void vec2_refract_ptr(vector2* res, const vector2* incident, const vector2* normal, vm_float_t eta)

Computes the refraction of incident across normal with ratio eta.

Parameters
res Output vector.
incident Incident vector.
normal Surface normal.
eta Ratio of indices of refraction.

void vec2_reject_ptr(vector2* res, const vector2* a, const vector2* b)

Returns the component of a orthogonal to b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec2_rotate_around_ptr(vector2* res, const vector2* v, const vector2* pivot, vm_float_t radians)

Rotates v around pivot by angle radians.

Parameters
res Output vector.
v Input vector.
pivot Rotation pivot.
radians Angle in radians.

void vec2_rotate_around_deg_ptr(vector2* res, const vector2* v, const vector2* pivot, vm_float_t degrees)

Rotates vector v around the given pivot point by the specified angle in degrees.

Parameters
res Output vector storing the rotated result.
v Input vector to rotate.
pivot Pivot point around which to rotate.
degrees Rotation angle in degrees.

This function converts the input angle from degrees to radians and then delegates to the radian-based rotation routine.

void vec2_move_toward_ptr(vector2* res, const vector2* current, const vector2* target, vm_float_t max_delta)

Moves current toward target by at most max_delta.

Parameters
res Output vector.
current Current position.
target Target position.
max_delta Maximum distance to move.

void vec2_limit_length_ptr(vector2* res, const vector2* v, vm_float_t max_len)

Clamps the vector length to max_len.

Parameters
res Output vector.
v Input vector.
max_len Maximum length.

void vec2_to_vec3_ptr(vector3* res, const vector2* v, vm_float_t z)

Converts a vector2 to a vector3 with the given z.

Parameters
res Output vector.
v Input vector.
z Z component.

void vec3_add_ptr(vector3* res, const vector3* a, const vector3* b)

Component-wise addition of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_sub_ptr(vector3* res, const vector3* a, const vector3* b)

Component-wise subtraction of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_mul_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)

Component-wise multiplication of vector by scalar.

Parameters
res Result vector.
v Vector.
s Scalar.

void vec3_div_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)

Component-wise division of vector by scalar.

Parameters
res Result vector.
v Vector.
s Scalar.

void vec3_mul_ptr(vector3* res, const vector3* a, const vector3* b)

Component-wise multiplication of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_neg_ptr(vector3* res, const vector3* v)

Negation of a vector.

Parameters
res Result vector.
v Vector.

void vec3_abs_ptr(vector3* res, const vector3* v)

Computes the absolute value per component of a vector3.

Parameters
res Result vector.
v Vector.

void vec3_normalize_ptr(vector3* res, const vector3* v)

Normalize a vector to unit length.

Parameters
res Result vector.
v Vector.

void vec3_cross_ptr(vector3* res, const vector3* a, const vector3* b)

Compute cross-product of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_min_ptr(vector3* res, const vector3* a, const vector3* b)

Component-wise minimum of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_max_ptr(vector3* res, const vector3* a, const vector3* b)

Component-wise maximum of two vectors.

Parameters
res Result vector.
a First vector.
b Second vector.

void vec3_sign_ptr(vector3* res, const vector3* v)

Component-wise sign of a vector.

Parameters
res Result vector.
v Vector.

void vec3_floor_ptr(vector3* res, const vector3* v)

Component-wise floor of a vector.

Parameters
res Result vector.
v Vector.

void vec3_ceil_ptr(vector3* res, const vector3* v)

Component-wise ceil of a vector.

Parameters
res Result vector.
v Vector.

void vec3_round_ptr(vector3* res, const vector3* v)

Component-wise round of a vector.

Parameters
res Result vector.
v Vector.

void vec3_reflect_ptr(vector3* res, const vector3* incident, const vector3* normal)

Compute reflection of the incident vector over normal.

Parameters
res Result vector.
incident Incident vector.
normal Normal vector.

void vec3_refract_ptr(vector3* res, const vector3* incident, const vector3* normal, vm_float_t eta)

Compute refraction of the incident vector through normal with eta.

Parameters
res Result vector.
incident Incident vector.
normal Normal vector.
eta Refraction index ratio.

void vec3_lerp_ptr(vector3* res, const vector3* a, const vector3* b, vm_float_t t)

Linear interpolation between two vectors.

Parameters
res Result vector.
a Start vector.
b End vector.
t Interpolation factor.

void vec3_clamp_ptr(vector3* res, const vector3* v, const vector3* min, const vector3* max)

Clamp vector components between min and max.

Parameters
res Result vector.
v Vector.
min Minimum bounds.
max Maximum bounds.

void vec3_scale_ptr(vector3* res, const vector3* v, vm_float_t s)

Scales the vector by a scalar.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec3_div_ptr(vector3* res, const vector3* a, const vector3* b)

Divides two vectors component-wise.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3_add_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)

Adds a scalar to each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec3_sub_scalar_ptr(vector3* res, const vector3* v, vm_float_t s)

Subtracts a scalar from each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec3_clamp_scalar_ptr(vector3* res, const vector3* v, vm_float_t min, vm_float_t max)

Clamps each component to the scalar range [min, max].

Parameters
res Output vector.
v Input vector.
min Lower bound.
max Upper bound.

void vec3_saturate_ptr(vector3* res, const vector3* v)

Clamps each component to the range [0, 1].

Parameters
res Output vector.
v Input vector.

void vec3_fract_ptr(vector3* res, const vector3* v)

Returns the fractional part of each component.

Parameters
res Output vector.
v Input vector.

void vec3_project_ptr(vector3* res, const vector3* a, const vector3* b)

Projects a onto b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3_slide_ptr(vector3* res, const vector3* v, const vector3* normal)

Removes the component of v along normal.

Parameters
res Output vector.
v Input vector.
normal Surface normal.

void vec3_reject_ptr(vector3* res, const vector3* a, const vector3* b)

Returns the component of a orthogonal to b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3_rotate_axis_ptr(vector3* res, const vector3* v, const vector3* axis, vm_float_t radians)

Rotates v around axis by angle radians.

Parameters
res Output vector.
v Input vector.
axis Rotation axis.
radians Angle in radians.

void vec3_rotate_axis_deg_ptr(vector3* res, const vector3* v, const vector3* axis, vm_float_t degrees)

Component-wise rotation of a vector around an axis by a given angle in degrees.

Parameters
res Result vector.
v Vector to rotate.
axis Rotation axis.
degrees Angle in degrees.

void vec3_from_vec2_ptr(vector3* res, const vector2* v, vm_float_t z)

Builds a higher-dimension vector from a vector2.

Parameters
res Output vector.
v Input vector.
z Z component.

void vec3_xy_ptr(vector2* res, const vector3* v)

Returns the x and y components as a 2D vector.

Parameters
res Output vector.
v Input vector.

void vec3_move_toward_ptr(vector3* res, const vector3* current, const vector3* target, vm_float_t max_delta)

Moves current toward target by at most max_delta.

Parameters
res Output vector.
current Current position.
target Target position.
max_delta Maximum distance to move.

void vec3_limit_length_ptr(vector3* res, const vector3* v, vm_float_t max_len)

Clamps the vector length to max_len.

Parameters
res Output vector.
v Input vector.
max_len Maximum length.

void vec3_orthonormal_basis_ptr(const vector3* n, vector3* t, vector3* b)

Builds a tangent and bitangent orthonormal to n.

Parameters
n Unit normal.
t Output tangent.
b Output bitangent.

void vec4_add_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise addition (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_sub_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise subtraction (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_mul_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)

Multiplies a vector by a scalar (dispatched).

Parameters
res Result vector.
v Input vector.
s Scalar.

void vec4_div_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)

Divides a vector by a scalar (dispatched).

Parameters
res Result vector.
v Input vector.
s Scalar.

void vec4_mul_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise multiplication (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_neg_ptr(vector4* res, const vector4* v)

Negates a vector (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_abs_ptr(vector4* res, const vector4* v)

Component-wise absolute value (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_normalize_ptr(vector4* res, const vector4* v)

Normalizes a vector (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_min_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise minimum (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_max_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise maximum (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_sign_ptr(vector4* res, const vector4* v)

Component-wise sign (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_floor_ptr(vector4* res, const vector4* v)

Component-wise floor (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_ceil_ptr(vector4* res, const vector4* v)

Component-wise ceil (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_round_ptr(vector4* res, const vector4* v)

Component-wise round (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_lerp_ptr(vector4* res, const vector4* a, const vector4* b, vm_float_t t)

Linear interpolation (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.
t Interpolation factor.

void vec4_clamp_ptr(vector4* res, const vector4* v, const vector4* min, const vector4* max)

Component-wise clamp (dispatched).

Parameters
res Result vector.
v Input vector.
min Lower bound.
max Upper bound.

void vec4_homogenize_ptr(vector4* res, const vector4* v)

Divides xyz by w (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_div_ptr(vector4* res, const vector4* a, const vector4* b)

Component-wise division (dispatched).

Parameters
res Result vector.
a First vector.
b Second vector.

void vec4_add_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)

Adds a scalar to each component (dispatched).

Parameters
res Result vector.
v Input vector.
s Scalar.

void vec4_sub_scalar_ptr(vector4* res, const vector4* v, vm_float_t s)

Subtracts a scalar from each component (dispatched).

Parameters
res Result vector.
v Input vector.
s Scalar.

void vec4_clamp_scalar_ptr(vector4* res, const vector4* v, vm_float_t min, vm_float_t max)

Clamps each component to a scalar range (dispatched).

Parameters
res Result vector.
v Input vector.
min Lower bound.
max Upper bound.

void vec4_saturate_ptr(vector4* res, const vector4* v)

Clamps each component to [0, 1] (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_fract_ptr(vector4* res, const vector4* v)

Component-wise fractional part (dispatched).

Parameters
res Result vector.
v Input vector.

void vec4_project_ptr(vector4* res, const vector4* a, const vector4* b)

Projects a onto b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec4_reject_ptr(vector4* res, const vector4* a, const vector4* b)

Returns the component of a orthogonal to b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec4_slide_ptr(vector4* res, const vector4* v, const vector4* normal)

Removes the component of v along normal.

Parameters
res Output vector.
v Input vector.
normal Surface normal.

void vec4_to_vec3_ptr(vector3* res, const vector4* v)

Copies the x, y, z components from a vector4 to a vector3.

Parameters
res Pointer to result vector3.
v Pointer to input vector4.

vector2i vec2i_add(vector2i a, vector2i b)

Adds two vectors component-wise.

Parameters
a The first vector.
b The second vector.
Returns The sum vector2i.

vector2i vec2i_sub(vector2i a, vector2i b)

Subtracts the second vector from the first component-wise.

Parameters
a The first vector.
b The second vector.
Returns The difference vector2i.

vector2i vec2i_mul_scalar(vector2i v, vm_int_t s)

Multiplies a vector by a scalar component-wise.

Parameters
v The input vector.
s The scalar multiplier.
Returns The scaled vector2i.

vector2i vec2i_div_scalar(vector2i v, vm_int_t s)

Divides a vector by a scalar component-wise (float division, truncated to int).

Parameters
v The input vector.
s The scalar divisor (sets to zero vector if zero).
Returns The divided vector2i.

vector2i vec2i_mul(vector2i a, vector2i b)

Multiplies two vectors component-wise (Hadamard product).

Parameters
a The first vector.
b The second vector.
Returns The product vector2i.

vector2i vec2i_neg(vector2i v)

Negates the vector (multiplies each component by -1).

Parameters
v The input vector.
Returns The negated vector2i.

vector2i vec2i_abs(vector2i v)

Returns the absolute values of each component.

Parameters
v The input vector.
Returns The absolute value vector2i.

vector2i vec2i_zero(void)

Returns a vector2i with both components set to 0.

Returns The zero vector2i.

vector2i vec2i_one(void)

Returns a vector2i with both components set to 1.

Returns The one vector2i.

vector2i vec2i_x_axis(vm_int_t x)

Returns a vector2i along the x-axis (y = 0).

Parameters
x The x component value.
Returns The x-axis vector2i.

vector2i vec2i_y_axis(vm_int_t y)

Returns a vector2i along the y-axis (x = 0).

Parameters
y The y component value.
Returns The y-axis vector2i.

vector2i vec2i_x_scale(vm_int_t x)

Returns a vector2i representing x-axis scaling (y = 1).

Parameters
x The x scale factor.
Returns The x-scale vector2i.

vector2i vec2i_y_scale(vm_int_t y)

Returns a vector2i representing y-axis scaling (x = 1).

Parameters
y The y scale factor.
Returns The y-scale vector2i.

vector2i vec2i_cross(vector2i a, vector2i b)

Computes the 2D cross-product as a vector.

Parameters
a The first vector.
b The second vector.
Returns The cross-product vector2i.

vector2i vec2i_normalize(vector2i v)

Normalizes the vector to approximate unit length (float length, truncated to int).

Parameters
v The input vector.
Returns The normalized vector2i (unchanged if zero length).

vector2i vec2i_min(vector2i a, vector2i b)

Returns the component-wise minimum of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The minimum vector2i.

vector2i vec2i_max(vector2i a, vector2i b)

Returns the component-wise maximum of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The maximum vector2i.

vector2i vec2i_sign(vector2i v)

Returns the sign of each component (+1, -1, or 0).

Parameters
v The input vector.
Returns The sign vector2i.

vector2i vec2i_perpendicular(vector2i v)

Returns the perpendicular vector (90 degrees counterclockwise).

Parameters
v The input vector.
Returns The perpendicular vector2i.

vector2i vec2i_lerp(vector2i a, vector2i b, vm_float_t t)

Linearly interpolates from a to b by t.

Parameters
a First input vector.
b Second input vector.
t Interpolation factor.
Returns The resulting vector2i.

vector2i vec2i_clamp(vector2i v, vector2i min, vector2i max)

Clamps each component between min and max.

Parameters
v Input vector.
min Lower bound.
max Upper bound.
Returns The resulting vector2i.

vector2i vec2i_div(vector2i a, vector2i b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector2i.

vector2i vec2i_add_scalar(vector2i v, vm_int_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector2i.

vector2i vec2i_sub_scalar(vector2i v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector2i.

vector2i vec2i_mod(vector2i a, vector2i b)

Component-wise floor modulo of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector2i.

vector2i vec2i_div_floor(vector2i a, vector2i b)

Component-wise floored division of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector2i.

vector2i vec2i_wrap(vector2i v, vector2i period)

Wraps each component of v into [0, period).

Parameters
v Input vector.
period Wrap period per component.
Returns The resulting vector2i.

vector2i vec2i_splat(vm_int_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector2i.

vector3i vec2i_to_vec3i(vector2i v, vm_int_t z)

Converts a vector2i to a vector3i using z.

Parameters
v Input vector.
z Z component.
Returns The resulting vector3i.

vector2 vec2i_normalize_to_vec2(vector2i v)

Converts to a unit-length vector2.

Parameters
v Input vector.
Returns The resulting vector2.

vm_int_t vec2i_dot(vector2i a, vector2i b)

Computes the dot product of two vectors.

Parameters
a The first vector.
b The second vector.
Returns The dot product (vm_int_t; may overflow).

vm_int_t vec2i_cross_scalar(vector2i a, vector2i b)

Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_int_t vec2i_length_squared(vector2i v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec2i_distance_squared(vector2i a, vector2i b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_int_t vec2i_length_manhattan(vector2i v)

Returns the Manhattan (L1) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec2i_length_chebyshev(vector2i v)

Returns the Chebyshev (L-inf) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec2i_min_component(vector2i v)

Returns the smallest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec2i_max_component(vector2i v)

Returns the largest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec2i_sum(vector2i v)

Returns the sum of all components.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec2i_length(vector2i v)

Computes the length (magnitude) of the vector.

Parameters
v The input vector.
Returns The length scalar.

vm_float_t vec2i_distance(vector2i a, vector2i b)

Computes the Euclidean distance between two vectors (treated as points).

Parameters
a The first point.
b The second point.
Returns The distance scalar.

vm_float_t vec2i_angle(vector2i a, vector2i b)

Computes the signed angle between two vectors (in radians, range [-PI, PI]) using atan2(cross, dot).

Parameters
a The first vector.
b The second vector.
Returns The signed angle scalar.

Returns 0.0f if either vector has zero length.

vm_float_t vec2i_aspect_ratio(vector2i v)

Computes the aspect ratio of the vector (x / y).

Parameters
v The input vector.
Returns The aspect ratio scalar.

Returns 0.0f if y == 0.

bool vec2i_is_zero(vector2i v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

vector3i vec3i_add(vector3i a, vector3i b)

Component-wise addition of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3i vec3i_sub(vector3i a, vector3i b)

Component-wise subtraction of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3i vec3i_mul_scalar(vector3i v, vm_int_t s)

Component-wise multiplication of vector by scalar.

Parameters
v The vector.
s The scalar.
Returns Result vector.

vector3i vec3i_div_scalar(vector3i v, vm_int_t s)

Component-wise division of vector by scalar.

Parameters
v The vector.
s The scalar (non-zero).
Returns Result vector.

vector3i vec3i_mul(vector3i a, vector3i b)

Component-wise multiplication of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector3i vec3i_neg(vector3i v)

Negation of a vector.

Parameters
v The vector.
Returns The negated vector.

vector3i vec3i_abs(vector3i v)

Computes the absolute value per component of a vector3i.

Parameters
v The vector.
Returns The absolute vector3i.

vector3i vec3i_zero(void)

Returns a zero-initialized vector3i.

Returns A vector3i with all components set to 0.

vector3i vec3i_one(void)

Returns a vector3i with all components set to 1.

Returns A vector3i with all components set to 1.

vector3i vec3i_x_axis(vm_int_t x)

Returns a vector3i along the x-axis.

Parameters
x The x component value.
Returns A vector3i with (x, 0, 0).

vector3i vec3i_y_axis(vm_int_t y)

Returns a vector3i along the y-axis.

Parameters
y The y component value.
Returns A vector3i with (0, y, 0).

vector3i vec3i_z_axis(vm_int_t z)

Returns a vector3i along the z-axis.

Parameters
z The z component value.
Returns A vector3i with (0, 0, z).

vector3i vec3i_x_scale(vm_int_t x)

Returns a vector3i for scaling along the x-axis.

Parameters
x The x scale factor.
Returns A vector3i with (x, 1, 1).

vector3i vec3i_y_scale(vm_int_t y)

Returns a vector3i for scaling along the y-axis.

Parameters
y The y scale factor.
Returns A vector3i with (1, y, 1).

vector3i vec3i_z_scale(vm_int_t z)

Returns a vector3i for scaling along the z-axis.

Parameters
z The z scale factor.
Returns A vector3i with (1, 1, z).

vector3i vec3i_cross(vector3i a, vector3i b)

Computes the cross-product of two vector3i.

Parameters
a First vector.
b Second vector.
Returns The cross-product (a × b).

vector3i vec3i_normalize(vector3i v)

Normalizes a vector3i to unit length.

Parameters
v The vector (non-zero).
Returns The normalized vector.

vector3i vec3i_min(vector3i a, vector3i b)

Computes the component-wise minimum of two vector3i.

Parameters
a First vector.
b Second vector.
Returns Per-component min(a, b).

vector3i vec3i_max(vector3i a, vector3i b)

Computes the component-wise maximum of two vector3i.

Parameters
a First vector.
b Second vector.
Returns Per-component max(a, b).

vector3i vec3i_sign(vector3i v)

Computes the sign per component of a vector3i (-1, 0, or 1).

Parameters
v The vector.
Returns The sign vector.

vector3i vec3i_lerp(vector3i a, vector3i b, vm_float_t t)

Linearly interpolates between two vector3i.

Parameters
a Start vector.
b End vector.
t Interpolation factor [0, 1].
Returns The interpolated vector (a * (1 - t) + b * t).

vector3i vec3i_clamp(vector3i v, vector3i min, vector3i max)

Clamps a vector3i between min and max per component.

Parameters
v The vector.
min Minimum bounds.
max Maximum bounds.
Returns The clamped vector.

vector3i vec3i_div(vector3i a, vector3i b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3i.

vector3i vec3i_add_scalar(vector3i v, vm_int_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector3i.

vector3i vec3i_sub_scalar(vector3i v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector3i.

vector3i vec3i_mod(vector3i a, vector3i b)

Component-wise floor modulo of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3i.

vector3i vec3i_div_floor(vector3i a, vector3i b)

Component-wise floored division of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector3i.

vector3i vec3i_wrap(vector3i v, vector3i period)

Wraps each component of v into [0, period).

Parameters
v Input vector.
period Wrap period per component.
Returns The resulting vector3i.

vector3i vec3i_splat(vm_int_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector3i.

vector3i vec3i_from_vec2i(vector2i v, vm_int_t z)

Builds a vector3i from a vector2i and z.

Parameters
v Input vector.
z Z component.
Returns The resulting vector3i.

vector2i vec3i_xy(vector3i v)

Returns the x and y components as a 2D vector.

Parameters
v Input vector.
Returns The resulting vector2i.

vector3 vec3i_normalize_to_vec3(vector3i v)

Converts to a unit-length vector3.

Parameters
v Input vector.
Returns The resulting vector3.

vm_int_t vec3i_dot(vector3i a, vector3i b)

Computes the dot product of two vector3i.

Parameters
a First vector.
b Second vector.
Returns The dot product (a.x * b.x + a.y * b.y + a.z * b.z).

vm_int_t vec3i_length_squared(vector3i v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec3i_distance_squared(vector3i a, vector3i b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_int_t vec3i_length_manhattan(vector3i v)

Returns the Manhattan (L1) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec3i_length_chebyshev(vector3i v)

Returns the Chebyshev (L-inf) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec3i_min_component(vector3i v)

Returns the smallest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec3i_max_component(vector3i v)

Returns the largest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec3i_sum(vector3i v)

Returns the sum of all components.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec3i_length(vector3i v)

Computes the length (magnitude) of a vector3i.

Parameters
v The vector.
Returns The Euclidean length of v.

vm_float_t vec3i_distance(vector3i a, vector3i b)

Computes the Euclidean distance between two vector3i.

Parameters
a First vector.
b Second vector.
Returns The distance between a and b.

vm_float_t vec3i_angle(vector3i a, vector3i b)

Computes the angle between two non-zero vector3i in radians.

Parameters
a First vector.
b Second vector.
Returns The angle between the directions of a and b.

bool vec3i_is_zero(vector3i v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

vector4i vec4i_add(vector4i a, vector4i b)

Component-wise addition of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4i vec4i_sub(vector4i a, vector4i b)

Component-wise subtraction of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4i vec4i_mul_scalar(vector4i v, vm_int_t s)

Component-wise multiplication of vector by scalar.

Parameters
v The vector.
s The scalar.
Returns Result vector.

vector4i vec4i_div_scalar(vector4i v, vm_int_t s)

Component-wise division of vector by scalar.

Parameters
v The vector.
s The scalar (non-zero).
Returns Result vector.

vector4i vec4i_mul(vector4i a, vector4i b)

Component-wise multiplication of two vectors.

Parameters
a First vector.
b Second vector.
Returns Result vector.

vector4i vec4i_neg(vector4i v)

Negation of a vector.

Parameters
v The vector.
Returns The negated vector.

vector4i vec4i_abs(vector4i v)

Computes the absolute value per component of a vector4i.

Parameters
v The vector.
Returns The absolute vector4i.

vector4i vec4i_zero(void)

Returns a zero-initialized vector4i.

Returns A vector4i with all components set to 0.

vector4i vec4i_one(void)

Returns a vector4i with all components set to 1.

Returns A vector4i with all components set to 1.

vector4i vec4i_x_axis(vm_int_t x)

Returns a vector4i along the x-axis.

Parameters
x The x component value.
Returns A vector4i with (x, 0, 0, 0).

vector4i vec4i_y_axis(vm_int_t y)

Returns a vector4i along the y-axis.

Parameters
y The y component value.
Returns A vector4i with (0, y, 0, 0).

vector4i vec4i_z_axis(vm_int_t z)

Returns a vector4i along the z-axis.

Parameters
z The z component value.
Returns A vector4i with (0, 0, z, 0).

vector4i vec4i_w_axis(vm_int_t w)

Returns a vector4i along the w-axis.

Parameters
w The w component value.
Returns A vector4i with (0, 0, 0, w).

vector4i vec4i_x_scale(vm_int_t x)

Returns a vector4i for scaling along the x-axis.

Parameters
x The x scale factor.
Returns A vector4i with (x, 1, 1, 1).

vector4i vec4i_y_scale(vm_int_t y)

Returns a vector4i for scaling along the y-axis.

Parameters
y The y scale factor.
Returns A vector4i with (1, y, 1, 1).

vector4i vec4i_z_scale(vm_int_t z)

Returns a vector4i for scaling along the z-axis.

Parameters
z The z scale factor.
Returns A vector4i with (1, 1, z, 1).

vector4i vec4i_w_scale(vm_int_t w)

Returns a vector4i for scaling along the w-axis.

Parameters
w The w scale factor.
Returns A vector4i with (1, 1, 1, w).

vector4i vec4i_normalize(vector4i v)

Normalizes a vector4i to unit length.

Parameters
v The vector (non-zero).
Returns The normalized vector.

vector4i vec4i_min(vector4i a, vector4i b)

Computes the component-wise minimum of two vector4i.

Parameters
a First vector.
b Second vector.
Returns Per-component min(a, b).

vector4i vec4i_max(vector4i a, vector4i b)

Computes the component-wise maximum of two vector4i.

Parameters
a First vector.
b Second vector.
Returns Per-component max(a, b).

vector4i vec4i_sign(vector4i v)

Computes the sign per component of a vector4i (-1, 0, or 1).

Parameters
v The vector.
Returns The sign vector.

vector4i vec4i_lerp(vector4i a, vector4i b, vm_float_t t)

Linearly interpolates between two vector4i.

Parameters
a Start vector.
b End vector.
t Interpolation factor [0, 1].
Returns The interpolated vector (a * (1 - t) + b * t).

vector4i vec4i_clamp(vector4i v, vector4i min, vector4i max)

Clamps each component of the input vector to the range defined by the minimum and maximum vectors.

Parameters
v The input vector.
min The minimum value for each component.
max The maximum value for each component.
Returns A new vector4i with each component clamped to [min, max].

vector4i vec4i_div(vector4i a, vector4i b)

Divides two vectors component-wise.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4i.

vector4i vec4i_add_scalar(vector4i v, vm_int_t s)

Adds a scalar to each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector4i.

vector4i vec4i_sub_scalar(vector4i v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
v Input vector.
s Scalar value.
Returns The resulting vector4i.

vector4i vec4i_mod(vector4i a, vector4i b)

Component-wise floor modulo of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4i.

vector4i vec4i_div_floor(vector4i a, vector4i b)

Component-wise floored division of a by b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting vector4i.

vector4i vec4i_wrap(vector4i v, vector4i period)

Wraps each component of v into [0, period).

Parameters
v Input vector.
period Wrap period per component.
Returns The resulting vector4i.

vector4i vec4i_splat(vm_int_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector4i.

vector3i vec4i_to_vec3i(vector4i v)

Converts a vector4i to a vector3i (discards the w component).

Parameters
v The source vector4i.
Returns A vector3i {v.x, v.y, v.z}.

vm_int_t vec4i_dot(vector4i a, vector4i b)

Computes the dot product of two vector4i.

Parameters
a First vector.
b Second vector.
Returns The dot product.

vm_int_t vec4i_length_squared(vector4i v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec4i_distance_squared(vector4i a, vector4i b)

Returns the squared Euclidean distance between a and b.

Parameters
a First input vector.
b Second input vector.
Returns The resulting scalar.

vm_int_t vec4i_length_manhattan(vector4i v)

Returns the Manhattan (L1) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec4i_length_chebyshev(vector4i v)

Returns the Chebyshev (L-inf) length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec4i_min_component(vector4i v)

Returns the smallest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec4i_max_component(vector4i v)

Returns the largest component.

Parameters
v Input vector.
Returns The resulting scalar.

vm_int_t vec4i_sum(vector4i v)

Returns the sum of all components.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec4i_length(vector4i v)

Computes the length (magnitude) of a vector4i.

Parameters
v The vector.
Returns The Euclidean length of v.

vm_float_t vec4i_distance(vector4i a, vector4i b)

Computes the Euclidean distance between two vector4i.

Parameters
a First vector.
b Second vector.
Returns The distance between a and b.

bool vec4i_is_zero(vector4i v)

Returns true if every component is zero.

Parameters
v Input vector.
Returns True if every component is zero.

void vec2i_add_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Adds vectors a and b component-wise, storing the result in res.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_sub_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Subtracts vector b from vector a component-wise, storing the result in res.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_mul_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)

Multiplies vector v by scalar s component-wise, storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.
s Scalar.

void vec2i_div_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)

Divides vector v by scalar s component-wise (float division, truncated to int), storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.
s Scalar.

Sets vector to zero if s == 0.

void vec2i_mul_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Multiplies vectors a and b component-wise (Hadamard product), storing the result in res.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_neg_ptr(vector2i* res, const vector2i* v)

Negates the components of vector v, storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.

void vec2i_abs_ptr(vector2i* res, const vector2i* v)

Computes the absolute values of the components of vector v (using int abs), storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.

void vec2i_normalize_ptr(vector2i* res, const vector2i* v)

Normalizes vector v to approximate unit length (float length computation, truncated to int), storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.

Copies v unchanged if the length is zero.

void vec2i_min_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Computes the component-wise minimum of vectors a and b, storing the result in res.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_max_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Computes the component-wise maximum of vectors a and b, storing the result in res.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_sign_ptr(vector2i* res, const vector2i* v)

Sets each component of res to the sign of the corresponding component in v (+1, -1, or 0).

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.

void vec2i_perpendicular_ptr(vector2i* res, const vector2i* v)

Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in res.

Parameters
res Pointer to result vector2i.
v Pointer to vector2i.

void vec2i_cross_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Computes the 2D cross-product of a and b, storing the scalar value in res->x and 0 in res->y.

Parameters
res Pointer to result vector2i.
a Pointer to first vector2i.
b Pointer to second vector2i.

void vec2i_lerp_ptr(vector2i* res, const vector2i* a, const vector2i* b, vm_float_t t)

Linearly interpolates from a to b by t.

Parameters
res Output vector.
a First input vector.
b Second input vector.
t Interpolation factor.

void vec2i_clamp_ptr(vector2i* res, const vector2i* v, const vector2i* min, const vector2i* max)

Clamps each component between min and max.

Parameters
res Output vector.
v Input vector.
min Lower bound.
max Upper bound.

void vec2i_div_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Divides two vectors component-wise.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec2i_add_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)

Adds a scalar to each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec2i_sub_scalar_ptr(vector2i* res, const vector2i* v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec2i_mod_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Component-wise floor modulo of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec2i_div_floor_ptr(vector2i* res, const vector2i* a, const vector2i* b)

Component-wise floored division of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec2i_wrap_ptr(vector2i* res, const vector2i* v, const vector2i* period)

Wraps each component of v into [0, period).

Parameters
res Output vector.
v Input vector.
period Wrap period per component.

void vec2i_to_vec3i_ptr(vector3i* res, const vector2i* v, vm_int_t z)

Converts a vector4i to a vector3i by dropping w.

Parameters
res Output vector.
v Input vector.
z Z component.

void vec2i_normalize_to_vec2_ptr(vector2* res, const vector2i* v)

Converts to a unit-length vector2.

Parameters
res Output vector.
v Input vector.

void vec3i_add_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the component-wise sum of two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_sub_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the component-wise difference of two vector3i (a minus b).

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_mul_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)

Scales a vector3i by an integer scalar.

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.
s The scalar multiplier.

void vec3i_div_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)

Scales a vector3i by the inverse of an integer scalar.

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.
s The scalar divisor.

If the scalar is zero, stores the zero vector.

void vec3i_mul_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the component-wise product (Hadamard) of two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_neg_ptr(vector3i* res, const vector3i* v)

Negates a vector3i (multiplies by -1).

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.

void vec3i_abs_ptr(vector3i* res, const vector3i* v)

Computes the absolute value of each component of a vector3i.

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.

void vec3i_normalize_ptr(vector3i* res, const vector3i* v)

Normalizes a vector3i to approximate unit length.

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.

If the vector length is zero, copies the input vector.

void vec3i_cross_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the cross-product of two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_min_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the component-wise minimum of two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_max_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Computes the component-wise maximum of two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the first vector.
b Pointer to the second vector.

void vec3i_sign_ptr(vector3i* res, const vector3i* v)

Computes the sign of each component of a vector3i (-1, 0, or 1).

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.

void vec3i_lerp_ptr(vector3i* res, const vector3i* a, const vector3i* b, vm_float_t t)

Performs linear interpolation between two vector3i.

Parameters
res Pointer to the vector that will store the result.
a Pointer to the start vector.
b Pointer to the end vector.
t Interpolation factor (typically between 0.0 and 1.0).

void vec3i_clamp_ptr(vector3i* res, const vector3i* v, const vector3i* min, const vector3i* max)

Clamps each component of a vector3i between corresponding min and max values.

Parameters
res Pointer to the vector that will store the result.
v Pointer to the input vector.
min Pointer to the minimum bounds vector.
max Pointer to the maximum bounds vector.

void vec3i_div_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Divides two vectors component-wise.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3i_add_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)

Adds a scalar to each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec3i_sub_scalar_ptr(vector3i* res, const vector3i* v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec3i_mod_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Component-wise floor modulo of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3i_div_floor_ptr(vector3i* res, const vector3i* a, const vector3i* b)

Component-wise floored division of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec3i_wrap_ptr(vector3i* res, const vector3i* v, const vector3i* period)

Wraps each component of v into [0, period).

Parameters
res Output vector.
v Input vector.
period Wrap period per component.

void vec3i_from_vec2i_ptr(vector3i* res, const vector2i* v, vm_int_t z)

Builds a vector3i from a vector2i and z.

Parameters
res Output vector.
v Input vector.
z Z component.

void vec3i_xy_ptr(vector2i* res, const vector3i* v)

Returns the x and y components as a 2D vector.

Parameters
res Output vector.
v Input vector.

void vec3i_normalize_to_vec3_ptr(vector3* res, const vector3i* v)

Converts to a unit-length vector3.

Parameters
res Output vector.
v Input vector.

void vec4i_add_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Adds the components of two vector4i and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector

void vec4i_sub_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Subtracts the components of the second vector from the first vector4i and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector

void vec4i_mul_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)

Multiplies the components of a vector4i by a scalar and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector
s Scalar value

void vec4i_div_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)

Divides the components of a vector4i by a scalar and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector
s Scalar divisor

If the scalar is zero, sets all components of res to zero.

void vec4i_mul_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Multiplies the components of two vector4i and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector

void vec4i_neg_ptr(vector4i* res, const vector4i* v)

Negates the components of a vector4i and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector

void vec4i_abs_ptr(vector4i* res, const vector4i* v)

Computes the absolute value of each component of a vector4i and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector

void vec4i_normalize_ptr(vector4i* res, const vector4i* v)

Normalizes a vector4i by dividing its components by the vector length and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector

If the length is zero, copies the input vector to res.

void vec4i_min_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Takes the component-wise minimum of two vector4i and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector

void vec4i_max_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Computes the component-wise maximum of two vector4i and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector

void vec4i_sign_ptr(vector4i* res, const vector4i* v)

Computes the sign (-1, 0, or 1) of each component of a vector4i and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector

void vec4i_lerp_ptr(vector4i* res, const vector4i* a, const vector4i* b, vm_float_t t)

Linearly interpolates between two vector4i using an interpolation factor t (clamped to [0,1]) and stores the result in res.

Parameters
res Pointer to result vector
a Pointer to first vector
b Pointer to second vector
t Interpolation factor

void vec4i_clamp_ptr(vector4i* res, const vector4i* v, const vector4i* min, const vector4i* max)

Clamps the components of a vector4i to the range [min, max] and stores the result in res.

Parameters
res Pointer to result vector
v Pointer to input vector
min Pointer to minimum bounds vector
max Pointer to maximum bounds vector

void vec4i_div_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Divides two vectors component-wise.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec4i_add_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)

Adds a scalar to each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec4i_sub_scalar_ptr(vector4i* res, const vector4i* v, vm_int_t s)

Subtracts a scalar from each component.

Parameters
res Output vector.
v Input vector.
s Scalar value.

void vec4i_mod_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Component-wise floor modulo of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec4i_div_floor_ptr(vector4i* res, const vector4i* a, const vector4i* b)

Component-wise floored division of a by b.

Parameters
res Output vector.
a First input vector.
b Second input vector.

void vec4i_wrap_ptr(vector4i* res, const vector4i* v, const vector4i* period)

Wraps each component of v into [0, period).

Parameters
res Output vector.
v Input vector.
period Wrap period per component.

void vec4i_to_vec3i_ptr(vector3i* res, const vector4i* v)

Copies the x, y, z components of a vector4i and stores the result in a vector3i.

Parameters
res Pointer to result vector3i
v Pointer to source vector4i

matrix2 mat2_identity(void)

Constructs the 2x2 identity matrix.

Returns The identity matrix2.

matrix2 mat2_mul(matrix2 a, matrix2 b)

Multiplies two 2x2 matrices (a * b).

Parameters
a The first matrix.
b The second matrix.
Returns The resulting product matrix2.

matrix2 mat2_transpose(matrix2 m)

Computes the transpose of a 2x2 matrix.

Parameters
m The input matrix.
Returns The transposed matrix2.

matrix2 mat2_inverse(matrix2 m)

Computes the inverse of a 2x2 matrix.

Parameters
m The input matrix.
Returns The inverse matrix2.

matrix2 mat2_rotation_z(vm_float_t radians)

Constructs a 2x2 rotation matrix around the Z axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix2.

matrix2 mat2_rotation_z_deg(vm_float_t degrees)

Constructs a 2x2 rotation matrix from an angle in degrees around the Z axis.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix2.

matrix2 mat2_scale(vector2 s)

Builds a 2x2 scaling matrix from a vector2.

Parameters
s Scale vector.
Returns The resulting matrix2.

matrix2 mat2_from_mat3(matrix3 m)

Copies the upper-left 2x2 of a matrix3.

Parameters
m Input matrix.
Returns The resulting matrix2.

vector2 mat2_mul_vec2(matrix2 m, vector2 v)

Multiplies a 2x2 matrix by a vector2.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector2.

vm_float_t mat2_determinant(matrix2 m)

Calculates the determinant of the given 2x2 matrix.

Parameters
m The matrix.
Returns The determinant value (m.v[0]*m.v[3] - m.v[1]*m.v[2]).

matrix3 mat3_identity(void)

Constructs the 3x3 identity matrix.

Returns The identity matrix3.

matrix3 mat3_mul(matrix3 a, matrix3 b)

Multiplies two 3x3 matrices.

Parameters
a The first matrix.
b The second matrix.
Returns The product matrix.

matrix3 mat3_transpose(matrix3 m)

Computes the transpose of a 3x3 matrix.

Parameters
m The input matrix.
Returns The transposed matrix.

matrix3 mat3_inverse(matrix3 m)

Computes the inverse of a 3x3 matrix.

Parameters
m The input matrix.
Returns The inverse matrix.

matrix3 mat3_rotation_x(vm_float_t radians)

Constructs a 3x3 rotation matrix around the X axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix3.

matrix3 mat3_rotation_y(vm_float_t radians)

Constructs a 3x3 rotation matrix around the Y axis.

Parameters
radians The rotation angle in radians.
Returns The rotation matrix3.

matrix3 mat3_rotation_z(vm_float_t radians)

Constructs a 3x3 rotation matrix around the Z axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix3.

matrix3 mat3_rotation_x_deg(vm_float_t degrees)

Constructs a 3x3 rotation matrix around the X axis.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix3.

The angle is provided in degrees and converted to radians internally.

matrix3 mat3_rotation_y_deg(vm_float_t degrees)

3x3 rotation about Y from an angle in degrees.

Parameters
degrees Rotation angle in degrees.
Returns Rotation matrix3.

matrix3 mat3_rotation_z_deg(vm_float_t degrees)

Constructs a 3x3 rotation matrix around the Z axis.

Parameters
degrees The rotation angle in degrees.
Returns The resulting rotation matrix3.

The angle is given in degrees and internally converted to radians.

matrix3 mat3_translate(vector2 t)

Builds a 3x3 2D translation matrix.

Parameters
t Translation vector.
Returns The resulting matrix3.

matrix3 mat3_scale(vector2 s)

Builds a 3x3 2D scaling matrix.

Parameters
s Scale vector.
Returns The resulting matrix3.

matrix3 mat3_normal(matrix3 m)

Inverse-transpose of a 3x3 (normal matrix).

Parameters
m Linear part of a model transform.
Returns The normal matrix3.

matrix3 mat3_from_mat4(matrix4 m)

Copies the upper-left 3x3 of a matrix4.

Parameters
m Input matrix.
Returns The resulting matrix3.

vector3 mat3_mul_vec3(matrix3 m, vector3 v)

Multiplies a 3x3 matrix by a vector3.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector3.

vector3 mat3_sym_eigen(matrix3 m, matrix3* axes)

Symmetric 3x3 eigensolve (Jacobi).

Parameters
m Input matrix (symmetrized internally).
axes Optional; receives eigenvector columns. May be NULL.
Returns Eigenvalues as a vector3.

m is symmetrized as (A+A^T)/2.

Eigenvalues are unsorted principal moments. Eigenvectors are the columns of the returned rotation (axes * diag(moments) * axes^T ~= m).

vector2 mat3_mul_vec2(matrix3 m, vector2 v)

Applies a 3x3 affine transform to a vector2.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector2.

vm_float_t mat3_determinant(matrix3 m)

Computes the determinant of a 3x3 matrix.

Parameters
m The input matrix.
Returns The determinant value.

matrix4 mat4_identity(void)

Constructs the 4x4 identity matrix.

Returns The identity matrix4.

matrix4 mat4_mul(matrix4 a, matrix4 b)

Multiplies two 4x4 matrices (a * b).

Parameters
a The first matrix.
b The second matrix.
Returns The resulting product matrix4.

matrix4 mat4_transpose(matrix4 m)

Computes the transpose of a 4x4 matrix.

Parameters
m The input matrix.
Returns The transposed matrix4.

matrix4 mat4_inverse(matrix4 m)

Computes the inverse of a 4x4 matrix.

Parameters
m The input matrix.
Returns The inverse matrix4.

matrix4 mat4_inverse_affine(matrix4 m)

Inverse of an affine matrix [R t; 0 1].

Parameters
m Affine 4×4 matrix.
Returns Inverse matrix.

matrix4 mat4_translate(vector3 v)

Constructs a translation matrix from the given vector.

Parameters
v The translation vector (x, y, z).
Returns The translation matrix4.

matrix4 mat4_scale(vector3 v)

Constructs a scaling matrix from the given scale vector.

Parameters
v The scale vector (x, y, z factors).
Returns The resulting scaling matrix4.

matrix4 mat4_normal(matrix4 m)

Inverse-transpose of the upper 3x3, embedded in a matrix4.

Parameters
m Model matrix.
Returns Normal matrix as a matrix4.

matrix4 mat4_rotation(vector3 axis, vm_float_t radians)

Constructs a 4x4 rotation matrix.

Parameters
axis The rotation axis.
radians The rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_x(vm_float_t radians)

Constructs a 4x4 rotation matrix around the X axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_y(vm_float_t radians)

Constructs a 4x4 rotation matrix around the Y axis.

Parameters
radians The rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_z(vm_float_t radians)

Constructs a 4x4 rotation matrix around the Z axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_deg(vector3 axis, vm_float_t degrees)

Constructs a 4x4 rotation matrix from an axis and angle in degrees.

Parameters
axis The rotation axis.
degrees The rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_rotation_x_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the X axis.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix4.

The angle is specified in degrees and internally converted to radians.

matrix4 mat4_rotation_y_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the Y axis.

Parameters
degrees Rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_rotation_z_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the Z axis from an angle in degrees.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_trs(vector3 translation, quaternion rotation, vector3 scale)

Builds a 4x4 TRS matrix from translation, rotation, and scale.

Parameters
translation Translation vector.
rotation Rotation quaternion.
scale Scale vector.
Returns The resulting matrix4.

matrix4 mat4_from_mat3(matrix3 m)

Embeds a matrix3 into the upper-left of a matrix4.

Parameters
m Input matrix.
Returns The resulting matrix4.

matrix4 mat4_ortho(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Constructs an orthographic projection matrix.

Parameters
left Left clipping plane.
right Right clipping plane.
bottom Bottom clipping plane.
top Top clipping plane.
near Near plane distance.
far Far plane distance.
Returns The orthographic matrix4.

matrix4 mat4_look_at(vector3 position, vector3 target, vector3 up)

Constructs a view matrix from eye position, target, and up vector.

Parameters
position Eye position.
target Target position.
up Up vector.
Returns The view matrix4.

matrix4 mat4_perspective(vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far)

Constructs a perspective projection matrix.

Parameters
fov Field of view (radians).
aspect Aspect ratio (width/height).
near Near plane distance.
far Far plane distance.
Returns The perspective matrix4.

matrix4 mat4_perspective_fov(vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Constructs a perspective projection matrix using FOV, width, and height.

Parameters
fov Vertical field of view (radians).
w Viewport width.
h Viewport height.
n Near plane.
f Far plane.
Returns The perspective matrix4.

matrix4 mat4_perspective_infinite(vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Constructs an infinite far-plane perspective projection matrix.

Parameters
fov_y Vertical field of view (radians).
aspect Aspect ratio.
n Near plane distance.
Returns The perspective matrix4.

matrix4 mat4_perspective_infinite_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite-far perspective with an explicit clip convention.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z(vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective (RH + ZO by default).

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective with an explicit clip convention.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_perspective_deg(vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.

Parameters
fov_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
Returns The perspective projection matrix.

matrix4 mat4_perspective_fov_deg(vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.

Parameters
fov_deg Vertical field of view in degrees.
w Width of the viewport.
h Height of the viewport.
n Distance to the near clipping plane.
f Distance to the far clipping plane.
Returns The perspective matrix4.

matrix4 mat4_perspective_infinite_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Constructs a 4x4 infinite perspective projection matrix using vertical field of view in degrees.

Parameters
fov_y_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns The infinite perspective matrix4.

matrix4 mat4_perspective_infinite_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite-far perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective (degrees + clip convention).

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_perspective_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Constructs a 4x4 perspective projection matrix.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
clip Clip space convention.
Returns The perspective matrix4.

matrix4 mat4_perspective_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Perspective projection from a vertical FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

OpenGL-style RH perspective, clip z in [-1, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Vulkan-style RH perspective, clip z in [0, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Direct3D-style LH perspective, clip z in [0, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Left-handed perspective, clip z in [-1, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

OpenGL-style RH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Vulkan-style RH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Direct3D-style LH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Left-handed NO perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_ortho_clip(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip)

Orthographic projection with an explicit clip convention.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
clip Clip-space convention.
Returns Orthographic matrix4.

matrix4 mat4_ortho_rh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

OpenGL-style RH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_rh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Vulkan-style RH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_lh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Direct3D-style LH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_lh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Left-handed NO orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_look_at_clip(vector3 position, vector3 target, vector3 up, vm_clip_t clip)

Look-at view matrix with an explicit clip convention.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
clip Clip-space convention.
Returns View matrix4.

matrix4 mat4_look_at_rh(vector3 position, vector3 target, vector3 up)

Right-handed look-at view matrix.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_at_lh(vector3 position, vector3 target, vector3 up)

Left-handed look-at view matrix.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir(vector3 position, vector3 direction, vector3 up)

View matrix from eye position and a look direction.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir_clip(vector3 position, vector3 direction, vector3 up, vm_clip_t clip)

Look-from-direction view matrix with an explicit clip convention.

Parameters
position Eye position.
direction Look direction.
up World up direction.
clip Clip-space convention.
Returns View matrix4.

matrix4 mat4_look_from_dir_rh(vector3 position, vector3 direction, vector3 up)

Right-handed look-from-direction view matrix.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir_lh(vector3 position, vector3 direction, vector3 up)

Left-handed look-from-direction view matrix.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_viewport(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height)

Pixel-box viewport matrix (NDC xy/z [-1,1] to window + depth [0,1]).

Parameters
x Viewport origin X.
y Viewport origin Y.
width Viewport width.
height Viewport height.
Returns Viewport matrix4.

matrix4 mat4_viewport_depth(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f)

Viewport matrix with an explicit depth range.

Parameters
x Viewport origin X.
y Viewport origin Y.
width Viewport width.
height Viewport height.
n Near depth mapped from clip z.
f Far depth mapped from clip z.
Returns Viewport matrix4.

vm_float_t mat4_determinant(matrix4 m)

Calculates the determinant of the given 4x4 matrix.

Parameters
m The matrix.
Returns The determinant value as a vm_float_t.

Uses cofactor expansion for computation.

vector3 mat4_extract_translation(matrix4 m)

Extracts the translation vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

vector3 mat4_extract_scale(matrix4 m)

Extracts the scale vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

vector3 mat4_mul_vec3(matrix4 m, vector3 v, vm_float_t w)

Transforms a vector3 by a 4x4 matrix using homogeneous w.

Parameters
m Input matrix.
v Input vector.
w Homogeneous w component.
Returns The resulting vector3.

vector4 mat4_mul_vec4(matrix4 m, vector4 v)

Multiplies a 4x4 matrix by a vector4.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector4.

quaternion mat4_extract_rotation(matrix4 m)

Extracts the rotation quaternion from a matrix4.

Parameters
m Input matrix.
Returns The resulting quaternion.

vector3 vec3_world_to_window(vector3 world, matrix4 model, matrix4 projection, vector4 viewport)

Projects a world space point to window coordinates.

Parameters
world World space position to project.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
Returns The projected window space vector3.

vector3 vec3_window_to_world(vector3 window, matrix4 model, matrix4 projection, vector4 viewport)

Un-projects a window coordinate back to world space.

Parameters
window The window coordinate to un-project.
model The model matrix.
projection The projection matrix.
viewport The viewport (x, y, width, height).
Returns The unprojected world space vector3.

vector3 vec3_world_to_window_clip(vector3 world, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip)

Projects a world-space point into window coordinates using model, projection and viewport.

Parameters
world World-space position to project.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
clip Clip-space convention to use.
Returns The projected window-space coordinates.

vector3 vec3_window_to_world_clip(vector3 window, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip)

Un-projects a window coordinate using model, projection, viewport and clip space.

Parameters
window The window coordinate to un-project.
model The model matrix.
projection The projection matrix.
viewport The viewport (x, y, width, height).
clip The clip space convention.
Returns The unprojected vector3.

void mat2_identity_ptr(matrix2* res)

Initializes the 2x2 matrix to identity (diagonal 1.0, others 0.0).

Parameters
res Pointer to the output matrix2.

void mat2_mul_ptr(matrix2* res, const matrix2* a, const matrix2* b)

Multiplies two 2x2 matrices (a * b) in column-major / column-vector convention.

Parameters
res Pointer to the output matrix2.
a Pointer to the first matrix.
b Pointer to the second matrix.

void mat2_transpose_ptr(matrix2* res, const matrix2* m)

Computes the transpose of the input 2x2 matrix and stores in res.

Parameters
res Pointer to the output matrix2.
m Pointer to the input matrix.

void mat2_inverse_ptr(matrix2* res, const matrix2* m)

Computes the inverse of the input 2x2 matrix using determinant and stores in res.

Parameters
res Pointer to the output matrix2.
m Pointer to the input matrix.

If the determinant is zero, sets res to identity matrix.

void mat2_rotation_z_ptr(matrix2* res, vm_float_t radians)

Sets the 2x2 matrix to a Z-axis (counter-clockwise) rotation.

Parameters
res Pointer to the output matrix2.
radians Rotation angle in radians.

void mat2_rotation_z_deg_ptr(matrix2* res, vm_float_t degrees)

Initializes the 2x2 matrix to a rotation around Z axis (counter-clockwise).

Parameters
res Pointer to the output matrix2.
degrees Rotation angle in degrees.

void mat2_scale_ptr(matrix2* res, const vector2* s)

Builds a 2x2 scaling matrix from a vector2.

Parameters
res Output value.
s Scale vector.

void mat2_from_mat3_ptr(matrix2* res, const matrix3* m)

Copies the upper-left 2x2 of a matrix3.

Parameters
res Output value.
m Input matrix.

void mat2_mul_vec2_ptr(vector2* res, const matrix2* m, const vector2* v)

Multiplies a 2x2 matrix by a vector2.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat3_identity_ptr(matrix3* res)

Initializes the 3x3 matrix to identity (diagonal 1.0, others 0.0).

Parameters
res Pointer to the output matrix3.

void mat3_mul_ptr(matrix3* res, const matrix3* a, const matrix3* b)

Multiplies two 3x3 matrices (a * b) in column-major / column-vector convention.

Parameters
res Pointer to the output matrix3.
a Pointer to the first matrix.
b Pointer to the second matrix.

Accumulates into a temporary matrix.

void mat3_transpose_ptr(matrix3* res, const matrix3* m)

Computes the transpose of the input 3x3 matrix and stores in res.

Parameters
res Pointer to the output matrix3.
m Pointer to the input matrix.

void mat3_inverse_ptr(matrix3* res, const matrix3* m)

Computes the inverse of the input 3x3 matrix using the adjugate method and stores in res.

Parameters
res Pointer to the output matrix3.
m Pointer to the input matrix.

If the determinant is zero, sets res to identity.

void mat3_rotation_x_ptr(matrix3* res, vm_float_t radians)

Sets the 3x3 matrix to a rotation around the X axis.

Parameters
res Pointer to the output matrix3.
radians Rotation angle in radians.

void mat3_rotation_y_ptr(matrix3* res, vm_float_t radians)

Sets the 3x3 matrix to a rotation around the Y axis.

Parameters
res Pointer to the output matrix3.
radians Rotation angle in radians.

void mat3_rotation_z_ptr(matrix3* res, vm_float_t radians)

Sets the 3x3 matrix to a Z-axis rotation by the given angle in radians.

Parameters
res Pointer to the output matrix3.
radians Rotation angle in radians.

void mat3_rotation_x_deg_ptr(matrix3* res, vm_float_t degrees)

Initializes the 3x3 matrix to a rotation around the X axis.

Parameters
res Pointer to the output matrix3.
degrees Rotation angle in degrees.

void mat3_rotation_y_deg_ptr(matrix3* res, vm_float_t degrees)

Initializes the 3x3 matrix to a rotation around the Y axis.

Parameters
res Pointer to the output matrix3.
degrees Rotation angle in degrees.

void mat3_rotation_z_deg_ptr(matrix3* res, vm_float_t degrees)

Initializes the 3x3 matrix to a rotation around the Z axis.

Parameters
res Pointer to the output matrix3.
degrees Rotation angle in degrees.

void mat3_translate_ptr(matrix3* res, const vector2* t)

Builds a 3x3 2D translation matrix.

Parameters
res Output value.
t Translation vector.

void mat3_scale_ptr(matrix3* res, const vector2* s)

Builds a 3x3 2D scaling matrix.

Parameters
res Output value.
s Scale vector.

void mat3_from_mat4_ptr(matrix3* res, const matrix4* m)

Copies the upper-left 3x3 of a matrix4.

Parameters
res Output value.
m Input matrix.

void mat3_normal_ptr(matrix3* res, const matrix3* m)

Inverse-transpose of a 3x3, for transforming normals.

Parameters
res Normal matrix.
m Linear part of a model transform.

If m is singular the result is identity.

void mat3_mul_vec3_ptr(vector3* res, const matrix3* m, const vector3* v)

Multiplies a 3x3 matrix by a vector3.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat3_mul_vec2_ptr(vector2* res, const matrix3* m, const vector2* v)

Applies a 3x3 affine transform to a vector2.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat3_sym_eigen_ptr(vector3* eigenvalues, matrix3* axes, const matrix3* m)

Jacobi eigensolve of a symmetric 3x3 matrix.

Parameters
eigenvalues Output eigenvalues.
axes Output eigenvector columns.
m Input matrix (copied and symmetrized).

m is first replaced by (m + m^T) / 2. Eigenvalues are the diagonal of the rotated matrix; eigenvector i is column i of axes.

void mat4_identity_ptr(matrix4* res)

Sets the matrix to the identity matrix.

Parameters
res Pointer to the matrix4 to set to identity.

The identity matrix is a 4x4 matrix with 1s on the main diagonal and 0s elsewhere.

void mat4_mul_ptr(matrix4* res, const matrix4* a, const matrix4* b)

Multiplies two 4x4 matrices (dispatched).

Parameters
res Result matrix.
a Left matrix.
b Right matrix.

void mat4_transpose_ptr(matrix4* res, const matrix4* m)

Transposes a 4x4 matrix (dispatched).

Parameters
res Result matrix.
m Input matrix.

void mat4_inverse_ptr(matrix4* res, const matrix4* m)

Computes the inverse of a 4x4 matrix.

Parameters
res Pointer to the matrix4 where the inverse will be stored.
m Pointer to the matrix4 to invert.

This function calculates the inverse of the given 4x4 matrix using the adjugate matrix and determinant. If the matrix is singular (determinant is zero), the result is set to the identity matrix.

void mat4_inverse_affine_ptr(matrix4* res, const matrix4* m)

Inverse of an affine matrix [R t; 0 1].

Parameters
res Output inverse matrix.
m Affine 4×4 matrix.

Inverts the upper-left 3×3 and corrects the translation. Last row is fixed as [0 0 0 1]. For a full 4×4 inverse, use mat4_inverse. Singular 3×3 yields identity.

void mat4_translate_ptr(matrix4* res, const vector3* v)

Sets the matrix to a translation matrix.

Parameters
res Pointer to the matrix4 to set.
v Pointer to the vector3 containing the translation values.

This function initializes a 4x4 matrix to represent a translation transformation based on the provided vector, with the translation components placed in the last column and the rest forming an identity matrix.

void mat4_scale_ptr(matrix4* res, const vector3* v)

Sets the matrix to a scaling matrix using the provided scale vector.

Parameters
res Pointer to the matrix4 to set as a scaling matrix.
v Pointer to the vector3 containing the scale factors (x, y, z).

This function constructs a 4x4 scaling matrix where the diagonal elements correspond to the x, y, and z scale factors from the input vector. The bottom-right element is set to 1.0f for homogeneous coordinates. All other elements are implicitly zero (not set, assuming the matrix is initialized).

void mat4_normal_ptr(matrix4* res, const matrix4* m)

Inverse-transpose of the upper-left 3x3, embedded in a matrix4.

Parameters
res Normal matrix as a matrix4.
m Model matrix.

Used to transform surface normals under a (possibly non-uniformly scaled) model matrix. Last row/column stay identity.

void mat4_rotation_ptr(matrix4* res, const vector3* axis, vm_float_t radians)

Sets the matrix to a rotation matrix around the given axis.

Parameters
res Pointer to the matrix4 that will receive the rotation matrix.
axis Pointer to the vector3 representing the rotation axis.
radians The rotation angle in radians.

Constructs a 4x4 rotation matrix that rotates by the specified angle (in radians) around the provided axis. The axis vector is normalized internally.

void mat4_rotation_x_ptr(matrix4* res, vm_float_t radians)

Builds a 4x4 rotation matrix around the X axis (radians).

Parameters
res Result matrix.
radians Rotation angle in radians.

void mat4_rotation_y_ptr(matrix4* res, vm_float_t radians)

Sets the matrix to a rotation matrix around the Y axis.

Parameters
res Pointer to the matrix4 to store the result.
radians Rotation angle in radians.

void mat4_rotation_z_ptr(matrix4* res, vm_float_t radians)

Sets the matrix to a rotation around the Z axis.

Parameters
res Pointer to the matrix4 to store the result.
radians Rotation angle in radians.

void mat4_rotation_deg_ptr(matrix4* res, const vector3* axis, vm_float_t degrees)

Sets the matrix to a rotation matrix using an axis and angle in degrees.

Parameters
res Pointer to the matrix4 that will receive the rotation matrix.
axis Pointer to the vector3 defining the rotation axis.
degrees The rotation angle in degrees.

void mat4_rotation_x_deg_ptr(matrix4* res, vm_float_t degrees)

Builds a 4x4 rotation matrix around the X axis (degrees).

Parameters
res Output value.
degrees Rotation angle in degrees.

void mat4_rotation_y_deg_ptr(matrix4* res, vm_float_t degrees)

Builds a 4x4 rotation matrix around the Y axis (degrees).

Parameters
res Output value.
degrees Rotation angle in degrees.

void mat4_rotation_z_deg_ptr(matrix4* res, vm_float_t degrees)

Builds a 4x4 rotation matrix around the Z axis (degrees).

Parameters
res Output value.
degrees Rotation angle in degrees.

void mat4_trs_ptr(matrix4* res, const vector3* translation, const quaternion* rotation, const vector3* scale)

Builds a 4x4 TRS matrix from translation, rotation, and scale.

Parameters
res Output value.
translation Translation vector.
rotation Rotation quaternion.
scale Scale vector.

void mat4_from_mat3_ptr(matrix4* res, const matrix3* m)

Embeds a matrix3 into the upper-left of a matrix4.

Parameters
res Output value.
m Input matrix.

void mat4_extract_translation_ptr(vector3* res, const matrix4* m)

Extracts the translation vector from a matrix4.

Parameters
res Output value.
m Input matrix.

void mat4_extract_scale_ptr(vector3* res, const matrix4* m)

Extracts the scale vector from a matrix4.

Parameters
res Output value.
m Input matrix.

void mat4_extract_rotation_ptr(quaternion* res, const matrix4* m)

Extracts the rotation quaternion from a matrix4.

Parameters
res Output value.
m Input matrix.

void mat4_ortho_ptr(matrix4* res, vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Sets the matrix to an orthographic projection matrix.

Parameters
res Pointer to the matrix4 to set to the orthographic projection matrix.
left The left clipping plane coordinate.
right The right clipping plane coordinate.
bottom The bottom clipping plane coordinate.
top The top clipping plane coordinate.
near The near clipping plane coordinate.
far The far clipping plane coordinate.

void mat4_look_at_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up)

Constructs a view matrix for a camera positioned at the given location, looking towards a target, with a specified up direction.

Parameters
res Pointer to the matrix4 where the result is stored.
position Pointer to the vector3 representing the camera's position.
target Pointer to the vector3 representing the point the camera is looking at.
up Pointer to the vector3 representing the up direction for the camera.

This function computes a 4x4 view matrix that orients the camera at the position vector, directing it towards the target vector, while aligning the up direction. The matrix is stored in column-major order.

void mat4_look_from_dir_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up)

View matrix from eye position and a look direction (no target point).

Parameters
res View matrix.
position Eye position.
direction Look direction.
up World up direction.

Equivalent to mat4_look_at(position, position + direction, up) with a default forward if direction is near zero.

void mat4_look_from_dir_clip_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up, vm_clip_t clip)

Clip-aware look-from-direction view matrix.

Parameters
res View matrix.
position Eye position.
direction World-space look direction (need not be unit).
up World up hint.
clip Handedness / depth convention.

void mat4_viewport_ptr(matrix4* res, vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height)

Viewport matrix from origin (x, y) and size (width, height).

Parameters
res Output 4×4 matrix.
x Viewport origin x.
y Viewport origin y.
width Viewport width.
height Viewport height.

Maps NDC to window coordinates with depth in [0, 1].

void mat4_viewport_depth_ptr(matrix4* res, vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f)

Viewport matrix from origin, size, and depth range [n, f].

Parameters
res Output 4×4 matrix.
x Viewport origin x.
y Viewport origin y.
width Viewport width.
height Viewport height.
n Near depth.
f Far depth.

Maps NDC to window coordinates with depth in [n, f].

void mat4_perspective_ptr(matrix4* res, vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far)

Creates a perspective projection matrix.

Parameters
res Pointer to the matrix4 to store the perspective projection matrix.
fov Field of view in radians.
aspect Aspect ratio of the viewport (width divided by height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.

This function computes a right-handed perspective projection matrix based on the given field of view, aspect ratio, and near and far clipping planes. The matrix is stored in the provided result pointer.

void mat4_perspective_fov_ptr(matrix4* res, vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Sets the matrix to a perspective projection matrix.

Parameters
res Pointer to the matrix4 to set to the perspective projection matrix.
fov Field of view angle in radians.
w Viewport width.
h Viewport height.
n Near clipping plane distance.
f Far clipping plane distance.

This function constructs a right-handed perspective projection matrix using the specified field of view, viewport width and height, near clipping plane, and far clipping plane.

void mat4_perspective_infinite_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Sets the matrix to an infinite perspective projection matrix.

Parameters
res Pointer to the matrix4 to set to the infinite perspective projection.
fov_y Vertical field of view in radians.
aspect Aspect ratio of the viewport (width / height).
n Distance to the near clipping plane.

This function constructs a perspective projection matrix with an infinite far plane, which is useful for rendering scenes where depth precision is less critical beyond the near plane. The matrix is set such that the field of view and aspect ratio are applied, with the near plane at distance n.

void mat4_perspective_infinite_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite perspective matrix for a chosen clip convention.

Parameters
res Output 4×4 matrix.
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip space convention (handedness and ZO/NO depth).

No far plane. fov_y is in radians.

void mat4_infinite_reverse_z_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective matrix (RH, [0, 1] depth).

Parameters
res Output 4×4 matrix.
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.

void mat4_infinite_reverse_z_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective matrix for a chosen clip convention.

Parameters
res Output 4×4 matrix.
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip space convention (handedness and ZO/NO depth).

No far plane; depth is reversed for better precision. fov_y is in radians.

void mat4_perspective_clip_ptr(matrix4* res, vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Constructs a perspective projection matrix with configurable clip space.

Parameters
res Pointer to the matrix4 to receive the computed projection matrix.
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
clip Clip space convention to use (VM_CLIP_RH_NO, VM_CLIP_RH_ZO, VM_CLIP_LH_ZO or VM_CLIP_LH_NO).

Computes a 4x4 perspective projection matrix based on vertical field of view, aspect ratio, near and far planes, and the desired clip space convention.

void mat4_perspective_deg_ptr(matrix4* res, vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Sets the matrix to a perspective projection matrix using field of view in degrees.

Parameters
res Pointer to the matrix4 to receive the perspective projection.
fov_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.

void mat4_perspective_fov_deg_ptr(matrix4* res, vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Sets the matrix to a perspective projection matrix using vertical field of view in degrees.

Parameters
res Pointer to the matrix4 to be set.
fov_deg Vertical field of view angle in degrees.
w Width of the viewport.
h Height of the viewport.
n Distance to the near clipping plane.
f Distance to the far clipping plane.

void mat4_perspective_infinite_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Sets the matrix to an infinite perspective projection matrix using vertical field of view in degrees.

Parameters
res Pointer to the matrix4 to store the resulting projection matrix.
fov_y_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
n Near clipping plane distance.

void mat4_perspective_infinite_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite perspective matrix from FOV in degrees and clip space.

Parameters
res Output 4×4 matrix.
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip space convention (handedness and ZO/NO depth).

void mat4_infinite_reverse_z_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective matrix from a vertical FOV in degrees.

Parameters
res Output 4×4 matrix.
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.

void mat4_infinite_reverse_z_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective matrix from FOV in degrees and clip space.

Parameters
res Output 4×4 matrix.
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip space convention (handedness and ZO/NO depth).

void mat4_perspective_clip_deg_ptr(matrix4* res, vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Sets a perspective projection matrix using vertical field of view in degrees.

Parameters
res Pointer to the matrix4 that will receive the computed projection matrix.
fov_y_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
clip Clip space convention to use.

void mat4_ortho_clip_ptr(matrix4* res, vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip)

Sets the matrix to an orthographic projection matrix.

Parameters
res Pointer to the matrix4 to store the result.
left Left clipping plane.
right Right clipping plane.
bottom Bottom clipping plane.
top Top clipping plane.
near Near clipping plane.
far Far clipping plane.
clip Clip space convention to use (one of the VM_CLIP_* values).

Constructs a 4x4 orthographic projection matrix based on the provided frustum bounds and the selected clip space convention.

void mat4_look_at_clip_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up, vm_clip_t clip)

Constructs a look-at view matrix with support for different clip space conventions.

Parameters
res Pointer to the matrix4 that will receive the computed view matrix.
position Camera position in world space.
target Target point in world space the camera is looking at.
up World up direction vector.
clip Clip space convention that determines handedness and depth range.

Computes a 4x4 view matrix that positions the camera at position looking towards target, with up defining the world up direction. The resulting matrix is affected by the selected clip space handedness and depth range via the clip parameter.

For right-handed clip conventions the function delegates to mat4_look_at_ptr. For left-handed conventions a dedicated basis is constructed where the camera forward direction points along positive Z.

void mat4_mul_vec4_ptr(vector4* res, const matrix4* m, const vector4* v)

Transforms a vector4 by a 4x4 matrix (dispatched).

Parameters
res Result vector.
m Input matrix.
v Input vector.

void mat4_mul_vec3_ptr(vector3* res, const matrix4* m, const vector3* v, vm_float_t w)

Transforms a vector3 by a 4x4 matrix using homogeneous w (dispatched).

Parameters
res Result vector.
m Input matrix.
v Input vector.
w Homogeneous w component.

void vec3_world_to_window_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport)

Projects a world-space point to window coordinates (OpenGL clip).

Parameters
res Window-space point.
world World-space position.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).

void vec3_window_to_world_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport)

Un-projects a window-space point to world coordinates using model, projection, and viewport.

Parameters
res Output world-space point.
window Window-space point (x, y, depth).
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).

Convenience wrapper around vec3_window_to_world_clip_ptr with VM_CLIP_RH_NO (right-handed, [-1, 1] depth).

void vec3_world_to_window_clip_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport, vm_clip_t clip)

Projects a world-space point into window coordinates using model, projection, viewport, and clip depth range.

Parameters
res Output window-space point (x, y, depth).
world World-space position.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
clip Clip depth range (ZO or NO).

Applies MVP, perspective-divides to NDC, then maps x/y into the viewport. Depth (res->z) is stored in the selected clip convention (ZO or NO). If w is near zero, writes (0, 0, 0).

void vec3_window_to_world_clip_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport, vm_clip_t clip)

Un-projects a window-space point to world coordinates using model, projection, viewport, and clip depth range.

Parameters
res Output world-space point.
window Window-space point (x, y, depth).
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
clip Clip depth range (ZO or NO).

Maps window x/y into NDC, converts depth with the selected clip convention (ZO or NO), then applies the inverse MVP and perspective-divides. If the viewport size or w is near zero, writes (0, 0, 0).

matrix2i mat2i_identity(void)

Constructs the 2x2 integer identity matrix.

Returns The identity matrix2i.

matrix2i mat2i_mul(matrix2i a, matrix2i b)

Multiplies two 2x2 integer matrices (a * b).

Parameters
a The first matrix.
b The second matrix.
Returns The resulting product matrix2i.

matrix2i mat2i_transpose(matrix2i m)

Computes the transpose of a 2x2 integer matrix.

Parameters
m The input matrix.
Returns The transposed matrix2i.

matrix2i mat2i_inverse(matrix2i m)

Computes the inverse of a 2x2 integer matrix.

Parameters
m The input matrix.
Returns The inverse matrix2i.

vector2i mat2i_mul_vec2i(matrix2i m, vector2i v)

Multiplies a 2x2 integer matrix by a vector2i.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector2i.

vm_int_t mat2i_determinant(matrix2i m)

Calculates the determinant of the given 2x2 integer matrix.

Parameters
m The matrix.
Returns The determinant value (m.v[0]*m.v[3] - m.v[1]*m.v[2]).

matrix3i mat3i_identity(void)

Constructs the 3x3 identity matrix.

Returns The identity matrix3i.

matrix3i mat3i_mul(matrix3i a, matrix3i b)

Multiplies two 3x3 integer matrices.

Parameters
a The first matrix.
b The second matrix.
Returns The product matrix.

matrix3i mat3i_transpose(matrix3i m)

Computes the transpose of a 3x3 integer matrix.

Parameters
m The input matrix.
Returns The transposed matrix.

matrix3i mat3i_inverse(matrix3i m)

Computes the inverse of a 3x3 integer matrix.

Parameters
m The input matrix.
Returns The inverse matrix.

vector3i mat3i_mul_vec3i(matrix3i m, vector3i v)

Multiplies a 3x3 integer matrix by a vector3i.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector3i.

vector2i mat3i_mul_vec2i(matrix3i m, vector2i v)

Applies a 3x3 integer affine transform to a vector2i.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector2i.

vm_int_t mat3i_determinant(matrix3i m)

Computes the determinant of a 3x3 integer matrix.

Parameters
m The input matrix.
Returns The determinant value.

matrix4i mat4i_identity(void)

Constructs the 4x4 identity matrix.

Returns The identity matrix4i.

matrix4i mat4i_mul(matrix4i a, matrix4i b)

Multiplies two 4x4 integer matrices.

Parameters
a The first matrix.
b The second matrix.
Returns The product matrix.

matrix4i mat4i_transpose(matrix4i m)

Computes the transpose of a 4x4 integer matrix.

Parameters
m The input matrix.
Returns The transposed matrix.

matrix4i mat4i_inverse(matrix4i m)

Computes the inverse of a 4x4 integer matrix.

Parameters
m The input matrix.
Returns The inverse matrix.

vector4i mat4i_mul_vec4i(matrix4i m, vector4i v)

Multiplies a 4x4 integer matrix by a vector4i.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector4i.

vector3i mat4i_mul_vec3i(matrix4i m, vector3i v, vm_int_t w)

Transforms a vector3i by a 4x4 integer matrix using homogeneous w.

Parameters
m Input matrix.
v Input vector.
w Homogeneous w component.
Returns The resulting vector3i.

vm_int_t mat4i_determinant(matrix4i m)

Computes the determinant of a 4x4 integer matrix (Laplace expansion along first row).

Parameters
m The input matrix.
Returns The determinant value.

void mat2i_identity_ptr(matrix2i* res)

Initializes the integer 2x2 matrix to identity (diagonal 1, others 0).

Parameters
res Pointer to the output matrix2i.

void mat2i_mul_ptr(matrix2i* res, const matrix2i* a, const matrix2i* b)

Multiplies two integer 2x2 matrices (a * b) using explicit loops and stores the result in res.

Parameters
res Pointer to the output matrix2i.
a Pointer to the first matrix.
b Pointer to the second matrix.

void mat2i_transpose_ptr(matrix2i* res, const matrix2i* m)

Computes the transpose of the input integer 2x2 matrix and stores in res.

Parameters
res Pointer to the output matrix2i.
m Pointer to the input matrix.

void mat2i_inverse_ptr(matrix2i* res, const matrix2i* m)

Computes the inverse of the input integer 2x2 matrix and stores in res.

Parameters
res Pointer to the output matrix2i.
m Pointer to the input matrix.

Uses double precision for inversion, truncates to int; sets to identity if det=0.

void mat2i_mul_vec2i_ptr(vector2i* res, const matrix2i* m, const vector2i* v)

Multiplies a 2x2 integer matrix by a vector2i.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat3i_identity_ptr(matrix3i* res)

Fills the given 3x3 integer matrix with the identity matrix.

Parameters
res Pointer to the result matrix.

void mat3i_mul_ptr(matrix3i* res, const matrix3i* a, const matrix3i* b)

Multiplies two 3x3 integer matrices (standard matrix multiplication).

Parameters
res Pointer to the result matrix.
a Pointer to the first input matrix.
b Pointer to the second input matrix.

void mat3i_transpose_ptr(matrix3i* res, const matrix3i* m)

Computes the transpose of a 3x3 integer matrix.

Parameters
res Pointer to the result matrix.
m Pointer to the input matrix.

void mat3i_inverse_ptr(matrix3i* res, const matrix3i* m)

Computes the inverse of a 3x3 integer matrix using adjugate over determinant.

Parameters
res Pointer to the result matrix.
m Pointer to the input matrix.

If the determinant is zero (singular), sets the result to the identity matrix.

void mat3i_mul_vec3i_ptr(vector3i* res, const matrix3i* m, const vector3i* v)

Multiplies a 3x3 integer matrix by a vector3i.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat3i_mul_vec2i_ptr(vector2i* res, const matrix3i* m, const vector2i* v)

Applies a 3x3 integer affine transform to a vector2i.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat4i_identity_ptr(matrix4i* res)

Sets the given 4x4 integer matrix to the identity matrix.

Parameters
res Pointer to the matrix structure to set to identity.

void mat4i_mul_ptr(matrix4i* res, const matrix4i* a, const matrix4i* b)

Performs matrix multiplication of two 4x4 matrices and stores the result.

Parameters
res Pointer to the matrix structure to store the result of the multiplication.
a Pointer to the first matrix operand.
b Pointer to the second matrix operand.

void mat4i_transpose_ptr(matrix4i* res, const matrix4i* m)

Transposes the given 4x4 integer matrix and stores the result in the provided matrix structure.

Parameters
res Pointer to the matrix structure to store the transposed matrix.
m Pointer to the input matrix to be transposed.

void mat4i_inverse_ptr(matrix4i* res, const matrix4i* m)

Computes the inverse of the given 4x4 integer matrix and stores the result in the specified matrix.

Parameters
res Pointer to the matrix structure to store the inverse matrix.
m Pointer to the constant matrix to be inverted.

If the matrix is singular (determinant is zero), the result is set to the identity matrix.

void mat4i_mul_vec4i_ptr(vector4i* res, const matrix4i* m, const vector4i* v)

Multiplies a 4x4 integer matrix by a vector4i.

Parameters
res Output value.
m Input matrix.
v Input vector.

void mat4i_mul_vec3i_ptr(vector3i* res, const matrix4i* m, const vector3i* v, vm_int_t w)

Transforms a vector3i by a 4x4 integer matrix using homogeneous w.

Parameters
res Output value.
m Input matrix.
v Input vector.
w Homogeneous w component.

quaternion quat_identity(void)

Constructs the identity quaternion.

Returns The identity quaternion.

quaternion quat_mul(quaternion a, quaternion b)

Multiplies two quaternions (a * b).

Parameters
a The first quaternion.
b The second quaternion.
Returns The resulting product quaternion.

quaternion quat_normalize(quaternion q)

Normalizes a quaternion.

Parameters
q The input quaternion.
Returns The normalized quaternion.

quaternion quat_conjugate(quaternion q)

Returns the conjugate of a quaternion.

Parameters
q Input quaternion.
Returns The resulting quaternion.

quaternion quat_inverse(quaternion q)

Returns the inverse of a quaternion.

Parameters
q Input quaternion.
Returns The resulting quaternion.

quaternion quat_from_euler(vector3 euler)

Constructs a quaternion from Euler angles.

Parameters
euler Euler angles in radians.
Returns The resulting quaternion.

quaternion quat_from_euler_deg(vector3 euler_deg)

Constructs a quaternion from Euler angles in degrees.

Parameters
euler_deg Euler angles in degrees.
Returns The resulting quaternion.

quaternion quat_from_axis_angle(vector3 axis, vm_float_t radians)

Constructs a quaternion from a rotation axis and angle.

Parameters
axis The rotation axis. Must be normalized.
radians The rotation angle in radians.
Returns The resulting rotation quaternion.

quaternion quat_from_axis_angle_deg(vector3 axis, vm_float_t degrees)

Constructs a quaternion from an axis and an angle in degrees.

Parameters
axis The rotation axis.
degrees The rotation angle in degrees.
Returns The resulting quaternion.

quaternion quat_from_mat3(matrix3 m)

Builds a quaternion from a 3x3 rotation matrix.

Parameters
m Input matrix.
Returns The resulting quaternion.

quaternion quat_from_mat4(matrix4 m)

Builds a quaternion from the rotation of a 4x4 matrix.

Parameters
m Input matrix.
Returns The resulting quaternion.

quaternion quat_look(vector3 direction, vector3 up)

Constructs a quaternion that rotates from the negative Z axis towards the given direction, with the specified up vector.

Parameters
direction The target direction vector to look towards.
up The up vector.
Returns The look rotation quaternion.

quaternion quat_look_clip(vector3 direction, vector3 up, vm_clip_t clip)

Constructs a quaternion representing a look-at rotation with specified clip space.

Parameters
direction The forward direction vector.
up The up direction vector.
clip The clip space convention.
Returns The look-at quaternion.

quaternion quat_from_to(vector3 from, vector3 to)

Constructs a quaternion representing the shortest rotation from one vector to another.

Parameters
from The source direction vector.
to The target direction vector.
Returns Quaternion that rotates from into to.

quaternion quat_slerp(quaternion a, quaternion b, vm_float_t t)

Spherical-linearly interpolates from a to b by t.

Parameters
a First input quaternion.
b Second input quaternion.
t Interpolation factor.
Returns The resulting quaternion.

quaternion quat_nlerp(quaternion a, quaternion b, vm_float_t t)

Normalized-linearly interpolates from a to b by t.

Parameters
a First input quaternion.
b Second input quaternion.
t Interpolation factor.
Returns The resulting quaternion.

quaternion quat_integrate(quaternion q, vector3 omega, vm_float_t dt)

Integrates a quaternion using angular velocity.

Parameters
q The starting quaternion.
omega Angular velocity vector.
dt Time delta.
Returns The integrated quaternion.

vector3 quat_rotate_vec3(quaternion q, vector3 v)

Rotates a vector3 by a quaternion.

Parameters
q Input quaternion.
v Input vector.
Returns The resulting vector3.

vector3 quat_to_euler(quaternion q)

Converts a quaternion to Euler angles in degrees (XYZ).

Parameters
q Input quaternion.
Returns The resulting vector3.

vector3 quat_to_euler_deg(quaternion q)

Converts a quaternion to Euler angles in degrees.

Parameters
q The quaternion to convert.
Returns The Euler angles in degrees as a vector3.

vector3 quat_to_axis_angle(quaternion q, vm_float_t* radians)

Converts a quaternion to axis-angle representation.

Parameters
q The input quaternion.
radians Pointer to a float that receives the rotation angle in radians.
Returns The rotation axis vector.

vector3 quat_to_axis_angle_deg(quaternion q, vm_float_t* degrees)

Converts a quaternion to axis-angle representation in degrees.

Parameters
q Input quaternion.
degrees Pointer to a float that receives the rotation angle in degrees.
Returns The rotation axis vector.

matrix4 quat_to_mat4(quaternion q)

Converts a quaternion to a 4x4 rotation matrix.

Parameters
q The input quaternion.
Returns The equivalent matrix4.

matrix3 quat_to_mat3(quaternion q)

Converts a quaternion to a 3x3 rotation matrix.

Parameters
q Input quaternion.
Returns The resulting matrix3.

vm_float_t quat_dot(quaternion a, quaternion b)

Returns the dot product of two quaternions.

Parameters
a First input quaternion.
b Second input quaternion.
Returns The resulting vm_float_t.

bool quat_near(quaternion a, quaternion b, vm_float_t eps)

Returns true if a and b are within eps of each other.

Parameters
a First input quaternion.
b Second input quaternion.
eps Distance tolerance.
Returns True if a and b are within eps.

void quat_identity_ptr(quaternion* res)

Sets the quaternion to the identity quaternion (x=0, y=0, z=0, w=1).

Parameters
res Pointer to the quaternion to initialize.

void quat_mul_ptr(quaternion* res, const quaternion* a, const quaternion* b)

Hamilton product a * b (dispatched).

Parameters
res Result quaternion.
a Left quaternion.
b Right quaternion.

void quat_normalize_ptr(quaternion* res, const quaternion* q)

Normalizes a quaternion (dispatched).

Parameters
res Result quaternion.
q Input quaternion.

void quat_conjugate_ptr(quaternion* res, const quaternion* q)

Writes the conjugate of a quaternion.

Parameters
res Output value.
q Input quaternion.

void quat_inverse_ptr(quaternion* res, const quaternion* q)

Writes the inverse of a quaternion.

Parameters
res Output value.
q Input quaternion.

void quat_from_euler_ptr(quaternion* res, const vector3* euler)

Converts Euler angles (in radians) to a normalized quaternion.

Parameters
res Pointer to the quaternion that will receive the result.
euler Pointer to a vector3 containing the Euler angles in radians (x, y, z).

Computes a quaternion from the given Euler rotation vector using the XYZ (Tait-Bryan) convention. The resulting quaternion is guaranteed to be normalized.

void quat_from_euler_deg_ptr(quaternion* res, const vector3* euler_deg)

Converts Euler angles in degrees to a quaternion.

Parameters
res Pointer to the quaternion to store the result.
euler_deg Pointer to the vector containing Euler angles in degrees.

void quat_from_axis_angle_ptr(quaternion* res, const vector3* axis, vm_float_t radians)

Converts an axis-angle rotation to a quaternion.

Parameters
res Pointer to the quaternion that will receive the result.
axis Pointer to the rotation axis vector.
radians Rotation angle around the axis in radians.

The axis vector is normalized internally. The angle is given in radians.

void quat_from_axis_angle_deg_ptr(quaternion* res, const vector3* axis, vm_float_t degrees)

Converts an axis-angle rotation (in degrees) to a quaternion.

Parameters
res Pointer to the quaternion that will receive the result.
axis Pointer to the rotation axis vector.
degrees Rotation angle around the axis in degrees.

void quat_from_mat3_ptr(quaternion* res, const matrix3* m)

Builds a quaternion from a 3x3 rotation matrix.

Parameters
res Output value.
m Input matrix.

void quat_from_mat4_ptr(quaternion* res, const matrix4* m)

Builds a quaternion from the rotation of a 4x4 matrix.

Parameters
res Output value.
m Input matrix.

void quat_look_ptr(quaternion* res, const vector3* direction, const vector3* up)

Orientation that aims local -Z along direction (RH / FPS camera).

Parameters
res Result quaternion.
direction Look direction.
up World up hint.

Matches the rotation part of mat4_look_from_dir inverted (view-to-world).

void quat_look_clip_ptr(quaternion* res, const vector3* direction, const vector3* up, vm_clip_t clip)

Orientation that aims along direction.

Parameters
res Result quaternion.
direction Look direction.
up World up hint.
clip Clip-space convention selecting handedness.

RH: local -Z maps to direction. LH: local +Z maps to direction.

void quat_from_to_ptr(quaternion* res, const vector3* from, const vector3* to)

Shortest rotation taking from onto to.

Parameters
res Result quaternion.
from Source direction.
to Target direction.

Opposite vectors pick a stable orthogonal axis (180 deg). Near-parallel vectors return identity.

void quat_slerp_ptr(quaternion* res, const quaternion* a, const quaternion* b, vm_float_t t)

Spherical-linearly interpolates from a to b by t.

Parameters
res Output value.
a First input quaternion.
b Second input quaternion.
t Interpolation factor.

void quat_nlerp_ptr(quaternion* res, const quaternion* a, const quaternion* b, vm_float_t t)

Normalized-linearly interpolates from a to b by t.

Parameters
res Output value.
a First input quaternion.
b Second input quaternion.
t Interpolation factor.

void quat_rotate_vec3_ptr(vector3* res, const quaternion* q, const vector3* v)

Rotates a vector3 by a quaternion.

Parameters
res Output value.
q Input quaternion.
v Input vector.

void quat_to_euler_ptr(vector3* res, const quaternion* q)

Converts a quaternion to Euler angles in degrees (XYZ).

Parameters
res Output value.
q Input quaternion.

void quat_to_euler_deg_ptr(vector3* res, const quaternion* q)

Converts a quaternion to XYZ Euler angles in degrees.

Parameters
res Euler angles in degrees (x, y, z).
q Input quaternion.

void quat_to_axis_angle_ptr(vector3* axis, vm_float_t* radians, const quaternion* q)

Converts a quaternion to an axis-angle representation.

Parameters
axis Pointer to the vector3 that will receive the rotation axis.
radians Pointer to a float that will receive the rotation angle in radians, or NULL.
q Pointer to the input quaternion.

The quaternion is first normalized. The axis is stored in the provided vector3 pointer. The rotation angle in radians is optionally written to the radians pointer if it is not NULL. When the axis cannot be uniquely determined (near zero rotation) the axis is set to (1, 0, 0).

void quat_to_axis_angle_deg_ptr(vector3* axis, vm_float_t* degrees, const quaternion* q)

Converts a quaternion to an axis-angle representation, with the angle in degrees.

Parameters
axis Pointer to the vector3 that will receive the normalized rotation axis.
degrees Pointer to a float that will receive the rotation angle in degrees (may be NULL).
q Pointer to the source quaternion.

Extracts the rotation axis and rotation angle (in degrees) equivalent to the given quaternion. The quaternion is first normalized internally. If the quaternion represents no rotation, the axis is set to (1, 0, 0).

void quat_to_mat4_ptr(matrix4* res, const quaternion* q)

Converts a unit quaternion to a 4x4 rotation matrix and stores in res.

Parameters
res Pointer to the output matrix4.
q Pointer to the input quaternion (should be normalized).

Starts with the identity matrix and applies rotation components.

void quat_to_mat3_ptr(matrix3* res, const quaternion* q)

Converts a quaternion to a 3x3 rotation matrix.

Parameters
res Output value.
q Input quaternion.

void quat_integrate_ptr(quaternion* res, const quaternion* q, const vector3* omega, vm_float_t dt)

Integrates angular velocity over a time step and applies the resulting rotation to the input quaternion.

Parameters
res Pointer to the quaternion where the integrated result is stored.
q Pointer to the source quaternion.
omega Pointer to the angular velocity vector (in radians per second).
dt Time step (in seconds).

Computes a delta quaternion from the angular velocity and timestep, multiplies it with the source quaternion and normalizes the result.

vector2 vec2_from(const vector2i* v)

Converts a vector2i to a vector2.

Parameters
v Input integer vector.
Returns The resulting vector2.

vector2i vec2i_from(const vector2* v)

Converts a vector2 to a vector2i by truncation.

Parameters
v Input vector.
Returns The resulting vector2i.

vector2i vec2i_from_floored(const vector2* v)

Converts a vector2 to a vector2i by flooring each component.

Parameters
v Input vector.
Returns The resulting vector2i.

vector2i vec2i_from_rounded(const vector2* v)

Converts a vector2 to a vector2i by rounding each component.

Parameters
v Input vector.
Returns The resulting vector2i.

vector3 vec3_from(const vector3i* v)

Converts a vector3i to a vector3.

Parameters
v Input integer vector.
Returns The resulting vector3.

vector3i vec3i_from(const vector3* v)

Converts a vector3 to a vector3i by truncation.

Parameters
v Input vector.
Returns The resulting vector3i.

vector3i vec3i_from_floored(const vector3* v)

Converts a vector3 to a vector3i by flooring each component.

Parameters
v Input vector.
Returns The resulting vector3i.

vector3i vec3i_from_rounded(const vector3* v)

Converts a vector3 to a vector3i by rounding each component.

Parameters
v Input vector.
Returns The resulting vector3i.

vm_float_t deg_to_rad(vm_float_t degrees)

Converts degrees to radians.

Parameters
degrees Angle in degrees.
Returns The angle in radians.

vm_float_t rad_to_deg(vm_float_t radians)

Converts radians to degrees.

Parameters
radians Angle in radians.
Returns The angle in degrees.

void vm_gemm(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout)

C = alpha * op(A) * op(B) + beta * C for dense float panels.

Parameters
C Output matrix (M×N), updated in place.
ldc Leading dimension of C.
A Left input matrix; ignored when alpha == 0 or K <= 0.
lda Leading dimension of A.
B Right input matrix; ignored when alpha == 0 or K <= 0.
ldb Leading dimension of B.
M Number of rows of op(A) and C.
N Number of columns of op(B) and C.
K Inner product length.
alpha Scale factor for the A*B product.
beta Scale factor for the existing C values.
transA If true, use A^T; otherwise A.
transB If true, use B^T; otherwise B.
layout Memory layout for A, B, and C.

Blocked packed kernel with thread-local A/B workspaces. Equivalent to vm_gemm_ex with op == VM_GEMM_OP_NONE.

void vm_gemm_ref(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout)

Triple-loop reference GEMM.

Parameters
C Output matrix (M×N), updated in place.
ldc Leading dimension of C.
A Left input matrix; ignored when alpha == 0 or K <= 0.
lda Leading dimension of A.
B Right input matrix; ignored when alpha == 0 or K <= 0.
ldb Leading dimension of B.
M Number of rows of op(A) and C.
N Number of columns of op(B) and C.
K Inner product length (columns of op(A), rows of op(B)).
alpha Scale factor for the A*B product.
beta Scale factor for the existing C values (0 skips reading C).
transA If true, use A^T; otherwise A.
transB If true, use B^T; otherwise B.
layout Memory layout for A, B, and C.

Useful for tests and tiny/fallback paths.

Computes C = alpha * op(A) * op(B) + beta * C. op(X) = X or X^T according to the matching transpose flag. Layout selects row-major or column-major indexing for A, B and C together.

void vm_gemm_batch(vm_float_t*const* C, int ldc, const vm_float_t*const* A, int lda, const vm_float_t*const* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int batch)

Batched GEMM: batch independent GEMMs with shared shape.

Parameters
C Array of batch pointers to output matrices (each M×N).
ldc Leading dimension shared by every C[p].
A Array of batch pointers to left matrices, or NULL.
lda Leading dimension shared by every A[p].
B Array of batch pointers to right matrices, or NULL.
ldb Leading dimension shared by every B[p].
M Number of rows of op(A) and C (same for all problems).
N Number of columns of op(B) and C (same for all problems).
K Inner product length (same for all problems).
alpha Scale factor for each A*B product.
beta Scale factor for each existing C[p].
transA If true, use A^T for every problem; otherwise A.
transB If true, use B^T for every problem; otherwise B.
layout Memory layout for all A, B, and C panels.
batch Number of independent GEMM problems.

A[p], B[p], C[p] are the p-th problem. If every B[p] aliases the same buffer, uses a shared-B pack path; otherwise runs per-item vm_gemm. The batch range is split across worker threads when the work is large enough.

void vm_gemm_strided_batch(vm_float_t* C, int ldc, int strideC, const vm_float_t* A, int lda, int strideA, const vm_float_t* B, int ldb, int strideB, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int batch)

Strided batched GEMM: problems live strideX elements apart.

Parameters
C Base pointer for output matrices; problem p at C + p*strideC.
ldc Leading dimension shared by every C panel.
strideC Element stride between consecutive C problems.
A Base pointer for left matrices, or NULL; problem p at A + p*strideA.
lda Leading dimension shared by every A panel.
strideA Element stride between consecutive A problems.
B Base pointer for right matrices, or NULL; problem p at B + p*strideB.
ldb Leading dimension shared by every B panel.
strideB Element stride between B problems (0 means one shared B).
M Number of rows of op(A) and C (same for all problems).
N Number of columns of op(B) and C (same for all problems).
K Inner product length (same for all problems).
alpha Scale factor for each A*B product.
beta Scale factor for each existing C panel.
transA If true, use A^T for every problem; otherwise A.
transB If true, use B^T for every problem; otherwise B.
layout Memory layout for all A, B, and C panels.
batch Number of independent GEMM problems.

Problem p uses A + p * strideA, B + p * strideB, C + p * strideC. When strideB == 0 (shared B), reuses the shared-B batch path.

void vm_gemm_ex(vm_float_t* C, int ldc, const vm_float_t* A, int lda, const vm_float_t* B, int ldb, int M, int N, int K, vm_float_t alpha, vm_float_t beta, bool transA, bool transB, vm_layout_t layout, int op, const vm_float_t* bias)

C = alpha * op(A) * op(B) + beta * C with optional fused epilogue.

Parameters
C Output matrix (M×N), updated in place.
ldc Leading dimension of C.
A Left input matrix; ignored when alpha == 0 or K <= 0.
lda Leading dimension of A.
B Right input matrix; ignored when alpha == 0 or K <= 0.
ldb Leading dimension of B.
M Number of rows of op(A) and C.
N Number of columns of op(B) and C.
K Inner product length.
alpha Scale factor for the A*B product.
beta Scale factor for the existing C values.
transA If true, use A^T; otherwise A.
transB If true, use B^T; otherwise B.
layout Memory layout for A, B, and C.
op Epilogue flags (VM_GEMM_OP_*).
bias Optional length-N bias vector (may be NULL).

Same blocked packed path as vm_gemm, plus last-K bias add and/or ReLU when requested via op.

int vm_gemm_threads(void)

Resolve the GEMM worker-thread budget.

Returns Requested thread count (>= 1 from hardware fallback when unset).

Order: vm_gemm_set_threads limit if > 0; else a positive integer from VECMAT_GEMM_THREADS (invalid values ignored); else online CPU count.

void vm_gemm_set_threads(int n)

Cap or force the GEMM worker-thread budget.

Parameters
n Thread limit (0 = auto, 1 = serial, N = cap at N).

n > 0 sets a fixed limit used by vm_gemm_threads; n == 0 (or negative, treated as 0) restores auto selection via env / hardware.

void vm_im2col(vm_float_t* col, int ld_col, const vm_float_t* img, int n, int c, int h, int w, int kh, int kw, int pad_h, int pad_w, int stride_h, int stride_w, vm_layout_t layout)

NCHW im2col into a GEMM-ready panel.

Parameters
col Destination matrix for unfolded patches.
ld_col Leading dimension of col under layout.
img Source image tensor in NCHW order.
n Batch size (N).
c Channel count (C).
h Input height (H).
w Input width (W).
kh Kernel height.
kw Kernel width.
pad_h Top/bottom padding in pixels.
pad_w Left/right padding in pixels.
stride_h Vertical kernel stride (<= 0 treated as 1).
stride_w Horizontal kernel stride (<= 0 treated as 1).
layout Row-major or column-major storage for col.

img is N×C×H×W packed as ((n*C+c)*H+y)*W+x. Output has C*kH*kW rows and N*outH*outW columns (zero-filled off-image taps). outH/outW use standard floor division with the given pads and strides; non-positive stride_h / stride_w are treated as 1.

vm_mat vm_mat_alloc(int rows, int cols)

Allocates a new matrix with the specified dimensions.

Parameters
rows number of rows in the matrix
cols number of columns in the matrix
Returns allocated matrix or zero matrix on failure

Memory is allocated using calloc to initialize all elements to zero. If allocation fails or if dimensions are invalid, a matrix with zero dimensions and NULL data pointer is returned.

void vm_mat_free(vm_mat* m)

Frees the memory allocated for a matrix and resets its state.

Parameters
m pointer to the matrix to free

If the matrix pointer is NULL, the function returns immediately. The data pointer is freed (if allocated), then set to NULL and both dimensions are reset to zero.

void vm_mat_zero(vm_mat* m)

Sets all elements of the matrix to zero.

Parameters
m pointer to the matrix to be zeroed

If the matrix pointer or its data pointer is NULL, the function returns immediately without performing any operation.

vm_float_t vm_mat_get(const vm_mat* m, int r, int c)

Returns the value of the matrix element at the specified row and column.

Parameters
m pointer to the matrix
r zero-based row index
c zero-based column index
Returns value at (r, c) or 0.0f on invalid input

If the matrix pointer is NULL, the data pointer is NULL, or the row or column indices are out of bounds, the function returns 0.0f without accessing memory.

void vm_mat_set(vm_mat* m, int r, int c, vm_float_t v)

Sets the element at the specified row and column in the matrix to the given value.

Parameters
m pointer to the matrix to modify
r row index
c column index
v value to set at the specified position

The function performs bounds checking and validates the matrix pointer and its data buffer before performing the assignment. If any validation fails, the function returns without modifying any data.

bool vm_mat_copy(vm_mat* dst, const vm_mat* src)

Copies the contents of one matrix to another.

Parameters
dst pointer to the destination matrix
src pointer to the source matrix
Returns true on success, false if either pointer is NULL, source data is NULL or memory allocation fails

If the destination matrix has incompatible dimensions or unallocated data it is freed and reallocated to match the source dimensions. The source matrix must be valid and have allocated data.

vm_float_t vm_mat_det(const vm_mat* A)

Determinant of a square matrix via LU.

Parameters
A Square matrix (not modified).
Returns det(A), or 0 on failure.

bool vm_mat_inverse(vm_mat* out, const vm_mat* A)

Inverse of a square matrix via LU.

Parameters
out Inverse on success.
A Square matrix (not modified).
Returns True on success.

Allocates or resizes out when it is not already n x n.

bool vm_lu_factor(vm_mat* A, int* pivot, int* sign)

In-place LU factorization with partial pivoting.

Parameters
A Square matrix, overwritten with L and U.
pivot Row permutation; length A->rows.
sign Optional; set to +1 or -1 for the permutation sign.
Returns True on success.

On success A holds L (unit diagonal, strictly below) and U (on and above the diagonal). pivot[i] is the original row now at position i.

bool vm_lu_solve(const vm_mat* LU, const int* pivot, const vm_float_t* b, vm_float_t* x)

Solves A x = b from a factored LU.

Parameters
LU Factored matrix from vm_lu_factor.
pivot Row permutation from vm_lu_factor.
b Right-hand side, length n.
x Solution, length n.
Returns True on success.

bool vm_qr_factor(vm_mat* A, vm_float_t* tau)

In-place Householder QR.

Parameters
A Matrix overwritten with R and Householder vectors.
tau Householder scales, length min(m, n).
Returns True on success.

A is m x n.

On success the upper triangle of A is R and the strict lower part stores Householder vectors. tau must hold min(m, n) scalars.

bool vm_qr_unpack(vm_mat* Q, vm_mat* R, const vm_mat* QR, const vm_float_t* tau)

Thin factors: Q is m x k, R is k x n, k = min(m, n).

Parameters
Q Orthonormal factor on success.
R Upper-triangular factor on success.
QR Factored matrix from vm_qr_factor.
tau Householder scales from vm_qr_factor.
Returns True on success.

Allocates or resizes Q and R when they do not already match.

bool vm_qr_solve(const vm_mat* QR, const vm_float_t* tau, const vm_float_t* b, vm_float_t* x)

Least-squares solve min ||A x - b|| from a factored QR.

Parameters
QR Factored matrix from vm_qr_factor.
tau Householder scales from vm_qr_factor.
b Right-hand side, length m.
x Solution, length n.
Returns True on success.

Requires m >= n. b has length m, x has length n.

bool vm_svd_factor(const vm_mat* A, vm_mat* U, vm_float_t* s, vm_mat* V)

Thin SVD A = U diag(s) V^T.

Parameters
A Input matrix (not modified).
U Left singular vectors on success.
s Singular values, length min(m, n).
V Right singular vectors on success.
Returns True on success.

s has length k = min(m, n) (descending). U is m x k, V is n x k (columns are singular vectors). Allocates or resizes U and V.

bool vm_chol_factor(vm_mat* A)

In-place dense Cholesky A = L Lᵀ (lower triangle overwritten).

Parameters
A Square dense matrix (destroyed / factored in place).
Returns true on success, false if not SPD or invalid input.

A must be square SPD. The strict upper triangle is left untouched.

bool vm_chol_solve(const vm_mat* L, const vm_float_t* b, vm_float_t* x)

Solve L Lᵀ x = b after vm_chol_factor.

Parameters
L Factored lower triangle from vm_chol_factor.
b Right-hand side (length n).
x Solution (length n).
Returns true on success, false on error.

void vm_spmat_init(vm_spmat* A)

Initialize a sparse matrix to empty.

Parameters
A Sparse matrix (may be NULL).

void vm_spmat_free(vm_spmat* A)

Free sparse matrix storage and reset it.

Parameters
A Sparse matrix (may be NULL).

bool vm_spmat_from_triplets(vm_spmat* A, int n, int nnz, const int* row, const int* col, const vm_float_t* val)

Build a square CSR matrix from unsorted (row, col, val) triplets.

Parameters
A Output sparse matrix.
n Matrix size (n×n).
nnz Number of input triplets.
row Row indices (length nnz).
col Column indices (length nnz).
val Values (length nnz).
Returns true on success, false on error.

Duplicate (i, j) entries are summed. Out-of-range indices are skipped. On success, existing storage in A is freed and replaced.

void vm_spmv(vm_float_t* y, const vm_spmat* A, const vm_float_t* x)

Sparse matrix–vector product y = A x.

Parameters
y Output vector (length A->n).
A CSR matrix.
x Input vector (length A->n).

bool vm_spmat_diag(const vm_spmat* A, vm_float_t* d)

Extract the main diagonal of A into d.

Parameters
A CSR matrix.
d Output diagonal (length A->n).
Returns true on success, false on error.

Missing diagonal entries are set to 0.

bool vm_cg(const vm_spmat* A, const vm_float_t* b, vm_float_t* x, vm_float_t tol, int max_iter, vm_ksp_prec_t pre_cond, vm_ksp_info* info)

Conjugate gradient for SPD A x = b.

Parameters
A SPD CSR matrix.
b Right-hand side (length A->n).
x Initial guess / solution (length A->n).
tol Relative residual tolerance (≤0 picks a default).
max_iter Max iterations (≤0 defaults to n).
pre_cond NONE, JACOBI, SSOR, or IC0.
info Optional solver stats (may be NULL).
Returns true if converged, false otherwise.

x is the initial guess and the solution. tol is relative residual ||r|| / max(||b||, ε).

bool vm_bicgstab(const vm_spmat* A, const vm_float_t* b, vm_float_t* x, vm_float_t tol, int max_iter, vm_ksp_prec_t pre_cond, vm_ksp_info* info)

BiCGSTAB for general (possibly nonsymmetric) A x = b.

Parameters
A CSR matrix.
b Right-hand side (length A->n).
x Initial guess / solution (length A->n).
tol Relative residual tolerance (≤0 picks a default).
max_iter Max iterations (≤0 defaults to 2n).
pre_cond NONE, JACOBI, SSOR, or IC0.
info Optional solver stats (may be NULL).
Returns true if converged, false otherwise.

Same calling convention as vm_cg. Jacobi / SSOR / IC0 are left preconditioners; IC0 still expects an SPD-like diagonal.

void vm_euler_semi(vm_float_t* x, vm_float_t* v, const vm_float_t* a, int n, vm_float_t dt)

Semi-implicit Euler: v += a dt, then x += v dt.

Parameters
x Position vector (in/out); length n.
v Velocity vector (in/out); length n.
a Acceleration vector; length n.
n State dimension.
dt Timestep.

void vm_verlet(vm_acc_fn acc, vm_float_t* x, vm_float_t* v, vm_float_t* a, int n, vm_float_t dt, void* ctx)

Velocity Verlet with an acceleration callback.

Parameters
acc Acceleration callback acc(x, a, ctx).
x Position vector (in/out); length n.
v Velocity vector (in/out); length n.
a Acceleration vector (in/out); length n.
n State dimension.
dt Timestep.
ctx User context passed to acc.

Uses the incoming a at x, advances x, re-evaluates acc, then completes the velocity half-kick.

void vm_rk2(vm_ode_fn f, vm_float_t* y, int n, vm_float_t dt, void* ctx)

Explicit midpoint RK2 for y' = f(y).

Parameters
f ODE right-hand side f(y, dy, ctx).
y State vector (in/out); length n.
n State dimension.
dt Timestep.
ctx User context passed to f.

void vm_rk4(vm_ode_fn f, vm_float_t* y, int n, vm_float_t dt, void* ctx)

Classic RK4 for y' = f(y).

Parameters
f ODE right-hand side f(y, dy, ctx).
y State vector (in/out); length n.
n State dimension.
dt Timestep.
ctx User context passed to f.

vm_float_t vm_cfl_dt(vm_float_t cfl, vm_float_t dx, vm_float_t speed)

CFL timestep dt = cfl * dx / (|u| + ε).

Parameters
cfl CFL number (typically in (0, 1]).
dx Characteristic cell size.
speed Characteristic speed (e.g. |u|).
Returns Stable timestep estimate.

bool mat3_chol(matrix3 a, matrix3* L)

3×3 Cholesky A = L Lᵀ.

Parameters
a SPD coefficient matrix.
L Lower-triangular Cholesky factor (out); upper triangle set to 0.
Returns true on success, false if L is NULL or a is not SPD.

L is lower; the upper triangle is zeroed.

bool mat3_spd_solve(matrix3 a, vector3 b, vector3* x)

Solve the 3×3 SPD system A x = b via Cholesky.

Parameters
a SPD coefficient matrix.
b Right-hand side vector.
x Solution vector (out).
Returns true on success, false if x is NULL or factorization fails.

matrix3 vm_inertia_world(matrix3 ib, quaternion q)

World-frame inertia I_w = R I_b Rᵀ from a body tensor and orientation.

Parameters
ib Body-frame inertia tensor.
q Orientation quaternion.
Returns World-frame inertia tensor.

vector3 vm_omega_from_angmom(matrix3 I, vector3 L)

Recover ω from angular momentum L = I ω.

Parameters
I Inertia tensor (same frame as L).
L Angular momentum.
Returns Angular velocity, or the zero vector if the solve fails.

vm_float_t vm_rigid_energy(vm_float_t mass, vector3 v, matrix3 I, vector3 w)

Rigid kinetic energy ½ m |v|² + ½ ω · (I ω).

Parameters
mass Mass.
v Linear velocity.
I Inertia tensor (same frame as w).
w Angular velocity (same frame as I).
Returns Kinetic energy.

I and ω must share a frame.

void vm_rigid_step(vector3* x, vector3* v, quaternion* q, vector3* w, vector3 F, vector3 tau, vm_float_t mass, matrix3 I_body, vm_float_t dt)

One symplectic-Euler rigid step.

Parameters
x World-frame position (in/out).
v World-frame linear velocity (in/out).
q Orientation quaternion (in/out).
w Body-frame angular velocity (in/out).
F World-frame force.
tau Body-frame torque.
mass Mass.
I_body Body-frame inertia tensor (SPD 3×3).
dt Timestep.

x, v, F are world-frame. w and tau are body-frame. I_body is the body inertia (any SPD 3×3). Orientation is advanced with quat_integrate.

void vm_baumgarte_correct(vector3* x, vector3* v, vector3 n, vm_float_t C, vm_float_t beta, vm_float_t gamma, vm_float_t dt)

Single-constraint Baumgarte correction along a unit normal.

Parameters
x Position to correct (in/out).
v Velocity to correct (in/out).
n Unit constraint normal.
C Signed constraint value (0 at contact).
beta Position Baumgarte coefficient.
gamma Velocity Baumgarte coefficient.
dt Timestep used for the velocity correction scale.

C is the signed constraint value (0 at contact). Position is moved by -beta C n; velocity by -gamma C / dt n.

vm_grid3 vm_grid3_make(int nx, int ny, int nz, vm_float_t dx, vm_float_t dy, vm_float_t dz)

Build a 3-D grid descriptor.

Parameters
nx Number of cells in x.
ny Number of cells in y.
nz Number of cells in z; values <= 0 are treated as 1.
dx Cell spacing in x.
dy Cell spacing in y.
dz Cell spacing in z.
Returns Grid descriptor with the given dimensions and spacing.

int vm_grid_ncells(vm_grid3 g)

Returns the total number of cells in the grid.

Parameters
g 3D grid descriptor.
Returns Total cell count (nx * ny * nz), or 0 if nx or ny is non-positive.

int vm_grid_cell(vm_grid3 g, int i, int j, int k)

Compute linear index of a cell in a 3-D grid stored in row-major order.

Parameters
g grid dimensions and spacing
i cell index along x
j cell index along y
k cell index along z
Returns flattened 1-D index of the cell

int vm_mac_nu(vm_grid3 g)

Returns the number of u-velocity MAC face values for the grid.

Parameters
g Grid definition.
Returns Number of u-faces, or zero if the grid is invalid.

int vm_mac_nv(vm_grid3 g)

Returns the number of MAC grid v-velocity components.

Parameters
g Grid dimensions and spacing.
Returns Number of v-velocity samples.

int vm_mac_nw(vm_grid3 g)

Returns the number of MAC grid faces in the z (vertical) direction.

Parameters
g Grid dimensions and spacing.
Returns Number of vertical MAC faces, or 0 if the grid is invalid.

int vm_mac_u(vm_grid3 g, int i, int j, int k)

Compute linear index of u-velocity on MAC grid.

Parameters
g Grid descriptor.
i Cell index in x.
j Cell index in y.
k Cell index in z.
Returns Linear array index for the u-face value.

int vm_mac_v(vm_grid3 g, int i, int j, int k)

Computes the linear index for the v-component of a MAC grid velocity.

Parameters
g Grid descriptor.
i Cell index in x.
j Cell index in y.
k Cell index in z.
Returns Linear array index for v at the given staggered location.

int vm_mac_w(vm_grid3 g, int i, int j, int k)

Compute linear index of MAC grid w-component at cell (i,j,k).

Parameters
g Grid descriptor.
i Cell index in x.
j Cell index in y.
k Cell index in z.
Returns Linear array index for the w velocity component.

bool vm_grid_laplacian(vm_spmat* A, vm_grid3 g, vm_bc_t bc)

Assemble the SPD operator -∇² on a cell-centered grid.

Parameters
A Output sparse matrix; size vm_grid_ncells(g).
g Grid dimensions and spacing.
bc Boundary condition (VM_BC_DIRICHLET or VM_BC_NEUMANN).
Returns true on success, false on invalid input or allocation failure.

5-point in 2-D (nz == 1), 7-point in 3-D. Dirichlet boundary cells become identity rows. Homogeneous Neumann drops the missing neighbour (singular constant nullspace).

void vm_mac_div(vm_float_t* div, const vm_float_t* u, const vm_float_t* v, const vm_float_t* w, vm_grid3 g)

Cell-centered divergence of a MAC velocity field.

Parameters
div Output cell-centered divergence; length vm_grid_ncells(g).
u MAC face-centered x-velocity; length vm_mac_nu(g).
v MAC face-centered y-velocity; length vm_mac_nv(g).
w MAC face-centered z-velocity, or NULL when g.nz <= 1; length vm_mac_nw(g).
g Grid dimensions and spacing.

w may be NULL when g.nz <= 1. div has length vm_grid_ncells(g).

void vm_mac_grad(vm_float_t* gu, vm_float_t* gv, vm_float_t* gw, const vm_float_t* p, vm_grid3 g)

MAC face gradient of a cell-centered scalar (pressure).

Parameters
gu Output MAC face gradient in x; length vm_mac_nu(g).
gv Output MAC face gradient in y; length vm_mac_nv(g).
gw Output MAC face gradient in z, or NULL when g.nz <= 1; length vm_mac_nw(g).
p Cell-centered scalar field; length vm_grid_ncells(g).
g Grid dimensions and spacing.

Boundary faces are left at 0. gw may be NULL when g.nz <= 1.

void vm_mac_curl_z(vm_float_t* cz, const vm_float_t* u, const vm_float_t* v, vm_grid3 g)

Cell-centered z-vorticity (∂v/∂x − ∂u/∂y) from MAC u, v.

Parameters
cz Output cell-centered vorticity; length vm_grid_ncells(g).
u MAC face-centered x-velocity.
v MAC face-centered y-velocity.
g Grid dimensions and spacing.

vector2 vec2(vm_float_t x, vm_float_t y)

Constructs a vector2 from x and y.

Parameters
x X component.
y Y component.
Returns The resulting vector2.

void vec2_assign(vector2* dest, const vector2* src)

Copies src into dest.

Parameters
dest Destination vector.
src Source vector.

void vec2_assign_xy(vector2* dest, vm_float_t x, vm_float_t y)

Assigns x and y to dest.

Parameters
dest Destination vector.
x X component.
y Y component.

void vec2_add_assign(vector2* dest, const vector2* src)

Adds src to dest in place.

Parameters
dest Destination vector.
src Vector to add.

vector3 vec3(vm_float_t x, vm_float_t y, vm_float_t z)

Constructs a vector3 from x, y, and z.

Parameters
x X component.
y Y component.
z Z component.
Returns The resulting vector3.

void vec3_assign(vector3* dest, const vector3* src)

Copies src into dest.

Parameters
dest Destination vector.
src Source vector.

void vec3_assign_xyz(vector3* dest, vm_float_t x, vm_float_t y, vm_float_t z)

Assigns x, y, and z to dest.

Parameters
dest Destination vector.
x X component.
y Y component.
z Z component.

void vec3_add_assign(vector3* dest, const vector3* src)

Adds src to dest in place.

Parameters
dest Destination vector.
src Vector to add.

vector2i vec2i(vm_int_t x, vm_int_t y)

Constructs a vector2i from x and y.

Parameters
x X component.
y Y component.
Returns The resulting vector2i.

void vec2i_assign(vector2i* dest, const vector2i* src)

Copies src into dest.

Parameters
dest Destination vector.
src Source vector.

void vec2i_assign_xy(vector2i* dest, vm_int_t x, vm_int_t y)

Assigns x and y to dest.

Parameters
dest Destination vector.
x X component.
y Y component.

void vec2i_add_assign(vector2i* dest, const vector2i* src)

Adds src to dest in place.

Parameters
dest Destination vector.
src Vector to add.

vector3i vec3i(vm_int_t x, vm_int_t y, vm_int_t z)

Constructs a vector3i from x, y, and z.

Parameters
x X component.
y Y component.
z Z component.
Returns The resulting vector3i.

void vec3i_assign(vector3i* dest, const vector3i* src)

Copies src into dest.

Parameters
dest Destination vector.
src Source vector.

void vec3i_assign_xyz(vector3i* dest, vm_int_t x, vm_int_t y, vm_int_t z)

Assigns x, y, and z to dest.

Parameters
dest Destination vector.
x X component.
y Y component.
z Z component.

void vec3i_add_assign(vector3i* dest, const vector3i* src)

Adds src to dest in place.

Parameters
dest Destination vector.
src Vector to add.

bool vec2_eq(vector2 a, vector2 b)

Returns true if two vectors are equal within VECMAT_EPSILON.

Parameters
a First vector.
b Second vector.
Returns True if a and b are approximately equal.

bool vec3_eq(vector3 a, vector3 b)

Returns true if two vectors are equal within VECMAT_EPSILON.

Parameters
a First vector.
b Second vector.
Returns True if a and b are approximately equal.

bool vec4_eq(vector4 a, vector4 b)

Returns true if two vectors are equal within VECMAT_EPSILON.

Parameters
a First vector.
b Second vector.
Returns True if a and b are approximately equal.

bool vec2i_eq(vector2i a, vector2i b)

Returns true if two vectors are exactly equal.

Parameters
a First vector.
b Second vector.
Returns True if a and b are equal.

bool vec3i_eq(vector3i a, vector3i b)

Returns true if two vectors are exactly equal.

Parameters
a First vector.
b Second vector.
Returns True if a and b are equal.

bool vec4i_eq(vector4i a, vector4i b)

Returns true if two vectors are exactly equal.

Parameters
a First vector.
b Second vector.
Returns True if a and b are equal.

bool mat2_eq(matrix2 a, matrix2 b)

Returns true if two matrices are equal within VECMAT_EPSILON.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are approximately equal.

bool mat3_eq(matrix3 a, matrix3 b)

Returns true if two matrices are equal within VECMAT_EPSILON.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are approximately equal.

bool mat4_eq(matrix4 a, matrix4 b)

Returns true if two matrices are equal within VECMAT_EPSILON.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are approximately equal.

bool mat2i_eq(matrix2i a, matrix2i b)

Returns true if two matrices are exactly equal.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are equal.

bool mat3i_eq(matrix3i a, matrix3i b)

Returns true if two matrices are exactly equal.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are equal.

bool mat4i_eq(matrix4i a, matrix4i b)

Returns true if two matrices are exactly equal.

Parameters
a First matrix.
b Second matrix.
Returns True if a and b are equal.

bool quat_eq(quaternion a, quaternion b)

Returns true if two quaternions are equal within VECMAT_EPSILON.

Parameters
a First quaternion.
b Second quaternion.
Returns True if a and b are approximately equal.

vm_float_t elastic_oscillation(vm_float_t f, vm_float_t exp_mult, vm_float_t sin_mult, vm_float_t sin_offset, vm_float_t period)

Damped sine used by the elastic easing curves.

Parameters
f Normalized time in [0, 1].
exp_mult Exponent scale on 2^(exp_mult * f).
sin_mult Frequency scale of the sine wave.
sin_offset Phase offset of the sine wave.
period Oscillation period.
Returns Combined exponential-sine value.

vm_float_t poly_ease_in(vm_float_t f, vm_float_t n)

Polynomial ease-in: f^n.

Parameters
f Normalized time in [0, 1].
n Polynomial degree.
Returns Eased value.

vm_float_t poly_ease_out(vm_float_t f, vm_float_t n)

Polynomial ease-out: 1 - (1-f)^n.

Parameters
f Normalized time in [0, 1].
n Polynomial degree.
Returns Eased value.

vm_float_t poly_ease_in_out(vm_float_t f, vm_float_t n)

Polynomial ease-in-out of degree n.

Parameters
f Normalized time in [0, 1].
n Polynomial degree.
Returns Eased value.

vm_float_t quadratic_ease_out(vm_float_t f)

Quadratic ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quadratic_ease_in(vm_float_t f)

Quadratic ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quadratic_ease_in_out(vm_float_t f)

Quadratic ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t cubic_ease_out(vm_float_t f)

Cubic ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t cubic_ease_in(vm_float_t f)

Cubic ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t cubic_ease_in_out(vm_float_t f)

Cubic ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quartic_ease_out(vm_float_t f)

Quartic ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quartic_ease_in(vm_float_t f)

Quartic ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quartic_ease_in_out(vm_float_t f)

Quartic ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quintic_ease_out(vm_float_t f)

Quintic ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quintic_ease_in(vm_float_t f)

Quintic ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t quintic_ease_in_out(vm_float_t f)

Quintic ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t sine_ease_out(vm_float_t f)

Sinusoidal ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t sine_ease_in(vm_float_t f)

Sinusoidal ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t sine_ease_in_out(vm_float_t f)

Sinusoidal ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t circular_ease_out(vm_float_t f)

Circular ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t circular_ease_in(vm_float_t f)

Circular ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t circular_ease_in_out(vm_float_t f)

Circular ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t exponential_ease_out(vm_float_t f)

Exponential ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t exponential_ease_in(vm_float_t f)

Exponential ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t exponential_ease_in_out(vm_float_t f)

Exponential ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t elastic_ease_out(vm_float_t f)

Elastic ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t elastic_ease_in(vm_float_t f)

Elastic ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t elastic_ease_in_out(vm_float_t f)

Elastic ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t back_ease_out(vm_float_t f)

Overshooting "back" ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t back_ease_in(vm_float_t f)

Overshooting "back" ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t back_ease_in_out(vm_float_t f)

Overshooting "back" ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t bounce_ease_out(vm_float_t f)

Bounce ease-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t bounce_ease_in(vm_float_t f)

Bounce ease-in.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

vm_float_t bounce_ease_in_out(vm_float_t f)

Bounce ease-in-out.

Parameters
f Normalized time in [0, 1].
Returns Eased value.

Define documentation

#define VM_DEG(d)

Angle literals in the library's native unit (radians).

VM_DEG(90) writes a human degree constant and yields radians. VM_RAD(M_PI_2) documents that the value is already radians and casts it to vm_float_t. Unsuffixed angle APIs take and return radians; use the _deg suffix at the human/config boundary.

#define FLOAT_EQ(a, b, eps)

Checks if two floats are approximately equal within tolerance.

Parameters
a First value
b Second value
eps Tolerance threshold
Returns True if values are equal within the given tolerance.

#define DOUBLE_EQ(a, b, eps)

Checks if two doubles are approximately equal within tolerance.

Parameters
a First value
b Second value
eps Tolerance threshold
Returns True if values are equal within the given tolerance.