A pure Ruby implementation of the Clipper2 polygon clipping and offsetting library.
This library is a Ruby port of clipper2-rust, which is itself a Rust port of the original Clipper2 C++ library by Angus Johnson. This project wouldn't be possible without both of these excellent libraries.
Licensed under the Boost Software License 1.0, the same license as the original Clipper2 library.
- Boolean polygon clipping (intersection, union, difference, XOR)
- Polygon and polyline offsetting with miter, round, and square joins
- Minkowski sum and difference
- Rect clipping
Add to your Gemfile:
gem "clipper2", github: "sideshow/clipper2-ruby"require "clipper2"
# Create paths
subject = [
Clipper2::Point64.new(x: 0, y: 0),
Clipper2::Point64.new(x: 100, y: 0),
Clipper2::Point64.new(x: 100, y: 100),
Clipper2::Point64.new(x: 0, y: 100)
]
# Union operation
result = Clipper2.union_subjects64([subject], Clipper2::FillRule::NON_ZERO)
# Path offsetting (e.g., wall thickness)
inflated = Clipper2.inflate_paths64(
[path],
delta: 60,
join_type: Clipper2::JoinType::MITER,
end_type: Clipper2::EndType::SQUARE,
miter_limit: 3.0
)