map-tile-toolkit 0.2.0

Clip integer polylines and polygons into per-tile pieces on a simple tile grid
Documentation
//! The error type returned by the slicers and the [`Mosaic`](crate::Mosaic) combiner.
//!
//! This crate never panics on caller input: every operation that cannot proceed returns one of
//! these variants instead. All coordinate math is checked, so out-of-range inputs are reported
//! rather than overflowing or producing a wrong result.

use thiserror::Error;

use crate::TileId;

/// Something the slicer or combiner cannot process. Returned in place of a panic or a silently-wrong
/// result.
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum TileError {
    /// The per-tile output resolution / tile side (`extent`) was zero, or larger than `i32::MAX`.
    #[error("extent must be between 1 and {}", i32::MAX)]
    InvalidExtent,

    /// The `buffer` was too large for the tile size: it must be **strictly less than half** the
    /// `extent`, so geometry near a tile edge spills into at most one neighboring tile per axis.
    #[error("buffer must be strictly less than half the extent")]
    BufferTooLarge,

    /// A line (or a polygon feature) has more than `u32::MAX` vertices, rings or pieces — beyond the
    /// `u32` offsets of the slicers' flat storage.
    #[error("geometry too large: at most {} vertices are supported", u32::MAX)]
    GeometryTooLarge,

    /// The geometry reaches too many tiles to slice: its segments collectively touch more tiles than
    /// the slicer's working-set bound of 2^25 tile visits per feature (a tile counts once per segment
    /// touching it, and so does a tile row a segment crosses without touching any tile; tiles a
    /// polygon merely covers are free). Far above any realistic feature, even a
    /// world-spanning diagonal at z16, it guards time and memory against adversarial input.
    #[error("geometry reaches too many tiles to slice")]
    TooManyTiles,

    /// Slicing one polygon feature would produce more vertices than the slicer allows (2^28). Valid
    /// geometry stays far below that; only rings winding around tiles many times, or many overlapping
    /// polygons, come close, and they are rejected rather than exhausting memory.
    #[error("slicing the feature would produce too many vertices")]
    OutputTooLarge,

    /// Coordinate arithmetic overflowed `i32` — a coordinate or tile lies too close to the limits of
    /// the representable range for the given `extent`/`buffer`.
    #[error("coordinate arithmetic overflowed the i32 range")]
    Overflow,

    /// While combining tiles, the added tile disagreed with the already-added tiles on a
    /// shared border segment (see [`Mosaic::add`](crate::Mosaic::add)). Ids are sorted and unique;
    /// the mosaic is left unchanged.
    #[error("tile conflicts with {} already-added tile(s)", .0.len())]
    Conflict(Vec<TileId>),
}