Skip to content

Commit

Permalink
feat(pixel): update getRegion() return type
Browse files Browse the repository at this point in the history
BREAKING CHANGE: update getRegion() to return undefined
if result region < 1 pixel

- add size checks to impls in IntBuffer/FloatBuffer
  • Loading branch information
postspectacular committed Nov 12, 2023
1 parent 86ced05 commit 6c22953
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/pixel/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export interface IPixelBuffer<T extends TypedArray = TypedArray, P = any>
y: number,
width: number,
height: number
): IPixelBuffer<T, P>;
): IPixelBuffer<T, P> | undefined;
}

export interface IBlit<T extends IPixelBuffer> {
Expand Down
1 change: 1 addition & 0 deletions packages/pixel/src/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export class FloatBuffer
this.width,
this.height
);
if (w < 1 || h < 1) return;
return this.blit(new FloatBuffer(w, h, this.format), {
sx,
sy,
Expand Down
5 changes: 3 additions & 2 deletions packages/pixel/src/int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export class IntBuffer
return 2;
}

as(fmt: IntFormat) {
return this.getRegion(0, 0, this.width, this.height, fmt);
as(fmt: IntFormat): IntBuffer {
return this.getRegion(0, 0, this.width, this.height, fmt)!;
}

copy() {
Expand Down Expand Up @@ -326,6 +326,7 @@ export class IntBuffer
this.width,
this.height
);
if (w < 1 || h < 1) return;
return this.blit(new IntBuffer(w, h, fmt || this.format), {
sx,
sy,
Expand Down

0 comments on commit 6c22953

Please sign in to comment.