rust/hwphysics/src/physics.rs
changeset 14737 8e74d4eb89f5
parent 14200 abbb74b9cb62
child 15141 febccab419b1
--- a/rust/hwphysics/src/physics.rs	Fri Mar 22 23:46:48 2019 +0300
+++ b/rust/hwphysics/src/physics.rs	Sat Mar 23 01:07:23 2019 +0300
@@ -1,10 +1,6 @@
-use crate::{
-    common::{GearId, GearData, GearDataProcessor}
-};
+use crate::common::{GearData, GearDataProcessor, GearId};
 use fpnum::*;
-use integral_geometry::{
-    Point, Size, GridIndex
-};
+use integral_geometry::{GridIndex, Point, Size};
 
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 pub struct PhysicsData {
@@ -14,6 +10,12 @@
 
 impl GearData for PhysicsData {}
 
+impl PhysicsData {
+    pub fn new(position: FPPoint, velocity: FPPoint) -> Self {
+        Self { position, velocity }
+    }
+}
+
 pub struct DynamicPhysicsCollection {
     gear_ids: Vec<GearId>,
     positions: Vec<FPPoint>,
@@ -25,7 +27,7 @@
         Self {
             gear_ids: Vec::new(),
             positions: Vec::new(),
-            velocities: Vec::new()
+            velocities: Vec::new(),
         }
     }
 
@@ -40,22 +42,23 @@
     }
 
     fn iter_pos_update(&mut self) -> impl Iterator<Item = (GearId, (&mut FPPoint, &FPPoint))> {
-        self.gear_ids.iter().cloned()
-            .zip(self.positions.iter_mut()
-                .zip(self.velocities.iter()))
+        self.gear_ids
+            .iter()
+            .cloned()
+            .zip(self.positions.iter_mut().zip(self.velocities.iter()))
     }
 }
 
 pub struct StaticPhysicsCollection {
     gear_ids: Vec<GearId>,
-    positions: Vec<FPPoint>
+    positions: Vec<FPPoint>,
 }
 
 impl StaticPhysicsCollection {
     fn new() -> Self {
         Self {
             gear_ids: Vec::new(),
-            positions: Vec::new()
+            positions: Vec::new(),
         }
     }
 
@@ -70,12 +73,12 @@
     static_physics: StaticPhysicsCollection,
 
     physics_cleanup: Vec<GearId>,
-    position_updates: PositionUpdates
+    position_updates: PositionUpdates,
 }
 
 pub struct PositionUpdates {
     pub gear_ids: Vec<GearId>,
-    pub positions: Vec<FPPoint>
+    pub positions: Vec<FPPoint>,
 }
 
 impl PositionUpdates {
@@ -98,7 +101,7 @@
             dynamic_physics: DynamicPhysicsCollection::new(),
             static_physics: StaticPhysicsCollection::new(),
             physics_cleanup: Vec::new(),
-            position_updates: PositionUpdates::new(0)
+            position_updates: PositionUpdates::new(0),
         }
     }
 
@@ -131,4 +134,4 @@
             self.dynamic_physics.push(gear_id, gear_data);
         }
     }
-}
\ No newline at end of file
+}