[][src]Struct nannou::geom::graph::Graph

pub struct Graph<S = Default> where
    S: BaseFloat
{ /* fields omitted */ }

A composition of geometry described by an acyclic directed graph.

The Nodes within a graph may describe some primitive geometry (e.g. Line, Cuboid, etc) or may contain other Graphs. This allows graphs to be composed of other graphs, which may then be composed with other graphs, etc.

The Edges within a graph describe the relationships between the nodes. They allow for describing the position, orientation and scale of nodes relative to others.

All Nodes other than the graph's "origin" node must have at least one parent, but may never have more than one parent of each edge::Kind.

Methods

impl<S> Graph<S> where
    S: BaseFloat
[src]

pub fn new() -> Self[src]

Construct a new empty Graph with a single "origin" node.

The "origin" is the "parent-most" of all nodes. Its transform is always equal to Transform::default().

Calling this is the same as calling Graph::default().

pub fn origin(&self) -> Index[src]

The node::Index of the origin node.

pub fn with_capacity(nodes: usize, edges: usize) -> Self[src]

Construct the graph with pre-allocated buffers for the given nodes, edges and vertices capacities.

pub fn node_count(&self) -> usize[src]

The total number of Nodes in the Graph.

pub fn edge_count(&self) -> usize[src]

The total number of Edges in the Graph.

pub fn node(&self, idx: Index) -> Option<&Node<S>>[src]

Borrow the node at the given node::Index if there is one.

pub fn node_transform(&self, idx: Index) -> Option<Transform<S>>[src]

Determine the full Transform for the Node.

Returns None if the node does not exist.

pub fn node_vertices<I>(
    &self,
    idx: Index,
    vertices: I
) -> Option<TransformedVertices<I::IntoIter, S>> where
    I: IntoIterator,
    I::Item: ApplyTransform<S>, 
[src]

Transform the given vertices with the given node's Transform.

This method uses the node_transform method internally.

Returns None if the node does not exist.

pub fn node_triangles<I, V>(
    &self,
    idx: Index,
    triangles: I
) -> Option<TransformedTriangles<I::IntoIter, V, S>> where
    I: IntoIterator<Item = Tri<V>>,
    V: Vertex + ApplyTransform<S>, 
[src]

Transform the given triangles with the given node's Transform.

This method uses the node_transform method internally.

Returns None if the node does not exist.

pub fn edge(&self, idx: Index) -> Option<&Edge<S>>[src]

Borrow the edge at the given edge::Index if there is one.

pub fn raw_nodes(&self) -> RawNodes<S>[src]

The slice containing all nodes.

pub fn raw_edges(&self) -> RawEdges<S>[src]

The slice containing all edges.

pub fn clear(&mut self)[src]

Removes all Nodes, Edges and vertices from the Graph and resets the origin node.

This does not de-allocate any buffers and should retain capacity. To drop all inner buffers, use mem::replace with a new empty Graph.

pub fn edge_endpoints(&self, idx: Index) -> Option<(Index, Index)>[src]

Return the parent and child nodes on either end of the Edge at the given index.

pub fn recursive_walk<F>(
    &self,
    start: Index,
    recursive_fn: F
) -> RecursiveWalk<F, S> where
    F: FnMut(&Self, Index) -> Option<(Index, Index)>, 
[src]

A Walker type that recursively walks the Graph using the given recursive_fn.

Panics If the given start index does not exist within the Graph.

pub fn dag(&self) -> &Dag<S>[src]

Borrow the inner daggy::Dag (directed acyclic graph) upon which Graph is built.

Can be useful/necessary for utilising some of the daggy::Walker types.

pub fn add_node(&mut self, node: Node<S>) -> Index[src]

Add the given Node to the graph.

The created node will be a child of the graph's origin node.

Returns the index of the new node.

pub fn set_edge(
    &mut self,
    a: Index,
    b: Index,
    edge: Edge<S>
) -> Result<Index, WouldCycle<S>>
[src]

Set the given Edge within the graph.

The added edge will be in the direction a -> b

There may only ever be one Edge of the given variant between a -> b.

Checks if the edge would create a cycle in the Graph.

