Trait Grid3D

Source
pub trait Grid3D {
    // Required method
    fn dimensions(&self) -> Point3D;

    // Provided methods
    fn lower_bound(&self) -> Point3D { ... }
    fn upper_bound(&self) -> Point3D { ... }
    fn in_bounds(&self, point: Point3D) -> bool { ... }
    fn point3d_to_index(&self, point: Point3D) -> usize { ... }
    fn index_to_point3d(&self, index: usize) -> Point3D { ... }
    fn is_opaque(&self, point: Point3D) -> bool { ... }
    fn get_possible_neighbors(&self, point: Point3D) -> [Point3D; 26] { ... }
    fn is_possible_neighbor(&self, p1: Point3D, p2: Point3D) -> bool { ... }
    fn get_neighbors(&self, point: Point3D) -> [Option<Point3D>; 26] { ... }
    fn is_neighbor(&self, p1: Point3D, p2: Point3D) -> bool { ... }
    fn get_neighbors_with_cost(
        &self,
        point: Point3D,
    ) -> [(Option<Point3D>, BigRational); 26] { ... }
}
Expand description

Trait for implementing a Grid in three dimensions

Required Methods§

Source

fn dimensions(&self) -> Point3D

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

Provided Methods§

Source

fn lower_bound(&self) -> Point3D

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

Source

fn upper_bound(&self) -> Point3D

The upper bound. Defaults to the dimensions itself.

Source

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

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

Source

fn point3d_to_index(&self, point: Point3D) -> usize

Convert a point to an index.

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

Source

fn index_to_point3d(&self, index: usize) -> Point3D

Convert an index to a point.

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

Source

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

Check if a point is traversable.

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

Source

fn get_possible_neighbors(&self, point: Point3D) -> [Point3D; 26]

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

Source

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

Check if two points are possible neighbors.

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

Source

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

Get the neighbors that is in bounds and not opaque.

Source

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

Check if two points are neighbors.

Checks if either points are inbounds or non-opaque.

Source

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

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.

Implementors§