fdg icon indicating copy to clipboard operation
fdg copied to clipboard

Undirected graphs not supported?

Open samuller opened this issue 10 months ago • 1 comments

I get the following compiler error when trying to use fdg::init_force_graph_uniform with a graph defined as StableGraph<(), (), Undirected>:

18 |     let mut force_graph: fdg::ForceGraph<f32, 3,(), ()> = fdg::init_force_graph_uniform(graph, 10.0);
   |                                                           ----------------------------- ^^^^^ the trait `From<StableGraph<(), (), Undirected>>` is not implemented for `StableGraph<_, _>`, which is required by `StableGraph<(), (), Undirected>: Into<StableGraph<_, _>>`
   |                                                           |
   |                                                           required by a bound introduced by this call

Here's example code that reproduces the issue:

use fdg::{petgraph::{prelude::{StableGraph, StableUnGraph}, Undirected}, Force};

fn main() {
    let mut graph: StableGraph<(), (), Undirected> = StableGraph::default();
    // let mut graph: StableUnGraph<(), ()> = StableGraph::default();
    // Add nodes to the graph
    let mut nodes = Vec::new();
    nodes.push(graph.add_node(()));
    nodes.push(graph.add_node(()));
    nodes.push(graph.add_node(()));
    nodes.push(graph.add_node(()));
    // Add edges
    graph.add_edge(nodes[0], nodes[1], ());
    graph.add_edge(nodes[1], nodes[2], ());
    graph.add_edge(nodes[2], nodes[3], ());
    println!("{:?}", graph);

    let mut force_graph: fdg::ForceGraph<f32, 3,(), ()> = fdg::init_force_graph_uniform(graph, 10.0);
    fdg::simple::Center::default().apply(&mut force_graph);
}

I'm currently using v1.0.0, i.e. my Cargo.toml contains this:

[dependencies]
fdg = { git = "https://github.com/grantshandy/fdg", version = "1.0.0" }

Are undirected graphs supposed to be supported, or is the algo somehow limited to directed graphs?

BTW, thanks for the awesome library.

samuller avatar Feb 18 '25 15:02 samuller