#include "network.h" #include #include #include template void NetworkOf::joinLinks(const Link::Ptr & link) const { for (const auto & oldLink : links) { Network::joinLinks(link, oldLink); } } template Link::Ptr NetworkOf::intersectRayLinks(const Ray & ray) const { // Click link if (const auto link = std::find_if(links.begin(), links.end(), [&ray](const std::shared_ptr & link) { return link->intersectRay(ray); }); link != links.end()) { return *link; } return {}; } template float NetworkOf::findNodeDirection(Node::AnyCPtr n) const { for (const auto & link : links) { for (const auto & end : link->ends) { // cppcheck-suppress useStlAlgorithm if (end.node.get() == n.get()) { return end.dir; } } } throw std::runtime_error("Node exists but couldn't find it"); } template Link::Ptr NetworkOf::create(const GenStraightDef & def) { return std::make_shared( *this, candidateNodeAt(std::get<0>(def)).first, candidateNodeAt(std::get<1>(def)).first); } template Link::Ptr NetworkOf::create(const GenCurveDef & def) { return std::make_shared( *this, candidateNodeAt(std::get<0>(def)).first, candidateNodeAt(std::get<1>(def)).first, std::get<2>(def)); } template bool NetworkOf::anyLinks() const { return !(static_cast *>(this)->vertices.empty() && ...); } template void NetworkOf::add(GeoData * geoData, const Link::Ptr & link) { const auto addIf = [this](auto && lptr) { if (lptr) { links.emplace(lptr); return true; } return false; }; for (auto & end : link->ends) { end.node = nodeAt(end.node->pos); } if (!(addIf(std::dynamic_pointer_cast(link)) || ...)) { throw std::logic_error("Unsupported link type for network"); } joinLinks(link); if (geoData) { geoData->setHeights(link->getBase(getBaseWidth()), GeoData::SetHeightsOpts {.surface = getBaseSurface()}); } }