Skip to content
Permalink
Browse files

Row and Column are now int8_t

Now row and column are int8_t. They really should be uint8_t but
I would have to change some of the logic and it would be messy.
  • Loading branch information
StefanBossbaly committed Mar 6, 2014
1 parent 4fdbded commit bd9412e1fabad7df73a61f27f8647fb48e90b9a9
Showing with 18 additions and 16 deletions.
  1. +4 −4 nav.cpp
  2. +8 −8 nav.h
  3. +1 −1 position.c
  4. +5 −3 position.h
@@ -11,7 +11,7 @@ int nav_is_pos_in_bounds(struct nav_array *array, pos_t *position)
return (position->column >= 0) && (position->row >= 0) && (position->column < array->columns) && (position->row < array->rows);
}

int nav_is_in_bounds(struct nav_array *array, int row, int column)
int nav_is_in_bounds(struct nav_array *array, int8_t row, int8_t column)
{
return (row >= 0) && (column >= 0) && (row < array->rows) && (column < array->columns);
}
@@ -21,7 +21,7 @@ int nav_size(struct nav_array *array)
return (array->rows * array->columns);
}

void nav_init(struct nav_array *array, struct nav_cell *cells, int rows, int columns)
void nav_init(struct nav_array *array, struct nav_cell *cells, int8_t rows, int8_t columns)
{
array->rows = rows;
array->columns = columns;
@@ -46,7 +46,7 @@ struct nav_cell *nav_get_cell_pos(struct nav_array *array, pos_t *position)
return nav_get_cell(array, position->row, position->column);
}

struct nav_cell *nav_get_cell(struct nav_array *array, int row, int column)
struct nav_cell *nav_get_cell(struct nav_array *array, int8_t row, int8_t column)
{
int index;
/*if (! nav_is_in_bounds(array, row, column))
@@ -181,7 +181,7 @@ void nav_drive_to_target(struct nav_array *array, pos_t *start, pos_t *target)
}
}

struct nav_cell *nav_get_next_neighbor(struct nav_array *array, int row, int column)
struct nav_cell *nav_get_next_neighbor(struct nav_array *array, int8_t row, int8_t column)
{
struct nav_cell *cell = nav_get_cell(array, row, column);
int target = cell->flood_num - 1;
16 nav.h
@@ -14,28 +14,28 @@ struct nav_cell
int flood_num;
uint8_t has_visited;
uint8_t wall;
int row;
int column;
int8_t row;
int8_t column;
};

struct nav_array
{
struct nav_cell *cells;
int columns;
int rows;
int8_t columns;
int8_t rows;
};

int nav_is_pos_in_bounds(struct nav_array *array, pos_t *position);
int nav_is_in_bounds(struct nav_array *array, int row, int column);
int nav_is_in_bounds(struct nav_array *array, int8_t row, int8_t column);
int nav_size(struct nav_array *array);


/*Init*/
void nav_init(struct nav_array *array, struct nav_cell *cells, int rows, int columns);
void nav_init(struct nav_array *array, struct nav_cell *cells, int8_t rows, int8_t columns);

/*Getters*/
struct nav_cell *nav_get_cell_pos(struct nav_array *array, pos_t *position);
struct nav_cell *nav_get_cell(struct nav_array *array, int row, int column);
struct nav_cell *nav_get_cell(struct nav_array *array, int8_t row, int8_t column);

/*Flood Stuff*/
void nav_reset_flood_num(struct nav_array *array);
@@ -48,7 +48,7 @@ void nav_explore_rec(struct nav_array *array, pos_t *current);

/*Driver*/
void nav_drive_to_target(struct nav_array *array, pos_t *start, pos_t *target);
struct nav_cell *nav_get_next_neighbor(struct nav_array *array, int row, int column);
struct nav_cell *nav_get_next_neighbor(struct nav_array *array, int8_t row, int8_t column);

/*Wall*/
void nav_update_wall_cell(struct nav_cell *cell, dir_t dir);
@@ -150,7 +150,7 @@ dir_t position_convert_to_direction(pos_t *position, facing_t dir)
}
}

dir_t position_get_direction_to(pos_t *position, int row, int column)
dir_t position_get_direction_to(pos_t *position, int8_t row, int8_t column)
{
/*North*/
if (position->row - 1 == row && position->column == column)
@@ -1,6 +1,8 @@
#ifndef POSITION_H
#define POSITION_H

#include "inttypes.h"

#ifdef __cplusplus
extern "C"
{
@@ -33,8 +35,8 @@ typedef enum
*/
typedef struct
{
int row;
int column;
int8_t row;
int8_t column;
dir_t direction;
} pos_t;

@@ -101,7 +103,7 @@ dir_t position_left_adj_direction(dir_t dir);
*/
dir_t position_convert_to_direction(pos_t *position, facing_t facing);

dir_t position_get_direction_to(pos_t *position, int row, int column);
dir_t position_get_direction_to(pos_t *position, int8_t row, int8_t column);

void position_copy(pos_t *value, pos_t *buffer);

0 comments on commit bd9412e

Please sign in to comment.
You can’t perform that action at this time.