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