pub struct Graph<T>where
T: VertexDataProvider,{
pub vertices: Vec<T>,
pub max_search_iterations: i32,
}
Expand description
A collection of GraphVertices for pathfinding.
See module docs
Fields§
§vertices: Vec<T>
Vertices of the graph.
max_search_iterations: i32
The maximum iterations A* pathfinding will attempt before giving up and returning its best path.
Default: 1000
§Notes
A* is inefficient when its desired destination is isolated or it must backtrack a substantial distance before it may reach the goal. Higher max iteration numbers will be required for huge graphs and graphs with many obstacles. Whereas, lower max iterations may be desired for smaller simple graphs.
Negative numbers disable max iterations
Implementations§
Source§impl<T: VertexDataProvider> Graph<T>
impl<T: VertexDataProvider> Graph<T>
Sourcepub fn set_vertices(&mut self, vertices: Vec<T>)
pub fn set_vertices(&mut self, vertices: Vec<T>)
Sets active set of vertices. Links between vertices must contain valid indices (which are not out-of-bounds), otherwise path from/to such vertices won’t be built.
Sourcepub fn link_bidirect(&mut self, a: usize, b: usize)
pub fn link_bidirect(&mut self, a: usize, b: usize)
Creates bidirectional link between two vertices. Bidirectional means
that point a
can be reached from point b
as well as point b
can be reached from point a
.
Sourcepub fn link_unidirect(&mut self, a: usize, b: usize)
pub fn link_unidirect(&mut self, a: usize, b: usize)
Creates unidirectional link between vertex a
and vertex b
. Unidirectional
means that there is no direct link between b
to a
, only from a
to b
.
Sourcepub fn vertex(&self, index: usize) -> Option<&T>
pub fn vertex(&self, index: usize) -> Option<&T>
Returns shared reference to a path vertex at the given index.
Sourcepub fn vertex_mut(&mut self, index: usize) -> Option<&mut T>
pub fn vertex_mut(&mut self, index: usize) -> Option<&mut T>
Returns mutable reference to a path vertex at the given index.
Sourcepub fn vertices_mut(&mut self) -> &mut [T]
pub fn vertices_mut(&mut self) -> &mut [T]
Returns mutable reference to the array of vertices.
Sourcepub fn add_vertex(&mut self, vertex: T) -> u32
pub fn add_vertex(&mut self, vertex: T) -> u32
Adds a new vertex to the path finder.
Sourcepub fn pop_vertex(&mut self) -> Option<T>
pub fn pop_vertex(&mut self) -> Option<T>
Removes last vertex from the graph. Automatically cleans “dangling” references to the deleted vertex from every other vertex in the graph and shifts indices of neighbour vertices, to preserve graph structure.
Sourcepub fn remove_vertex(&mut self, index: usize) -> T
pub fn remove_vertex(&mut self, index: usize) -> T
Removes a vertex at the given index from the graph. Automatically cleans “dangling” references to the deleted vertex from every other vertex in the graph and shifts indices of neighbour vertices, to preserve graph structure.
Sourcepub fn insert_vertex(&mut self, index: u32, vertex: T)
pub fn insert_vertex(&mut self, index: u32, vertex: T)
Inserts the vertex at the given index. Automatically shifts neighbour indices of every other vertex in the graph to preserve graph structure.
Sourcepub fn build_indexed_path(
&self,
from: usize,
to: usize,
path: &mut Vec<usize>,
) -> Result<PathKind, PathError>
pub fn build_indexed_path( &self, from: usize, to: usize, path: &mut Vec<usize>, ) -> Result<PathKind, PathError>
Tries to build path of vertex indices from beginning point to endpoint. Returns path kind:
- Full: Path vector is a direct path from beginning to end.
- Partial: Path vector is a path that ends closest to the desired end, because pathfinder could not find a full path.
See PathKind
§Notes
This implementation is fast and allows for multiple searches in parallel, but does not attempt to find the optimal route
See Graph<T>.max_search_iterations
to change the maximum amount of search iterations
Sourcepub fn build_positional_path(
&self,
from: usize,
to: usize,
path: &mut Vec<Vector3<f32>>,
) -> Result<PathKind, PathError>
pub fn build_positional_path( &self, from: usize, to: usize, path: &mut Vec<Vector3<f32>>, ) -> Result<PathKind, PathError>
Tries to build path of Vector3’s from beginning point to endpoint. Returns path kind:
- Full: Path vector is a direct path from beginning to end.
- Partial: Path vector is a path that ends closest to the desired end, because pathfinder could not find a full path.
See PathKind
§Notes
This implementation is fast and allows for multiple searches in parallel, but does not attempt to find the optimal route
See Graph<T>.max_search_iterations
to change the maximum amount of search iterations
Sourcepub fn build(
&self,
from: usize,
to: usize,
path: &mut Vec<Vector3<f32>>,
) -> Result<PathKind, PathError>
👎Deprecated: name is too ambiguous use build_positional_path instead
pub fn build( &self, from: usize, to: usize, path: &mut Vec<Vector3<f32>>, ) -> Result<PathKind, PathError>
Deprecated use Graph<T>.build_positional_path()
instead
Tries to build path of Vector3’s from beginning point to endpoint. Returns path kind:
- Full: Path vector is a direct path from beginning to end.
- Partial: Path vector is a path that ends closest to the desired end, because pathfinder could not find a full path.
See PathKind
§Notes
This implementation is fast and allows for multiple searches in parallel, but does not attempt to find the optimal route
See Graph<T>.max_search_iterations
to change the maximum amount of search iterations
Trait Implementations§
Source§impl<T: VertexDataProvider> Default for Graph<T>
impl<T: VertexDataProvider> Default for Graph<T>
Source§impl<T> Visit for Graph<T>
impl<T> Visit for Graph<T>
Source§fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult
impl<T> StructuralPartialEq for Graph<T>where
T: VertexDataProvider,
Auto Trait Implementations§
impl<T> Freeze for Graph<T>
impl<T> RefUnwindSafe for Graph<T>where
T: RefUnwindSafe,
impl<T> Send for Graph<T>where
T: Send,
impl<T> Sync for Graph<T>where
T: Sync,
impl<T> Unpin for Graph<T>where
T: Unpin,
impl<T> UnwindSafe for Graph<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> MessageData for T
impl<T> MessageData for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.