A high-performance pure Go port of Clipper2, the industry-standard polygon clipping and offsetting library. Go Clipper2 provides robust geometric operations with 64-bit integer precision, eliminating floating-point numerical errors common in computational geometry.
- π Pure Go Implementation: Zero C/C++ dependencies for production use
- π― Complete API: All Clipper2 operations including boolean ops, offsetting, and clipping
- π§ͺ Comprehensive Testing: Property-based testing with different cases
- π¦ Easy Integration: Simple Go module with clean, idiomatic API
- Go 1.23 or later
go get github.com/bolom009/go-clipper2
package main
import (
"fmt"
goclipper2 "github.com/bolom009/go-clipper2"
)
func main() {
// Define two overlapping rectangles
var (
subject = goclipper2.Paths64{
{{0, 0}, {100, 0}, {100, 100}, {0, 100}},
}
clip = goclipper2.Paths64{
{{50, 50}, {150, 50}, {150, 150}, {50, 150}},
}
)
// wrapped method booleanOp (simplify usage of lib)
unionResults := goclipper2.UnionWithClipPaths64(subject, clip, goclipper2.NonZero)
fmt.Printf("Union area: %v\n", unionResults)
// booleanOp
unionResults = goclipper2.BooleanOpPaths64(goclipper2.Union, subject, clip, goclipper2.NonZero)
fmt.Printf("Union area: %v\n", unionResults)
/*
goclipper2.UnionPaths64(...)
goclipper2.UnionWithClipPaths64(...)
goclipper2.IntersectWithClipPaths64(...)
goclipper2.DifferenceWithClipPaths64(...)
goclipper2.XorWithClipPaths64(...)
goclipper2.UnionWithClipPathsD(...)
...
*/
}| Feature | Status |
|---|---|
| Boolean Operations {64,D} | β |
| Union64, UnionD | β |
| Intersect64, IntersectD | β |
| Difference64, DifferenceD | β |
| Xor64, XorD | β |
| Polygon Offsetting | β |
| Rectangle Clipping | β |
| Area Calculation | β |
| Orientation Detection | β |
| Path Reversal | β |
| Minkowski Operations | β |
| PolyTree, PolyPath {64, D} | β |
| ZCallback | β |
Legend: β Implemented, β Not implemented, π§ In progress
- Use integer coordinates when possible (more robust than float64)
- For simple rectangular clipping, use
RectClip64instead of boolean operations - Pre-simplify complex polygons before operations
- Consider polygon orientation for optimal performance
This project is licensed under the Boost Software License 1.0, the same as the original Clipper2 library. See LICENSE for details.