1
0
Fork 0

vector2d: refactor ‹in_range›

This commit is contained in:
Matej Focko 2022-12-30 12:11:56 +01:00
parent b02e7207ac
commit cdd4087cd6

View file

@ -45,22 +45,14 @@ where
&mut v[y][x] &mut v[y][x]
} }
pub fn in_range<T, U>(v: &[Vec<U>], idx: &Vector2D<T>) -> bool pub fn in_range<I, C>(v: &[Vec<C>], idx: &Vector2D<I>) -> bool
where where
usize: TryInto<T>, I: Copy,
<usize as TryInto<T>>::Error: Debug, usize: TryFrom<I>,
usize: TryFrom<T>,
<usize as TryFrom<T>>::Error: Debug,
T: PartialOrd + Copy,
{ {
idx.y >= 0.try_into().unwrap() usize::try_from(idx.y)
&& idx.y < v.len().try_into().unwrap() .and_then(|y| usize::try_from(idx.x).map(|x| y < v.len() && x < v[y].len()))
&& idx.x >= 0.try_into().unwrap() .unwrap_or(false)
&& idx.x
< v[TryInto::<usize>::try_into(idx.y).unwrap()]
.len()
.try_into()
.unwrap()
} }
impl<T: Copy> Vector2D<T> { impl<T: Copy> Vector2D<T> {