If adding the edge would not cause the graph to cycle, the edge will be added and its edge::Index returned.

If adding the edge would cause the graph to cycle, the edge will not be added and instead a WouldCycle error with the given weight will be returned.

Panics if either a or b do not exist within the Graph.

Panics if the Graph is at the maximum number of nodes for its index type.

pub fn add_child<E>(
    &mut self,
    parent: Index,
    edges: E,
    node: Node<S>
) -> (Indices, Index) where
    E: IntoIterator<Item = Edge<S>>, 
[src]

Add the given node as a child to the given parent connected via the given edges.

There may only ever be one Edge of the given variant between a -> b.

Panics if:

  • parent does not exist within the Graph.
  • edges does not contain at least one Edge.
  • the Graph is at the maximum number of nodes for its index type.

pub fn add_children<C, E>(
    &mut self,
    parent: Index,
    children: C
) -> Vec<(Indices, Index)> where
    C: IntoIterator<Item = (E, Node<S>)>,
    E: IntoIterator<Item = Edge<S>>, 
[src]

Add the given children to the given parent connected via the given edges for each child.

Returns an iterator yielding the node and edge indices for each child that was added.

There may only ever be one Edge of the given variant between a -> b.

Panics if:

  • parent does not exist within the Graph.
  • any of the child edges iterators do not contain at least one Edge.
  • the Graph is at the maximum number of nodes for its index type.

pub fn walk_vertices<'a, F, I>(
    &self,
    dfs: &'a mut Dfs<S>,
    vertices_fn: F
) -> WalkVertices<'a, F, I, S> where
    F: Fn(&Index) -> I,
    I: IntoIterator,
    I::Item: ApplyTransform<S>, 
[src]

Produce a walker yielding all vertices from all nodes within the graph in order of discovery within a depth-first-search.

pub fn walk_triangles<'a, F, I, V>(
    &self,
    dfs: &'a mut Dfs<S>,
    triangles_fn: F
) -> WalkTriangles<'a, F, I, V, S> where
    F: Fn(&Index) -> I,
    I: IntoIterator<Item = Tri<V>>,
    V: Vertex + ApplyTransform<S>, 
[src]

Produce a walker yielding all vertices from all nodes within the graph in order of discovery within a depth-first-search.

pub fn vertices<'a, 'b, F, I>(
    &'a self,
    dfs: &'b mut Dfs<S>,
    vertices_fn: F
) -> Vertices<'a, 'b, F, I, S> where
    F: Fn(&Index) -> I,
    I: IntoIterator,
    I::Item: ApplyTransform<S>, 
[src]

Produce an iterator yielding all vertices from all nodes within the graph in order of discovery within a depth-first-search.

pub fn triangles<'a, 'b, F, I, V>(
    &'a self,
    dfs: &'b mut Dfs<S>,
    triangles_fn: F
) -> Triangles<'a, 'b, F, I, V, S> where
    F: Fn(&Index) -> I,
    I: IntoIterator<Item = Tri<V>>,
    V: Vertex + ApplyTransform<S>, 
[src]

Produce an iterator yielding all triangles from all nodes within the graph in order of discovery within a depth-first-search.

pub fn bounding_cuboid<F, I>(
    &self,
    dfs: &mut Dfs<S>,
    vertices_fn: F
) -> Option<Cuboid<S>> where
    F: Fn(&Index) -> I,
    I: IntoIterator<Item = Point3<S>>, 
[src]

The Cuboid that bounds all nodes within the geometry graph.

Returns None if the graph contains no vertices.

  1. Iterates over all nodes.
  2. Expands a cuboid to the max bounds of each node.
  3. Returns the resulting cuboid.

pub fn parents(&self, child: Index) -> Parents<S>[src]

A Walker type that may be used to step through the parents of the given child node.

pub fn edge_parent(&self, idx: Index, edge: Kind) -> Option<Index>[src]

If the Node at the given index has some parent along an Edge of the given variant, return an index to it.

pub fn position_parent(&self, idx: Index, axis: Axis) -> Option<Index>[src]

Return the index of the parent along the given node's Position Edge.

pub fn x_position_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Position Edge.

