From cdd4087cd6abaa51930fba6d0f6ba74d4f8dc6f7 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 30 Dec 2022 12:11:56 +0100 Subject: [PATCH] =?UTF-8?q?vector2d:=20refactor=20=E2=80=B9in=5Frange?= =?UTF-8?q?=E2=80=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vector2d.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) 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 {