$ show linebender/kurbo
Kurbo is a Rust library for 2D vector geometry, primarily used in the Linebender ecosystem (e.g., the Vello rendering engine). It provides core geometric types such as BezPath, PathSeg, curves (cubic, quadratic, arc), affine transforms, and advanced algorithms for offset, stroke expansion, curve fitting, flattening, and polynomial root-finding. The architecture is a Cargo workspace with two crates: `kurbo` (main geometry library) and `polycool` (polynomial utilities). Key entry points include the `BezPath` builder, `ParamCurve` traits for generic curve operations, and high-level functions like `expand_path`, `stroke`, and `fit_to_bezpath`. External dependencies are optional (serde, euclid, mint, schemars) and the library supports no_std via the `libm` feature. Data flows involve constructing paths from elements, applying transformations, and then processing them for rendering or analysis. The codebase demonstrates strong numerical methods, trait-based abstractions, and careful handling of edge cases, making it a high-quality foundation for vector graphics applications.
The LLM identified 3 files worth highlighting for reuse:
Provides robust, numerically stable solvers for cubic, quadratic, and quartic equations. These functions are self-contained (no internal dependencies) and can be extracted into any Rust project requiring polynomial root-finding. The implementation uses techniques like solving depressed cubics and handling degenerate cases, demonstrating non-obvious numerical craftsmanship.
Implements 2D affine transformations (rotation, scaling, translation, skew) as a 3x3 matrix with efficient multiplication and inversion. While it depends on `Vec2` and `Point` types, those are minimal and could be extracted alongside. The module is well-structured, supports composition, and is reusable as a standalone geometry utility for any 2D graphics or game engine.
Implements cubic polynomial root-finding using analytical formulas and numerical fallbacks, with careful handling of edge cases (e.g., multiple roots, near-zero coefficients). This is part of the `polycool` subcrate, which is already a separate library with its own `Cargo.toml`. It can be reused independently for any polynomial arithmetic needs, and demonstrates high-quality numerical programming.