12namespace 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);
void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
Methods to update, remove and retrieve vehicles passing through a waypoint.
void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
static const float EPSILON
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
void PopWaypoint(ActorId actor_id, TrackTraffic &track_traffic, Buffer &buffer, bool front_or_back)
std::pair< SimpleWaypointPtr, uint64_t > TargetWPInfo
Method to return the wayPoints from the waypoint Buffer by using target point distance.
void PushWaypoint(ActorId actor_id, TrackTraffic &track_traffic, Buffer &buffer, SimpleWaypointPtr &waypoint)
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...
TargetWPInfo GetTargetWaypoint(const Buffer &waypoint_buffer, const float &target_point_distance)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
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...
This file contains definitions of common data structures used in traffic manager.
Vector3D MakeUnitVector(const float epsilon=2.0f *std::numeric_limits< float >::epsilon()) const
Return a unit-length copy of this vector.