Struct controlled_astar::node::Node
source · pub struct Node {
pub x: usize,
pub y: usize,
pub is_blocked: bool,
pub neighbors: BTreeMap<Direction, Option<(usize, usize)>>,
}
Expand description
Represents a node on a map.
Fields§
§x: usize
§y: usize
§is_blocked: bool
§neighbors: BTreeMap<Direction, Option<(usize, usize)>>
Implementations§
source§impl Node
impl Node
sourcepub fn new(
x: usize,
y: usize,
is_blocked: bool,
max_x: usize,
max_y: usize
) -> Self
pub fn new( x: usize, y: usize, is_blocked: bool, max_x: usize, max_y: usize ) -> Self
Creates a new Node
and initializes neighbors for the four basic directions.
§Parameters
x
: The x-coordinate of the node.y
: The y-coordinate of the node.is_blocked
: Indicates whether the node is blocked.max_x
: The maximum x dimension of the map.max_y
: The maximum y dimension of the map.
§Returns
A newly created Node
instance.
§Examples
use my_crate::Node;
// Create a new `Node` at position (2, 3) which is not blocked
let node = Node::new(2, 3, false, 10, 10);
// Check the node's coordinates and blocked status
assert_eq!(node.x, 2);
assert_eq!(node.y, 3);
assert_eq!(node.is_blocked, false);
sourcepub fn remove_neighbor(&mut self, direction: Direction)
pub fn remove_neighbor(&mut self, direction: Direction)
sourcepub fn set_blocked(&mut self, blocked: bool)
pub fn set_blocked(&mut self, blocked: bool)
sourcepub fn get_directions(&self) -> Vec<Direction>
pub fn get_directions(&self) -> Vec<Direction>
sourcepub fn grid_to_nodes(grid: &[Vec<i32>]) -> HashMap<(usize, usize), Node>
pub fn grid_to_nodes(grid: &[Vec<i32>]) -> HashMap<(usize, usize), Node>
Converts a 2D grid into Node
objects.
§Parameters
grid
: The 2D grid where1
represents a blocked node and0
represents a free node.
§Returns
A HashMap
containing Node
objects mapped by their positions.
§Example
let grid = vec![
vec![0, 1, 0],
vec![0, 0, 1],
];
let nodes = Node::grid_to_nodes(&grid);
Trait Implementations§
source§impl PartialEq for Node
impl PartialEq for Node
impl Eq for Node
impl StructuralPartialEq for Node
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnwindSafe for Node
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more