Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
vector2_ptr.c File Reference
#include <vecmat.h>

Go to the source code of this file.

Functions

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, const 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, const 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_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_scale_ptr (vector2 *res, const vector2 *v, const vm_float_t s)
 Scales a vector by a scalar component-wise, storing the result in res.
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, const vm_float_t angle)
 Rotates the input vector counterclockwise by the given angle (radians).
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, const 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, const vm_float_t s)
 Adds a scalar to each component.
void vec2_sub_scalar_ptr (vector2 *res, const vector2 *v, const vm_float_t s)
 Subtracts a scalar from each component.
void vec2_clamp_scalar_ptr (vector2 *res, const vector2 *v, const vm_float_t min, const 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, const 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, const vm_float_t angle)
 Rotates v around pivot by angle radians.
void vec2_move_toward_ptr (vector2 *res, const vector2 *current, const vector2 *target, const vm_float_t max_delta)
 Moves current toward target by at most max_delta.
void vec2_limit_length_ptr (vector2 *res, const vector2 *v, const vm_float_t max_len)
 Clamps the vector length to max_len.
void vec2_to_vec3_ptr (vector3 *res, const vector2 *v, const vm_float_t z)
 Converts a vector2 to a vector3 with the given z.

Function Documentation

◆ vec2_abs_ptr()

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
resOutput vector.
vInput vector.

Definition at line 95 of file vector2_ptr.c.

References VECMAT_FABS, vector2::x, and vector2::y.

Referenced by vec2_abs().

◆ vec2_add_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 14 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_add().

◆ vec2_add_scalar_ptr()

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

Adds a scalar to each component.

Parameters
resOutput vector.
vInput vector.
sScalar value.

Definition at line 371 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_add_scalar().

◆ vec2_ceil_ptr()

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
resOutput vector.
vInput vector.

Definition at line 180 of file vector2_ptr.c.

References VECMAT_CEIL, vector2::x, and vector2::y.

Referenced by vec2_ceil().

◆ vec2_clamp_ptr()

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
resOutput vector.
vInput vector to clamp.
minMinimum bounds vector.
maxMaximum bounds vector.

Definition at line 331 of file vector2_ptr.c.

References VECMAT_FMAX, VECMAT_FMIN, vector2::x, and vector2::y.

Referenced by vec2_clamp().

◆ vec2_clamp_scalar_ptr()

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

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

Parameters
resOutput vector.
vInput vector.
minLower bound.
maxUpper bound.

Definition at line 398 of file vector2_ptr.c.

References VECMAT_FMAX, VECMAT_FMIN, vector2::x, and vector2::y.

Referenced by vec2_clamp_scalar(), and vec2_saturate_ptr().

◆ vec2_cross_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 220 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_cross().

◆ vec2_div_ptr()

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

Divides two vectors component-wise.

Parameters
resOutput vector.
aFirst input vector.
bSecond input vector.

Definition at line 358 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_div().

◆ vec2_div_scalar_ptr()

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

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

Parameters
resOutput vector.
vInput vector.
sInput scalar.

Definition at line 53 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_div_scalar().

◆ vec2_floor_ptr()

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
resOutput vector.
vInput vector.

Definition at line 167 of file vector2_ptr.c.

References VECMAT_FLOOR, vector2::x, and vector2::y.

Referenced by vec2_floor().

◆ vec2_fract_ptr()

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

Returns the fractional part of each component.

Parameters
resOutput vector.
vInput vector.

Definition at line 421 of file vector2_ptr.c.

References VECMAT_FLOOR, vector2::x, and vector2::y.

Referenced by vec2_fract().

◆ vec2_lerp_ptr()

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

Linearly interpolates from a to b by t.

Parameters
resOutput vector.
aFirst input vector.
bSecond input vector.
tInterpolation factor.

Definition at line 345 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_lerp().

◆ vec2_limit_length_ptr()

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

Clamps the vector length to max_len.

Parameters
resOutput vector.
vInput vector.
max_lenMaximum length.

Definition at line 511 of file vector2_ptr.c.

References vec2_length(), vector2::x, and vector2::y.

Referenced by vec2_limit_length().

◆ vec2_max_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 141 of file vector2_ptr.c.

References VECMAT_FMAX, vector2::x, and vector2::y.

Referenced by vec2_max().

◆ vec2_min_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 127 of file vector2_ptr.c.

References VECMAT_FMIN, vector2::x, and vector2::y.

Referenced by vec2_min().

◆ vec2_move_toward_ptr()

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

Moves current toward target by at most max_delta.

Parameters
resOutput vector.
currentCurrent position.
targetTarget position.
max_deltaMaximum distance to move.

Definition at line 490 of file vector2_ptr.c.

References VECMAT_SQRT, vector2::x, and vector2::y.

Referenced by vec2_move_toward().

◆ vec2_mul_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 70 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_mul().

