PistonDevelopers / conrod

An easy-to-use, 2D GUI library written entirely in Rust.
Other
3.35k stars 296 forks source link

Can't easily and efficiently draw concave polygons #721

Open trishume opened 8 years ago

trishume commented 8 years ago

I'm trying to write a visualization application with a disk tree graph that looks like DaisyDisk which requires buttons shaped like arc segments.

I tried implementing a custom button widget rendered with a polygon, but unfortunately it wasn't clearly documented either by Conrod or Piston that polygon means convex polygon. So I spent a bunch of time generating point lists for arcs for polygons, only to find they didn't render correctly because arc segments are concave. Instead of closing between the last point and the first it renders the convex hull of the point list.

The only way I can think of to work around this is to render tens of thousands of Polygon widgets which just contain triangles. This sounds slow and bad but if it isn't let me know. It's at least harder to generate a list of triangles for an arc rather than a list of points, but not that hard.

It would be great if either there was some way to directly render concave polygons, but even a half-measure like a widget for rendering a whole bunch of triangles directly would be okay. Ideally for my case but not other people's cases would be a primitive for rendering arc segments.

I'm interested in contributing if there's something a newbie to Conrod could do to solve this, but I'd appreciate some feedback on how best to solve this problem before I do anything.

screen shot 2016-05-08 at 4 27 19 pm screen shot 2016-05-08 at 4 35 26 pm

@bvssvni @mitchmindtree

trishume commented 8 years ago

It looks like a good way to implement this might be to add a flag to Polygon for convexity (or a new primitive) that renders with draw_tri instead of draw in graphics.rs. That or just always use draw_tri and take a small (or large?) perf hit on convex polygons. Either way it should be clear in the documentation what it does.

See https://github.com/PistonDevelopers/graphics/blob/26d74ebfd7dfcfcc76278a1afccd66d2d247d0b5/src/polygon.rs#L43

sunjay commented 6 years ago

Hi, I'm running into this as well. Did you find a way to work around it? Is draw_tri the solution? I tried it but I wasn't successful in getting concave shapes to be filled correctly.