diff --git a/src/vector2d.rs b/src/vector2d.rs index a90c1d9..b3aa335 100644 --- a/src/vector2d.rs +++ b/src/vector2d.rs @@ -45,22 +45,14 @@ where &mut v[y][x] } -pub fn in_range(v: &[Vec], idx: &Vector2D) -> bool +pub fn in_range(v: &[Vec], idx: &Vector2D) -> bool where - usize: TryInto, - >::Error: Debug, - usize: TryFrom, - >::Error: Debug, - T: PartialOrd + Copy, + I: Copy, + usize: TryFrom, { - idx.y >= 0.try_into().unwrap() - && idx.y < v.len().try_into().unwrap() - && idx.x >= 0.try_into().unwrap() - && idx.x - < v[TryInto::::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 Vector2D {