//! Cross-links: lines between any two nodes, besides the branches of the //! tree. use super::ids::NodeId; use super::look::LineLook; use super::text::Label; /// Identifies the link between two nodes. Two nodes have at most one link /// between them, whichever way it points, so the key is just the pair (the /// smaller id first). #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct LinkKey { low: NodeId, high: NodeId, } impl LinkKey { /// The key for the link between `a` and `b`, or `None` when they're the /// same node (a node can't link to itself). pub fn new(a: NodeId, b: NodeId) -> Option { if a == b { return None; } Some(LinkKey { low: a.min(b), high: a.max(b) }) } /// Both nodes, the smaller id first. pub fn nodes(self) -> (NodeId, NodeId) { (self.low, self.high) } /// Whether `node` is one of the two ends. pub fn touches(self, node: NodeId) -> bool { self.low == node || self.high == node } } /// A cross-link between two nodes. It points from its start to its end, which /// only matters for where the arrowheads go. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Link { key: LinkKey, /// True when the link points from the higher id to the lower one. downward: bool, /// Text shown in the middle of the line. pub label: Option