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]
}
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
usize: TryInto<T>,
<usize as TryInto<T>>::Error: Debug,
usize: TryFrom<T>,
<usize as TryFrom<T>>::Error: Debug,
T: PartialOrd + Copy,
I: Copy,
usize: TryFrom<I>,
{
idx.y >= 0.try_into().unwrap()
&& idx.y < v.len().try_into().unwrap()
&& idx.x >= 0.try_into().unwrap()
&& idx.x
< v[TryInto::<usize>::try_into(idx.y).unwrap()]
.len()
.try_into()
.unwrap()
usize::try_from(idx.y)
.and_then(|y| usize::try_from(idx.x).map(|x| y < v.len() && x < v[y].len()))
.unwrap_or(false)
}
impl<T: Copy> Vector2D<T> {