diff --git a/src/context.ts b/src/context.ts index ed53e8b..1e1a645 100644 --- a/src/context.ts +++ b/src/context.ts @@ -304,7 +304,10 @@ export class Context { if (new_rgba[3] === 255) { for (let i = x; i < x + w; i++) { for (let j = y; j < y + h; j++) { - if (this.pixelInsideClip(i, j)) { + if ( + this.pixelInsideClip(i, j) && + this._bitmap._isValidCoords(i, j) + ) { this._bitmap.setPixelRGBA(i, j, this._fillColor as number); } } diff --git a/test/path.test.ts b/test/path.test.ts index fe0735f..cc9f6f3 100644 --- a/test/path.test.ts +++ b/test/path.test.ts @@ -23,6 +23,15 @@ describe("draw rect", () => { expect(image.getPixelRGBA(100, 100)).to.eq(WHITE); await save(image, "path/rect/fill_square-fillRect"); }); + it("fill rect partially outside of buffer", async () => { + c.fillStyle = "black"; + c.fillRect(100, 100, 200, 200); + expect(image.getPixelRGBA(0, 0)).to.eq(WHITE); + // expect(image.getPixelRGBA(11, 11)).to.eq(BLACK); + expect(image.getPixelRGBA(150, 150)).to.eq(BLACK); + // expect(image.getPixelRGBA(100, 100)).to.eq(WHITE); + await save(image, "path/rect/fill_outside-fillRect"); + }); it("fill square with lines", async () => { c.beginPath(); c.moveTo(10, 10);