43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* map_helpers.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/04/05 06:50:28 by tischmid #+# #+# */
|
|
/* Updated: 2023/04/05 19:06:18 by apago ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "ft_bsq.h"
|
|
|
|
// index to column
|
|
int itoc(int idx, int width)
|
|
{
|
|
return (idx % width);
|
|
}
|
|
|
|
// index to row
|
|
int itor(int idx, int width)
|
|
{
|
|
return (idx / width);
|
|
}
|
|
|
|
int get_index(t_map *map, int idx, int bottom, int right)
|
|
{
|
|
int row;
|
|
int col;
|
|
|
|
if ((bottom | right) == 0)
|
|
return (map->index[idx]);
|
|
row = itor(idx, map->meta.width);
|
|
col = itoc(idx, map->meta.width);
|
|
row += bottom;
|
|
col += right;
|
|
if (row >= map->meta.height || col >= map->meta.width || col < 0 || row < 0)
|
|
return (0);
|
|
idx = col + row * map->meta.width;
|
|
return (map->index[idx]);
|
|
}
|