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§
Sourcefn dimensions(&self) -> Point3D
fn dimensions(&self) -> Point3D
The dimensions of the Grid. The only method that must be defined.
Provided Methods§
Sourcefn lower_bound(&self) -> Point3D
fn lower_bound(&self) -> Point3D
The lower bound. Defaults to (0, 0, 0).
Sourcefn upper_bound(&self) -> Point3D
fn upper_bound(&self) -> Point3D
The upper bound. Defaults to the dimensions itself.
Sourcefn point3d_to_index(&self, point: Point3D) -> usize
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.
Sourcefn index_to_point3d(&self, index: usize) -> Point3D
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.
Sourcefn is_opaque(&self, point: Point3D) -> bool
fn is_opaque(&self, point: Point3D) -> bool
Check if a point is traversable.
Defaults to always, so you may want to implement this.
Sourcefn get_possible_neighbors(&self, point: Point3D) -> [Point3D; 26]
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.
Sourcefn is_possible_neighbor(&self, p1: Point3D, p2: Point3D) -> bool
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.
Sourcefn get_neighbors(&self, point: Point3D) -> [Option<Point3D>; 26]
fn get_neighbors(&self, point: Point3D) -> [Option<Point3D>; 26]
Get the neighbors that is in bounds and not opaque.
Sourcefn is_neighbor(&self, p1: Point3D, p2: Point3D) -> bool
fn is_neighbor(&self, p1: Point3D, p2: Point3D) -> bool
Check if two points are neighbors.
Checks if either points are inbounds or non-opaque.
Sourcefn get_neighbors_with_cost(
&self,
point: Point3D,
) -> [(Option<Point3D>, BigRational); 26]
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".