fix: prevent zero-division in rare cases

This commit is contained in:
Khaïs COLIN 2025-07-31 11:55:41 +02:00
parent 6fe6eb0a9a
commit ca5fa86d10
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ray.c :+: :+: :+: */ /* ray.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/30 12:10:17 by tchampio #+# #+# */ /* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/07/30 16:06:19 by tchampio ### ########.fr */ /* Updated: 2025/07/31 11:58:02 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,7 @@
#include "../player/player.h" #include "../player/player.h"
#include "../consts.h" #include "../consts.h"
#include "../cub3d_data.h" #include "../cub3d_data.h"
#include <float.h>
#include <math.h> #include <math.h>
void init_ray(t_ray *ray, int pos_x, t_player *player) void init_ray(t_ray *ray, int pos_x, t_player *player)
@ -79,6 +80,8 @@ void calculate_wall_dist(t_ray *ray, char **map)
void calculate_wall_height(t_ray *ray, t_player *player) void calculate_wall_height(t_ray *ray, t_player *player)
{ {
if (ray->wall_dist <= FLT_EPSILON)
ray->wall_dist = 0.1;
ray->wall_height = (int)(HEIGHT / ray->wall_dist); ray->wall_height = (int)(HEIGHT / ray->wall_dist);
ray->draw_start = -ray->wall_height / 2 + HEIGHT / 2; ray->draw_start = -ray->wall_height / 2 + HEIGHT / 2;
if (ray->draw_start < 0) if (ray->draw_start < 0)