◆ vec2_mul_scalar_ptr()

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

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

Parameters
resOutput vector.
vInput vector.
sInput scalar.

Definition at line 40 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_mul_scalar().

◆ vec2_neg_ptr()

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

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

Parameters
resOutput vector.
vInput vector.

Definition at line 82 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_neg().

◆ vec2_normalize_ptr()

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

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

Parameters
resOutput vector.
vInput vector.

Definition at line 107 of file vector2_ptr.c.

References vec2_length(), vector2::x, and vector2::y.

Referenced by vec2_normalize(), and vec2i_normalize_to_vec2_ptr().

◆ vec2_perpendicular_ptr()

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
resOutput vector.
vInput vector.

Definition at line 206 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_perpendicular().

◆ vec2_project_ptr()

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

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

Parameters
resThe output projected vector.
aThe vector to project.
bThe direction vector (non-zero length recommended).

Definition at line 261 of file vector2_ptr.c.

References vec2_dot(), vector2::x, and vector2::y.

Referenced by vec2_project(), and vec2_reject_ptr().

◆ vec2_reflect_ptr()

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

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

Parameters
resOutput vector.
vInput incident vector.
normalInput surface normal.

Definition at line 247 of file vector2_ptr.c.

References vec2_dot(), vector2::x, and vector2::y.

Referenced by vec2_reflect().

◆ vec2_refract_ptr()

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

Computes the refraction of incident across normal with ratio eta.

Parameters
resOutput vector.
incidentIncident vector.
normalSurface normal.
etaRatio of indices of refraction.

Definition at line 435 of file vector2_ptr.c.

References vec2_dot(), VECMAT_SQRT, vector2::x, and vector2::y.

Referenced by vec2_refract().

◆ vec2_reject_ptr()

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

Returns the component of a orthogonal to b.

Parameters
resOutput vector.
aFirst input vector.
bSecond input vector.

Definition at line 456 of file vector2_ptr.c.

References vec2_project_ptr(), vector2::x, and vector2::y.

Referenced by vec2_reject().

◆ vec2_rotate_around_ptr()

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

Rotates v around pivot by angle radians.

Parameters
resOutput vector.
vInput vector.
pivotRotation pivot.
angleAngle in radians.

Definition at line 472 of file vector2_ptr.c.

References vec2_rotate_ptr(), vector2::x, and vector2::y.

Referenced by vec2_rotate_around().

◆ vec2_rotate_ptr()

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

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

Uses standard 2D rotation matrix.

Parameters
resultThe output rotated vector.
vThe input vector.
angleThe rotation angle in radians.

Definition at line 297 of file vector2_ptr.c.

References VECMAT_COS, VECMAT_SIN, vector2::x, and vector2::y.

Referenced by vec2_rotate(), and vec2_rotate_around_ptr().

◆ vec2_round_ptr()

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
resOutput vector.
vInput vector.

Definition at line 193 of file vector2_ptr.c.

References VECMAT_ROUND, vector2::x, and vector2::y.

Referenced by vec2_round().

◆ vec2_saturate_ptr()

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

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

Parameters
resOutput vector.
vInput vector.

Definition at line 410 of file vector2_ptr.c.

References vec2_clamp_scalar_ptr().

Referenced by vec2_saturate().

◆ vec2_scale_ptr()

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

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

Parameters
resOutput vector.
vInput vector.
sInput scalar.

Definition at line 234 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_scale().

◆ vec2_sign_ptr()

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
resOutput vector.
vInput vector.

Definition at line 154 of file vector2_ptr.c.

References VECMAT_COPYSIGN, vector2::x, and vector2::y.

Referenced by vec2_sign().

◆ vec2_slide_ptr()

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

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

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

Parameters
resultThe output slid vector.
vThe input vector.
normalThe unit normal vector.

Definition at line 316 of file vector2_ptr.c.

References vec2_dot(), vector2::x, and vector2::y.

Referenced by vec2_slide().

◆ vec2_sub_ptr()

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
resOutput vector.
aInput vector a.
bInput vector b.

Definition at line 27 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_sub().

◆ vec2_sub_scalar_ptr()

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

Subtracts a scalar from each component.

Parameters
resOutput vector.
vInput vector.
sScalar value.

Definition at line 384 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_sub_scalar().

◆ vec2_tangent_ptr()

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

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

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

Parameters
resThe output tangent vector.
vThe input vector.

Definition at line 282 of file vector2_ptr.c.

References vector2::x, and vector2::y.

Referenced by vec2_tangent().

◆ vec2_to_vec3_ptr()

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

Converts a vector2 to a vector3 with the given z.

Parameters
resOutput vector.
vInput vector.
zZ component.

Definition at line 530 of file vector2_ptr.c.

References vector2::x, vector3::x, vector2::y, vector3::y, and vector3::z.

Referenced by vec2_to_vec3().