本文整理汇总了C++中PathNode::Dist2方法的典型用法代码示例。如果您正苦于以下问题:C++ PathNode::Dist2方法的具体用法?C++ PathNode::Dist2怎么用?C++ PathNode::Dist2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode::Dist2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_paths_from_db
bool load_paths_from_db(MYSQL *m, Map *map, const char *zone, list<PathGraph*> &db_paths, list<PathNode*> &end_points) {
char query[512];
sprintf(query,
"SELECT x,y,z,gridid FROM grid_entries,zone "
"WHERE zone.zoneidnumber=zoneid AND short_name='%s' "
"ORDER BY gridid,number", zone);
if(mysql_query(m, query) != 0) {
printf("Unable to query: %s\n", mysql_error(m));
return(false);
}
MYSQL_RES *res = mysql_store_result(m);
if(res == NULL) {
printf("Unable to store res: %s\n", mysql_error(m));
return(false);
}
MYSQL_ROW row;
PathNode *cur = NULL, *last = NULL, *first = NULL;
PathGraph *g = NULL;
int cur_g = -1,last_g = -1;
// int lid = 0;
while((row = mysql_fetch_row(res))) {
last = cur;
cur = new PathNode;
// cur->load_id = lid++;
cur->x = atof(row[0]);
cur->y = atof(row[1]);
cur->z = atof(row[2]);
cur_g = atoi(row[3]);
if(cur_g != last_g) {
if(g != NULL) {
//if we have a first and last node for this path
//and they are not the same node, try to connect them.
if(first != NULL && last != NULL && first != last && last->Dist2(first) < ENDPOINT_CONNECT_MAX_DISTANCE*ENDPOINT_CONNECT_MAX_DISTANCE) {
if(CheckLOS(map, last, first))
g->add_edge(last, first);
}
#ifdef LINK_PATH_ENDPOINTS
if(first != last && last != NULL)
end_points.push_back(last);
#endif
db_paths.push_back(g);
}
g = new PathGraph();
first = cur;
last_g = cur_g;
last = NULL;
}
g->nodes.push_back(cur);
#ifdef LINK_PATH_ENDPOINTS
//this is a begining point
if(last == NULL)
end_points.push_back(cur);
#endif
if(last != NULL) {
#ifdef SPLIT_INVALID_PATHS
if(CheckLOS(map, last, cur)) {
g->edges.push_back(new PathEdge(last, cur));
} else {
//no LOS, split the path into two
load_split_paths++;
last_g = -1; //tell this thing to start over
}
#else
g->edges.push_back(new PathEdge(last, cur));
#endif
}
}
//handle the last active path
if(g != NULL) {
if(first != NULL && cur->Dist2(first) < ENDPOINT_CONNECT_MAX_DISTANCE*ENDPOINT_CONNECT_MAX_DISTANCE) {
if(CheckLOS(map, cur, first))
g->add_edge(cur, first);
}
db_paths.push_back(g);
}
mysql_free_result(res);
return(true);
}