Compact code grid code#485
Merged
Merged
Conversation
Refactor code to enhance readability and optimize performance by reducing redundancy and improving structure.
There was a problem hiding this comment.
Pull request overview
This PR refactors and “compacts” the Drive grid-map code in drive.h, mainly by reorganizing GridMap fields, simplifying several grid/neighbor helper routines, and deduplicating infraction behavior handling.
Changes:
- Reordered/trimmed
GridMapstruct members (including removing unusedcell_size_x/yfields). - Added
apply_infraction_behavior()to centralize STOP/REMOVE handling for offroad/collision/red-light infractions. - Simplified variable naming and small logic cleanup in grid index calculation, grid map initialization, and neighbor offset caching.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WaelDLZ
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Cleanup-only refactor of the grid-map code in
drive.hplus a smallbehavioral fix to how the grid's spatial bounds are computed. No change to
the training loop or Python side.
Changes
GridMapstruct (drive.h)cell_size_x/cell_size_yfields (always equal toGRID_CELL_SIZE).stale inline comments.
init_grid_mapis_road_grid_candidate()helper (datatypes.h), instead of all road elements. Road lines no longer stretch the grid extent.elementpointer alias in the count/populate passes.INVALID_POSITIONguards into one.cell_entities_insert_index != 0re-zeroing loop(the array comes straight from
calloc).apply_infraction_behavior()helperSTOP_AGENT/REMOVE_AGENTblock (offroad,collision, red-light) into one inline helper in
compute_metrics.Misc
init_neighbor_offsets,cache_neighbor_offsets,get_neighbors_entities,get_grid_index: shorter local names(
vr,rel_x,cell_x/cell_y,cols) and dropped redundant comments.Net
+72 / −128acrossdrive.handdatatypes.h.