Skip to content

Commit

Permalink
feat(shader-ast-stdlib): update cossin(), sincos(), add opt. scale fa…
Browse files Browse the repository at this point in the history
…ctor arg
  • Loading branch information
postspectacular committed Mar 5, 2024
1 parent 7a20ae9 commit e3e8979
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/shader-ast-stdlib/src/math/sincos.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import type { FloatTerm } from "@thi.ng/shader-ast";
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
import { mul } from "@thi.ng/shader-ast/ast/ops";
import { cos, sin } from "@thi.ng/shader-ast/builtin/math";

/**
* Inline function. Returns vec2(sin(x), cos(x)).
* Inline function. Returns vec2(sin(x), cos(x)), optionally scaled by `r`
*
* @param x -
* @param r -
*/
export const sincos = (x: FloatTerm) => vec2(sin(x), cos(x));
export const sincos = (x: FloatTerm, r?: FloatTerm | number) => {
const res = vec2(sin(x), cos(x));
return r != undefined ? mul(res, r) : res;
};

/**
* Inline function. Returns vec2(cos(x), sin(x)).
* Inline function. Returns vec2(cos(x), sin(x)), optionally scaled by `r`.
*
* @param x -
* @param r -
*/
export const cossin = (x: FloatTerm) => vec2(cos(x), sin(x));
export const cossin = (x: FloatTerm, r?: FloatTerm | number) => {
const res = vec2(cos(x), sin(x));
return r != undefined ? mul(res, r) : res;
};

0 comments on commit e3e8979

Please sign in to comment.