Skip to content

Commit

Permalink
feat(shader-ast-stdlib): add fitNorm()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Oct 25, 2023
1 parent 800318f commit d5f21c5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/shader-ast-stdlib/src/math/fit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ export const fit = <T extends PrimTerm>(
b: T,
c: T,
d: T
): Term<TermType<T>> => mix(c, d, div(sub(x, a), sub(b, a)));
): Term<TermType<T>> => mix(c, d, fitNorm(x, a, b));

/**
* Scales value `x` from closed interval [a,b] to closed [0,1] interval. No
* clamping performed.
*
* @param x
* @param a
* @param b
* @returns
*/
export const fitNorm = <T extends PrimTerm>(
x: T,
a: T,
b: T
): Term<TermType<T>> => div(sub(x, a), sub(b, a));

/**
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
Expand Down

0 comments on commit d5f21c5

Please sign in to comment.