silly connection of edges
parent
780c8ac25a
commit
e164a1537c
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(graphs VERSION 0.1.8)
|
||||
project(graphs VERSION 0.1.9)
|
||||
|
||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||
|
|
|
@ -46,7 +46,9 @@ struct bounding_box
|
|||
class graph_t
|
||||
{
|
||||
friend struct loader_t;
|
||||
|
||||
friend class selector_t;
|
||||
|
||||
private:
|
||||
std::vector<node_t> nodes;
|
||||
blt::hashmap_t<std::string, blt::u64> names_to_node;
|
||||
|
@ -60,7 +62,7 @@ class graph_t
|
|||
int current_iterations = 0;
|
||||
int max_iterations = 5000;
|
||||
std::unique_ptr<force_equation> equation;
|
||||
|
||||
|
||||
void create_random_graph(bounding_box bb, blt::size_t min_nodes, blt::size_t max_nodes, blt::f64 connectivity,
|
||||
blt::f64 scaling_connectivity, blt::f64 distance_factor);
|
||||
|
||||
|
@ -100,6 +102,18 @@ class graph_t
|
|||
edges.insert({n1, n2});
|
||||
}
|
||||
|
||||
void disconnect(const blt::u64 n1, const blt::u64 n2)
|
||||
{
|
||||
connected_nodes[n1].erase(n2);
|
||||
connected_nodes[n2].erase(n1);
|
||||
edges.erase({n1, n2});
|
||||
}
|
||||
|
||||
bool is_connected(const blt::u64 n1, const blt::u64 n2)
|
||||
{
|
||||
return edges.contains({n1, n2});
|
||||
}
|
||||
|
||||
void connect(const edge_t& edge)
|
||||
{
|
||||
connected_nodes[edge.getFirst()].insert(edge.getSecond());
|
||||
|
@ -188,7 +202,7 @@ class engine_t
|
|||
friend struct loader_t;
|
||||
private:
|
||||
graph_t graph;
|
||||
selector_t selector {graph};
|
||||
selector_t selector{graph};
|
||||
|
||||
void draw_gui(const blt::gfx::window_data& data);
|
||||
|
||||
|
|
|
@ -115,10 +115,19 @@ void selector_t::process_keyboard(blt::i32 width, blt::i32 height)
|
|||
{
|
||||
if (blt::gfx::isKeyPressed(GLFW_KEY_C))
|
||||
{
|
||||
if (placement)
|
||||
destroy_node(primary_selection);
|
||||
else
|
||||
create_placement_node(mouse_pos);
|
||||
if (primary_selection != -1 && secondary_selection != -1)
|
||||
{
|
||||
if (graph.is_connected(primary_selection, secondary_selection))
|
||||
graph.disconnect(primary_selection, secondary_selection);
|
||||
else
|
||||
graph.connect(primary_selection, secondary_selection);
|
||||
} else
|
||||
{
|
||||
if (placement)
|
||||
destroy_node(primary_selection);
|
||||
else
|
||||
create_placement_node(mouse_pos);
|
||||
}
|
||||
} else if (blt::gfx::isKeyPressed(GLFW_KEY_X))
|
||||
{
|
||||
if (primary_selection != -1)
|
||||
|
|
Loading…
Reference in New Issue