Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concave polygon fill and the plot widget #513

Open
jbuckmccready opened this issue Jun 25, 2021 · 4 comments
Open

Concave polygon fill and the plot widget #513

jbuckmccready opened this issue Jun 25, 2021 · 4 comments

Comments

@jbuckmccready
Copy link

From what I can tell by reading the docs/playing with the code currently only convex polygon filling is supported. Is supporting concave (or possibly even complex polygons) a future goal for egui or is that outside the scope of the project? I think something like Lyon could be used for tessellation, and I saw the Mesh type so I can probably combine the two, but I didn't see support for the mesh type with the plot widget.

I really like the egui API in general and the recent improvements to the plot widget are very nice. I would like to be able to add concave polygons to plots. I am currently using wasm + html/js to create the cavalier contours web demo (web demo link here), but the egui API looks very nice and keeps everything in Rust.

I looked briefly at the code and I see the plot widget structs use the shape types/rendering under the hood. One option I see is just adding generic mesh object support to the plot widget (kind of a low level interface for the widget), another possibility is building out support for concave polygons in general, any thoughts/plans already around this?

@EmbersArc
Copy link
Contributor

I touched on this in #471 but haven't gotten a response yet:

I also have an implementation of the ear-clipping algorithm lying around that can be used to tessellate non-convex polygons. It's relatively few lines of code, but it's not the most efficient algorithm with O(n²) time complexity. I could add this to the plotting library, but maybe it's something for egui in general?

More efficient algorithms are exponentially more difficult to implement, so going with lyon's faster algorithms may be a good option as well.

@emilk
Copy link
Owner

emilk commented Apr 16, 2022

The problem with lyon is that it doesn't support feathering (what epaint uses to smooth edges) AFAIK. Creating a convex filling algorithm that also supports feathering seems like a big task, but I agree it would be very nice to have.

There is another alternative: turn off feathering and turn on MSAA to get smoother edges. This is already supported on eframe native, and it could be added to egui_web too. Then we could just use lyon directly to produce epaint::Meshes.

@TYPEmber
Copy link

TYPEmber commented Sep 5, 2022

Maybe we could decompose one concave polygon into some convex polygons, and store them.
And I can implement it if possible.

@techninja1008
Copy link

Just came across this same issue - has any work towards this been done? My use case in particular is filling the area underneath a line plot.

I'm currently implementing a workaround but ideally this would be something that egui supports natively - let me know if there's anything I can do to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants