[][src]Struct pathfinder::Node

pub struct Node {
    pub hash: u64,
    pub geo: Coordinate,
    pub color: Rgba<u8>,
    pub radius: Option<u32>,
    // some fields omitted
}

A Location object that can be drawn on an image, along with set size and color.

Fields

hash: u64geo: Coordinatecolor: 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.

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);

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<P: Hash + Location>(&self, other: &P) -> 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.

The available HL can be retrieved through get_link_avail_index.

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]

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);

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);

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();

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]

Draws the node on an IW.

It is recommended to not use this directory. But instead use the Map struct, which uses this trait implementation.

impl Location for Node[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]

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<'a> PartialEq<Node> for Node[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Copy for Node[src]

impl From<Coordinate> for Node[src]

impl From<Group> for Node[src]

impl From<Node> for Group[src]

impl From<Node> for Coordinate[src]

impl Clone for 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

impl Send for Node

impl Unpin for Node

impl Sync for Node

impl UnwindSafe for Node

impl RefUnwindSafe for Node

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T[src]

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 
[src]

Sets value as a parameter of self.