本文整理汇总了C++中Polyline::reverse方法的典型用法代码示例。如果您正苦于以下问题:C++ Polyline::reverse方法的具体用法?C++ Polyline::reverse怎么用?C++ Polyline::reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline::reverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
Polyline
MotionPlannerGraph::shortest_path(size_t from, size_t to)
{
// this prevents a crash in case for some reason we got here with an empty adjacency list
if (this->adjacency_list.empty()) return Polyline();
const weight_t max_weight = std::numeric_limits<weight_t>::infinity();
std::vector<weight_t> dist;
std::vector<node_t> previous;
{
// number of nodes
size_t n = this->adjacency_list.size();
// initialize dist and previous
dist.clear();
dist.resize(n, max_weight);
dist[from] = 0; // distance from 'from' to itself
previous.clear();
previous.resize(n, -1);
// initialize the Q with all nodes
std::set<node_t> Q;
for (node_t i = 0; i < n; ++i) Q.insert(i);
while (!Q.empty())
{
// get node in Q having the minimum dist ('from' in the first loop)
node_t u;
{
double min_dist = -1;
for (std::set<node_t>::const_iterator n = Q.begin(); n != Q.end(); ++n) {
if (dist[*n] < min_dist || min_dist == -1) {
u = *n;
min_dist = dist[*n];
}
}
}
Q.erase(u);
// stop searching if we reached our destination
if (u == to) break;
// Visit each edge starting from node u
const std::vector<neighbor> &neighbors = this->adjacency_list[u];
for (std::vector<neighbor>::const_iterator neighbor_iter = neighbors.begin();
neighbor_iter != neighbors.end();
++neighbor_iter)
{
// neighbor node is v
node_t v = neighbor_iter->target;
// skip if we already visited this
if (Q.find(v) == Q.end()) continue;
// calculate total distance
weight_t alt = dist[u] + neighbor_iter->weight;
// if total distance through u is shorter than the previous
// distance (if any) between 'from' and 'v', replace it
if (alt < dist[v]) {
dist[v] = alt;
previous[v] = u;
}
}
}
}
Polyline polyline;
for (node_t vertex = to; vertex != -1; vertex = previous[vertex])
polyline.points.push_back(this->nodes[vertex]);
polyline.points.push_back(this->nodes[from]);
polyline.reverse();
return polyline;
}