casting vec2

This commit is contained in:
whaffman 2025-05-12 11:44:02 +02:00
parent 0287cad1b3
commit e03ff1e9ab
3 changed files with 61 additions and 1 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */
/* Updated: 2025/05/11 13:36:45 by whaffman ######## odam.nl */
/* Updated: 2025/05/12 11:04:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -102,4 +102,20 @@ t_vec2 perp(t_vec2 a);
*/
t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis);
/**
* @brief Converts a 2D vector to a 2D integer vector.
*
* @param vec The 2D vector to convert.
* @return The converted 2D integer vector.
*/
t_vec2_int vec2_to_int(t_vec2 vec);
/**
* @brief Converts a 2D integer vector to a 2D vector.
*
* @param vec The 2D integer vector to convert.
* @return The converted 2D vector.
*/
t_vec2 vec2_from_int(t_vec2_int vec);
#endif // VEC_MATH_H

22
src/math/vec2_from_int.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* vec2_from_int.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/12 11:03:47 by whaffman #+# #+# */
/* Updated: 2025/05/12 11:03:58 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_vec2 vec2_from_int(t_vec2_int vec)
{
t_vec2 result;
result.x = (double)vec.x;
result.y = (double)vec.y;
return (result);
}

22
src/math/vec2_to_int.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* vec2_to_int.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/12 11:02:49 by whaffman #+# #+# */
/* Updated: 2025/05/12 11:03:27 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_vec2_int vec2_to_int(t_vec2 vec)
{
t_vec2_int result;
result.x = (int)vec.x;
result.y = (int)vec.y;
return (result);
}