UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

26 lines (25 loc) 1.72 kB
import { type AnyBooleanVecInstance, type AnyMatInstance, type AnyVec2Instance, type AnyVec3Instance, type AnyVec4Instance, type AnyVecInstance, type v2b, type v3b, type v4b } from './wgslTypes.ts'; type Vec = AnyVecInstance; type Mat = AnyMatInstance; type Algebraic = number | boolean | Vec | Mat; export type ToBool<T extends Algebraic> = T extends number | boolean ? boolean : T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : T extends AnyVec4Instance ? v4b : never; /** * Generalizes function of 1 to 3 arguments to work component-wise on vectors and matrices. * Assumes the types are already correct (in particular, that they have the same length), * and performs no additional checks. * The return type is the same as the first argument's type. */ export declare function generalizeFn<T extends Algebraic>(fn: (a: number) => number, args: [T]): T; export declare function generalizeFn<T extends Algebraic>(fn: (a: number, b: number) => number, args: [T, T]): T; export declare function generalizeFn<T extends Algebraic>(fn: (a: number, b: number, c: number) => number, args: [T, T, T]): T; /** * Analogous to `generalizeFn`, but the return type is a boolean vector instead. */ export declare function generalizeBoolFn<T extends Algebraic>(fn: (a: number, b: number) => boolean, args: [T, T]): ToBool<T>; export declare function generalizeBoolFn<T extends boolean | AnyBooleanVecInstance>(fn: (a: boolean, b: boolean) => boolean, args: [T, T]): ToBool<T>; /** * If one of the arguments is a vector and other is a number, * the number is up-cased to a vector. */ export declare function upCast<T extends number | Vec>(args: [T, T]): [Exclude<T, number>, Exclude<T, number>]; export {};