src/vector4.c file

Functions

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(const vm_float_t x) -> vector4
Returns a vector4 along the x-axis.
auto vec4_y_axis(const vm_float_t y) -> vector4
Returns a vector4 along the y-axis.
auto vec4_z_axis(const vm_float_t z) -> vector4
Returns a vector4 along the z-axis.
auto vec4_w_axis(const vm_float_t w) -> vector4
Returns a vector4 along the w-axis.
auto vec4_x_scale(const vm_float_t x) -> vector4
Returns avector4 for scaling along the x-axis.
auto vec4_y_scale(const vm_float_t y) -> vector4
Returns a vector4 for scaling along the y-axis.
auto vec4_z_scale(const vm_float_t z) -> vector4
Returns a vector4for scaling along the z-axis.
auto vec4_w_scale(const vm_float_t w) -> vector4
Returns a vector4 for scaling along the w-axis.
auto vec4_add(const vector4 a, const vector4 b) -> vector4
Component-wise addition of two vectors.
auto vec4_sub(const vector4 a, const vector4 b) -> vector4
Component-wise subtraction of two vectors.
auto vec4_mul_scalar(const vector4 v, const vm_float_t s) -> vector4
Component-wise multiplication of vector by scalar.
auto vec4_div_scalar(const vector4 v, const vm_float_t s) -> vector4
Component-wise division of vector by scalar.
auto vec4_mul(const vector4 a, const vector4 b) -> vector4
Component-wise multiplication of two vectors.
auto vec4_neg(const vector4 v) -> vector4
Negation of a vector.
auto vec4_abs(const vector4 v) -> vector4
Computes the absolute value per component of a vector4.
auto vec4_normalize(const vector4 v) -> vector4
Normalizes a vector4 to unit length.
auto vec4_min(const vector4 a, const vector4 b) -> vector4
Computes the component-wise minimum of two vector4.
auto vec4_max(const vector4 a, const vector4 b) -> vector4
Computes the component-wise maximum of two vector4.
auto vec4_sign(const vector4 v) -> vector4
Computes the sign per component of a vector4 (-1, 0, or 1).
auto vec4_floor(const vector4 v) -> vector4
Applies the floor per component to a vector4.
auto vec4_ceil(const vector4 v) -> vector4
Applies ceil per component to a vector4.
auto vec4_round(const vector4 v) -> vector4
Applies round per component to a vector4.
auto vec4_lerp(const vector4 a, const vector4 b, const vm_float_t t) -> vector4
Linearly interpolates between two vector4.
auto vec4_clamp(const vector4 v, const vector4 min, const vector4 max) -> vector4
Clamps a vector4 between min and max per component.
auto vec4_homogenize(const vector4 v) -> vector4
Homogenizes a vector4 (divides x, y, z by w).
auto vec4_dot(const vector4 a, const vector4 b) -> vm_float_t
Computes the dot product of two vector4.
auto vec4_length(const vector4 v) -> vm_float_t
Computes the length (magnitude) of a vector4.
auto vec4_distance(const vector4 a, const vector4 b) -> vm_float_t
Computes the Euclidean distance between two vector4.
auto vec4_to_vec3(const vector4 v) -> vector3
Converts a vector4 to a vector3 (discards the w component).
auto vec4_div(const vector4 a, const vector4 b) -> vector4
Divides two vectors component-wise.
auto vec4_add_scalar(const vector4 v, const vm_float_t s) -> vector4
Adds a scalar to each component.
auto vec4_sub_scalar(const vector4 v, const vm_float_t s) -> vector4
Subtracts a scalar from each component.
auto vec4_clamp_scalar(const vector4 v, const vm_float_t min, const vm_float_t max) -> vector4
Clamps each component to the scalar range [min, max].
auto vec4_saturate(const vector4 v) -> vector4
Clamps each component to the range [0, 1].
auto vec4_fract(const vector4 v) -> vector4
Returns the fractional part of each component.
auto vec4_project(const vector4 a, const vector4 b) -> vector4
Projects a onto b.
auto vec4_reject(const vector4 a, const vector4 b) -> vector4
Returns the component of a orthogonal to b.
auto vec4_slide(const vector4 v, const vector4 normal) -> vector4
Removes the component of v along normal.
auto vec4_splat(const vm_float_t s) -> vector4
Returns a vector with every component set to s.
auto vec4_length_squared(const vector4 v) -> vm_float_t
Returns the squared Euclidean length.
auto vec4_distance_squared(const vector4 a, const vector4 b) -> vm_float_t
Returns the squared Euclidean distance between a and b.
auto vec4_is_zero(const vector4 v) -> bool
Returns true if every component is zero.
auto vec4_is_normalized(const vector4 v) -> bool
Returns true if the vector has unit length.
auto vec4_near(const vector4 a, const vector4 b, const vm_float_t eps) -> bool
Returns true if a and b are within eps of each other.

