[−][src]Struct pathtracer::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.
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]
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);
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
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();
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 Clone for Node
[src]
impl Copy for Node
[src]
impl Debug for Node
[src]
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.
fn size(&self) -> u32
[src]
fn links(&self) -> &[HL]
[src]
impl Find for Node
[src]
fn find<H: Hash>(&self, hash: H) -> Option<Coordinate>
[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 Hash for Node
[src]
impl Location for Node
[src]
fn position(&self) -> Coordinate
[src]
fn eq<L: Location>(&self, other: &L) -> bool
[src]
fn x(&self) -> i16
[src]
fn y(&self) -> i16
[src]
fn sum(&self) -> i16
[src]
impl MinMax for Node
[src]
fn min_max(&self) -> (Coordinate, Coordinate)
[src]
impl<'a> PartialEq<Node> for Node
[src]
Auto Trait Implementations
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnwindSafe for Node
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,