woah
This commit is contained in:
22
src/misc.rs
22
src/misc.rs
@@ -1,5 +1,7 @@
|
||||
use std::{iter::Rev, ops::RangeInclusive};
|
||||
|
||||
use num::CheckedSub;
|
||||
|
||||
pub fn split_from<T>(min: T, max: T, x: T) -> Vec<Vec<T>>
|
||||
where
|
||||
T: num::Integer + Copy,
|
||||
@@ -22,6 +24,26 @@ where
|
||||
output
|
||||
}
|
||||
|
||||
pub fn offsets(i: usize, j: usize, range: usize) -> Vec<(usize, usize)> {
|
||||
let mut output = Vec::new();
|
||||
for i_o in [-(range as i16), 0, range as i16] {
|
||||
let new_i = i as i16 + i_o;
|
||||
if 0 > new_i {
|
||||
continue;
|
||||
}
|
||||
|
||||
for j_o in [-(range as i16), 0, range as i16] {
|
||||
let new_j = j as i16 + j_o;
|
||||
if 0 > new_j {
|
||||
continue;
|
||||
}
|
||||
output.push((new_i as usize, new_j as usize));
|
||||
}
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user