#pragma once #include "link.h" #include #include #include #include #include #include #include #include #include class Texture; class Shader; class Ray; class Network { public: using LinkEnd = std::pair; explicit Network(const std::string & textureName); virtual ~Network() = default; [[nodiscard]] Node::Ptr findNodeAt(glm::vec3) const; [[nodiscard]] Node::Ptr nodeAt(glm::vec3); [[nodiscard]] std::pair newNodeAt(glm::vec3); [[nodiscard]] std::pair candidateNodeAt(glm::vec3) const; [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray &) const = 0; [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const; [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, glm::vec3) const; [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const; virtual Link::CPtr addStraight(glm::vec3, glm::vec3) = 0; virtual Link::CCollection addJoins(glm::vec3, glm::vec3) = 0; protected: static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol); using Nodes = std::set>; Nodes nodes; std::shared_ptr texture; }; template class NetworkOf : public Network, public Renderable { protected: using Network::Network; Collection links; void joinLinks(const Link::Ptr &) const; protected: [[nodiscard]] Link::Ptr intersectRayLinks(const Ray &) const override; public: template std::shared_ptr addLink(glm::vec3 a, glm::vec3 b, Params &&... params) requires std::is_base_of_v { const auto node1 = nodeAt(a), node2 = nodeAt(b); auto l {links.template create(node1, node2, std::forward(params)...)}; joinLinks(l); return l; } Link::CPtr addStraight(glm::vec3 n1, glm::vec3 n2) override; Link::CCollection addJoins(glm::vec3, glm::vec3) override; void render(const Shader &) const override; };