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 has more than `u16::MAX` vertices, or the geometry has more than `u16::MAX` lines —
26    /// beyond what the slicer's compact indexing supports.
27    #[error(
28        "polyline too large: at most {0} lines, and {0} vertices per line, are supported",
29        u16::MAX
30    )]
31    PolylineTooLarge,
32
33    /// The geometry reaches too many tiles to slice: it spans more than `i16::MAX` tiles from its
34    /// first vertex on an axis, or its segments would collectively require examining more candidate
35    /// tiles than the slicer's working-set bound.
36    #[error("polyline reaches too many tiles to slice")]
37    TooManyTiles,
38
39    /// Coordinate arithmetic overflowed `i32` — a coordinate or tile lies too close to the limits of
40    /// the representable range for the given `extent`/`buffer`.
41    #[error("coordinate arithmetic overflowed the i32 range")]
42    Overflow,
43
44    /// While combining tiles, the added tile disagreed with the already-added tiles on a
45    /// shared border segment (see [`Mosaic::add`](crate::Mosaic::add)). Ids are sorted and unique;
46    /// the mosaic is left unchanged.
47    #[error("tile conflicts with {} already-added tile(s)", .0.len())]
48    Conflict(Vec<TileId>),
49}