Skip to main content

projective_grid/
direction.rs

1use serde::{Deserialize, Serialize};
2
3/// Cardinal direction along a 4-connected grid.
4#[non_exhaustive]
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum NeighborDirection {
7    Right,
8    Left,
9    Up,
10    Down,
11}
12
13impl NeighborDirection {
14    /// The opposite direction.
15    pub fn opposite(self) -> Self {
16        match self {
17            Self::Right => Self::Left,
18            Self::Left => Self::Right,
19            Self::Up => Self::Down,
20            Self::Down => Self::Up,
21        }
22    }
23
24    /// Grid coordinate delta `(di, dj)` for this direction.
25    ///
26    /// Convention: `i` increases rightward, `j` increases downward.
27    pub fn delta(self) -> (i32, i32) {
28        match self {
29            Self::Right => (1, 0),
30            Self::Left => (-1, 0),
31            Self::Up => (0, -1),
32            Self::Down => (0, 1),
33        }
34    }
35}
36
37/// A validated grid neighbor with direction, distance, and quality score.
38#[derive(Debug)]
39pub struct NodeNeighbor {
40    /// Direction from the source node to this neighbor.
41    pub direction: NeighborDirection,
42    /// Index of the neighbor in the original point array.
43    pub index: usize,
44    /// Euclidean distance in pixels.
45    pub distance: f32,
46    /// Quality score (lower is better).
47    pub score: f32,
48}