$ show hfutrell/BezierKit
BezierKit is a comprehensive Swift library for constructing, manipulating, and computing with BΓ©zier curves and paths. It provides linear, quadratic, and cubic curve types, along with advanced operations including curve-curve intersection (via monotone subdivision with implicitization fallback), offsetting, boolean operations (union, subtract, intersect), bounding box computation, nearest-point projection, arc length via Legendre-Gauss quadrature, and self-intersection removal. The library is designed for cross-platform use (macOS, iOS, Linux, WebAssembly) and includes a macOS demo application for interactive testing. The codebase demonstrates strong software engineering practices: protocol-oriented design, extensive unit tests (including adversarial edge cases), performance optimizations (concrete type overloads, stack allocation, manual memory management in hot paths), and a clean separation of concerns. While pre-release (semver < 1.0) with some known numerical edge cases documented as expected failures, the library is production-ready for vector graphics, CAD, and computational geometry applications.
The LLM identified 5 files worth highlighting for reuse:
Defines generic BernsteinPolynomial types (degree 0 through 9) with value evaluation, derivative, splitting, and root-finding conformance. These are self-contained, type-safe implementations of Bernstein basis polynomials that can be extracted and reused in any Swift project requiring polynomial arithmetic or BΓ©zier curve mathematics.
A generic bounding volume hierarchy (BVH) for fast overlap queries on axis-aligned bounding boxes. Uses a recursive subdivision strategy and is parameterized over element type. Could be extracted for use in collision detection, spatial indexing, or any domain requiring efficient bounding box intersection tests.
Provides comprehensive vector arithmetic extensions for CGPoint: addition, subtraction, scalar multiplication/division, dot product, cross product, length, normalization, perpendicular, and angle computation. These are pure math operations with no internal dependencies, making them trivially reusable in any Swift project needing 2D vector operations.
Implements an UnfairLock wrapper for thread-safe lazy property initialization. Uses os_unfair_lock on Apple platforms and a fallback for Linux/WASI. This is a small, self-contained concurrency utility that can be extracted for any Swift project requiring performant, reentrant locking for lazy computation.
Defines core value types used throughout the library: Subcurve (curve with parameter range), Intersection (curve intersection with parameter values), IndexedPathLocation, IndexedPathComponentLocation, PathComponentRange, and BoundingBox. These are lightweight, well-designed structs that encapsulate geometric concepts and could be reused in any computational geometry project.