pub struct Point {
pub x: i32,
pub y: i32,
}Expand description
2D (grid) point with integer coordinates x and y. It has member functions for many common operations such as computing the manhattan distance as well as operator implementations for easy arithmetic.
Fields§
§x: i32§y: i32Implementations§
Source§impl Point
impl Point
pub fn new(x: i32, y: i32) -> Point
Sourcepub fn dir_obj(&self, other: &Point) -> Direction
pub fn dir_obj(&self, other: &Point) -> Direction
Compares this to another point and gives the direction the other is in seen from this point.
Sourcepub fn abs_dir(&self) -> Direction
pub fn abs_dir(&self) -> Direction
Gives the direction in which the given point is as seen from the origin.
Sourcepub fn manhattan_distance(&self, other: &Point) -> i32
pub fn manhattan_distance(&self, other: &Point) -> i32
L-1 norm. As a grid-pathfinding heuristic it represents number of moves on a uniform cost 4-connected grid.
Sourcepub fn move_distance(&self, other: &Point) -> i32
pub fn move_distance(&self, other: &Point) -> i32
L-inf norm. As a grid-pathfinding heuristic it represents number of moves on a uniform cost 8-connected grid.
Sourcepub fn euclidean_distance(&self, other: &Point) -> f32
pub fn euclidean_distance(&self, other: &Point) -> f32
L-2 norm.
Sourcepub fn moore_neighbor(&self, dir_num: i32) -> Point
pub fn moore_neighbor(&self, dir_num: i32) -> Point
Retrieves a single neighbour on an 8-connected grid, with the indexing used being similar to that in Direction.
Sourcepub fn neumann_neighborhood(&self) -> Vec<Point>
pub fn neumann_neighborhood(&self) -> Vec<Point>
Neighbours on a 4-connected grid.
Sourcepub fn neumann_neighborhood_array(&self) -> [Point; 4]
pub fn neumann_neighborhood_array(&self) -> [Point; 4]
Neighbours on a 4-connected grid.
Sourcepub fn moore_neighborhood(&self) -> Vec<Point>
pub fn moore_neighborhood(&self) -> Vec<Point>
Neighbours on an 8-connected grid.
Sourcepub fn moore_neighborhood_array(&self) -> [Point; 8]
pub fn moore_neighborhood_array(&self) -> [Point; 8]
Neighbours on an 8-connected grid.
Sourcepub fn general_moore_neighborhood(&self, size: i32) -> Vec<Point>
pub fn general_moore_neighborhood(&self, size: i32) -> Vec<Point>
Alternative neighborhood, takes a square of a given size centered around self.