14 return (
vector2){.x = 0.0f, .y = 0.0f};
24 return (
vector2){.x = 1.0f, .y = 1.0f};
35 return (
vector2){.x = x, .y = 0.0f};
46 return (
vector2){.x = 0.0f, .y = y};
57 return (
vector2){.x = x, .y = 1.0f};
68 return (
vector2){.x = 1.0f, .y = y};
441 return a.
x * b.
x + a.
y * b.
y;
465 if (v.
y == 0.0f)
return 0.0f;
497 if (len_a == 0.0f || len_b == 0.0f)
return 0.0f;
656 return (
vector2){.x = s, .y = s};
782 return dx * dx + dy * dy;
794 return a.
x * b.
y - a.
y * b.
x;
#define VECMAT_FMAX(a, b)
void vec2_rotate_ptr(vector2 *result, const vector2 *v, vm_float_t angle)
Rotates the input vector counterclockwise by the given angle (radians).
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_clamp_ptr(vector2 *res, const vector2 *v, const vector2 *min, const vector2 *max)
Clamps vector v component-wise between min and max.
void vec2_perpendicular_ptr(vector2 *res, const vector2 *v)
Computes the perpendicular vector to v (90 degrees counterclockwise rotation), storing the result in ...
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_normalize_ptr(vector2 *res, const vector2 *v)
Normalizes vector v to unit length, storing the result in res.
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].
#define VECMAT_FMIN(a, b)
void vec2_limit_length_ptr(vector2 *res, const vector2 *v, vm_float_t max_len)
Clamps the vector length to max_len.
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_round_ptr(vector2 *res, const vector2 *v)
Applies the round function to each component of vector v, storing the result in res.
void vec2_tangent_ptr(vector2 *res, const vector2 *v)
Computes a tangent vector perpendicular to the input (90 degrees clockwise).
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_ceil_ptr(vector2 *res, const vector2 *v)
Applies the ceil function to each component of vector v, 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_saturate_ptr(vector2 *res, const vector2 *v)
Clamps each component to the range [0, 1].
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_add_ptr(vector2 *res, const vector2 *a, const vector2 *b)
Adds vectors a and b component-wise, storing the result in res.
void vec2_reject_ptr(vector2 *res, const vector2 *a, const vector2 *b)
Returns the component of a orthogonal to 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).
void vec2_neg_ptr(vector2 *res, const vector2 *v)
Negates the components of vector v, storing the result in res.
void vec2_div_ptr(vector2 *res, const vector2 *a, const vector2 *b)
Divides two vectors component-wise.
void vec2_rotate_around_ptr(vector2 *res, const vector2 *v, const vector2 *pivot, vm_float_t angle)
Rotates v around pivot by angle radians.
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_reflect_ptr(vector2 *res, const vector2 *v, const vector2 *normal)
Reflects vector v across the normal, 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_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_slide_ptr(vector2 *result, const vector2 *v, const vector2 *normal)
Slides the input vector tangent to the normal (removes normal component).
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 vec2_sub_scalar_ptr(vector2 *res, const vector2 *v, vm_float_t s)
Subtracts a scalar from each component.
void vec2_add_scalar_ptr(vector2 *res, const vector2 *v, vm_float_t s)
Adds a scalar to 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_mul_ptr(vector2 *res, const vector2 *a, const vector2 *b)
Multiplies vectors a and b component-wise, storing the result in res.
#define VECMAT_ATAN2(y, x)
void vec2_fract_ptr(vector2 *res, const vector2 *v)
Returns the fractional part of each component.
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_floor_ptr(vector2 *res, const vector2 *v)
Applies the floor function to each component of vector v, 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.
vm_float_t vec2_length_chebyshev(const vector2 v)
Returns the Chebyshev (L-inf) length.
vm_float_t vec2_cross_scalar(const vector2 a, const vector2 b)
Returns the 2D cross product as a scalar (a.x*b.y - a.y*b.x).
vm_float_t vec2_sum(const vector2 v)
Returns the sum of all components.
vector2 vec2_min(const vector2 a, const vector2 b)
Returns the component-wise minimum of two vectors.
vector2 vec2_slide(const vector2 v, const vector2 normal)
Slides the input vector tangent to the normal (removes normal component).
vector2 vec2_project(const vector2 a, const vector2 b)
Projects the first vector onto the second.
vector2 vec2_reflect(const vector2 v, const vector2 normal)
Reflects vector v across the normal, storing the result in res.
vm_float_t vec2_distance_squared(const vector2 a, const vector2 b)
Returns the squared Euclidean distance between a and b.
vector2 vec2_sign(const vector2 v)
Returns the sign of each component (+1.0f, -1.0f, or 0.0f).
vector2 vec2_sub_scalar(const vector2 v, const vm_float_t s)
Subtracts a scalar from each component.
vector2 vec2_x_scale(const vm_float_t x)
Returns a vector2 representing x-axis scaling (y = 1.0f).
vector2 vec2_ceil(const vector2 v)
Applies ceil to each component.
vm_float_t vec2_angle(const vector2 a, const vector2 b)
Computes the angle between two vectors (in radians, range [0, PI]).
bool vec2_is_normalized(const vector2 v)
Returns true if the vector has unit length.
vector2 vec2_rotate_around(const vector2 v, const vector2 pivot, const vm_float_t angle)
Rotates v around pivot by angle radians.
vector2 vec2_sub(const vector2 a, const vector2 b)
Subtracts the second vector from the first component-wise.
vector2 vec2_floor(const vector2 v)
Applies floor to each component.
vm_float_t vec2_heading(const vector2 v)
Returns the heading angle of the vector in radians.
vector2 vec2_move_toward(const vector2 current, const vector2 target, const vm_float_t max_delta)
Moves current toward target by at most max_delta.
vector2 vec2_clamp(const vector2 v, const vector2 min, const vector2 max)
Clamps vector v component-wise between min and max.
vector2 vec2_round(const vector2 v)
Applies round to each component.
vector2 vec2_mul(const vector2 a, const vector2 b)
Multiplies two vectors component-wise (Hadamard product).
vector2 vec2_from_angle(const vm_float_t angle)
Returns the unit vector at the given angle in radians.
vm_float_t vec2_aspect_ratio(const vector2 v)
Computes the aspect ratio of the vector (x / y).
vm_float_t vec2_length_manhattan(const vector2 v)
Returns the Manhattan (L1) length.
vector2 vec2_limit_length(const vector2 v, const vm_float_t max_len)
Clamps the vector length to max_len.
vector2 vec2_max(const vector2 a, const vector2 b)
Returns the component-wise maximum of two vectors.
vector2 vec2_splat(const vm_float_t s)
Returns a vector with every component set to s.
bool vec2_near(const vector2 a, const vector2 b, const vm_float_t eps)
Returns true if a and b are within eps of each other.
vector2 vec2_add_scalar(const vector2 v, const vm_float_t s)
Adds a scalar to each component.
vector2 vec2_refract(const vector2 incident, const vector2 normal, const vm_float_t eta)
Computes the refraction of incident across normal with ratio eta.
vector2 vec2_one(void)
Returns a vector2 with both components set to 1.0f.
bool vec2_is_zero(const vector2 v)
Returns true if every component is zero.
vector2 vec2_clamp_scalar(const vector2 v, const vm_float_t min, const vm_float_t max)
Clamps each component to the scalar range [min, max].
vm_float_t vec2_min_component(const vector2 v)
Returns the smallest component.
vector2 vec2_cross(const vector2 a, const vector2 b)
Computes the 2D cross-product as a vector.
vector2 vec2_y_scale(const vm_float_t y)
Returns a vector2 representing y-axis scaling (x = 1.0f).
vector2 vec2_fract(const vector2 v)
Returns the fractional part of each component.
vector3 vec2_to_vec3(const vector2 v, const vm_float_t z)
Converts a vector2 to a vector3 using z.
vector2 vec2_reject(const vector2 a, const vector2 b)
Returns the component of a orthogonal to b.
vector2 vec2_tangent(const vector2 v)
Returns the tangent vector perpendicular to the input (90 degrees clockwise).
vector2 vec2_perpendicular(const vector2 v)
Returns the perpendicular vector (90 degrees counterclockwise).
vector2 vec2_lerp(const vector2 a, const vector2 b, const vm_float_t t)
Linearly interpolates from a to b by t.
vector2 vec2_scale(const vector2 v, const vm_float_t s)
Scales a vector by a scalar component-wise.
vector2 vec2_div_scalar(const vector2 v, const vm_float_t s)
Divides a vector by a scalar component-wise.
vm_float_t vec2_dot(const vector2 a, const vector2 b)
Computes the dot product of two vectors.
vector2 vec2_add(const vector2 a, const vector2 b)
Adds two vectors component-wise.
vm_float_t vec2_length_squared(const vector2 v)
Returns the squared Euclidean length.
vm_float_t vec2_max_component(const vector2 v)
Returns the largest component.
vector2 vec2_normalize(const vector2 v)
Normalizes the vector to unit length.
vector2 vec2_saturate(const vector2 v)
Clamps each component to the range [0, 1].
vector2 vec2_rotate(const vector2 v, const vm_float_t angle)
Rotates the input vector counterclockwise by the given angle (radians).
vm_float_t vec2_length(const vector2 v)
Computes the length (magnitude) of the vector.
vector2 vec2_neg(const vector2 v)
Negates the vector (multiplies each component by -1.0f).
vector2 vec2_x_axis(const vm_float_t x)
Returns a vector2 along the x-axis (y = 0.0f).
vector2 vec2_zero(void)
Returns a vector2 with both components set to 0.0f.
vm_float_t vec2_distance(const vector2 a, const vector2 b)
Computes the Euclidean distance between two vectors (treated as points).
vector2 vec2_abs(const vector2 v)
Returns the absolute values of each component.
vector2 vec2_y_axis(const vm_float_t y)
Returns a vector2 along the y-axis (x = 0.0f).
vector2 vec2_div(const vector2 a, const vector2 b)
Divides two vectors component-wise.
vector2 vec2_mul_scalar(const vector2 v, const vm_float_t s)
Multiplies a vector by a scalar component-wise.