Skip to content

Commit

Permalink
add boundary visualization for limited-size environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovannibriglia committed Sep 20, 2024
1 parent a6526da commit 6f4e1e2
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions vmas/simulator/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,23 +774,32 @@ def render(
return self.viewer.render(return_rgb_array=mode == "rgb_array")

def plot_boundary(self):

# include boundaries in the rendering
# check if the environment is dimension-limited
# include boundaries in the rendering if the environment is dimension-limited
if self.world.x_semidim is not None or self.world.y_semidim is not None:
from vmas.simulator.rendering import Line
from vmas.simulator.utils import Color

# set a big value for the cases where the environment is dimension-limited only in one coordinate
infinite_value = 100

x_semi = self.world.x_semidim if self.world.x_semidim else infinite_value
y_semi = self.world.y_semidim if self.world.y_semidim else infinite_value
x_semi = (
self.world.x_semidim
if self.world.x_semidim is not None
else infinite_value
)
y_semi = (
self.world.y_semidim
if self.world.y_semidim is not None
else infinite_value
)

# set the color for the boundary line
color = Color.GRAY.value

# Define boundary points based on whether world semidims are provided
if (self.world.x_semidim and self.world.y_semidim) or self.world.x_semidim:
if (
self.world.x_semidim is not None and self.world.y_semidim is not None
) or self.world.y_semidim is not None:
boundary_points = [
(-x_semi, y_semi),
(x_semi, y_semi),
Expand All @@ -800,16 +809,21 @@ def plot_boundary(self):
else:
boundary_points = [
(-x_semi, y_semi),
(-x_semi, -y_semi),
(x_semi, y_semi),
(x_semi, -y_semi),
(-x_semi, -y_semi),
]

# Create lines by connecting points
for i in range(
0,
len(boundary_points),
1 if (self.world.x_semidim and self.world.y_semidim) else 2,
1
if (
self.world.x_semidim is not None
and self.world.y_semidim is not None
)
else 2,
):
start = boundary_points[i]
end = boundary_points[(i + 1) % len(boundary_points)]
Expand Down

0 comments on commit 6f4e1e2

Please sign in to comment.