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

Go to the source code of this file.

Functions

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, const 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, const 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.
static vm_int_t vm_div_floor (const vm_int_t a, const vm_int_t b)
static vm_int_t vm_mod_floor (const vm_int_t a, const vm_int_t b)
void vec2i_lerp_ptr (vector2i *res, const vector2i *a, const vector2i *b, const 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, const vm_int_t s)
 Adds a scalar to each component.
void vec2i_sub_scalar_ptr (vector2i *res, const vector2i *v, const 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, const 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.

Function Documentation

◆ vec2i_abs_ptr()

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
resPointer to result vector2i.
vPointer to vector2i.

Definition at line 101 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_abs().

◆ vec2i_add_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 15 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_add().

◆ vec2i_add_scalar_ptr()

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

Adds a scalar to each component.

Parameters
resOutput vector.
vInput vector.
sScalar value.

Definition at line 270 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_add_scalar().

◆ vec2i_clamp_ptr()

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

Clamps each component between min and max.

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

Definition at line 244 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_clamp().

◆ vec2i_cross_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 189 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_cross().

◆ vec2i_div_floor_ptr()

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

Component-wise floored division of a by b.

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

Definition at line 309 of file vector2i_ptr.c.

References vm_div_floor(), vector2i::x, and vector2i::y.

Referenced by vec2i_div_floor().

◆ vec2i_div_ptr()

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

Divides two vectors component-wise.

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

Definition at line 257 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_div().

◆ vec2i_div_scalar_ptr()

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

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

Sets vector to zero if s == 0.

Parameters
resPointer to result vector2i.
vPointer to vector2i.
sScalar.

Definition at line 57 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_div_scalar().

◆ vec2i_lerp_ptr()

void vec2i_lerp_ptr ( vector2i * res,
const vector2i * a,
const vector2i * 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 230 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_lerp().

◆ vec2i_max_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 149 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_max().

◆ vec2i_min_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 135 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_min().

◆ vec2i_mod_ptr()

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

Component-wise floor modulo of a by b.

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

Definition at line 296 of file vector2i_ptr.c.

References vm_mod_floor(), vector2i::x, and vector2i::y.

Referenced by vec2i_mod().

◆ vec2i_mul_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 76 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_mul().

◆ vec2i_mul_scalar_ptr()

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

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

Parameters
resPointer to result vector2i.
vPointer to vector2i.
sScalar.

Definition at line 41 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_mul_scalar().

◆ vec2i_neg_ptr()

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

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

Parameters
resPointer to result vector2i.
vPointer to vector2i.

Definition at line 88 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_neg().

◆ vec2i_normalize_ptr()

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.

Copies v unchanged if the length is zero.

Parameters
resPointer to result vector2i.
vPointer to vector2i.

Definition at line 116 of file vector2i_ptr.c.

References vec2i_length(), vector2i::x, and vector2i::y.

Referenced by vec2i_normalize().

◆ vec2i_normalize_to_vec2_ptr()

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

Converts to a unit-length vector2.

Parameters
resOutput vector.
vInput vector.

Definition at line 348 of file vector2i_ptr.c.

References vec2_normalize_ptr(), vector2i::x, and vector2i::y.

Referenced by vec2i_normalize_to_vec2().

◆ vec2i_perpendicular_ptr()

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
resPointer to result vector2i.
vPointer to vector2i.

Definition at line 175 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_perpendicular().

◆ vec2i_sign_ptr()

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
resPointer to result vector2i.
vPointer to vector2i.

Definition at line 162 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_sign().

◆ vec2i_sub_ptr()

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
resPointer to result vector2i.
aPointer to first vector2i.
bPointer to second vector2i.

Definition at line 28 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_sub().

◆ vec2i_sub_scalar_ptr()

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

Subtracts a scalar from each component.

Parameters
resOutput vector.
vInput vector.
sScalar value.

Definition at line 283 of file vector2i_ptr.c.

References vector2i::x, and vector2i::y.

Referenced by vec2i_sub_scalar().

◆ vec2i_to_vec3i_ptr()

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

Converts a vector4i to a vector3i by dropping w.

Parameters
resOutput vector.
vInput vector.
zZ component.

Definition at line 335 of file vector2i_ptr.c.

References vector2i::x, vector3i::x, vector2i::y, vector3i::y, and vector3i::z.

Referenced by vec2i_to_vec3i().

◆ vec2i_wrap_ptr()

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

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

Parameters
resOutput vector.
vInput vector.
periodWrap period per component.

Definition at line 322 of file vector2i_ptr.c.

References vm_mod_floor(), vector2i::x, and vector2i::y.

Referenced by vec2i_wrap().

◆ vm_div_floor()

vm_int_t vm_div_floor ( const vm_int_t a,
const vm_int_t b )
static

Definition at line 196 of file vector2i_ptr.c.

Referenced by vec2i_div_floor_ptr().

◆ vm_mod_floor()

vm_int_t vm_mod_floor ( const vm_int_t a,
const vm_int_t b )
static

Definition at line 210 of file vector2i_ptr.c.

Referenced by vec2i_mod_ptr(), and vec2i_wrap_ptr().