`drawPolygon` is closing polygons

, ,

I'm creating an open polygon like so:

gfx.drawPolygon(table.unpack({10, 10, 60, 10, 60, 60}))

The documentation states:

If the polygon’s first and last points are coincident, the polygon will be considered closed.

I assumed that this meant the juxtaposition would be true, that non-coincident end points would leave it open, however the polygon is being drawn closed.

Is this my misunderstanding or is this a bug?

image

1 Like

I think you're probably right that there is a bug lurking there, as this code:

local poly = playdate.geometry.polygon.new(10, 10, 60, 10, 60, 60)
gfx.drawPolygon(poly)

will produce:

image

I'll file a bug, but you should be able to use that workaround for now!

1 Like

The points in the polygon are generated dynamically, so that won't be a workaround for me.

I fell back on generating a series of lines.

You can still create an intermediate polygon object from these dynamically generated points, no?

1 Like

What do you mean by intermediate polygon? If that different to just drawing lines?

Something like this?

local poly = playdate.geometry.polygon.new(table.unpack({10, 10, 60, 10, 60, 60}))
gfx.drawPolygon(poly)
1 Like

I see what you mean, I'll try that.

1 Like

Yeah, my understanding from @dan was that the workaround is creating a polygon object and drawing that, instead of passing individual points directly to drawPolygon.