PistonDevelopers / graphics

A library for 2D graphics, written in Rust, that works with multiple back-ends
MIT License
479 stars 55 forks source link

Draw path #1089

Open sunjay opened 7 years ago

sunjay commented 7 years ago

Hi, Is there a way to draw multiple points that are collected by lines? The polygon method fills the shape. What can I use to draw the entire path as a set of lines? Drawing each line of the path individually is extremely slow at the moment.

Thanks!

bvssvni commented 7 years ago

This library doesn't do triangulation of paths in general, only convex polygons. Perhaps you could use https://github.com/nical/lyon for paths?

sunjay commented 7 years ago

@bvssvni Thanks! Can I use that with piston?

bvssvni commented 7 years ago

I have not tried it yet, but believe it should work.

sunjay commented 7 years ago

Would it be possible to add support for simple paths without bringing in something like lyon? All I need is something like line that accepts more than two points. It could be like polygon except the color shades the line instead of filling the area within the points. Is that a hard thing to add? (I'm genuinely asking because I don't know how much effort that would take.)

bvssvni commented 7 years ago

Could use this method https://github.com/PistonDevelopers/graphics/blob/master/src/triangulation.rs#L493. It generates triangles by emitting 2 points.

The work is to get the edge cases right. Depending on how the corner bends, you want to "lock" one point and move the other.

This could be added to the Polygon struct, just like Rectangle that has border settings.

sunjay commented 7 years ago

If I'm understanding correctly, triangles would need to be closed. Is there a way to render a path of points that wouldn't connect end-to-end?

bvssvni commented 7 years ago

I don't think the quad stream function requires closing.