pub(crate) fn draw_line_with_coords(
x1: usize,
y1: usize,
x2: usize,
y2: usize,
max_width: Option<usize>,
max_height: Option<usize>,
) -> Vec<(usize, usize)> {
let mut coords = Vec::new();
let dx = (x2 as isize - x1 as isize).abs();
let dy = (y2 as isize - y1 as isize).abs();
let sx = if x1 < x2 { 1isize } else { -1isize };
let sy = if y1 < y2 { 1isize } else { -1isize };
let mut err = dx - dy;
let mut x = x1 as isize;
let mut y = y1 as isize;
while x != x2 as isize || y != y2 as isize {
let in_bounds = x >= 0
&& y >= 0
&& (max_width.is_none() || x < max_width.expect("Operation failed") as isize)
&& (max_height.is_none() || y < max_height.expect("Operation failed") as isize);
if in_bounds {
coords.push((x as usize, y as usize));
}
let e2 = 2 * err;
if e2 > -dy {
err -= dy;
x += sx;
}
if e2 < dx {
err += dx;
y += sy;
}
}
let end_in_bounds = (max_width.is_none() || x2 < max_width.expect("Operation failed"))
&& (max_height.is_none() || y2 < max_height.expect("Operation failed"));
if end_in_bounds {
coords.push((x2, y2));
}
coords
}