pub struct Node {
pub hash: u64,
pub geo: Coordinate,
pub color: Rgba<u8>,
pub radius: Option<u32>,
/* private fields */
}
Expand description
A Location object that can be drawn on an image, along with set size and color.
Fields§
§hash: u64
§geo: Coordinate
§color: Rgba<u8>
§radius: Option<u32>
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(name: &str, geo: Coordinate) -> Self
pub fn new(name: &str, geo: Coordinate) -> Self
Constructs a Node struct.
The name is converted from a &str to a hash.
Sourcepub fn from_file(path: &str) -> Result<Vec<Self>, Error>
pub fn from_file(path: &str) -> Result<Vec<Self>, Error>
Retrive coordinate from a csv format.
§Examples
Example file format:
100,20
40,60
30,30
Would be equivalent to the following.
let list = [(100, 20), (40, 60), (30, 30)];
let nodes = Node::from_list(&list);
assert_eq!(nodes.len(), 3);
Sourcepub fn center(&self) -> Coordinate
pub fn center(&self) -> Coordinate
Gets the center position of the node accounting for size.
Sourcepub fn from_list(list: &[(i16, i16)]) -> Vec<Self>
pub fn from_list(list: &[(i16, i16)]) -> Vec<Self>
Converts a list of tuples (x,y) to a Vector of Nodes.
Names are assigned from “A” and upwards automatically.
§Examples
Create three nodes from a list.
let list = [(0, 0), (10, 10), (15, 15)];
let nodes = Node::from_list(&list);
assert_eq!(nodes.len(), 3);
Returns an empty array if given an empty list.
let nodes = Node::from_list(&[]);
assert_eq!(nodes.len(), 0);
Sourcepub fn is_directly_connected<P: Hash + Location>(&self, other: &P) -> bool
pub fn is_directly_connected<P: Hash + Location>(&self, other: &P) -> bool
Looks through all connected Nodes and returns if they are connected.
Sourcepub fn linked_list(list: Vec<Node>) -> Vec<Self>
pub fn linked_list(list: Vec<Node>) -> Vec<Self>
Links a list of nodes together in the order they are indexed.
A list of A, B, C. Will result in them being linked as: A -> B -> C.
§Examples
let nodes = Node::from_list(&[(0, 0), (20, 20)]);
let linked_list = Node::linked_list(nodes);
Sourcepub fn hl(&self, index: usize) -> Result<&HL>
pub fn hl(&self, index: usize) -> Result<&HL>
Returns a specific link if it exists. Returns none if not.
§Examples
If the Node has not been linked.
let node = node!();
let hl = node.hl(0);
assert!(hl.is_err());
Linking Nodes makes us able to interface with Edges.
let a = node!("A", 0, 0);
let mut b = node!("B", 50, 50);
b.link(&a);
assert!(b.hl(0).is_ok());
§Errors
If the index is larger than the available HL.
The available HL can be retrieved through get_link_avail_index.
You can only retrieve HL which are connected to other nodes.
Sourcepub fn hl_mut(&mut self, index: usize) -> Result<&mut HL>
pub fn hl_mut(&mut self, index: usize) -> Result<&mut HL>
Returns a mutable reference to a HL.
§Examples
A mutable variant is required when setting Edge styles.
let mut a = node!("A", 0, 0);
let mut b = node!("B", 50, 50);
b.link(&a);
b.hl_mut(0)?.style(EdgeStyle::Straight);
a.link(&b);
a.hl_mut(0)?.style(EdgeStyle::Ellipse);
Ok(())
§Errors
If the index is larger than the available HL.
You can only retrieve HL which are connected to other nodes.
Sourcepub fn linked_list_predicate(
list: Vec<Node>,
f: &dyn Fn(Coordinate, Coordinate) -> bool,
) -> Vec<Self>
pub fn linked_list_predicate( list: Vec<Node>, f: &dyn Fn(Coordinate, Coordinate) -> bool, ) -> Vec<Self>
Links a list of nodes together in the order they are indexed.
A list of A, B, C. Will result in them being linked as: A -> B -> C.
§Examples
The two following are the same.
let nodes = Node::from_list(&[(0, 0), (20, 20)]);
let linked_list = Node::linked_list(nodes);
let nodes = Node::from_list(&[(0, 0), (20, 20)]);
let linked_list = Node::linked_list_predicate(nodes, &|_, _| true);
Will link the items with the same x value.
let predicate = &|c1, c2| c1 > c2;
let linked_list = Node::linked_list_predicate(nodes, predicate);
Sourcepub fn get_link_avail_index(&self) -> usize
pub fn get_link_avail_index(&self) -> usize
Returns the next point which is available to link.
It is a good practice to call this method before attempting to call hl or hl_mut to having to error handle.
§Examples
Connects two nodes.
let a = node!("A", 0, 0);
let mut b = node!("B", 50, 50);
assert_eq!(b.get_link_avail_index(), 0);
b.link(&a);
assert_eq!(b.get_link_avail_index(), 1);
Disconnecting decreases the number back to 0.
b.disconnect();
assert_eq!(b.get_link_avail_index(), 0);
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Removes all connects leaving this node. This still leaves connections going towards this node.
§Examples
Connects two nodes and then disconnects it.
let a = node!(0, 0);
let mut b = node!(50, 50);
b.link(&a);
assert!(b.hl(0).is_ok());
b.disconnect();
assert!(b.hl(0).is_err());
A node does not need to be connected, before attempted to disconnect it.
let mut a = node!(0, 0);
a.disconnect();
Sourcepub fn link<P: Hash + Location>(&mut self, other: &P)
pub fn link<P: Hash + Location>(&mut self, other: &P)
Links Node self to another point that has Hash and Location implemented.
§Examples
Connects two nodes, and verifies that they are connected.
let b = node!();
let mut a = node!();
a.link(&b);
assert!(a.is_directly_connected(&b));
Connects a node with a group.
let b = cluster!();
let mut a = node!();
a.link(&b);