Bug with playdate.graphics.fillPolygon and setDrawOffset

I noticed a strange behavior with the polygon drawing with an offset.

I have a sky made out of polygons filled with a pattern. I use the setDrawOffset to move the camera, and change at once all the positions where the polygons (clouds) are displayed.

If I draw this polygon, it's fine, until the horizontal offset goes under -70
So

gfx.setDrawOffset(-30, 0)
gfx.fillPolygon(0, 0, 9, -3, 16, -3, 20, -5, 26, -2, 38, -5, 43, -5, 46, -3, 49, -5, 51, -11, 63, -11, 69, -5, 99, 0)

The polygon is correctly drawn, partially clipped by the left side of the screen

But with this offset:

gfx.setDrawOffset(-70, 0)
None of the polygon is drawn, even though about 30 pixels should still be on screen

I think it's due to a problem with two much distance between 2 vertices.
If I add one vertice between the 2 extreme vertices in the horizontal axis:
Like this:
gfx.fillPolygon(0, 0, 9, -3, 16, -3, 20, -5, 26, -2, 38, -5, 43, -5, 46, -3, 49, -5, 51, -11, 63, -11, 69, -5, 99, 0, 50, 0)

then the polygon is drawn correctly even with an offset inferior to -70 pixels.

So it looks like if a polygon has a side that is too long, then if it's clipped above a certain value by the offset, the whole polygon is skipped, instead of being properly clipped.

1 Like

aha, I see the problem: we weren't including the last point when we're computing the bounding box, so the draw function thinks the poly is off-screen. Adding that extra point causes (99,0) to be included in the bounding box and hides the problem. Nice catch! I've got that fixed for the next update. :slight_smile:

Awesome! Thanks for the fix :slight_smile:

Here's a more dramatic case: gfx.fillPolygon(-10, 0, -10, 240, 410, 120) should be a big triangle, but doesn't draw at all :flushed:

Yeah it’s really that last point. I understand now. I was looking over my code again and again, since I do some clipping on my own, and couldn’t make heads or tails of it. It’s only after stripping down everything bare bones that I realized the draw function was acting up. In the meantime I’ll just add a point to every polygon.
Thanks again for checking this so quickly :slight_smile:

1 Like