Skip to main content

map_tile_toolkit/
error.rs

1//! The error type returned by the slicers and the [`Mosaic`](crate::Mosaic) combiner.
2//!
3//! This crate never panics on caller input: every operation that cannot proceed returns one of
4//! these variants instead. All coordinate math is checked, so out-of-range inputs are reported
5//! rather than overflowing or producing a wrong result.
6
7use thiserror::Error;
8
9use crate::TileId;
10
11/// Something the slicer or combiner cannot process. Returned in place of a panic or a silently-wrong
12/// result.
13#[derive(Debug, Clone, PartialEq, Eq, Error)]
14#[non_exhaustive]
15pub enum TileError {
16    /// The per-tile output resolution / tile side (`extent`) was zero, or larger than `i32::MAX`.
17    #[error("extent must be between 1 and {}", i32::MAX)]
18    InvalidExtent,
19
20    /// The `buffer` was too large for the tile size: it must be **strictly less than half** the
21    /// `extent`, so geometry near a tile edge spills into at most one neighboring tile per axis.
22    #[error("buffer must be strictly less than half the extent")]
23    BufferTooLarge,
24
25    /// A line (or a polygon feature) has more than `u32::MAX` vertices, rings or pieces — beyond the
26    /// `u32` offsets of the slicers' flat storage.
27    #[error("geometry too large: at most {} vertices are supported", u32::MAX)]
28    GeometryTooLarge,
29
30    /// The geometry reaches too many tiles to slice: its segments collectively touch more tiles than
31    /// the slicer's working-set bound of 2^25 tile visits per feature (a tile counts once per segment
32    /// touching it, and so does a tile row a segment crosses without touching any tile; tiles a
33    /// polygon merely covers are free). Far above any realistic feature, even a
34    /// world-spanning diagonal at z16, it guards time and memory against adversarial input.
35    #[error("geometry reaches too many tiles to slice")]
36    TooManyTiles,
37
38    /// Slicing one polygon feature would produce more vertices than the slicer allows (2^28). Valid
39    /// geometry stays far below that; only rings winding around tiles many times, or many overlapping
40    /// polygons, come close, and they are rejected rather than exhausting memory.
41    #[error("slicing the feature would produce too many vertices")]
42    OutputTooLarge,
43
44    /// Coordinate arithmetic overflowed `i32` — a coordinate or tile lies too close to the limits of
45    /// the representable range for the given `extent`/`buffer`.
46    #[error("coordinate arithmetic overflowed the i32 range")]
47    Overflow,
48
49    /// While combining tiles, the added tile disagreed with the already-added tiles on a
50    /// shared border segment (see [`Mosaic::add`](crate::Mosaic::add)). Ids are sorted and unique;
51    /// the mosaic is left unchanged.
52    #[error("tile conflicts with {} already-added tile(s)", .0.len())]
53    Conflict(Vec<TileId>),
54}