Struct nannou::geom::graph::Graph [−][src]
pub struct Graph<S = DefaultScalar> where
S: BaseFloat, { /* fields omitted */ }
A composition of geometry described by an acyclic directed graph.
The Node
s within a graph may describe some primitive geometry (e.g. Line
, Cuboid
, etc) or
may contain other Graph
s. This allows graphs to be composed of other graphs, which may then
be composed with other graphs, etc.
The Edge
s within a graph describe the relationships between the nodes. They allow for
describing the position, orientation and scale of nodes relative to others.
All Node
s 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]
impl<S> Graph<S> where
S: BaseFloat,
pub fn new() -> Self
[src]
pub fn new() -> Self
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]
pub fn origin(&self) -> Index
The node::Index of the origin node.
pub fn with_capacity(nodes: usize, edges: usize) -> Self
[src]
pub fn with_capacity(nodes: usize, edges: usize) -> Self
Construct the graph with pre-allocated buffers for the given nodes
, edges
and
vertices
capacities.
pub fn node_count(&self) -> usize
[src]
pub fn node_count(&self) -> usize
The total number of Nodes in the Graph.
pub fn edge_count(&self) -> usize
[src]
pub fn edge_count(&self) -> usize
The total number of Edges in the Graph.
pub fn node(&self, idx: Index) -> Option<&Node<S>>
[src]
pub fn node(&self, idx: Index) -> Option<&Node<S>>
Borrow the node at the given node::Index if there is one.
pub fn node_transform(&self, idx: Index) -> Option<Transform<S>>
[src]
pub fn node_transform(&self, idx: Index) -> Option<Transform<S>>
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]
pub fn node_vertices<I>(
&self,
idx: Index,
vertices: I
) -> Option<TransformedVertices<I::IntoIter, S>> where
I: IntoIterator,
I::Item: ApplyTransform<S>,
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]
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>,
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]
pub fn edge(&self, idx: Index) -> Option<&Edge<S>>
Borrow the edge at the given edge::Index if there is one.
pub fn raw_nodes(&self) -> RawNodes<S>
[src]
pub fn raw_nodes(&self) -> RawNodes<S>
The slice containing all nodes.
pub fn raw_edges(&self) -> RawEdges<S>
[src]
pub fn raw_edges(&self) -> RawEdges<S>
The slice containing all edges.
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
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]
pub fn edge_endpoints(&self, idx: Index) -> Option<(Index, Index)>
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]
pub fn recursive_walk<F>(
&self,
start: Index,
recursive_fn: F
) -> RecursiveWalk<F, S> where
F: FnMut(&Self, Index) -> Option<(Index, Index)>,
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]
pub fn dag(&self) -> &Dag<S>
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]
pub fn add_node(&mut self, node: Node<S>) -> Index
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]
pub fn set_edge(
&mut self,
a: Index,
b: Index,
edge: Edge<S>
) -> Result<Index, WouldCycle<S>>
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]
pub fn add_child<E>(
&mut self,
parent: Index,
edges: E,
node: Node<S>
) -> (Indices, Index) where
E: IntoIterator<Item = Edge<S>>,
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]
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>>,
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]
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>,
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]
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>,
Produce a walker yielding all vertices from all nodes within the graph in order of discovery within a depth-first-search.
ⓘImportant traits for Vertices<'a, 'b, F, I, S>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]
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>,
Produce an iterator yielding all vertices from all nodes within the graph in order of discovery within a depth-first-search.
ⓘImportant traits for Triangles<'a, 'b, F, I, V, S>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]
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>,
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]
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>>,
The Cuboid
that bounds all nodes within the geometry graph.
Returns None
if the graph contains no vertices.
- Iterates over all nodes.
- Expands a cuboid to the max bounds of each node.
- Returns the resulting cuboid.
pub fn parents(&self, child: Index) -> Parents<S>
[src]
pub fn parents(&self, child: Index) -> Parents<S>
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]
pub fn edge_parent(&self, idx: Index, edge: Kind) -> Option<Index>
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]
pub fn position_parent(&self, idx: Index, axis: Axis) -> Option<Index>
Return the index of the parent along the given node's Position Edge.
pub fn x_position_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn x_position_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Position Edge.
pub fn y_position_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn y_position_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Position Edge.
pub fn z_position_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn z_position_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Position Edge.
pub fn position_parents(&self, idx: Index) -> PositionParents
[src]
pub fn position_parents(&self, idx: Index) -> PositionParents
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]
pub fn orientation_parent(&self, idx: Index, axis: Axis) -> Option<Index>
Return the index of the parent along the given node's Orientation Edge.
pub fn x_orientation_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn x_orientation_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Orientation Edge.
pub fn y_orientation_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn y_orientation_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Orientation Edge.
pub fn z_orientation_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn z_orientation_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Orientation Edge.
pub fn orientation_parents(&self, idx: Index) -> OrientationParents
[src]
pub fn orientation_parents(&self, idx: Index) -> OrientationParents
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]
pub fn scale_parent(&self, idx: Index, axis: Axis) -> Option<Index>
Return the index of the parent along the given node's Scale Edge.
pub fn x_scale_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn x_scale_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Scale Edge.
pub fn y_scale_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn y_scale_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Scale Edge.
pub fn z_scale_parent(&self, idx: Index) -> Option<Index>
[src]
pub fn z_scale_parent(&self, idx: Index) -> Option<Index>
Return the index of the parent along the given node's Scale Edge.
pub fn scale_parents(&self, idx: Index) -> ScaleParents
[src]
pub fn scale_parents(&self, idx: Index) -> ScaleParents
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]
pub fn x_parents(&self, idx: Index) -> XParents
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]
pub fn y_parents(&self, idx: Index) -> YParents
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]
pub fn z_parents(&self, idx: Index) -> ZParents
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]
pub fn children(&self, parent: Index) -> Children<S>
A Walker type that may be used to step through the children of the given parent node.
Trait Implementations
impl<'a, S> Walker<&'a Graph<S>> for Dfs<S> where
S: BaseFloat,
[src]
impl<'a, S> Walker<&'a Graph<S>> for Dfs<S> where
S: BaseFloat,
type Item = (Index, Transform<S>)
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
[src]
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
Advance to the next item
ⓘImportant traits for WalkerIter<W, C>fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
[src]
fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
Create an iterator out of the walker and given context
.
impl<S: Clone> Clone for Graph<S> where
S: BaseFloat,
[src]
impl<S: Clone> Clone for Graph<S> where
S: BaseFloat,
fn clone(&self) -> Graph<S>
[src]
fn clone(&self) -> Graph<S>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<S: Debug> Debug for Graph<S> where
S: BaseFloat,
[src]
impl<S: Debug> Debug for Graph<S> where
S: BaseFloat,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<S> Default for Graph<S> where
S: BaseFloat,
[src]
impl<S> Default for Graph<S> where
S: BaseFloat,
impl<S> GraphBase for Graph<S> where
S: BaseFloat,
[src]
impl<S> GraphBase for Graph<S> where
S: BaseFloat,
impl<S> Visitable for Graph<S> where
S: BaseFloat,
[src]
impl<S> Visitable for Graph<S> where
S: BaseFloat,
type Map = <Dag<S> as Visitable>::Map
The associated map type
fn visit_map(&self) -> Self::Map
[src]
fn visit_map(&self) -> Self::Map
Create a new visitor map
fn reset_map(&self, map: &mut Self::Map)
[src]
fn reset_map(&self, map: &mut Self::Map)
Reset the visitor map (and resize to new size of graph if needed)
impl<'a, S> IntoNeighbors for &'a Graph<S> where
S: BaseFloat,
[src]
impl<'a, S> IntoNeighbors for &'a Graph<S> where
S: BaseFloat,
type Neighbors = <&'a Dag<S> as IntoNeighbors>::Neighbors
fn neighbors(self, n: Self::NodeId) -> Self::Neighbors
[src]
fn neighbors(self, n: Self::NodeId) -> Self::Neighbors
Return an iterator of the neighbors of node a
.
impl<S> Index<Index> for Graph<S> where
S: BaseFloat,
[src]
impl<S> Index<Index> for Graph<S> where
S: BaseFloat,
type Output = Node<S>
The returned type after indexing.
fn index<'a>(&'a self, id: Index) -> &'a Self::Output
[src]
fn index<'a>(&'a self, id: Index) -> &'a Self::Output
Performs the indexing (container[index]
) operation.
impl<S> Index<Index> for Graph<S> where
S: BaseFloat,
[src]
impl<S> Index<Index> for Graph<S> where
S: BaseFloat,
type Output = Edge<S>
The returned type after indexing.
fn index<'a>(&'a self, idx: Index) -> &'a Self::Output
[src]
fn index<'a>(&'a self, idx: Index) -> &'a Self::Output
Performs the indexing (container[index]
) operation.
impl<'a, S> Walker<&'a Graph<S>> for Children<S> where
S: BaseFloat,
[src]
impl<'a, S> Walker<&'a Graph<S>> for Children<S> where
S: BaseFloat,
type Item = (Index, Index)
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
[src]
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
Advance to the next item
ⓘImportant traits for WalkerIter<W, C>fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
[src]
fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
Create an iterator out of the walker and given context
.
impl<'a, S> Walker<&'a Graph<S>> for Parents<S> where
S: BaseFloat,
[src]
impl<'a, S> Walker<&'a Graph<S>> for Parents<S> where
S: BaseFloat,
type Item = (Index, Index)
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
[src]
fn walk_next(&mut self, graph: &'a Graph<S>) -> Option<Self::Item>
Advance to the next item
ⓘImportant traits for WalkerIter<W, C>fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
[src]
fn iter(self, context: Context) -> WalkerIter<Self, Context> where
Context: Clone,
Create an iterator out of the walker and given context
.