1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::Node;
use glam::Vec3;
use petgraph::{graph::NodeIndex, stable_graph::StableGraph, EdgeType, Undirected};
pub type ForceGraph<N, E, Ty = Undirected> = StableGraph<Node<N>, E, Ty>;
pub trait ForceGraphHelper<N, E, Ty> {
fn add_force_node(&mut self, name: impl AsRef<str>, data: N) -> NodeIndex;
fn add_force_node_with_coords(
&mut self,
name: impl AsRef<str>,
data: N,
location: Vec3,
) -> NodeIndex;
}
impl<N, E, Ty: EdgeType> ForceGraphHelper<N, E, Ty> for ForceGraph<N, E, Ty> {
fn add_force_node(&mut self, name: impl AsRef<str>, data: N) -> NodeIndex {
self.add_node(Node::new(name, data))
}
fn add_force_node_with_coords(
&mut self,
name: impl AsRef<str>,
data: N,
location: Vec3,
) -> NodeIndex {
self.add_node(Node::new_with_coords(name, data, location))
}
}