Skip to main content

hfx_core/
lib.rs

1//! Shared types and validation primitives for HFX artifacts.
2//!
3//! This crate defines the canonical in-memory representation of HFX
4//! domain concepts. All types enforce their invariants at construction
5//! time ("parse, don't validate"). No I/O — deserialization from
6//! Parquet/Arrow/JSON/GeoTIFF is the responsibility of downstream crates.
7
8pub mod area;
9pub mod catchment;
10pub mod geo;
11pub mod graph;
12pub mod id;
13pub mod manifest;
14pub mod raster;
15pub mod snap;
16
17// --- Re-exports for ergonomic imports ---
18
19pub use area::{AreaKm2, MeasureError, Weight};
20pub use catchment::CatchmentAtom;
21pub use geo::{BoundingBox, GeoError, Latitude, Longitude, WkbGeometry};
22pub use graph::{AdjacencyRow, DrainageGraph, GraphError};
23pub use id::{AtomId, IdError, SnapId};
24pub use manifest::{
25    AtomCount, Crs, FormatVersion, Manifest, ManifestBuilder, ManifestError, RasterAvailability,
26    SnapAvailability, Topology, UpAreaAvailability,
27};
28pub use raster::{FlowDirEncoding, FlowDirEncodingError};
29pub use snap::{MainstemStatus, SnapTarget};
30
31/// Trait for types that carry a spatial bounding box.
32///
33/// Enables generic spatial filtering over catchments, snap targets,
34/// or any future artifact row type.
35pub trait HasBbox {
36    /// Return a reference to the bounding box.
37    fn bbox(&self) -> &BoundingBox;
38}
39
40impl HasBbox for CatchmentAtom {
41    fn bbox(&self) -> &BoundingBox {
42        catchment::CatchmentAtom::bbox(self)
43    }
44}
45
46impl HasBbox for SnapTarget {
47    fn bbox(&self) -> &BoundingBox {
48        snap::SnapTarget::bbox(self)
49    }
50}
51
52/// Trait for types identified by an [`AtomId`].
53///
54/// Enables generic operations over catchments and graph rows.
55pub trait HasAtomId {
56    /// Return the atom identifier.
57    fn atom_id(&self) -> AtomId;
58}
59
60impl HasAtomId for CatchmentAtom {
61    fn atom_id(&self) -> AtomId {
62        self.id()
63    }
64}
65
66impl HasAtomId for AdjacencyRow {
67    fn atom_id(&self) -> AtomId {
68        self.id()
69    }
70}