Skip to content

Commit

Permalink
feat(pixel): add/update buffer factory fns
Browse files Browse the repository at this point in the history
- add fn overrides to simplify userland API
  • Loading branch information
postspectacular committed Feb 28, 2021
1 parent b98d05d commit ba38e13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/pixel/src/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ import { clampRegion, ensureChannel, ensureSize, prepRegions } from "./utils";
* @param fmt -
* @param pixels -
*/
export const floatBuffer = (
export function floatBuffer(
w: number,
h: number,
fmt: FloatFormat | FloatFormatSpec,
pixels?: Float32Array
) => new FloatBuffer(w, h, fmt, pixels);
): FloatBuffer;
export function floatBuffer(
src: PackedBuffer,
fmt: FloatFormat | FloatFormatSpec
): FloatBuffer;
export function floatBuffer(...args: any[]) {
return args[0] instanceof PackedBuffer
? // @ts-ignore
FloatBuffer.fromPacked(...args)
: // @ts-ignore
new FloatBuffer(...args);
}

export class FloatBuffer
implements
Expand Down
14 changes: 12 additions & 2 deletions packages/pixel/src/packed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,22 @@ import {
* @param fmt -
* @param pixels -
*/
export const packedBuffer = (
export function packedBuffer(
w: number,
h: number,
fmt: PackedFormat | PackedFormatSpec,
pixels?: UIntArray
) => new PackedBuffer(w, h, fmt, pixels);
): PackedBuffer;
export function packedBuffer(
src: PackedBuffer,
fmt: PackedFormat | PackedFormatSpec
): PackedBuffer;
export function packedBuffer(...args: any[]) {
return args[0] instanceof PackedBuffer
? args[0].as(args[1])
: // @ts-ignore
new PackedBuffer(...args);
}

/**
* @deprecated use {@link packedBuffer} instead.
Expand Down

0 comments on commit ba38e13

Please sign in to comment.