iOverlay

The i_overlay is a poly-bool library that supports main operations such as union, intersection, difference, xor, and self-intersection by the even-odd rule. This algorithm is based on Vatti clipping ideas but is an original implementation.

Demo

Try out iOverlay with an interactive demo. The demo covers operations like union, intersection, difference and exclusion

Features

Working Range and Precision

The i_overlay library operates within the following ranges and precision levels:

Extended Range: From -1,000,000 to 1,000,000 with a precision of 0.001. Recommended Range: From -100,000 to 100,000 with a precision of 0.01 for more accurate results. Utilizing the library within the recommended range ensures optimal accuracy in computations and is advised for most use cases.

Getting Started

Add the following to your Cargo.toml: [dependencies] i_float = "^0.1.0" i_shape = "^0.1.0" i_overlay = "^0.2.0"

Example

Here is a simple example that demonstrates how to use the iOverlay library for polygon union operations. ```rust use ifloat::fixvec::FixVec; use ioverlay::{layout::overlay::Overlay, fill::shapetype::ShapeType, bool::fill_rule::FillRule};

fn main() { let mut overlay = Overlay::new(1);

let subj = [
    FixVec::new_number(-10, -10),
    FixVec::new_number(-10,  10),
    FixVec::new_number( 10,  10),
    FixVec::new_number( 10, -10)
];

let clip = [
    FixVec::new_number(-5, -5),
    FixVec::new_number(-5, 15),
    FixVec::new_number(15, 15),
    FixVec::new_number(15, -5)
];

overlay.add_path(subj.to_vec(), ShapeType::SUBJECT);
overlay.add_path(clip.to_vec(), ShapeType::CLIP);

let graph = overlay.build_graph();

let shapes = graph.extract_shapes(FillRule::Union);

println!("shapes count: {}", shapes.len());

if shapes.len() > 0 {
    let contour = shapes[0].contour();
    println!("shape 0 contour: ");
    for p in contour {
        let x = p.x.float();
        let y = p.x.float();
        println!("({}, {})", x, y);
    }
}

} ```

Union

Difference

Intersection

Exclusion (xor)

Self-intersection