pub fn y_position_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Position Edge.

pub fn z_position_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Position Edge.

pub fn position_parents(&self, idx: Index) -> PositionParents[src]

Produce an Iterator yielding the Position parents to the given node.

Parents are always yielded in order of axis, e.g. X, Y then Z.

pub fn orientation_parent(&self, idx: Index, axis: Axis) -> Option<Index>[src]

Return the index of the parent along the given node's Orientation Edge.

pub fn x_orientation_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Orientation Edge.

pub fn y_orientation_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Orientation Edge.

pub fn z_orientation_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Orientation Edge.

pub fn orientation_parents(&self, idx: Index) -> OrientationParents[src]

Produce an Iterator yielding the Orientation parents to the given node.

Parents are always yielded in order of axis, e.g. X, Y then Z.

pub fn scale_parent(&self, idx: Index, axis: Axis) -> Option<Index>[src]

Return the index of the parent along the given node's Scale Edge.

pub fn x_scale_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Scale Edge.

pub fn y_scale_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Scale Edge.

pub fn z_scale_parent(&self, idx: Index) -> Option<Index>[src]

Return the index of the parent along the given node's Scale Edge.

pub fn scale_parents(&self, idx: Index) -> ScaleParents[src]

Produce an Iterator yielding the Scale parents to the given node.

Parents are always yielded in order of axis, e.g. X, Y then Z.

pub fn x_parents(&self, idx: Index) -> XParents[src]

Produce an Iterator yielding the X parents to the given node.

Parents are always yielded in order of Position, Orientation and Scale.

pub fn y_parents(&self, idx: Index) -> YParents[src]

Produce an Iterator yielding the Y parents to the given node.

Parents are always yielded in order of Position, Orientation and Scale.

pub fn z_parents(&self, idx: Index) -> ZParents[src]

Produce an Iterator yielding the Z parents to the given node.

Parents are always yielded in order of Position, Orientation and Scale.

pub fn children(&self, parent: Index) -> Children<S>[src]

A Walker type that may be used to step through the children of the given parent node.

Trait Implementations

impl<S: Clone> Clone for Graph<S> where
    S: BaseFloat
[src]

impl<S: Debug> Debug for Graph<S> where
    S: BaseFloat
[src]

impl<S> Default for Graph<S> where
    S: BaseFloat
[src]

impl<S> GraphBase for Graph<S> where
    S: BaseFloat
[src]

type NodeId = Index

node identifier

type EdgeId = Index

edge identifier

impl<S> Index<EdgeIndex<usize>> for Graph<S> where
    S: BaseFloat
[src]

type Output = Edge<S>

The returned type after indexing.

impl<S> Index<NodeIndex<usize>> for Graph<S> where
    S: BaseFloat
[src]

type Output = Node<S>

The returned type after indexing.

impl<'a, S> IntoNeighbors for &'a Graph<S> where
    S: BaseFloat
[src]

type Neighbors = <&'a Dag<S> as IntoNeighbors>::Neighbors

impl<S> Visitable for Graph<S> where
    S: BaseFloat
[src]

type Map = <Dag<S> as Visitable>::Map

The associated map type

impl<'a, S> Walker<&'a Graph<S>> for Dfs<S> where
    S: BaseFloat
[src]

type Item = (Index, Transform<S>)

impl<'a, S> Walker<&'a Graph<S>> for Children<S> where
    S: BaseFloat
[src]

type Item = (Index, Index)

impl<'a, S> Walker<&'a Graph<S>> for Parents<S> where
    S: BaseFloat
[src]

type Item = (Index, Index)

Auto Trait Implementations

impl<S> RefUnwindSafe for Graph<S> where
    S: RefUnwindSafe

impl<S> Send for Graph<S> where
    S: Send

impl<S> Sync for Graph<S> where
    S: Sync

impl<S> Unpin for Graph<S> where
    S: Unpin

impl<S> UnwindSafe for Graph<S> where
    S: UnwindSafe

Blanket Implementations

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

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, U> ConvertInto<U> for T where
    U: ConvertFrom<T>, 
[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

impl<T> SetParameter for T

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,