map_tile_toolkit/error.rs
1//! The error type returned by the [`Slicer`](crate::Slicer) and the [`Mosaic`](crate::Mosaic) combiners.
2//!
3//! This crate never panics on caller input: every operation that cannot proceed returns one of
4//! these variants instead. Out-of-range inputs are reported rather than overflowing or producing a
5//! wrong result: coordinate math is checked, or runs on values proven in range up front.
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 `extent + buffer` was
17 /// larger than `i32::MAX`.
18 #[error("extent must be between 1 and {} minus the buffer", i32::MAX)]
19 InvalidExtent,
20
21 /// The `buffer` was too large for the tile size: it must be **strictly less than half** the
22 /// `extent`, so geometry near a tile edge spills into at most one neighboring tile per axis.
23 #[error("buffer must be strictly less than half the extent")]
24 BufferTooLarge,
25
26 /// A polygon has more than `u32::MAX` rings or edges, or one of its pieces more than `u32::MAX`
27 /// vertices — beyond the `u32` indices the slicer keeps.
28 #[error(
29 "geometry too large: at most {} rings or edges are supported",
30 u32::MAX
31 )]
32 GeometryTooLarge,
33
34 /// Coordinate arithmetic overflowed `i32` — a coordinate or tile lies too close to the limits of
35 /// the representable range for the given `extent`/`buffer`.
36 #[error("coordinate arithmetic overflowed the i32 range")]
37 Overflow,
38
39 /// While combining tiles, the added tile disagreed with the already-added tiles on a
40 /// shared border segment (see [`Mosaic::add`](crate::Mosaic::add)). Ids are sorted and unique;
41 /// the mosaic is left unchanged.
42 #[error("tile conflicts with {} already-added tile(s)", .0.len())]
43 Conflict(Vec<TileId>),
44}