本文整理汇总了C++中Coord::invalidate方法的典型用法代码示例。如果您正苦于以下问题:C++ Coord::invalidate方法的具体用法?C++ Coord::invalidate怎么用?C++ Coord::invalidate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coord
的用法示例。
在下文中一共展示了Coord::invalidate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCenterOfOSMElement
bool getCenterOfOSMElement(const OSMElement &element, Coord &coord) {
coord.invalidate();
std::queue <OSMElement> queue;
std::set<uint64_t> nodeIds;
queue.push(element);
while (!queue.empty()) {
const OSMElement &cur = queue.front();
if (cur.type == OSMElement::Node)
nodeIds.insert(cur.id);
else if (cur.type == OSMElement::Way) {
WayNodes wn;
if (wayNodes->retrieve(cur.id, wn)) {
if (wn.num_nodes == 0)
Error::err("Got %s without nodes: %llu", cur.operator std::string().c_str(), cur.id);
else if (wn.num_nodes == 1) {
Error::warn("%s has only a single node: %llu", cur.operator std::string().c_str(), wn.nodes[0]);
nodeIds.insert(wn.nodes[0]); ///< Way's only node
} else { /** wn.num_nodes>=2 */
nodeIds.insert(wn.nodes[0]); ///< Way's first node
nodeIds.insert(wn.nodes[wn.num_nodes - 1]); ///< Way's last node
if (wn.num_nodes > 3) {
nodeIds.insert(wn.nodes[wn.num_nodes / 2]); ///< Way's middle node
if (wn.num_nodes > 6) {
nodeIds.insert(wn.nodes[wn.num_nodes / 4]); ///< Way's 1st quartile node
nodeIds.insert(wn.nodes[wn.num_nodes * 3 / 4]); ///< Way's 3st quartile node
if (wn.num_nodes > 12) {
nodeIds.insert(wn.nodes[wn.num_nodes / 8]);
nodeIds.insert(wn.nodes[wn.num_nodes * 3 / 8]);
nodeIds.insert(wn.nodes[wn.num_nodes * 5 / 8]);
nodeIds.insert(wn.nodes[wn.num_nodes * 7 / 8]);
}
}
}
}
}
} else if (cur.type == OSMElement::Relation) {
RelationMem rm;
if (relMembers->retrieve(cur.id, rm)) {
for (int i = rm.num_members - 1; i >= 0; --i)
queue.push(rm.members[i]);
}
}
queue.pop(); ///< remove front element that was just processed
}
if (nodeIds.empty()) return false; ///< no nodes referred to, nothing to do
int64_t sumX = 0, sumY = 0;
size_t count = 0;
for (const uint64_t nodeId : nodeIds) {
Coord c;
if (node2Coord->retrieve(nodeId, c)) {
sumX += c.x;
sumY += c.y;
++count;
}
}
if (count > 0) {
coord.x = sumX / count;
coord.y = sumY / count;
return true;
} else
return false;
}