fillPolygon off by 1 (both C and Lua)

,

In both x and y directions, fillPolygon falls 1 pixel short of what I would expect.

However, this is does not apply to all vertices. It seems the vertices that are at the right and bottom of the shape are affected.

When I use fillPolygon, I expect the coordinates are "inclusive", ie. when the coordinate (8,8) is included, I expect the 9th pixel from the top left to be set, just as it actually is for drawLine and drawPolygon.

The - very wasteful - workaround seems to be to call both fill and drawPolygon functions with the same parameters*. I expect the result of fillPolygon to be equal to "fill+draw" in the screenshot and reproduction sample code.

Affects both Lua and C APIs

*drawPolygon not available in C

image

function playdate:update()
    gfx.setPattern({ 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF })
    gfx.fillRect(0, 0, 400, 240)
    gfx.setColor(gfx.kColorBlack)

    gfx.drawText("Draw", 80, 10)
    gfx.drawPolygon(
            80, 80,
            120, 80,
            120, 120,
            80, 120,
            80, 80
    )

    gfx.drawText("Fill", 160, 10)
    gfx.fillPolygon(
            160, 80,
            200, 80,
            200, 120,
            160, 120,
            160, 80
    )

    gfx.drawText("Fill+Draw", 240, 10)
    gfx.fillPolygon(
            240, 80,
            280, 80,
            280, 120,
            240, 120,
            240, 80
    )
    gfx.drawPolygon(
            240, 80,
            280, 80,
            280, 120,
            240, 120,
            240, 80
    )

    -- more complex shape
    gfx.fillPolygon(
            8, 144,
            200, 136,
            248, 144,
            248, 152,
            200, 144,
            8, 152,
            8, 144
    )
end
4 Likes

@dave could I get some triage for this? Bug or expected?