[][src]Struct pathtracer::Group

pub struct Group {
    pub nodes: Vec<Node>,
    // some fields omitted
}

Holds a set of nodes and applies properties to all child nodes when drawn.

The group itself has no displayed output and is not visible.

It contains a Node used for Group meta data.

Fields

nodes: Vec<Node>

Methods

impl Group[src]

pub fn new(name: &str, coordinates: Coordinate) -> Self[src]

Constructs a new Group.

name is converted internally as a hash.

pub fn new_node(&mut self)[src]

Adds a Node dynamically to the Group.

Examples

let a = cluster!();
let mut group = cluster!();
group.new_node();

pub fn radius(&mut self, radius: u32)[src]

Set the radius for the group's meta-data.

Examples

let a = cluster!();
let mut group = cluster!();
group.radius(100);

pub fn nodes(&self) -> &Vec<Node>[src]

Retrieves the nodes drawing in the group. Positions are relative to the group.

Examples

let group = cluster!();
let mut group = cluster!();
group.add(50);
assert_eq!(group.nodes().len(), 50);

pub fn set(&mut self) -> &mut Node[src]

Retrieves the group meta data, used for setting properties such as hash and color.

Examples

let group = cluster!();
let mut group = cluster!();
group.set().hash = 105;
assert_eq!(group.hash(), 105);

pub fn add(&mut self, nr: u32)[src]

Adds a set of nodes randomly located inside the group's radius.

Examples

let group = cluster!();
let mut group = cluster!();
group.add(500);
assert_eq!(group.nodes().len(), 500);

pub fn each(&mut self, func: &dyn Fn(&mut Node))[src]

Applies the closure over each mutable child node.

Examples

Prints all the nodes positions.

let mut group = cluster!();
group.add(10);
group.each(&|node: &mut Node| println!("{}", node.position()));

Since it returns a mutable reference, It is more adapted for modifying the nodes.

group.each(&|node: &mut Node| node.geo = coordinate!());

pub fn all(&self, func: &dyn Fn(&Node) -> bool) -> bool[src]

Returns true if every node in the group pass the predicate.

Examples

let mut group = cluster!();
group.add(50);
let result = group.all(&|node: &Node| node.x() <= 100);
assert!(result);

pub fn any(&self, func: &dyn Fn(&Node) -> bool) -> bool[src]

Returns true if any node in the group pass the predicate.

Examples

let mut group = cluster!();
group.add(50);
let result = group.any(&|node: &Node| node.x() < 20);
assert!(result);

pub fn color(&mut self, rgba: Rgba<u8>)[src]

Sets the color of the Group.

pub fn node_plot(&mut self, calc: &dyn Fn(usize) -> Coordinate)[src]

Plots node according to the fn provided.

The closure parameter is the number of children the group has.

Examples

let mut group = cluster!();
group.node_plot(&|u| coordinate!(u));

pub fn new_node_min_max(&mut self, min: u32, max: u32)[src]

Adds a Node with a specific minimum and maximum distance from the center of the Group.

Examples

let mut group = cluster!();
group.new_node_min_max(50, 60);
assert!(group.nodes()[0].geo.lt(61));

pub fn new_simple(x: i16, y: i16) -> Self[src]

Removes all non-essentials from the standard implementation.

Examples

The cluster macro allows for this exact invocation.

let mut group = cluster!(10, 10);
let group2 = Group::new_simple(10, 10);
assert_eq!(group.position(), group2.position());

pub fn push(&mut self, node: Node)[src]

Pushes a Node to the Group.

Examples

let mut group = cluster!();
let node = node!();
group.push(node);
assert_eq!(group.nodes().len(), 1);

pub fn dynamic_radius(&self) -> u32[src]

Returns a dynamic radius based on the number of Nodes in the Group.

It returns a larger number if it has more nodes.

pub fn rotate(&mut self, rad: f64)[src]

Rotates all the nodes inside the group.

pub fn gen_color(&self, coordinates: Coordinate) -> Rgba<u8>[src]

Generate a image::Rgba based on the color of the Group and the distance from center.

This is useful to make nodes places in groups, but outside it's radius or close to it's radius appear as darker.

Examples

let mut cluster = cluster!();
cluster.radius(10);
cluster.color(image::Rgba {data: [100, 100, 100, 255]});
let rgba = cluster.gen_color(coordinate!(10, 10));
assert!(rgba.data[0] < 50);

pub fn from_list(list: &[(i16, i16)]) -> Vec<Self>[src]

Converts a list of tuples (x,y) to a Vector of Groups. Names are assigned from "A" and upwards automatically.

Examples

let list = [(0, 0), (10, 10), (15, 15)];
let groups = Group::from_list(&list);
assert_eq!(groups.len(), 3);

Link together groups.

Examples

let b: Group = Group::new("B", Coordinate::new(100, 100));
let mut a: Group = Group::new("A", Coordinate::new(0, 0));
a.link(&b);

Trait Implementations

impl Clone for Group[src]

impl Debug for Group[src]

impl Draw for Group[src]

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

Draws the Nodes inside that Group.

If none the Group is draw as blank.

impl Find for Group[src]

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

Recursively calls find as the group contains sets of Nodes.

impl From<Coordinate> for Group[src]

impl From<Group> for Node[src]

impl From<Group> for Coordinate[src]

impl From<Node> for Group[src]

impl Hash for Group[src]

impl Location for Group[src]

impl MinMax for Group[src]

fn min_max(&self) -> (Coordinate, Coordinate)[src]

Returns the the largest and smallest x and y position found in the group.

Examples

let mut group = Group::new_simple(0, 0);
group.push(node!(100, 100));
let (min, max) = group.min_max();
assert_eq!(min.x, 0);
assert_eq!(max.x, 104);

impl<'a> PartialEq<Group> for Group[src]

Auto Trait Implementations

impl RefUnwindSafe for Group

impl Send for Group

impl Sync for Group

impl Unpin for Group

impl UnwindSafe for Group

Blanket Implementations

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

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

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

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

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

impl<T> SetParameter for T[src]

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

type Owned = T

The resulting type after obtaining ownership.

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.