Skip to main content

ndslive_math/
lib.rs

1// SPDX-License-Identifier: BSD-3-Clause
2//! `ndslive-math` — coordinate math, packed tile IDs, and Morton (Z-order)
3//! codes for NDS.Live geographic tiling.
4//!
5//! This crate is a faithful Rust port of the Python reference implementation
6//! (`ndslive.math`). It provides:
7//!
8//! - [`Wgs84`] — a WGS84 lon/lat/alt point with NDS coordinate conversion,
9//!   distance and bearing helpers.
10//! - [`MortonCode`] — a standalone Z-order encoder/decoder.
11//! - [`PackedTileId`] — an NDS.Live Packed Tile ID with geometry accessors and
12//!   neighbour traversal.
13//! - [`NdsBoundingBox`] — a rectangle in NDS coordinate space.
14//! - [`get_tile_ids_for_bounding_box`] / [`bounding_box_from_tile_ids`] — bulk
15//!   tile enumeration helpers.
16//!
17//! # Example
18//!
19//! ```
20//! use ndslive_math::{Wgs84, MortonCode, PackedTileId};
21//!
22//! // WGS84 -> NDS coordinates (uses floor, per the NDS recommendation).
23//! let point = Wgs84::new(11.585, 48.137); // Munich
24//! let (nds_x, nds_y) = point.to_nds_coordinates();
25//!
26//! // Find the level-13 tile containing the point.
27//! let morton = MortonCode::from_nds_coordinates(nds_x, nds_y);
28//! let tile = PackedTileId::from_morton_and_level(morton, 13).unwrap();
29//!
30//! let sw = tile.south_west_corner();
31//! let east = tile.east_neighbour();
32//! ```
33
34pub mod bounding_box;
35pub mod morton;
36pub mod polygon;
37pub mod polygon_triangulation;
38pub mod tileid;
39pub mod vec2;
40pub mod wgs84;
41pub mod wgs84_aabb;
42pub mod wgs84_polygon;
43
44pub use bounding_box::NdsBoundingBox;
45pub use morton::MortonCode;
46pub use polygon::{Orientation, Polygon, PolygonType};
47pub use polygon_triangulation::PolygonTriangulation;
48pub use tileid::{
49    bounding_box_from_tile_ids, get_tile_ids_for_bounding_box, PackedTileId, TileIdError,
50};
51pub use vec2::Vec2;
52pub use wgs84::{
53    Wgs84, EARTH_RADIUS_IN_METERS, LAT_MAX, LAT_MIN, LAT_NDS_DELTA, LAT_NDS_DELTA_POW2, LON_MAX,
54    LON_MIN, LON_NDS_DELTA, LON_NDS_DELTA_POW2, METERS_PER_DEGREE,
55};
56pub use wgs84_aabb::Wgs84Aabb;
57pub use wgs84_polygon::Wgs84Polygon;