#include "network.h" #include #include template void NetworkOf::joinLinks(const Link::Ptr & l) const { for (const auto & ol : links.objects) { Network::joinLinks(l, ol); } } template Link::Ptr NetworkOf::intersectRayLinks(const Ray & ray) const { // Click link if (const auto link = std::find_if(links.objects.begin(), links.objects.end(), [&ray](const std::shared_ptr & link) { return link->intersectRay(ray); }); link != links.objects.end()) { return *link; } return {}; } template float NetworkOf::findNodeDirection(Node::AnyCPtr n) const { for (const auto & l : links.objects) { for (const auto & e : l->ends) { // cppcheck-suppress useStlAlgorithm if (e.node.get() == n.get()) { return e.dir; } } } throw std::runtime_error("Node exists but couldn't find it"); } template Link::CCollection NetworkOf::candidateStraight(GlobalPosition3D n1, GlobalPosition3D n2) { return {candidateLink(n1, n2)}; } template Link::CCollection NetworkOf::candidateJoins(GlobalPosition3D start, GlobalPosition3D end) { if (glm::length(RelativePosition3D(start - end)) < 2000.F) { return {}; } const auto defs = genCurveDef( start, end, findNodeDirection(candidateNodeAt(start).first), findNodeDirection(candidateNodeAt(end).first)); const auto & [c1s, c1e, c1c] = defs.first; const auto & [c2s, c2e, c2c] = defs.second; return {candidateLink(c1s, c1e, c1c), candidateLink(c2s, c2e, c2c)}; } template Link::CCollection NetworkOf::candidateExtend(GlobalPosition3D start, GlobalPosition3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first)); return {candidateLink(cstart, cend, centre)}; } template Link::CCollection NetworkOf::addStraight(GlobalPosition3D n1, GlobalPosition3D n2) { return {addLink(n1, n2)}; } template Link::CCollection NetworkOf::addJoins(GlobalPosition3D start, GlobalPosition3D end) { if (glm::length(RelativePosition3D(start - end)) < 2000.F) { return {}; } const auto defs = genCurveDef(start, end, findNodeDirection(nodeAt(start)), findNodeDirection(nodeAt(end))); const auto & [c1s, c1e, c1c] = defs.first; const auto & [c2s, c2e, c2c] = defs.second; return {addLink(c1s, c1e, c1c), addLink(c2s, c2e, c2c)}; } template Link::CCollection NetworkOf::addExtend(GlobalPosition3D start, GlobalPosition3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start))); return {addLink(cstart, cend, centre)}; }