GithubHelp home page GithubHelp logo

ishape-rust / ioverlay Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 498 KB

Boolean Operations for 2D Polygons: Supports intersection, union, difference, xor, and self-intersections for all polygon varieties.

Home Page: https://ishape-rust.github.io/iShape-js/

License: MIT License

Rust 100.00%
poly-bool polygon-clipping vatti-clipper clipping union clipper polygon xor boolean-operations difference

ioverlay's Introduction

iOverlay

Balloons

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:

Features

  • Operations: union, intersection, difference, and exclusion.
  • Polygons: with holes, self-intersections, and multiple paths.
  • Simplification: removes degenerate vertices and merges collinear edges.
  • Fill Rules: even-odd and non-zero.

Getting Started

Add the following to your Cargo.toml:

[dependencies]
i_float = "^1.0.0"
i_overlay = "^1.0.0"

Hello world

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);
    }
}

Overlay Rules

Union, A or B

Union

Intersection, A and B

Intersection

Difference, B - A

Difference

Exclusion, A xor B

Exclusion

ioverlay's People

Contributors

lagradost avatar nailxsharipov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lagradost

ioverlay's Issues

Docs?

I get that you have some interactive docs in https://ishape-rust.github.io/iShape-js/overlay/stars_demo.html but right now you have ZERO comments in your code. When I use a lib it would be nice to at least know just a line or two what a function does or what an enum is. Like wth is ShapeType?? and what is the difference between Subject and Clip??

A simple /** explain here */ or /// before the enum or function would make it much easier to follow when coding as you get that as an editor hint. It does not need to be an essay, but just something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.