UNPKG

@thi.ng/shader-ast-stdlib

Version:

Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast

30 lines (29 loc) 789 B
import { F, V2 } from "@thi.ng/shader-ast/api/types"; import { defn, ret } from "@thi.ng/shader-ast/ast/function"; import { bool } from "@thi.ng/shader-ast/ast/lit"; import { add } from "@thi.ng/shader-ast/ast/ops"; import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle"; import { sym } from "@thi.ng/shader-ast/ast/sym"; import { distance, min, step } from "@thi.ng/shader-ast/builtin/math"; const isPointInCircle = defn( "bool", null, [V2, V2, F], (p, pos, radius) => [ret(bool(step(distance(p, pos), radius)))] ); const isPointInRect = defn( "bool", null, [V2, V2, V2], (p, pos, size) => { let q; return [ q = sym(min(step(pos, p), step(p, add(pos, size)))), ret(bool(min($x(q), $y(q)))) ]; } ); export { isPointInCircle, isPointInRect };