Fix: calculate distance to next lane and intersection using NPC route instead of 3D distance #373
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.
Description
The Random Traffic calculated the distance to the closest traffic light lane in 3D space. The distance did not take the NPC route into account. This can cause situations where NPC stops moving along a lane, since currently it passes a TrafficLight, that it will reach in the future on its route. (Internal evidence 1, Internal evidence 2)
The PR solves Internal issue 1 and Internal issue 2
Details
The PR introduces:
FollowingLanes
inNPCVehicleInternalState
TrafficLightLane
andFollowingLanes
inNPCVehicleInternalState
Part of the implementation is extracted to
RandomTrafficUtils
for better code reusage in the future.The currently implemented
SignedDistanceToPointOnLane
was left intact for the following situations:TargetPoint
andCurrentWaypoint
(green arrow on the image below). As I checked both attributes reference the closest waypoint on a TrafficLane. Calculating the distance in this manner is robust, performing and calculates the distance between the actual position of an NPC and the next waypoint, making it a good solution as is.FollowingLanes
since when NPC enters new lane, the lane gets deleted from the list. In this scenario we do not have access to the previous lanes. Even if we had this would increase computation time to analyze previous lanes and would add significant overhead to the calculation processDistanceToTargetPoint
andDistanceToCurrentWaypoint
) - calculating distance projected on TrafficLane could require much computation time for a small benefit of calculation accuracy