# HG changeset patch # User alfadur # Date 1564000678 -10800 # Node ID d8c4fd911b37f9d167eb850ac90c6e3299c00ee6 # Parent 501dfa1c8deb67f39d29dbcc1856a93f4d2c980f check dynamic collision arrays first diff -r 501dfa1c8deb -r d8c4fd911b37 rust/hwphysics/src/grid.rs --- a/rust/hwphysics/src/grid.rs Wed Jul 24 23:33:06 2019 +0300 +++ b/rust/hwphysics/src/grid.rs Wed Jul 24 23:37:58 2019 +0300 @@ -81,7 +81,20 @@ let new_bin_index = self.bin_index(new_position); let old_bin = self.lookup_bin(old_position); - if let Some(index) = old_bin.static_refs.iter().position(|id| *id == gear_id) { + if let Some(index) = old_bin.dynamic_refs.iter().position(|id| *id == gear_id) { + if old_bin_index == new_bin_index { + old_bin.dynamic_entries[index].center = *new_position + } else { + let bounds = old_bin.dynamic_entries.swap_remove(index); + let new_bin = self.get_bin(new_bin_index); + + new_bin.dynamic_refs.push(gear_id); + new_bin.dynamic_entries.push(CircleBounds { + center: *new_position, + ..bounds + }); + } + } else if let Some(index) = old_bin.static_refs.iter().position(|id| *id == gear_id) { let bounds = old_bin.static_entries.swap_remove(index); old_bin.static_refs.swap_remove(index); @@ -96,19 +109,6 @@ center: *new_position, ..bounds }); - } else if let Some(index) = old_bin.dynamic_refs.iter().position(|id| *id == gear_id) { - if old_bin_index == new_bin_index { - old_bin.dynamic_entries[index].center = *new_position - } else { - let bounds = old_bin.dynamic_entries.swap_remove(index); - let new_bin = self.get_bin(new_bin_index); - - new_bin.dynamic_refs.push(gear_id); - new_bin.dynamic_entries.push(CircleBounds { - center: *new_position, - ..bounds - }); - } } }