Function documentation

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(const 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(const 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(const 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(const 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(const 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(const 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(const 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(const 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_add(const vector4 a, const vector4 b)

Component-wise addition of two vectors.

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

vector4 vec4_sub(const vector4 a, const vector4 b)

Component-wise subtraction of two vectors.

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

vector4 vec4_mul_scalar(const vector4 v, const 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(const vector4 v, const 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(const vector4 a, const vector4 b)

Component-wise multiplication of two vectors.

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

vector4 vec4_neg(const vector4 v)

Negation of a vector.

Parameters
v The vector.
Returns The negated vector.

vector4 vec4_abs(const vector4 v)

Computes the absolute value per component of a vector4.

Parameters
v The vector.
Returns The absolute vector4.

vector4 vec4_normalize(const vector4 v)

Normalizes a vector4 to unit length.

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

vector4 vec4_min(const vector4 a, const 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(const vector4 a, const 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(const 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(const vector4 v)

Applies the floor per component to a vector4.

Parameters
v The vector.
Returns The floored vector.

vector4 vec4_ceil(const vector4 v)

Applies ceil per component to a vector4.

Parameters
v The vector.
Returns The ceiling vector.

vector4 vec4_round(const vector4 v)

Applies round per component to a vector4.

Parameters
v The vector.
Returns The rounded vector.

vector4 vec4_lerp(const vector4 a, const vector4 b, const 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(const vector4 v, const vector4 min, const 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(const vector4 v)

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

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

vm_float_t vec4_dot(const vector4 a, const 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(const vector4 v)

Computes the length (magnitude) of a vector4.

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

vm_float_t vec4_distance(const vector4 a, const vector4 b)

Computes the Euclidean distance between two vector4.

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

vector3 vec4_to_vec3(const 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}.

vector4 vec4_div(const vector4 a, const vector4 b)

Divides two vectors component-wise.

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

vector4 vec4_add_scalar(const vector4 v, const 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(const vector4 v, const 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(const vector4 v, const vm_float_t min, const 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(const vector4 v)

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

Parameters
v Input vector.
Returns The resulting vector4.

vector4 vec4_fract(const vector4 v)

Returns the fractional part of each component.

Parameters
v Input vector.
Returns The resulting vector4.

vector4 vec4_project(const vector4 a, const vector4 b)

Projects a onto b.

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

vector4 vec4_reject(const vector4 a, const 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(const vector4 v, const vector4 normal)

Removes the component of v along normal.

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

vector4 vec4_splat(const vm_float_t s)

Returns a vector with every component set to s.

Parameters
s Scalar value.
Returns The resulting vector4.

vm_float_t vec4_length_squared(const vector4 v)

Returns the squared Euclidean length.

Parameters
v Input vector.
Returns The resulting scalar.

vm_float_t vec4_distance_squared(const vector4 a, const 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(const vector4 v)

Returns true if every component is zero.

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

bool vec4_is_normalized(const 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(const vector4 a, const vector4 b, const 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.