diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cc5287..7d21df6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(graphs VERSION 0.1.7) +project(graphs VERSION 0.1.8) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/graph_base.h b/include/graph_base.h index 04853b5..7d74243 100644 --- a/include/graph_base.h +++ b/include/graph_base.h @@ -75,6 +75,8 @@ struct node_t struct edge_t { + // fuck you too :3 + friend selector_t; float ideal_spring_length = conf::DEFAULT_SPRING_LENGTH; float thickness = conf::DEFAULT_THICKNESS; blt::color4 color = conf::EDGE_COLOR; diff --git a/src/loader.cpp b/src/loader.cpp index 6ef664c..053c7a4 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -98,7 +98,7 @@ std::optional loader_t::load_for(engine_t& engine, const blt::gfx::win auto ideal_length = load_with_default(edge, "length", conf::DEFAULT_SPRING_LENGTH); auto thickness = load_with_default(edge, "thickness", conf::DEFAULT_THICKNESS); - ::edge_t e{graph.names_to_node[index1], graph.names_to_node[index2]}; + edge_t e{graph.names_to_node[index1], graph.names_to_node[index2]}; e.ideal_spring_length = ideal_length; e.thickness = thickness; diff --git a/src/selector.cpp b/src/selector.cpp index c02396e..9e802d6 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -192,13 +192,45 @@ void selector_t::destroy_node(blt::i64 node) { auto& node_v = graph.nodes[node]; graph.names_to_node.erase(node_v.name); - erase_if(graph.edges, [node](const edge_t& v) { - return static_cast(v.getFirst()) == node || static_cast(v.getSecond()) == node; + erase_if(graph.edges, [node](const edge_t& e) { + return static_cast(e.getFirst()) == node || static_cast(e.getSecond()) == node; }); + std::vector corrected_edges; + for (const edge_t& v : graph.edges) + { + auto copy = v; + auto c = static_cast(node); + if (copy.i1 > c) + copy.i1--; + if (copy.i2 > c) + copy.i2--; + if (v.i1 > c || v.i2 > c) + corrected_edges.push_back(copy); + } + erase_if(graph.edges, [node](const edge_t& e) { + return static_cast(e.getFirst()) > node || static_cast(e.getSecond()) > node; + }); + for (const auto& v : corrected_edges) + graph.edges.insert(v); graph.connected_nodes.erase(node); for (auto& v : graph.connected_nodes) { - v.second.erase(node); + auto& map = v.second; + // generate the list of corrected nodes. + std::vector corrected_nodes; + for (auto& n : map) + { + // shift back then nodes after this one by one + if (static_cast(n) > node) + { + corrected_nodes.push_back(n - 1); + } + } + erase_if(map, [node](blt::u64 n) { + return static_cast(n) > node; + }); + for (const auto& n : corrected_nodes) + map.insert(n); } graph.nodes.erase(graph.nodes.begin() + node);