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]
|
||||
}
|
||||
|
||||
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> {
|
||||
|
|
Loading…
Reference in a new issue