iOverlay
The iOverlay library provides high-performance boolean operations on polygons, including union, intersection, difference, and xor. It is designed for applications that require precise polygon operations, such as computer graphics, CAD systems, and geographical information systems (GIS). By supporting both integer (i32) and floating-point (f32, f64) APIs, iOverlay offers flexibility and precision across diverse use cases.
For detailed performance benchmarks, check out the Performance Comparison
Documentation
Try out iOverlay with an interactive demo:
Features
- Boolean Operations: union, intersection, difference, and exclusion.
- String Line Operations: clip and slice.
- Polygons: with holes, self-intersections, and multiple contours.
- Simplification: removes degenerate vertices and merges collinear edges.
- Fill Rules: even-odd, non-zero, positive and negative.
- Data Types: Supports i32, f32, and f64 APIs.
Getting Started
Add the following to your Cargo.toml:
[dependencies]
i_overlay = "^1.8"
Simple Example
Here's an example of performing a union operation between two polygons:
// Define the subject "O"
let subj = ;
// Define the clip "-"
let clip = ;
let result = subj.overlay;
println!;
The result is a vec of shapes:
[
// first shape
[
// main contour
[
[0.0, 2.0], [0.0, 3.0], [1.0, 3.0], [1.0, 5.0], [4.0, 5.0], [4.0, 3.0], [5.0, 3.0], [5.0, 2.0], [4.0, 2.0], [4.0, 0.0], [1.0, 0.0], [1.0, 2.0]
],
// first hole
[
[2.0, 2.0], [2.0, 1.0], [3.0, 1.0], [3.0, 2.0]
],
// second hole
[
[2.0, 4.0], [2.0, 3.0], [3.0, 3.0], [3.0, 4.0]
]
]
// ... other shapes if present
]
The overlay function returns a Vec<Shapes>:
Vec<Shape>: A collection of shapes.Shape: Represents a shape made up of:Vec<Contour>: A list of contours.- The first contour is the outer boundary (clockwise), and subsequent contours represent holes (counterclockwise).
Contour: A sequence of points (Vec<P: FloatPointCompatible>) forming a closed contour.
Note: Outer boundary contours have a clockwise order, and holes have a counterclockwise order. More information about contours.
Custom Point
iOverlay allows users to define custom point types, as long as they implement the FloatPointCompatible trait.
let subj = ;
let clip = ;
let result = subj.overlay;
println!;
Slicing a Polygon by a String Line
let polygon = ;
let slicing_line = ;
let result = polygon.slice_by;
println!;
Clip a String Lines by a Polygon
let polygon = ;
let string_line = ;
let clip_rule = ClipRule ;
let result = string_line.clip_by;
println!;