earlygrey/shapedrawer

Possibility of implement a fillPath() method

Closed this issue · 4 comments

Hello! I'm wondering to know if, in this library, is viable to implement fill path behavior. For example, in standard Java we have the class Path2d (in float or double format) and we can easly choose between drawer.drawPath() and drawer.fillPath().

This should help a lot in some personal projects, once I saw that is very hard get a result for a filled custom shape in LibGDX.

I'll try to draft something here in my fork, anyway, let me know what do you think.

Thanks in advance!

Hey thanks for the interest! I'm not familiar with Path2d, but does that just draw the filled polygon defined by the path? If so, do the ShapeDrawer#filledPolygon do what you want?

Perhaps I could add a few filledPolygon methods that take in something like an Array of Vector2s? I'm not sure what structures you're using, but there are methods for Polygon objects and float[] arrays which define the vertices. So you can give it a list of points, and it will draw the filled polygon defined by them.

If that's not what you're after, just let me know!

In the case of using filledPolygon() what would vertices[] array be? Coordinates? Sorry for question this but I didn't got some time to experiment the code.

Anyway, my using approach is suggest something that draws any kind of segment between the path coordinates.

As you can see in the method sumary the path2D offers the way to draw lines, quadratic and/or Bezier curves. This is very good while creating a complex shape like this.

This implies that we need something to handle curves drawing in some point. What do you think, then?

The vertices[] array contains the consecutive ordered pairs of the x-y coordinates, it's in the docs. It's the same as the way most libgdx classes use it, so for example if you have points (0,0), (1,1) and (1,0) your array is [0,0,1,1,1,0].

There are already many classes in libgdx to calculate the points of curves and I have no plans to duplicate this in shape drawer, but perhaps in the future I could add some curve methods that use the libgdx classes. I'll have a think about what these would look like. Right now, since these are just drawn as lots of little straight lines, you should use the libgdx classes to calculate the points you would like and draw them using the methods that take a float[] or Polygon. Of course cache what you can. More info here.

I'm not completely sure what you mean by "something that draws any kind of segment between the path coordinates", but if you're talking about lines and not filled shapes there are many path() methods available. Otherwise for filled shapes it would be a matter of filling your float[] or Polygon with the vertices you calculate yourself.

I'll close this issue now, you can re-open if there's something specific you want to suggest.