From 742dc85414e0d469552eedfcfa91955b6baa30bb Mon Sep 17 00:00:00 2001 From: dusk Date: Sun, 29 Sep 2024 04:27:36 +0300 Subject: [PATCH] refactor: minor code refactor so it looks slightly better --- rust/src/boid/boid_2d.rs | 6 +++--- rust/src/boid/boid_3d.rs | 7 +++---- rust/src/boid_properties.rs | 2 +- rust/src/flock_properties.rs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/rust/src/boid/boid_2d.rs b/rust/src/boid/boid_2d.rs index 7e03276..edec907 100644 --- a/rust/src/boid/boid_2d.rs +++ b/rust/src/boid/boid_2d.rs @@ -83,9 +83,9 @@ impl Boid for Boid2D { #[inline(always)] fn apply_force(&mut self, force: Vec3) { self.vel += force.xy(); - let new_vel = self.vel.clamp_length_max(self.props.max_speed); - self.vel = new_vel; - self.base_mut().translate(Vector2::new(new_vel.x, new_vel.y)); + self.vel = self.vel.clamp_length_max(self.props.max_speed); + let force_to_apply = Vector2::new(self.vel.x, self.vel.y); + self.base_mut().translate(force_to_apply); } #[inline(always)] diff --git a/rust/src/boid/boid_3d.rs b/rust/src/boid/boid_3d.rs index 9daf0d9..db6f311 100644 --- a/rust/src/boid/boid_3d.rs +++ b/rust/src/boid/boid_3d.rs @@ -82,10 +82,9 @@ impl Boid for Boid3D { #[inline(always)] fn apply_force(&mut self, force: Vec3) { self.vel += force; - let new_vel = self.vel.clamp_length_max(self.props.max_speed); - self.vel = new_vel; - self.base_mut() - .translate(Vector3::new(new_vel.x, new_vel.y, new_vel.z)); + self.vel = self.vel.clamp_length_max(self.props.max_speed); + let force_to_apply = Vector3::new(self.vel.x, self.vel.y, self.vel.z); + self.base_mut().translate(force_to_apply); } #[inline(always)] diff --git a/rust/src/boid_properties.rs b/rust/src/boid_properties.rs index db60c79..aa34e8a 100644 --- a/rust/src/boid_properties.rs +++ b/rust/src/boid_properties.rs @@ -28,4 +28,4 @@ pub struct BoidProperties { #[init(val = 0.8)] /// How much to follow a flock target (if there is one). pub targeting: f32, -} \ No newline at end of file +} diff --git a/rust/src/flock_properties.rs b/rust/src/flock_properties.rs index b3dd037..da7ca65 100644 --- a/rust/src/flock_properties.rs +++ b/rust/src/flock_properties.rs @@ -16,4 +16,4 @@ pub struct FlockProperties { #[init(val = 2500.0)] /// Distance (squared) to apply cohesion force between boids in a flock. pub goal_cohesion: f32, -} \ No newline at end of file +}