46 lines
1.4 KiB
C
46 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* map_helpers.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/04/05 06:50:28 by tischmid #+# #+# */
|
|
/* Updated: 2023/04/05 09:05:18 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "solution.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);
|
|
}
|
|
|
|
char get_cell(t_map *map, int idx, int bottom, int right)
|
|
{
|
|
int row;
|
|
int col;
|
|
|
|
if ((bottom | right) == 0)
|
|
return (map->data[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->data[idx]);
|
|
}
|