rectutils
Common rectangle algorithms for Rust: clipping, quadtree, and rect packing
Repository Health
Technical Analysis
rectutils is a small Rust crate that collects common algorithms for working with rectangles, including clipping, transformation, quadtree spatial partitioning, and rectangle bin packing. It defines a generic Rect<T> type parameterized over any numeric type, along with helper structures for building bounding rectangles from points.
Built on nalgebra and num-traits, the crate forbids unsafe code and is used within the Fyrox game engine ecosystem for tasks such as UI layout, texture atlas packing, and spatial queries. It is distributed under the permissive MIT license.
What You Get
- A generic
Rect<T>type over any numeric scalar - Clipping and matrix transformation helpers for rectangles
- A quadtree module for spatial partitioning and queries
- A rectangle bin-packing module for atlas and layout building
Common Use Cases
- Packing sprites or glyphs into a texture atlas
- Spatially partitioning 2D scenes with a quadtree
- Computing bounding rectangles from a series of points
- Clipping and transforming UI or game rectangles
Under The Hood
Architecture - The crate centers on a generic Rect<T> struct (position and size as nalgebra Vector2<T>) with a Number trait blanket-implemented for numeric types. Functionality is split into a pack module for rectangle bin packing and a quadtree module for spatial partitioning, plus an optional-bounds RectOpt helper for accumulating bounding rects.
Tech Stack - Pure Rust built on nalgebra for vectors and matrices and num-traits for generic numerics; it forbids unsafe code and is published as the rectutils crate on crates.io.
Code Quality - A compact, focused codebase that enforces #![warn(missing_docs)] and #![forbid(unsafe_code)], split cleanly across lib.rs, pack.rs, and quadtree.rs; it is a young crate with a small contributor base.
API Design - The API is straightforward and generic: a single Rect<T> type with intuitive methods and two self-contained algorithm modules, making it easy to drop into graphics or game code without ceremony.