[−][src]Struct pathfinder::Node
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>
Methods
impl Node
[src]
pub fn new(name: &str, geo: Coordinate) -> Self
[src]
Constructs a Node struct.
The name is converted from a &str to a hash.
pub fn from_file(path: &str) -> Result<Vec<Self>, Error>
[src]
Retrive coordinate from a csv format.
pub fn center(&self) -> Coordinate
[src]
Gets the center position of the node accounting for size.
pub fn from_list(list: &[(i16, i16)]) -> Vec<Self>
[src]
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);
pub fn is_directly_connected(&self, other: &Node) -> bool
[src]
Looks through all connected Nodes and returns if they are connected.
pub fn linked_list(list: Vec<Node>) -> Vec<Self>
[src]
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);
pub fn hl(&self, index: usize) -> Result<&HL>
[src]
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.
You can only retrieve HL which are connected to other nodes.
pub fn hl_mut(&mut self, index: usize) -> Result<&mut HL>
[src]
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.
pub fn linked_list_predicate(
list: Vec<Node>,
f: &dyn Fn(Coordinate, Coordinate) -> bool
) -> Vec<Self>
[src]
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
let nodes = Node::from_list(&[(0, 0), (20, 20)]); let linked_list = Node::linked_list(nodes);
pub fn get_link_avail_index(&self) -> usize
[src]
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
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);
pub fn disconnect(&mut self)
[src]
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();
pub fn link<P: Hash + Location>(&mut self, other: &P)
[src]
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);
Trait Implementations
impl Draw for Node
[src]
fn draw(&self, image: IW, offset: Coordinate, shape: &Shape) -> IW
[src]
fn size(&self) -> u32
[src]
fn links(&self) -> &[HL]
[src]
impl Location for Node
[src]
fn position(&self) -> Coordinate
[src]
fn eq<L: Location>(&self, other: &L) -> bool
[src]
Returns if the positions are equal or not.
fn x(&self) -> i16
[src]
Retrieves the X coordinate.
fn y(&self) -> i16
[src]
Retrieves the Y coordinate.
fn sum(&self) -> i16
[src]
Returns the sum of the x and y value.
impl MinMax for Node
[src]
fn min_max(&self) -> (Coordinate, Coordinate)
[src]
impl Find for Node
[src]
fn find<H: Hash>(&self, hash: H) -> Option<Coordinate>
[src]
Matches the Hashes and returns Some if it matches.
impl Hash for Node
[src]
impl From<Coordinate> for Node
[src]
fn from(c: Coordinate) -> Self
[src]
impl From<Group> for Node
[src]
impl From<Node> for Group
[src]
impl From<Node> for Coordinate
[src]
impl<'a> PartialEq<Node> for Node
[src]
fn eq(&self, other: &Node) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Copy for Node
[src]
impl Clone for Node
[src]
fn clone(&self) -> Node
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Node
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.