core_pb::grid::computed_grid

Struct ComputedGrid

Source
pub struct ComputedGrid {
    grid: Grid,
    standard_grid: Option<StandardGrid>,
    walkable_nodes: Vec<Point2<i8>>,
    coords_to_node: HashMap<Point2<i8>, usize>,
    valid_actions: Vec<[bool; 5]>,
    distance_matrix: Vec<Vec<Option<u8>>>,
    walls: Vec<Wall>,
}
Expand description

A Grid with precomputed data for faster pathfinding.

This struct is created by ComputedGrid::try_from.

§Examples

use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();

Fields§

§grid: Grid§standard_grid: Option<StandardGrid>§walkable_nodes: Vec<Point2<i8>>§coords_to_node: HashMap<Point2<i8>, usize>§valid_actions: Vec<[bool; 5]>

walkable, right, left, up, down

§distance_matrix: Vec<Vec<Option<u8>>>

note that all walkable nodes might not be reachable from each other

§walls: Vec<Wall>

walls represent rectangles with top left corner at the specified point

Implementations§

Source§

impl ComputedGrid

Source

pub fn grid(&self) -> &Grid

Returns the underlying Grid.

§Examples
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();

assert_eq!(grid.grid()[0][0], true);
Source

pub fn standard_grid(&self) -> &Option<StandardGrid>

Returns the underlying StandardGrid, if one was used to construct it.

Source

pub fn walkable_nodes(&self) -> &Vec<Point2<i8>>

Returns the positions of all walkable nodes in the grid.

§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();
assert_eq!(grid.walkable_nodes()[0], Point2::new(1, 1));
Source

pub fn coords_to_node(&self, p: &Point2<i8>) -> Option<usize>

Returns the index of the given position in the walkable_nodes vector, or None if the position is not walkable.

§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();
assert_eq!(grid.coords_to_node(&Point2::new(1, 1)), Some(0));
assert_eq!(grid.coords_to_node(&Point2::new(0, 0)), None);
Source

pub fn valid_actions(&self, p: Point2<i8>) -> Option<[bool; 5]>

Returns the valid actions for the given position.

The five values represent:

  • whether the node is walkable
  • whether the node to the right is walkable
  • whether the node to the left is walkable
  • whether the node above is walkable
  • whether the node below is walkable
§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();
assert_eq!(grid.valid_actions(Point2::new(1, 1)), Some([true, false, false, false, false]));
Source

pub fn wall_at(&self, p: &Point2<i8>) -> bool

Returns whether there is a wall at a given position

§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Blank.compute_grid();
assert_eq!(grid.wall_at(&Point2::new(0, 0)), true);
assert_eq!(grid.wall_at(&Point2::new(1, 1)), false);
assert_eq!(grid.wall_at(&Point2::new(32, 32)), true);
Source

pub fn dist(&self, p1: &Point2<i8>, p2: &Point2<i8>) -> Option<u8>

Returns the distance between two points, or None if the points are not both walkable.

§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Pacman.compute_grid();
assert_eq!(grid.dist(&Point2::new(1, 1), &Point2::new(1, 1)), Some(0));
assert_eq!(grid.dist(&Point2::new(1, 1), &Point2::new(1, 2)), Some(1));
Source

pub fn neighbors(&self, p: &Point2<i8>) -> Vec<Point2<i8>>

Returns all the walkable neighbors of the given position.

§Examples
use nalgebra::Point2;
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Pacman.compute_grid();
assert!(grid.neighbors(&Point2::new(1, 1)).contains(&Point2::new(1, 2)));
assert!(grid.neighbors(&Point2::new(1, 1)).contains(&Point2::new(2, 1)));
Source

pub fn walls(&self) -> &Vec<Wall>

Returns the Walls in the grid.

§Examples
use core_pb::grid::standard_grid::StandardGrid;

let grid = StandardGrid::Pacman.compute_grid();
let walls = grid.walls();
Source

pub fn node_nearest(&self, x: f32, y: f32) -> Option<Point2<i8>>

Return the walkable node from the nodes surrounding this point

Source

pub fn bfs_path( &self, start: Point2<i8>, finish: Point2<i8>, ) -> Option<Vec<Point2<i8>>>

Returns the shortest path, if one exists, from start to finish The path includes path the start and the finish

Source

fn compute_open_grid() -> Self

Trait Implementations§

Source§

impl Clone for ComputedGrid

Source§

fn clone(&self) -> ComputedGrid

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 ComputedGrid

Source§

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

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

impl Default for ComputedGrid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ComputedGrid

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<StandardGrid> for ComputedGrid

Source§

fn from(value: StandardGrid) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ComputedGrid

Source§

fn eq(&self, other: &ComputedGrid) -> 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 Serialize for ComputedGrid

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<[[bool; 32]; 32]> for ComputedGrid

Source§

type Error = String

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

fn try_from(grid: Grid) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for ComputedGrid

Auto Trait Implementations§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> FormatOrDebug for T
where T: Debug,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,