Struct Node

Source
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

Source

pub fn new(name: &str, geo: Coordinate) -> Self

Constructs a Node struct.

The name is converted from a &str to a hash.

Source

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

pub fn center(&self) -> Coordinate

Gets the center position of the node accounting for size.

Source

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

pub fn is_directly_connected<P: Hash + Location>(&self, other: &P) -> bool

Looks through all connected Nodes and returns if they are connected.

Source

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

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.

Source

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.

Source

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

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

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

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§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Draw for Node

Source§

fn draw(&self, image: IW, offset: Coordinate, shape: &Shape) -> IW

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.

Source§

fn size(&self) -> u32

Source§

impl Find for Node

Source§

fn find<H: Hash>(&self, hash: H) -> Option<Coordinate>

Matches the Hashes and returns Some if it matches.
Source§

impl From<Coordinate> for Node

Source§

fn from(c: Coordinate) -> Self

Converts to this type from the input type.
Source§

impl From<Group> for Node

Source§

fn from(group: Group) -> Self

Converts to this type from the input type.
Source§

impl From<Node> for Coordinate

Source§

fn from(node: Node) -> Self

Converts to this type from the input type.
Source§

impl From<Node> for Group

Source§

fn from(node: Node) -> Self

Converts to this type from the input type.
Source§

impl Hash for Node

Source§

fn hash(&self) -> u64

Source§

impl Location for Node

Source§

fn position(&self) -> Coordinate

Retrieves the position Coordinates.
Source§

fn eq<L: Location>(&self, other: &L) -> bool

Returns if the positions are equal or not.
Source§

fn x(&self) -> i16

Retrieves the X coordinate.
Source§

fn y(&self) -> i16

Retrieves the Y coordinate.
Source§

fn sum(&self) -> i16

Returns the sum of the x and y value.
Source§

impl MinMax for Node

Source§

impl<'a> PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SetParameter for T

Source§

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

Sets value as a parameter of self.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.