added new sub-types for entities Agent, RoadMapElement, TrafficControlElement#278
Conversation
Greptile OverviewGreptile SummaryThis PR introduces a new Key changes:
Critical issues found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant PR as Pull Request
participant DH as drive.h
participant DT as datatypes.h
participant DS as Drive Struct
Note over PR,DS: New Type System Introduction
PR->>DT: Create new datatypes.h
DT->>DT: Define Agent struct
DT->>DT: Define RoadMapElement struct
DT->>DT: Define TrafficControlElement struct
DT->>DT: Define helper functions
DT->>DT: Define free_agent/free_road_element/free_traffic_element
PR->>DH: Modify drive.h
DH->>DT: Include datatypes.h
Note over DH: Conflicts with existing defines
DH->>DH: Save STOP_SIGN as DT_STOP_SIGN
DH->>DH: Save CROSSWALK as DT_CROSSWALK
DH->>DH: Undef conflicting macros from datatypes.h
DH->>DH: Redefine macros with legacy values
DH->>DS: Add typedef for Agent
DH->>DS: Add typedef for RoadMapElement
DH->>DS: Add typedef for TrafficControlElement
DH->>DS: Add placeholder fields (agents, road_elements, traffic_elements)
Note over DS: Legacy Entity struct still active
Note over DS: New structs available but unused
|
| @@ -0,0 +1,277 @@ | |||
| #define UNKNOWN 0 | |||
There was a problem hiding this comment.
Missing header guards - this file needs #ifndef, #define, and #endif to prevent multiple inclusion issues
| int is_road_lane(int type) { return (type >= 0 && type <= 9); } | ||
|
|
||
| int is_drivable_road_lane(int type) { return (type == LANE_FREEWAY || type == LANE_SURFACE_STREET); } | ||
|
|
||
| int is_road_line(int type) { return (type >= 10 && type <= 19); } | ||
|
|
||
| int is_road_edge(int type) { return (type >= 20 && type <= 29); } | ||
|
|
||
| int is_road(int type) { return is_road_lane(type) || is_road_line(type) || is_road_edge(type); } | ||
|
|
||
| int is_controllable_agent(int type) { return (type == VEHICLE || type == PEDESTRIAN || type == CYCLIST); } | ||
|
|
||
| int is_traffic_light_red(int state) { return state == 1 || state == 4 || state == 7; } | ||
|
|
||
| int is_traffic_light_green(int state) { return state == 3 || state == 6 || state == 9; } | ||
|
|
||
| int is_traffic_light_yellow(int state) { return state == 2 || state == 5 || state == 8; } | ||
|
|
||
| int normalize_road_type(int type) { | ||
| if (is_road_lane(type)) { | ||
| return 0; | ||
| } else if (is_road_line(type)) { | ||
| return 1; | ||
| } else if (is_road_edge(type)) { | ||
| return 2; | ||
| } else { | ||
| return -1; | ||
| } | ||
| } |
There was a problem hiding this comment.
Functions defined in header will cause multiple definition errors when included in multiple .c files. These should be declared static inline or moved to a .c file
| void free_agent(struct Agent *agent) { | ||
| free(agent->log_trajectory_x); | ||
| free(agent->log_trajectory_y); | ||
| free(agent->log_trajectory_z); | ||
| free(agent->log_heading); | ||
| free(agent->log_velocity_x); | ||
| free(agent->log_velocity_y); | ||
| free(agent->log_length); | ||
| free(agent->log_width); | ||
| free(agent->log_height); | ||
| free(agent->log_valid); | ||
| free(agent->route); | ||
| free(agent->path); | ||
| } |
There was a problem hiding this comment.
free_agent frees agent->path but Path is a struct containing a static array, not a pointer. If path was allocated with malloc, this is correct, but the function should also free the path struct itself. If path points to a struct with nested dynamic allocations, those need to be freed first. Same issue applies to free_road_element and free_traffic_element
| #undef NONE | ||
| #undef VEHICLE | ||
| #undef PEDESTRIAN | ||
| #undef CYCLIST | ||
| #undef ROAD_LANE | ||
| #undef ROAD_LINE | ||
| #undef ROAD_EDGE | ||
| #undef STOP_SIGN | ||
| #undef CROSSWALK | ||
| #undef SPEED_BUMP | ||
| #undef DRIVEWAY |
There was a problem hiding this comment.
ROAD_LANE, ROAD_LINE, and ROAD_EDGE are undefined but don't exist in datatypes.h - only specific types like LANE_FREEWAY, ROAD_LINE_UNKNOWN, ROAD_EDGE_UNKNOWN are defined
This PR introduces the new datatypes.h file and the new datatypes that will eventually replace the Entity struct.
It also adds support for the declaration of the new macros in datatypes.h. This PR does not implement ANY new method, the working code remains as is.