clipper.cr
Clipper for Crystal
require "clipper" provides copied, immutable Clipper::Paths over Clipper2 2.0.1. LibClipper is the low-level FFI; Paths exposes Boolean operations, polygon/polyline offsets and constrained triangulation without native pointers.
square = Clipper::Paths.new([[{0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}]])
expanded = square.offset(2, join: :miter)
ring = expanded.combine(square, :difference)
triangles = ring.triangulate
combine accepts intersection, union, difference or xor, and even-odd/nonzero/positive/negative winding. offset accepts join/end styles and world-unit arc tolerance. precision selects decimal quantization from -8 to 8 (default 6). Inputs are finite, copied and range-checked; native outputs are copied and freed before returning. to_a returns independent arrays. Failed operations raise Clipper::Error; invalid arguments raise ArgumentError. Empty Boolean results and collapsed offsets are ordinary empty paths. Triangulation requires already valid, nonintersecting polygon boundaries; Boolean normalization can prepare them first.
Build with make -C native; shards install runs this through the postinstall hook. A C++17 compiler, make, archive tool and C++ runtime are required. The vendored geometry implementation is unmodified upstream code. The small export translation unit contains exceptions at the FFI boundary. macOS arm64 is tested; other native targets require their own toolchain verification. This is not a claim of mobile or console packaging support.
Input/output limits protect Crystal allocations and numeric conversion; they are not a time or native-memory quota for Clipper2. Precision and flattening tolerance are independent choices. Coordinates after scaling are limited to 1e12, below Clipper2's documented degradation range.
See upstream provenance. The Crystal wrapper uses MIT; vendored Clipper2 uses the Boost Software License.
clipper.cr
- 0
- 0
- 0
- 1
- 0
- 1 day ago
- November 30, 2026
MIT License
Wed, 02 Dec 2026 02:09:30 GMT