2-Component Vector

#include <graphics/vec2.h>
struct vec2

Two component vector structure.

float vec2.x

X component

float vec2.y

Y component

float vec2.ptr[2]

Unioned array of both components


void vec2_zero(struct vec2 *dst)

Zeroes a vector

Parameters
  • dst – Destination


void vec2_set(struct vec2 *dst, float x, float y)

Sets the individual components of a 2-component vector.

Parameters
  • dst – Destination

  • x – X component

  • y – Y component


void vec2_copy(struct vec2 *dst, const struct vec2 *v)

Copies a vector

Parameters
  • dst – Destination

  • v – Vector to copy


void vec2_add(struct vec2 *dst, const struct vec2 *v1, const struct vec2 *v2)

Adds two vectors

Parameters
  • dst – Destination

  • v1 – Vector 1

  • v2 – Vector 2


void vec2_sub(struct vec2 *dst, const struct vec2 *v1, const struct vec2 *v2)

Subtracts two vectors

Parameters
  • dst – Destination

  • v1 – Vector being subtracted from

  • v2 – Vector being subtracted


void vec2_mul(struct vec2 *dst, const struct vec2 *v1, const struct vec2 *v2)

Multiplies two vectors

Parameters
  • dst – Destination

  • v1 – Vector 1

  • v2 – Vector 2


void vec2_div(struct vec2 *dst, const struct vec2 *v1, const struct vec2 *v2)

Divides two vectors

Parameters
  • dst – Destination

  • v1 – Dividend

  • v2 – Divisor


void vec2_addf(struct vec2 *dst, const struct vec2 *v, float f)

Adds a floating point to all components

Parameters
  • dst – Destination

  • dst – Vector

  • f – Floating point


void vec2_subf(struct vec2 *dst, const struct vec2 *v, float f)

Subtracts a floating point from all components

Parameters
  • dst – Destination

  • v – Vector being subtracted from

  • f – Floating point being subtracted


void vec2_mulf(struct vec2 *dst, const struct vec2 *v, float f)

Multiplies a floating point with all components

Parameters
  • dst – Destination

  • dst – Vector

  • f – Floating point


void vec2_divf(struct vec2 *dst, const struct vec2 *v, float f)

Divides a floating point from all components

Parameters
  • dst – Destination

  • v – Vector (dividend)

  • f – Floating point (divisor)


void vec2_neg(struct vec2 *dst, const struct vec2 *v)

Negates a vector

Parameters
  • dst – Destination

  • v – Vector to negate


float vec2_dot(const struct vec2 *v1, const struct vec2 *v2)

Performs a dot product between two vectors

Parameters
  • v1 – Vector 1

  • v2 – Vector 2

Returns

Result of the dot product


float vec2_len(const struct vec2 *v)

Gets the length of a vector

Parameters
  • v – Vector

Returns

The vector’s length


float vec2_dist(const struct vec2 *v1, const struct vec2 *v2)

Gets the distance between two vectors

Parameters
  • v1 – Vector 1

  • v2 – Vector 2

Returns

Distance between the two vectors


void vec2_minf(struct vec2 *dst, const struct vec2 *v, float val)

Gets the minimum values between a vector’s components and a floating point

Parameters
  • dst – Destination

  • v – Vector

  • val – Floating point


void vec2_min(struct vec2 *dst, const struct vec2 *v, const struct vec2 *min_v)

Gets the minimum values between two vectors

Parameters
  • dst – Destination

  • v – Vector 1

  • min_v – Vector 2


void vec2_maxf(struct vec2 *dst, const struct vec2 *v, float val)

Gets the maximum values between a vector’s components and a floating point

Parameters
  • dst – Destination

  • v – Vector

  • val – Floating point


void vec2_max(struct vec2 *dst, const struct vec2 *v, const struct vec2 *max_v)

Gets the maximum values between two vectors

Parameters
  • dst – Destination

  • v – Vector 1

  • max_v – Vector 2


void vec2_abs(struct vec2 *dst, const struct vec2 *v)

Gets the absolute values of each component

Parameters
  • dst – Destination

  • v – Vector


void vec2_floor(struct vec2 *dst, const struct vec2 *v)

Gets the floor values of each component

Parameters
  • dst – Destination

  • v – Vector


void vec2_ceil(struct vec2 *dst, const struct vec2 *v)

Gets the ceiling values of each component

Parameters
  • dst – Destination

  • v – Vector


int vec2_close(const struct vec2 *v1, const struct vec2 *v2, float epsilon)

Compares two vectors

Parameters
  • v1 – Vector 1

  • v2 – Vector 2

  • epsilon – Maximum precision for comparison


void vec2_norm(struct vec2 *dst, const struct vec2 *v)

Normalizes a vector

Parameters
  • dst – Destination

  • v – Vector to normalize