GithubHelp home page GithubHelp logo

ishape-rust / ioverlay Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 2.0 673 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 People

Contributors

lagradost avatar nailxsharipov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ioverlay's Issues

Issue with calculation of `union_rect` in `FloatOverlay::build_graph_with_solver` when `clip_paths` is empty

I found a issue when using ShapeType::Subject in FloatOverlay and would like to report it.

I added only ShapeType::Subject paths for FloatOverlay and tried to do graph.extract_shapes with OverlayRule::Subject, but the calculation does not seem to be correct.

overlay.add_paths(&shape, ShapeType::Subject);  
let graph = overlay.build_graph(FillRule::NonZero);
let shapes = graph.extract_shapes(OverlayRule::Subject);

In the library code, src/core/float_overlay.rs calculates union_rect from subj_rect and clip_rect, but there seems to be a problem in this part.
When subj_rect and clip_rect are created with F64Rect::with_shape, if empty paths are inserted, rects with -f64::MAX min and max values are created.
Calculating union_rect based on these all -f64::MAX rects will result in an incorrect rect, and since PointAdapter is calculated based on it, the process will be incorrect.

To fix the above problem, it seems that if self.subj_paths or self.clip_paths is empty, it is necessary to create a PointAdapter by calculating the rect with only the other one.

More to the point, it might be better to return Result Err if build_graph is called with both self.subj_paths and self.clip_paths empty.

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.

Output interpretation

It isn't fully clear to me how to interpret the output of the algorithm. It's a Vec<Vec<Vec<F64Point>>>, and I understand it represents a set of polygons, that can have holes. I am not familiar with the convention for representing holes though. Is the following assumption correct:

  • The outer Vec represents a set of shapes
  • Each shape Vec represents a collection of polygons, where the first polygon is the outer boundary, and all subsequent polygons are holes in this boundary
  • Each polygon Vec represents a collection of points, where every two consecutive points (cyclically) make up the boundary edge of the polygon

I think it would be worth being very eplicit about this in the docs/comments, for people that are not familiar with the conventions.

But it's worth mentioning that overall this library looks really great!

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.