pub fn all_index(
row_index: usize,
column_index: usize,
max_row_index: usize,
max_column_index: usize,
step: usize,
) -> CoordinateIndexStruct {
let mut temp_row = row_index as i32;
let mut temp_column = column_index as i32 + step as i32;
if temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
let right = (temp_row, temp_column);
temp_row = row_index as i32;
temp_column = column_index as i32 - 1;
if temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
let left = (temp_row, temp_column);
temp_row = row_index as i32 + 1;
temp_column = column_index as i32;
if temp_row > max_row_index as i32 {
temp_row = -1;
temp_column = -1;
}
let down = (temp_row, temp_column);
temp_row = row_index as i32 - 1;
temp_column = column_index as i32;
if temp_row < 0 {
temp_row = -1;
temp_column = -1;
}
let up = (temp_row, temp_column);
temp_row = row_index as i32 - 1;
temp_column = column_index as i32 + 1;
if temp_row < 0 || temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
let right_up = (temp_row, temp_column);
temp_row = row_index as i32 + 1;
temp_column = column_index as i32 + 1;
if temp_row > max_row_index as i32 || temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
let right_down = (temp_row, temp_column);
temp_row = row_index as i32 - 1;
temp_column = column_index as i32 - 1;
if temp_row < 0 || temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
let left_up = (temp_row, temp_column);
temp_row = row_index as i32 + 1;
temp_column = column_index as i32 - 1;
if temp_row > max_row_index as i32 || temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
let left_down = (temp_row, temp_column);
CoordinateIndexStruct {
right,
left,
down,
up,
right_down,
right_up,
left_up,
left_down,
}
}
pub fn right_index(
row_index: usize,
column_index: usize,
_max_row_index: usize,
max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32;
let mut temp_column = column_index as i32 + step as i32;
if temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn left_index(
row_index: usize,
column_index: usize,
_max_row_index: usize,
_max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32;
let mut temp_column = column_index as i32 - step as i32;
if temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn down_index(
row_index: usize,
column_index: usize,
max_row_index: usize,
_max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 + step as i32;
let mut temp_column = column_index as i32;
if temp_row > max_row_index as i32 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn up_index(
row_index: usize,
column_index: usize,
_max_row_index: usize,
_max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 - step as i32;
let mut temp_column = column_index as i32;
if temp_row < 0 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn right_up_index(
row_index: usize,
column_index: usize,
_max_row_index: usize,
max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 - step as i32;
let mut temp_column = column_index as i32 + step as i32;
if temp_row < 0 || temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn right_down_index(
row_index: usize,
column_index: usize,
max_row_index: usize,
max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 + step as i32;
let mut temp_column = column_index as i32 + step as i32;
if temp_row > max_row_index as i32 || temp_column > max_column_index as i32 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn left_up_index(
row_index: usize,
column_index: usize,
_max_row_index: usize,
_max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 - step as i32;
let mut temp_column = column_index as i32 - step as i32;
if temp_row < 0 || temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
pub fn left_down_index(
row_index: usize,
column_index: usize,
max_row_index: usize,
_max_column_index: usize,
step: usize,
) -> (i32, i32) {
let mut temp_row = row_index as i32 + step as i32;
let mut temp_column = column_index as i32 - step as i32;
if temp_row > max_row_index as i32 || temp_column < 0 {
temp_row = -1;
temp_column = -1;
}
(temp_row, temp_column)
}
#[derive(Debug)]
pub struct CoordinateIndexStruct {
pub right: (i32, i32),
pub left: (i32, i32),
pub down: (i32, i32),
pub up: (i32, i32),
pub right_down: (i32, i32),
pub right_up: (i32, i32),
pub left_up: (i32, i32),
pub left_down: (i32, i32),
}