Skip to main content

projective_grid/
direction.rs

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