CavalierContours icon indicating copy to clipboard operation
CavalierContours copied to clipboard

Support clipping open polylines

Open karl-nilsson opened this issue 4 years ago • 8 comments

Thanks for the excellent library!

Currently, boolean operations only support closed polylines: https://github.com/jbuckmccready/CavalierContours/blob/b955785cc3db9689704d6135cbb60177fab835bb/include/cavc/polylinecombine.hpp#L415

It would be useful to support boolean operations between both open and closed polylines, as clipper does: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/ClipType.htm

karl-nilsson avatar Dec 17 '20 06:12 karl-nilsson

I think that would be fairly easy to implement based on how the algorithm works. I don't have an exact time line for this but I'll maybe take a look.

I'm actually in the process of rewriting the library in rust (with intent to create a clean C API wrapper, more elaborate documentation of the algorithms and code, guaranteed memory safety, and further performance optimizations around memory allocations). If I don't get around to supporting open polylines here then it will definitely be a target for the rust release.

I have some plans for supporting more around boolean operations. Specifically I want to implement support for generic shapes defined by a graph of positive and negative area polylines (negative areas represent holes) so that you can easily and efficiently do boolean operations between donut like shapes or even many layers deep of nested shapes (e.g. donuts within donuts). Right now to perform that type of operation you have to repeatedly perform boolean ops between only two polylines which is messy and inefficient.

jbuckmccready avatar Dec 17 '20 10:12 jbuckmccready

Will you continue to develop the c++ library?

karl-nilsson avatar Dec 17 '20 19:12 karl-nilsson

I'll fix any major bugs and accept pull requests for fixes/improvements. I don't know yet how much I will build out the API/features in C++. If I get frustrated/disillusioned with rust in the process of working on it then I may abandon it and stay with C++ (so far I'm really enjoying rust, so I don't see that as being likely but I have only rewritten the spatial index so far).

My hope/goal is to make the documentation of the algorithms themselves and quality of the code really good so that it becomes easy to port to any language. If I succeed in that goal then it may be easy for me/anyone to add any additions I make in rust to the C++.

I am also hoping to make an effective C API so it's accessible across the broadest range of languages via C FFI.

jbuckmccready avatar Dec 17 '20 20:12 jbuckmccready

For your particular request you could implement that behavior by finding the intersects between the open polyline and closed polyline, slice the open polyline at the intersect points and keep/discard (depending on the boolean op) any slices that are outside/inside of the closed polyline (can be tested using the winding number).

That is how I would implement it in the combine function.

jbuckmccready avatar Dec 17 '20 20:12 jbuckmccready

@jbuckmccready i'm leaving this here just in case of something other than "Rust" www.dlang.org it has worth a look. it's almost C with the same performance, OOP and modern programming, available for all major OS. you will find it very familiar. also you can directly run C libraries without a change just click "Show examples" below at home page and see how beautiful it is.

ASHIT-AXAR avatar Feb 04 '21 11:02 ASHIT-AXAR

I think that would be fairly easy to implement based on how the algorithm works. I don't have an exact time line for this but I'll maybe take a look.

I'm actually in the process of rewriting the library in rust (with intent to create a clean C API wrapper, more elaborate documentation of the algorithms and code, guaranteed memory safety, and further performance optimizations around memory allocations). If I don't get around to supporting open polylines here then it will definitely be a target for the rust release.

I have some plans for supporting more around boolean operations. Specifically I want to implement support for generic shapes defined by a graph of positive and negative area polylines (negative areas represent holes) so that you can easily and efficiently do boolean operations between donut like shapes or even many layers deep of nested shapes (e.g. donuts within donuts). Right now to perform that type of operation you have to repeatedly perform boolean ops between only two polylines which is messy and inefficient.

Any update on the implementation of the rust portation? Do you have a repo for this and need people to help?

Nevsden avatar Mar 03 '21 13:03 Nevsden

@Nevsden The rust project is progressing and I plan to make the repo public sometime this week or beginning of next. There is a lot that is still under construction, but I'll make the repo available for people to contribute and see progress. My plan is to make more documentation within the repo on the project architecture and algorithms to facilitate contribution.

jbuckmccready avatar Mar 03 '21 19:03 jbuckmccready

@Nevsden The repository is now up here and under construction.

jbuckmccready avatar Mar 07 '21 01:03 jbuckmccready