vector2d: refactor ‹in_range›
This commit is contained in:
parent
b02e7207ac
commit
cdd4087cd6
1 changed files with 6 additions and 14 deletions
|
@ -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> {
|
||||||
|
|
Loading…
Reference in a new issue