12 namespace traffic_manager {
19 cg::Vector3D next_vector = target_location - reference_location;
21 const float cross_z = heading_vector.
x * next_vector.
y - heading_vector.
y * next_vector.
x;
28 cg::Vector3D next_vector = target_location - reference_location;
31 cg::Vector3D heading_vector_flat(heading_vector.
x, heading_vector.
y, 0);
33 float dot_product =
cg::Math::Dot(next_vector, heading_vector_flat);
34 dot_product = std::max(0.0f,
std::min(dot_product, 1.0f));
41 const uint64_t waypoint_id = waypoint->GetId();
42 buffer.push_back(waypoint);
47 Buffer &buffer,
bool front_or_back) {
49 SimpleWaypointPtr removed_waypoint = front_or_back ? buffer.front() : buffer.back();
50 const uint64_t removed_waypoint_id = removed_waypoint->GetId();
63 uint64_t startPosn =
static_cast<uint64_t
>(std::fabs(target_point_distance *
INV_MAP_RESOLUTION));
64 uint64_t index = startPosn;
67 if (startPosn < waypoint_buffer.size()) {
68 bool mScanForward =
false;
69 const float target_point_dist_power = target_point_distance * target_point_distance;
70 if (buffer_front->DistanceSquared(target_waypoint) < target_point_dist_power) {
75 for (uint64_t i = startPosn;
76 (i < waypoint_buffer.size()) && (buffer_front->DistanceSquared(target_waypoint) < target_point_dist_power);
78 target_waypoint = waypoint_buffer.at(i);
82 for (uint64_t i = startPosn;
83 (buffer_front->DistanceSquared(target_waypoint) > target_point_dist_power);
85 target_waypoint = waypoint_buffer.at(i);
90 target_waypoint = waypoint_buffer.back();
91 index = waypoint_buffer.size() - 1;
93 return std::make_pair(target_waypoint, index);
TargetWPInfo GetTargetWaypoint(const Buffer &waypoint_buffer, const float &target_point_distance)
static const float EPSILON
void PopWaypoint(ActorId actor_id, TrackTraffic &track_traffic, Buffer &buffer, bool front_or_back)
float DeviationDotProduct(const cg::Location &reference_location, const cg::Vector3D &heading_vector, const cg::Location &target_location)
Returns the dot product between the vehicle's heading vector and the vector along the direction to th...
void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
Methods to update, remove and retrieve vehicles passing through a waypoint.
This file contains definitions of common data structures used in traffic manager. ...
void PushWaypoint(ActorId actor_id, TrackTraffic &track_traffic, Buffer &buffer, SimpleWaypointPtr &waypoint)
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
double min(double v1, double v2)
float DeviationCrossProduct(const cg::Location &reference_location, const cg::Vector3D &heading_vector, const cg::Location &target_location)
Returns the cross product (z component value) between the vehicle's heading vector and the vector alo...
static auto Dot(const Vector3D &a, const Vector3D &b)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
std::pair< SimpleWaypointPtr, uint64_t > TargetWPInfo
Method to return the wayPoints from the waypoint Buffer by using target point distance.
static const float INV_MAP_RESOLUTION
Vector3D MakeSafeUnitVector(const float epsilon) const
static constexpr double EPSILON
We use this epsilon to shift the waypoints away from the edges of the lane sections to avoid floating...