Crates.io | i_overlay |
lib.rs | i_overlay |
version | 1.2.2 |
source | src |
created_at | 2023-08-28 08:44:18.582108 |
updated_at | 2024-07-13 10:34:58.071384 |
description | Boolean Operations for 2D Polygons: Supports intersection, union, difference, xor, and self-intersections for all polygon varieties. |
homepage | |
repository | https://github.com/iShape-Rust/iOverlay |
max_upload_size | |
id | 956703 |
size | 1,359,805 |
The iOverlay is a fast poly-bool library supporting main operations like union, intersection, difference, and xor, governed by either the even-odd or non-zero rule. This algorithm is based on Vatti clipping ideas but is an original implementation.
Try out iOverlay with an interactive demo:
Add the following to your Cargo.toml:
[dependencies]
i_float = "^1.0.0"
i_overlay = "^1.0.0"
Let's union two squares
let subj = [
F64Point::new(-10.0, -10.0),
F64Point::new(-10.0, 10.0),
F64Point::new(10.0, 10.0),
F64Point::new(10.0, -10.0),
];
let clip = [
F64Point::new(-5.0, -5.0),
F64Point::new(-5.0, 15.0),
F64Point::new(15.0, 15.0),
F64Point::new(15.0, -5.0),
];
let mut overlay = FloatOverlay::new();
overlay.add_path(&subj, ShapeType::Subject);
overlay.add_path(&clip, ShapeType::Clip);
let graph = overlay.build_graph(FillRule::NonZero);
let shapes = graph.extract_shapes(OverlayRule::Union);
println!("shapes count: {}", shapes.len());
if shapes.len() > 0 {
let contour = &shapes[0][0];
println!("shape 0 contour: ");
for p in contour {
let x = p.x;
let y = p.y;
println!("({}, {})", x, y);
}
}