A high-performance 2D polygon clipping library - Rust port of the Clipper2 C++ library by Angus Johnson.
Clipper2 is a comprehensive 2D polygon clipping library that performs intersection, union, difference and XOR boolean operations on polygons. It also performs polygon offsetting/inflating and path simplification.
This Rust port aims to provide identical functionality and performance characteristics to the original C++ implementation while leveraging Rust's memory safety and modern language features.
- Boolean Operations: Intersection, Union, Difference, XOR
- Polygon Offsetting: Inflate/deflate polygons with various join types
- Rectangle Clipping: High-performance rectangular clipping
- Path Simplification: Reduce polygon complexity while preserving shape
- Multiple Precision: Support for both integer (
i64) and floating-point (f64) coordinates - PolyTree Structure: Hierarchical representation of polygon relationships
- Memory Safe: All the benefits of Rust's ownership system
🚧 This project is currently under active development 🚧
Following a ZERO TOLERANCE POLICY for incomplete implementations:
- ✅ Core Types: Basic geometric types and operations
- ✅ Version Info: Library version constants
- 🚧 Clipping Engine: Main boolean operations engine
- 🚧 Polygon Offsetting: Path inflation/deflation
- 🚧 Rectangle Clipping: Optimized rectangular clipping
- 🚧 Minkowski Operations: Advanced geometric operations
- 🚧 Export Utilities: Data export functionality
Progress: 2/857 total items implemented (790 functions + 56 classes + 11 enums)
See IMPLEMENTATION_CHECKLIST.md for detailed progress tracking.
Add this to your Cargo.toml:
[dependencies]
clipper2 = "0.1.0"use clipper2::*;
// Create some polygons
let subject = vec![
Point64::new(100, 100),
Point64::new(300, 100),
Point64::new(300, 300),
Point64::new(100, 300),
];
let clip = vec![
Point64::new(200, 200),
Point64::new(400, 200),
Point64::new(400, 400),
Point64::new(200, 400),
];
// Note: Full clipping operations not yet implemented
// This is a preview of the planned APIThe library supports two coordinate systems:
Path64/Paths64: Integer coordinates usingi64PathD/PathsD: Floating-point coordinates usingf64
// Points
pub struct Point64 { pub x: i64, pub y: i64 }
pub struct PointD { pub x: f64, pub y: f64 }
// Paths (polygons)
pub type Path64 = Vec<Point64>;
pub type PathD = Vec<PointD>;
pub type Paths64 = Vec<Path64>;
pub type PathsD = Vec<PathD>;
// Rectangles
pub struct Rect64 { /* ... */ }
pub struct RectD { /* ... */ }- Rust 1.70+ (2021 edition)
- Git
git clone https://github.com/your-username/clipper2-rust.git
cd clipper2-rust
cargo buildcargo testcargo benchThis project follows extremely strict implementation rules:
- No Stubs: Every function must be complete and production-ready
- Dependency-Driven: Functions only implemented when all dependencies are ready
- Comprehensive Testing: 100% test coverage with exact C++ behavioral matching
- Database Tracking: All progress tracked in SQLite database
- Zero Tolerance: No compromises, shortcuts, or "good enough" implementations
See CLAUDE.md for complete implementation guidelines.
Target performance characteristics:
- Match or exceed C++ Clipper2 performance
- Leverage Rust's zero-cost abstractions
- Optimize for modern CPU architectures
- Comprehensive benchmarking against reference implementation
Contributions are welcome! However, please note the strict implementation requirements:
- All functions must be complete - no
todo!()or stubs - Comprehensive tests required before marking functions as implemented
- Must exactly match C++ behavioral semantics
- Follow the dependency-driven implementation order
See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the Boost Software License 1.0 - see the LICENSE file for details.
This is the same license as the original Clipper2 C++ library.
- Angus Johnson - Original Clipper2 C++ library author
- Clipper2 Community - Testing, feedback, and contributions to the original library
- Clipper2 C++ - Original implementation
- clipper-sys - Rust bindings to C++ Clipper
- geo - Rust geospatial primitives and algorithms
For the latest implementation status and progress updates, see:
- PROJECT_STATUS.md - Current implementation status
- Issues - Bug reports and feature requests
- Discussions - Community discussions
Note: This library is currently in early development. APIs may change before 1.0 release.