bgc-c/docs/vector2/set-values-eng.md

1.2 KiB

Setting the coordinates of a two-dimensional vector

Русская версия / Russian version

You can set the coordinates of vectors either directly or using functions. The functions for setting coordinate values allow you to do this in one line.

Function for BGC_FP32_Vector2:

inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x, const float y);

Function for BGC_FP64_Vector2:

inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x, const double y);

Each of these functions is equivalent to the following lines of code:

destination->x = x;
destination->y = y;

Valid pointers should pass in the destination parameter. The NULL (0) value is considered invalid.

This function is good for setting up the initial values of coordinates with one-line especially when the values are fixed constants like in the example below.

Example of use:

#include <stdio.h>
#include <basic-geometry.h>

int main()
{
    BGC_FP32_Vector2 v;

    bgc_fp32_vector2_set_values(&v, -2.2f, 7.1f);

    printf("x = %f, y = %f\n", v.x, v.y);

    return 0;
}

Documentation / 2D vectors