edge_by_screen_pos panics if you are clicking and holding a node while extending the graph.
Seems to be because self.g.edge_endpoints(e.id()) returns None.
The following seems to work as a fix, but not sure if this is a bigger bug.
pub fn edge_by_screen_pos(&self, meta: &Metadata, screen_pos: Pos2) -> Option<EdgeIndex<Ix>> {
let pos_in_graph = meta.screen_to_canvas_pos(screen_pos);
for (idx, e) in self.edges_iter() {
let (idx_start, idx_end) = match self.g.edge_endpoints(e.id()) {
Some((start, end)) => (start, end),
None => continue,
};
let start = self.g.node_weight(idx_start).unwrap();
let end = self.g.node_weight(idx_end).unwrap();
if e.display().is_inside(start, end, pos_in_graph) {
return Some(idx);
}
}
None
}
edge_by_screen_pos
panics if you are clicking and holding a node while extending the graph. Seems to be becauseself.g.edge_endpoints(e.id())
returns None.The following seems to work as a fix, but not sure if this is a bigger bug.