@@ -741,6 +741,9 @@ def render(
741741 )
742742
743743 # Render
744+ if self .scenario .visualize_semidims :
745+ self .plot_boundary ()
746+
744747 self ._set_agent_comm_messages (env_index )
745748
746749 if plot_position_function is not None :
@@ -770,6 +773,64 @@ def render(
770773 # render to display or array
771774 return self .viewer .render (return_rgb_array = mode == "rgb_array" )
772775
776+ def plot_boundary (self ):
777+ # include boundaries in the rendering if the environment is dimension-limited
778+ if self .world .x_semidim is not None or self .world .y_semidim is not None :
779+ from vmas .simulator .rendering import Line
780+ from vmas .simulator .utils import Color
781+
782+ # set a big value for the cases where the environment is dimension-limited only in one coordinate
783+ infinite_value = 100
784+
785+ x_semi = (
786+ self .world .x_semidim
787+ if self .world .x_semidim is not None
788+ else infinite_value
789+ )
790+ y_semi = (
791+ self .world .y_semidim
792+ if self .world .y_semidim is not None
793+ else infinite_value
794+ )
795+
796+ # set the color for the boundary line
797+ color = Color .GRAY .value
798+
799+ # Define boundary points based on whether world semidims are provided
800+ if (
801+ self .world .x_semidim is not None and self .world .y_semidim is not None
802+ ) or self .world .y_semidim is not None :
803+ boundary_points = [
804+ (- x_semi , y_semi ),
805+ (x_semi , y_semi ),
806+ (x_semi , - y_semi ),
807+ (- x_semi , - y_semi ),
808+ ]
809+ else :
810+ boundary_points = [
811+ (- x_semi , y_semi ),
812+ (- x_semi , - y_semi ),
813+ (x_semi , y_semi ),
814+ (x_semi , - y_semi ),
815+ ]
816+
817+ # Create lines by connecting points
818+ for i in range (
819+ 0 ,
820+ len (boundary_points ),
821+ 1
822+ if (
823+ self .world .x_semidim is not None
824+ and self .world .y_semidim is not None
825+ )
826+ else 2 ,
827+ ):
828+ start = boundary_points [i ]
829+ end = boundary_points [(i + 1 ) % len (boundary_points )]
830+ line = Line (start , end , width = 0.7 )
831+ line .set_color (* color )
832+ self .viewer .add_onetime (line )
833+
773834 def plot_function (
774835 self , f , precision , plot_range , cmap_range , cmap_alpha , cmap_name
775836 ):
0 commit comments