From fe4e15eac12818dd0468e14fdaf30f540422181b Mon Sep 17 00:00:00 2001 From: Sam <61994039+fourthDimensional@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:55:40 -0500 Subject: [PATCH 1/3] Enforce world bounds for object positioning and update related tests --- tests/test_world.py | 8 ++++++-- world/render_objects.py | 2 +- world/world.py | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_world.py b/tests/test_world.py index 1e6adb5..744b850 100644 --- a/tests/test_world.py +++ b/tests/test_world.py @@ -83,5 +83,9 @@ def test_tick_all_calls_tick(world): def test_add_object_out_of_bounds(world): entity = DummyEntity(Position(x=1000, y=1000)) - with pytest.raises(ValueError): - world.add_object(entity) + + world.add_object(entity) + + entity = world.get_objects()[0] + + assert entity.position.x == 49 and entity.position.y == 49 diff --git a/world/render_objects.py b/world/render_objects.py index 9f47d41..897fa79 100644 --- a/world/render_objects.py +++ b/world/render_objects.py @@ -151,4 +151,4 @@ class FoodObject(BaseEntity): :return: String representation. """ - return f"FoodObject({self.position}, decay={self.decay:.0f}, decay_rate={self.decay_rate * (1 + (self.neighbors / 10))})" + return f"FoodObject({self.position}, decay={self.decay:.0f }, decay_rate={self.decay_rate * (1 + (self.neighbors / 10))})" diff --git a/world/world.py b/world/world.py index 63ef11a..dd3c38e 100644 --- a/world/world.py +++ b/world/world.py @@ -111,7 +111,9 @@ class World: # Ensure position is within world bounds, considering a center origin if position.x < -self.world_size[0] / 2 or position.x >= self.world_size[0] / 2 or position.y < - \ self.world_size[1] / 2 or position.y >= self.world_size[1] / 2: - raise ValueError(f"Position is out of world bounds. {position} is out of bounds.") + # force position to be within bounds + position.x = max(-self.world_size[0] / 2, min(position.x, self.world_size[0] / 2 - 1)) + position.y = max(-self.world_size[1] / 2, min(position.y, self.world_size[1] / 2 - 1)) return int(position.x // self.partition_size), int(position.y // self.partition_size) From 330f199657559f1fda05c6087edea1125becf7b2 Mon Sep 17 00:00:00 2001 From: Sam <61994039+fourthDimensional@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:00:40 -0500 Subject: [PATCH 2/3] Update food object representation to use one decimal place for decay value --- world/render_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/world/render_objects.py b/world/render_objects.py index 897fa79..2e2c100 100644 --- a/world/render_objects.py +++ b/world/render_objects.py @@ -151,4 +151,4 @@ class FoodObject(BaseEntity): :return: String representation. """ - return f"FoodObject({self.position}, decay={self.decay:.0f }, decay_rate={self.decay_rate * (1 + (self.neighbors / 10))})" + return f"FoodObject({self.position}, decay={self.decay:.1f}, decay_rate={self.decay_rate * (1 + (self.neighbors / 10))})" From 737d595d50665a02b4e5d56a59131cd311ce0ac1 Mon Sep 17 00:00:00 2001 From: Sam <61994039+fourthDimensional@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:01:47 -0500 Subject: [PATCH 3/3] Increase zoom threshold for smoother zoom transitions in simulation --- world/simulation_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/world/simulation_interface.py b/world/simulation_interface.py index 278d476..352bc7a 100644 --- a/world/simulation_interface.py +++ b/world/simulation_interface.py @@ -80,7 +80,7 @@ class Camera: zoom_smoothing_factor = 1 - pow(1 - self.zoom_smoothing, deltatime * 60) self.zoom += (self.target_zoom - self.zoom) * zoom_smoothing_factor - zoom_threshold = 0.001 + zoom_threshold = 0.01 if abs(self.zoom - self.target_zoom) < zoom_threshold: self.zoom = self.target_zoom