diff options
author | tom barrett <spalf0@gmail.com> | 2019-07-01 09:14:17 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-07-01 09:14:17 -0500 |
commit | 0947ce5a918207efeaf2a4f67a1cc410795f057a (patch) | |
tree | 30d601261754e236fc064faa9138eec9d1314d7c /src/math.rs | |
parent | 4b01b87d8aca041304c927560095af92feb406da (diff) |
simpilfied interfaces and added new xml properties
Diffstat (limited to 'src/math.rs')
-rw-r--r-- | src/math.rs | 23 |
1 files changed, 10 insertions, 13 deletions
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<Vec<(usize, Rect)>>, - 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) } |