32constexpr double kSegmentationEpsilon = 0.5;
46 stop_for_destination_ = stop_for_destination;
51 return waypoint.
lane &&
52 lane_segment.
lane->id().id() == waypoint.
lane->id().id() &&
53 lane_segment.
start_s - kSegmentationEpsilon <= waypoint.
s &&
54 lane_segment.
end_s + kSegmentationEpsilon >= waypoint.
s;
59 return lane_segment.
lane && lane_segment.
lane->id().id() == waypoint.
id() &&
60 lane_segment.
start_s - kSegmentationEpsilon <= waypoint.
s() &&
61 lane_segment.
end_s + kSegmentationEpsilon >= waypoint.
s();
66 return waypoint.
lane && lane_segment.
id() == waypoint.
lane->id().id() &&
67 lane_segment.
start_s() - kSegmentationEpsilon <= waypoint.
s &&
68 lane_segment.
end_s() + kSegmentationEpsilon >= waypoint.
s;
73 return lane_segment.
id() == waypoint.
id() &&
74 lane_segment.
start_s() - kSegmentationEpsilon <= waypoint.
s() &&
75 lane_segment.
end_s() + kSegmentationEpsilon >= waypoint.
s();
82 auto iter = other.begin();
86 begin()->start_s = std::min(begin()->start_s, iter->start_s);
87 begin()->end_s = std::max(begin()->end_s, iter->end_s);
88 insert(begin(), other.begin(), iter);
93 auto iter = other.rbegin();
97 back().start_s = std::min(back().start_s, iter->start_s);
98 back().end_s = std::max(back().end_s, iter->end_s);
99 insert(end(), iter.base(), other.end());
106 return route_end_waypoint_;
112 is_on_segment_ = on_segment;
118 is_neighbor_ = is_neighbor;
122 route_end_waypoint_ = waypoint;
126 return LaneWaypoint(front().lane, front().start_s, 0.0);
145 for (
const auto &seg : segments) {
154 return GetProjection({point_enu.
x(), point_enu.
y()}, sl_point, waypoint);
158 if (empty() || other.empty()) {
177 const double look_backward,
178 const double look_forward) {
185 return Shrink(sl_point.
s(), look_backward, look_forward);
189 const double look_forward) {
194 return Shrink(s, waypoint, look_backward, look_forward);
198 const double look_backward,
199 const double look_forward) {
202 while (iter != end() && acc_s + iter->Length() < s - look_backward) {
203 acc_s += iter->Length();
210 std::max(iter->start_s, s - look_backward - acc_s + iter->start_s);
211 if (iter->Length() < kSegmentationEpsilon) {
214 erase(begin(), iter);
224 acc_s = iter->end_s - waypoint.
s;
225 if (acc_s >= look_forward) {
226 iter->end_s = waypoint.
s + look_forward;
232 while (iter != end() && acc_s + iter->Length() < look_forward) {
233 acc_s += iter->Length();
239 iter->end_s = std::min(iter->end_s, look_forward - acc_s + iter->start_s);
240 erase(iter + 1, end());
245 double accumulated_s = 0.0;
246 bool has_projection =
false;
247 for (
auto iter = begin(); iter != end();
248 accumulated_s += (iter->end_s - iter->start_s), ++iter) {
249 if (accumulated_s - kSegmentationEpsilon < s &&
250 s < accumulated_s + iter->end_s - iter->start_s +
251 kSegmentationEpsilon) {
252 waypoint->
lane = iter->lane;
253 waypoint->
s = s - accumulated_s + iter->start_s;
254 if (waypoint->
s < iter->start_s) {
255 waypoint->
s = iter->start_s;
256 }
else if (waypoint->
s > iter->end_s) {
257 waypoint->
s = iter->end_s;
259 has_projection =
true;
263 return has_projection;
269 double min_l = std::numeric_limits<double>::infinity();
270 double accumulated_s = 0.0;
271 bool has_projection =
false;
272 for (
auto iter = begin(); iter != end();
273 accumulated_s += (iter->end_s - iter->start_s), ++iter) {
276 if (!iter->lane->GetProjection(point, &lane_s, &lane_l)) {
278 <<
" on lane " << iter->lane->id().id();
281 if (lane_s < iter->start_s - kSegmentationEpsilon ||
282 lane_s > iter->end_s + kSegmentationEpsilon) {
285 if (std::fabs(lane_l) < min_l) {
286 has_projection =
true;
287 lane_s = std::max(iter->start_s, lane_s);
288 lane_s = std::min(iter->end_s, lane_s);
289 min_l = std::fabs(lane_l);
290 sl_point->set_l(lane_l);
291 sl_point->set_s(lane_s - iter->start_s + accumulated_s);
292 waypoint->
lane = iter->lane;
293 waypoint->
s = lane_s;
296 return has_projection;
300 const double heading,
303 double min_l = std::numeric_limits<double>::infinity();
304 double accumulated_s = 0.0;
305 bool has_projection =
false;
306 for (
auto iter = begin(); iter != end();
307 accumulated_s += (iter->end_s - iter->start_s), ++iter) {
310 if (!iter->lane->GetProjection(point, heading, &lane_s, &lane_l)) {
312 <<
" on lane " << iter->lane->id().id();
315 if (lane_s < iter->start_s - kSegmentationEpsilon ||
316 lane_s > iter->end_s + kSegmentationEpsilon) {
319 if (std::fabs(lane_l) < min_l) {
320 has_projection =
true;
321 lane_s = std::max(iter->start_s, lane_s);
322 lane_s = std::min(iter->end_s, lane_s);
323 min_l = std::fabs(lane_l);
324 sl_point->set_l(lane_l);
325 sl_point->set_s(lane_s - iter->start_s + accumulated_s);
326 waypoint->
lane = iter->lane;
327 waypoint->
s = lane_s;
330 return has_projection;
334 previous_action_ = action;
338 return previous_action_;
342 next_action_ = action;
350 for (
auto iter = begin(); iter != end(); ++iter) {
359 auto point = waypoint.
lane->GetSmoothPoint(waypoint.
s);
369 bool has_projection =
GetProjection(point, &route_sl, &segment_waypoint);
370 if (!has_projection) {
374 static constexpr double kMaxLaneWidth = 10.0;
375 if (std::fabs(route_sl.
l()) > 2 * kMaxLaneWidth) {
380 double waypoint_heading = waypoint.
lane->Heading(waypoint.
s);
381 double segment_heading = segment_waypoint.
lane->Heading(segment_waypoint.
s);
382 double heading_diff =
384 if (std::fabs(heading_diff) > M_PI / 2) {
385 ADEBUG <<
"Angle diff too large:" << heading_diff;
390 double waypoint_left_width = 0.0;
391 double waypoint_right_width = 0.0;
392 waypoint.
lane->GetWidth(waypoint.
s, &waypoint_left_width,
393 &waypoint_right_width);
394 double segment_left_width = 0.0;
395 double segment_right_width = 0.0;
396 segment_waypoint.
lane->GetWidth(segment_waypoint.
s, &segment_left_width,
397 &segment_right_width);
398 auto segment_projected_point =
399 segment_waypoint.
lane->GetSmoothPoint(segment_waypoint.
s);
401 const double kLaneSeparationDistance = 0.3;
402 if (route_sl.
l() < 0) {
404 waypoint_left_width + segment_right_width + kLaneSeparationDistance) {
405 AERROR <<
"waypoint is too far to reach: " << dist;
410 waypoint_right_width + segment_left_width + kLaneSeparationDistance) {
411 AERROR <<
"waypoint is too far to reach: " << dist;
Implements a class of 2-dimensional vectors.
std::string DebugString() const
Returns a human-readable string representing this object
void SetId(const std::string &id)
bool StopForDestination() const
bool GetWaypoint(const double s, LaneWaypoint *waypoint) const
bool Stitch(const RouteSegments &other)
Stitch current route segments with the other route segment.
void SetStopForDestination(bool stop_for_destination)
bool Shrink(const common::math::Vec2d &point, const double look_backward, const double look_forward)
bool IsWaypointOnSegment(const LaneWaypoint &waypoint) const
Check if a waypoint is on segment
const std::string & Id() const
LaneWaypoint LastWaypoint() const
Get the last waypoint from the lane segments.
bool IsConnectedSegment(const RouteSegments &other) const
Check if we can reach the other segment from current segment just by following lane.
void SetIsNeighborSegment(bool is_neighbor)
void SetProperties(const RouteSegments &other)
Copy the properties of other segments to current one
LaneWaypoint FirstWaypoint() const
Get the first waypoint from the lane segments.
bool CanExit() const
Whether the passage region that generate this route segment can lead to another passage region in rou...
void SetRouteEndWaypoint(const LaneWaypoint &waypoint)
void SetIsOnSegment(bool on_segment)
static bool WithinLaneSegment(const LaneSegment &lane_segment, const LaneWaypoint &waypoint)
bool CanDriveFrom(const LaneWaypoint &waypoint) const
Check whether the map allows a vehicle can reach current RouteSegment from a point on a lane (LaneWay...
void SetPreviousAction(routing::ChangeLaneType action)
routing::ChangeLaneType PreviousAction() const
Get the previous change lane action need to take by the vehicle to reach current segment,...
static double Length(const RouteSegments &segments)
const LaneWaypoint & RouteEndWaypoint() const
routing::ChangeLaneType NextAction() const
Get the next change lane action need to take by the vehicle, if the vehicle is on this RouteSegments.
bool GetProjection(const common::PointENU &point_enu, common::SLPoint *sl_point, LaneWaypoint *waypoint) const
Project a point to this route segment.
void SetCanExit(bool can_exit)
bool IsNeighborSegment() const
void SetNextAction(routing::ChangeLaneType action)
double AngleDiff(const double from, const double to)
Calculate the difference between angle from and to
double DistanceXY(const U &u, const V &v)
calculate the distance beteween Point u and Point v, which are all have member function x() and y() i...
std::string DebugString() const