rust/hwphysics/src/grid.rs
changeset 15262 d8c4fd911b37
parent 15261 501dfa1c8deb
child 15263 24828281c9c5
equal deleted inserted replaced
15261:501dfa1c8deb 15262:d8c4fd911b37
    79     ) {
    79     ) {
    80         let old_bin_index = self.bin_index(old_position);
    80         let old_bin_index = self.bin_index(old_position);
    81         let new_bin_index = self.bin_index(new_position);
    81         let new_bin_index = self.bin_index(new_position);
    82 
    82 
    83         let old_bin = self.lookup_bin(old_position);
    83         let old_bin = self.lookup_bin(old_position);
    84         if let Some(index) = old_bin.static_refs.iter().position(|id| *id == gear_id) {
    84         if let Some(index) = old_bin.dynamic_refs.iter().position(|id| *id == gear_id) {
       
    85             if old_bin_index == new_bin_index {
       
    86                 old_bin.dynamic_entries[index].center = *new_position
       
    87             } else {
       
    88                 let bounds = old_bin.dynamic_entries.swap_remove(index);
       
    89                 let new_bin = self.get_bin(new_bin_index);
       
    90 
       
    91                 new_bin.dynamic_refs.push(gear_id);
       
    92                 new_bin.dynamic_entries.push(CircleBounds {
       
    93                     center: *new_position,
       
    94                     ..bounds
       
    95                 });
       
    96             }
       
    97         } else if let Some(index) = old_bin.static_refs.iter().position(|id| *id == gear_id) {
    85             let bounds = old_bin.static_entries.swap_remove(index);
    98             let bounds = old_bin.static_entries.swap_remove(index);
    86             old_bin.static_refs.swap_remove(index);
    99             old_bin.static_refs.swap_remove(index);
    87 
   100 
    88             let new_bin = if old_bin_index == new_bin_index {
   101             let new_bin = if old_bin_index == new_bin_index {
    89                 old_bin
   102                 old_bin
    94             new_bin.dynamic_refs.push(gear_id);
   107             new_bin.dynamic_refs.push(gear_id);
    95             new_bin.dynamic_entries.push(CircleBounds {
   108             new_bin.dynamic_entries.push(CircleBounds {
    96                 center: *new_position,
   109                 center: *new_position,
    97                 ..bounds
   110                 ..bounds
    98             });
   111             });
    99         } else if let Some(index) = old_bin.dynamic_refs.iter().position(|id| *id == gear_id) {
       
   100             if old_bin_index == new_bin_index {
       
   101                 old_bin.dynamic_entries[index].center = *new_position
       
   102             } else {
       
   103                 let bounds = old_bin.dynamic_entries.swap_remove(index);
       
   104                 let new_bin = self.get_bin(new_bin_index);
       
   105 
       
   106                 new_bin.dynamic_refs.push(gear_id);
       
   107                 new_bin.dynamic_entries.push(CircleBounds {
       
   108                     center: *new_position,
       
   109                     ..bounds
       
   110                 });
       
   111             }
       
   112         }
   112         }
   113     }
   113     }
   114 
   114 
   115     pub fn check_collisions(&self, collisions: &mut DetectedCollisions) {
   115     pub fn check_collisions(&self, collisions: &mut DetectedCollisions) {
   116         for bin in &self.bins {
   116         for bin in &self.bins {