Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/scenic/simulators/metadrive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@
from scenic.core.vectors import Vector


def calculateFilmSize(sumo_map_boundary, scaling=5, margin_factor=1.1):
"""Calculates the film size for rendering based on the map's boundary."""
# Calculate the width and height based on the sumo_map_boundary
def calculateFilmSize(
sumo_map_boundary,
scaling=5,
margin_factor=1.1,
min_extent=200.0,
):
"""Compute film_size (width, height) in pixels for MetaDrive's top-down renderer.

The SUMO convBoundary gives the map extent (xmin, ymin, xmax, ymax) in meters.
If one dimension is zero (e.g. a single straight road), clamp it to min_extent
to avoid a zero-width/height film size.
"""
xmin, ymin, xmax, ymax = sumo_map_boundary
width = xmax - xmin
height = ymax - ymin

# Apply margin and convert to pixels
# Clamp zero-width/height maps (e.g. straight roads) to a reasonable minimum.
width = max(width, min_extent)
height = max(height, min_extent)

adjusted_width = width * margin_factor
adjusted_height = height * margin_factor
return int(adjusted_width * scaling), int(adjusted_height * scaling)

film_w = int(adjusted_width * scaling)
film_h = int(adjusted_height * scaling)
return film_w, film_h


def extractNetOffsetAndBoundary(sumo_map_path):
Expand Down
Loading