[][src]Trait alg_grid::two_dim::Grid2D

pub trait Grid2D {
    fn dimensions(&self) -> Point2D;

    fn lower_bound(&self) -> Point2D { ... }
fn upper_bound(&self) -> Point2D { ... }
fn in_bounds(&self, point: Point2D) -> bool { ... }
fn point2d_to_index(&self, point: Point2D) -> usize { ... }
fn index_to_point2d(&self, index: usize) -> Point2D { ... }
fn is_opaque(&self, point: Point2D) -> bool { ... }
fn get_possible_neighbors(&self, point: Point2D) -> [Point2D; 8] { ... }
fn is_possible_neighbor(&self, p1: Point2D, p2: Point2D) -> bool { ... }
fn get_neighbors(&self, point: Point2D) -> [Option<Point2D>; 8] { ... }
fn is_neighbor(&self, p1: Point2D, p2: Point2D) -> bool { ... }
fn get_neighbors_with_cost(
        &self,
        point: Point2D
    ) -> [(Option<Point2D>, BigRational); 8] { ... } }

Trait for implementing a Grid in two dimensions

Required methods

fn dimensions(&self) -> Point2D

The dimensions of the Grid. The only method that must be defined.

Loading content...

Provided methods

fn lower_bound(&self) -> Point2D

The lower bound. Defaults to (0, 0).

fn upper_bound(&self) -> Point2D

The upper bound. Defaults to the dimensions itself.

fn in_bounds(&self, point: Point2D) -> bool

Check if a point is in the bounds of the grid.

fn point2d_to_index(&self, point: Point2D) -> usize

Convert a point to an index.

Useful if you store the grid in a one-dimensional array.

fn index_to_point2d(&self, index: usize) -> Point2D

Convert an index to a point.

Useful if you store the grid in a one-dimensional array.

fn is_opaque(&self, point: Point2D) -> bool

Check if a point is traversable.

Defaults to always, so you may want to implement this.

fn get_possible_neighbors(&self, point: Point2D) -> [Point2D; 8]

Get all possible neighbors of the point, regardless if the point or its neighbors is in bounds, opaque, or neither.

fn is_possible_neighbor(&self, p1: Point2D, p2: Point2D) -> bool

Check if two points are possible neighbors.

Does not check if either points are inbounds or non-opaque.

fn get_neighbors(&self, point: Point2D) -> [Option<Point2D>; 8]

Get the neighbors that is in bounds and not opaque.

fn is_neighbor(&self, p1: Point2D, p2: Point2D) -> bool

Check if two points are neighbors.

Checks if either points are inbounds or non-opaque.

fn get_neighbors_with_cost(
    &self,
    point: Point2D
) -> [(Option<Point2D>, BigRational); 8]

Get the neighbors with the associated cost.

Defaults to all eight neighbors having a cost of 1.0 if the neighbor is valid.

If you want the diagonals to cost sqrt(2), reimplement this method yourself.

Loading content...

Implementors

Loading content...