Add time complexity annotations to methods in world.py
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 1m2s
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 1m2s
This commit is contained in:
parent
b775813cbd
commit
b9027ab935
@ -153,6 +153,8 @@ class World:
|
||||
|
||||
:param camera: The camera object for coordinate transformation.
|
||||
:param screen: The Pygame screen surface.
|
||||
|
||||
Time complexity: O(n), where n is the number of objects in the current buffer.
|
||||
"""
|
||||
for obj_list in self.buffers[self.current_buffer].values():
|
||||
for obj in obj_list:
|
||||
@ -161,6 +163,9 @@ class World:
|
||||
def tick_all(self) -> None:
|
||||
"""
|
||||
Advances all objects in the world by one tick, updating their state and handling interactions.
|
||||
|
||||
Time complexity: O(N + K) / O(N*M), where N is the number of objects in the current buffer,
|
||||
K is the number of objects that can interact with each object, and M is number of objects in checked cells where C is the number of cells checked within the interaction radius.
|
||||
"""
|
||||
next_buffer: int = 1 - self.current_buffer
|
||||
self.buffers[next_buffer].clear()
|
||||
@ -208,6 +213,8 @@ class World:
|
||||
:param y: Y coordinate of the center.
|
||||
:param radius: Search radius.
|
||||
:return: List of objects within the radius.
|
||||
|
||||
Time complexity: O(C * M) / O(N), where C is the number of cells checked within the radius and M is the number of objects in those cells.
|
||||
"""
|
||||
result: List[BaseEntity] = []
|
||||
cell_x, cell_y = int(x // self.partition_size), int(y // self.partition_size)
|
||||
@ -234,6 +241,8 @@ class World:
|
||||
:param x2: Maximum X coordinate.
|
||||
:param y2: Maximum Y coordinate.
|
||||
:return: List of objects within the rectangle.
|
||||
|
||||
Time complexity: O(C * M) / O(N), where C is the number of cells checked within the rectangle and M is the number of objects in those cells.
|
||||
"""
|
||||
result: List[BaseEntity] = []
|
||||
cell_x1, cell_y1 = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user