From 738d970d26794db8bb3dcf459c4a787b624910ba Mon Sep 17 00:00:00 2001 From: art0007i Date: Tue, 24 Sep 2024 15:11:32 +0200 Subject: make paintings 1 directional and add "arrows" the "arrows" are circles because I couldn't figure out how to use the DrawPolygon function... --- src/network_set.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/network_set.cpp') diff --git a/src/network_set.cpp b/src/network_set.cpp index 2a9e12c..c7639ad 100644 --- a/src/network_set.cpp +++ b/src/network_set.cpp @@ -4,9 +4,8 @@ void NetworkSet::Clear() { network_by_item_.clear(); } -void NetworkSet::AddLink(int id1, int id2) { - if (id2 > id1) { - // Make sure id1 < id2 +void NetworkSet::AddLink(int id1, int id2, bool two_way) { + if (two_way && id2 > id1) { std::swap(id1, id2); } @@ -17,13 +16,14 @@ void NetworkSet::AddLink(int id1, int id2) { network_by_item_[id2] = {}; } - network_by_item_[id1].insert({id1, id2}); - network_by_item_[id2].insert({id1, id2}); + NetworkNode node = {id1, id2, two_way}; + + network_by_item_[id1].insert(node); + network_by_item_[id2].insert(node); } -void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2) { - if (id2 > id1) { - // Make sure id1 < id2 +void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2, bool two_way) { + if (two_way && id2 > id1) { std::swap(id1, id2); } @@ -31,13 +31,22 @@ void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2) { network_by_item_[network_id] = {}; } - network_by_item_[network_id].insert({id1, id2}); + NetworkNode node = {id1, id2, two_way}; + + network_by_item_[network_id].insert(node); } bool NetworkSet::IsItemInNetwork(int id) const { return network_by_item_.count(id); } -const std::set>& NetworkSet::GetNetworkGraph(int id) const { +const std::set& NetworkSet::GetNetworkGraph(int id) const { return network_by_item_.at(id); } + +bool NetworkNode::operator<(const NetworkNode& rhs) const { + if (entry != rhs.entry) return entry < rhs.entry; + if (exit != rhs.exit) return exit < rhs.exit; + if (two_way != rhs.two_way) return two_way < rhs.two_way; + return false; +} \ No newline at end of file -- cgit 1.4.1