typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
129 lines (128 loc) • 6.99 kB
TypeScript
import { type AnyBooleanVecInstance, type AnyFloatVecInstance, type AnyNumericVecInstance, type AnyVec2Instance, type AnyVec3Instance, type AnyVecInstance, type AnyWgslData, type v2b, type v3b, type v4b } from '../data/wgslTypes.ts';
/**
* Checks whether `lhs == rhs` on all components.
* Equivalent to `all(eq(lhs, rhs))`.
* @example
* allEq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns false
* allEq(vec3u(0, 1, 2), vec3u(0, 1, 2)) // returns true
*/
export declare const allEq: import("../types.ts").DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => boolean)>;
/**
* Checks **component-wise** whether `lhs == rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `all`, or use `allEq`.
* @example
* eq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(true, false)
* eq(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, false)
* all(eq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1))) // returns true
* allEq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1)) // returns true
*/
export declare const eq: import("../types.ts").DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
/**
* Checks **component-wise** whether `lhs != rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `any`.
* @example
* ne(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(false, true)
* ne(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, true)
* any(ne(vec4i(4, 3, 2, 1), vec4i(4, 2, 2, 1))) // returns true
*/
export declare const ne: import("../types.ts").DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
/**
* Checks **component-wise** whether `lhs < rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
* @example
* lt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, true)
* lt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, false)
* all(lt(vec4i(1, 2, 3, 4), vec4i(2, 3, 4, 5))) // returns true
*/
export declare const lt: import("../types.ts").DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
/**
* Checks **component-wise** whether `lhs <= rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
* @example
* le(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, true)
* le(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, true, false)
* all(le(vec4i(1, 2, 3, 4), vec4i(2, 3, 3, 5))) // returns true
*/
export declare const le: import("../types.ts").DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<import("../data/generalizeFn.ts").ToBool<T>>)>;
/**
* Checks **component-wise** whether `lhs > rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
* @example
* gt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, false)
* gt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, false, true)
* all(gt(vec4i(2, 3, 4, 5), vec4i(1, 2, 3, 4))) // returns true
*/
export declare const gt: import("../types.ts").DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<import("../data/generalizeFn.ts").ToBool<T>>)>;
/**
* Checks **component-wise** whether `lhs >= rhs`.
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
* @example
* ge(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, false)
* ge(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, true)
* all(ge(vec4i(2, 2, 4, 5), vec4i(1, 2, 3, 4))) // returns true
*/
export declare const ge: import("../types.ts").DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
declare function cpuNot(value: boolean): boolean;
declare function cpuNot<T extends AnyBooleanVecInstance>(value: T): T;
/**
* Returns the logical negation of the given value.
* For booleans returns `!value`.
* For boolean vectors, returns **component-wise** `!value`.
* @example
* not(true) // returns false
* not(vec3b(true, true, false)) // returns vec3b(false, false, true)
*/
export declare const not: import("../types.ts").DualFn<typeof cpuNot>;
/**
* Returns **component-wise** logical `or` result.
* @example
* or(vec2b(false, true), vec2b(false, false)) // returns vec2b(false, true)
* or(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(true, true, false)
*/
export declare const or: import("../types.ts").DualFn<(<T extends AnyBooleanVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
/**
* Returns **component-wise** logical `and` result.
* @example
* and(vec2b(false, true), vec2b(true, true)) // returns vec2b(false, true)
* and(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(false, true, false)
*/
export declare const and: import("../types.ts").DualFn<(<T extends AnyBooleanVecInstance>(lhs: T, rhs: T) => import("../data/generalizeFn.ts").ToBool<T>)>;
/**
* Returns `true` if each component of `value` is true.
* @example
* all(vec2b(false, true)) // returns false
* all(vec3b(true, true, true)) // returns true
*/
export declare const all: import("../types.ts").DualFn<(value: AnyBooleanVecInstance) => boolean>;
/**
* Returns `true` if any component of `value` is true.
* @example
* any(vec2b(false, true)) // returns true
* any(vec3b(false, false, false)) // returns false
*/
export declare const any: import("../types.ts").DualFn<(value: AnyBooleanVecInstance) => boolean>;
/**
* Checks whether the given elements differ by at most the `precision` value.
* Checks all elements of `lhs` and `rhs` if arguments are vectors.
* @example
* isCloseTo(0, 0.1) // returns false
* isCloseTo(vec3f(0, 0, 0), vec3f(0.002, -0.009, 0)) // returns true
*
* @param {number} precision argument that specifies the maximum allowed difference, 0.01 by default.
*/
export declare const isCloseTo: import("../types.ts").DualFn<(<T extends AnyFloatVecInstance | number>(lhs: T, rhs: T, precision?: number) => boolean)>;
declare function cpuSelect(f: boolean, t: boolean, cond: boolean): boolean;
declare function cpuSelect(f: number, t: number, cond: boolean): number;
declare function cpuSelect<T extends AnyVecInstance>(f: T, t: T, cond: boolean | (T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)): T;
export declare const validSelectBranchTypes: AnyWgslData[];
/**
* Returns `t` if `cond` is `true`, and `f` otherwise.
* Component-wise if `cond` is a vector.
* @example
* select(1, 2, false) // returns 1
* select(1, 2, true) // returns 2
* select(vec2i(1, 2), vec2i(3, 4), true) // returns vec2i(3, 4)
* select(vec2i(1, 2), vec2i(3, 4), vec2b(false, true)) // returns vec2i(1, 4)
*/
export declare const select: import("../types.ts").DualFn<typeof cpuSelect>;
export {};