Skip to main content

projective_grid/
lib.rs

1//! Generic 2D projective grid graph construction, traversal, and homography tools.
2//!
3//! This crate provides reusable algorithms for building 4-connected grid graphs
4//! from detected 2D corners, assigning grid coordinates via BFS traversal,
5//! and computing projective mappings (homographies) for grid rectification.
6//!
7//! It is pattern-agnostic: the [`NeighborValidator`] trait lets callers plug in
8//! pattern-specific logic (chessboard orientation checks, marker constraints, etc.)
9//! while the graph construction, traversal, and geometry remain generic.
10//!
11//! # Hex Grid Support
12//!
13//! The [`hex`] module provides 6-connected hexagonal grid counterparts for
14//! pointy-top axial coordinates `(q, r)`.
15//!
16//! # Built-in Validators
17//!
18//! The [`validators`] module provides ready-to-use implementations of
19//! [`NeighborValidator`] and [`hex::HexNeighborValidator`] for common scenarios.
20
21mod float_helpers;
22
23pub mod direction;
24pub mod graph;
25pub mod grid_alignment;
26pub mod grid_index;
27pub mod grid_mesh;
28pub mod grid_rectify;
29pub mod grid_smoothness;
30pub mod hex;
31pub mod homography;
32pub mod traverse;
33pub mod validators;
34
35/// Trait alias for floating-point types supported by this crate.
36///
37/// Both `f32` and `f64` satisfy this bound. All public generic types default
38/// to `f32` for backward compatibility.
39pub trait Float: nalgebra::RealField + Copy {}
40impl<T: nalgebra::RealField + Copy> Float for T {}
41
42pub use direction::{NeighborDirection, NodeNeighbor};
43pub use graph::{GridGraph, GridGraphParams, NeighborCandidate, NeighborValidator};
44pub use grid_alignment::{GridAlignment, GridTransform, GRID_TRANSFORMS_D4};
45pub use grid_index::GridIndex;
46pub use grid_mesh::GridHomographyMesh;
47pub use grid_rectify::GridHomography;
48pub use grid_smoothness::{find_inconsistent_corners, predict_grid_position};
49pub use homography::{estimate_homography, homography_from_4pt, Homography};
50pub use traverse::{assign_grid_coordinates, connected_components};