From 0947ce5a918207efeaf2a4f67a1cc410795f057a Mon Sep 17 00:00:00 2001 From: tom barrett Date: Mon, 1 Jul 2019 09:14:17 -0500 Subject: simpilfied interfaces and added new xml properties --- src/math.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/math.rs') diff --git a/src/math.rs b/src/math.rs index 7599f87..c747cce 100644 --- a/src/math.rs +++ b/src/math.rs @@ -13,20 +13,17 @@ pub fn flip(rect: Rect) -> Rect { r } -pub fn next_source( - source: Rect, - animation: &Option>, - timer: Instant, -) -> (Rect, Instant) { - if let Some(animation) = animation { - if let Some(mut i) = animation.iter().position(|a| a.1 == source) { - if timer.elapsed().as_millis() > animation[i].0 as u128 { - i = if i == animation.len() - 1 { 0 } else { i + 1 }; - return (animation[i].1, Instant::now()); - } +pub fn next_source(source: Rect, animation: &[(usize, Rect)], timer: Instant) -> (Rect, Instant) { + if let Some(mut i) = animation.iter().position(|a| a.1 == source) { + if timer.elapsed().as_millis() > animation[i].0 as u128 { + i = if i == animation.len() - 1 { 0 } else { i + 1 }; + (animation[i].1, Instant::now()) } else { - return (animation[0].1, Instant::now()); + (source, timer) } + } else if !animation.is_empty() { + (animation[0].1, timer) + } else { + (source, timer) } - (source, timer) } -- cgit v1.2.3