Skip to content

Commit

Permalink
refactor(shader-ast-stdlib): update cross2() as non-inline fn
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 5, 2022
1 parent 07bd445 commit 59d631a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/shader-ast-stdlib/src/math/cross2.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { FloatTerm, Vec2Term } from "@thi.ng/shader-ast";
import type { FloatTerm } from "@thi.ng/shader-ast";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";

/**
* Inline function. Computes 2D "cross product" of given vectors. See
* Computes 2D "cross product" of given vectors. Also see
* {@link crossC2}.
*
* @param a -
* @param b -
*/
export const cross2 = (a: Vec2Term, b: Vec2Term) =>
crossC2($x(a), $y(a), $x(b), $y(b));
export const cross2 = defn("float", "cross2", ["vec2", "vec2"], (a, b) => [
ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b)))),
]);

/**
* Inline function. Computes 2D cross product of given individual
Expand Down
3 changes: 2 additions & 1 deletion packages/shader-ast-stdlib/src/sdf/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const sdfUnion = (a: FloatTerm, ...terms: FloatTerm[]) =>

/**
* SDF shape union for vec2 terms, i.e. the common form where the X coord
* defines distance and Y an object or material ID.
* defines distance and Y an object or material ID. Returns `a` or `b`,
* depending whose x-coord (dist) is smaller.
*
* @param a -
* @param b -
Expand Down

0 comments on commit 59d631a

Please sign in to comment.