Closed Hantsouski closed 9 months ago
Hi @Hantsouski - thank you so much for this! Can only look through over the next couple of days, please also ignore the nagging from the Codeclimate bot... :)
@Hantsouski - It's only a small thing, but since all of these functions have the same signature, I think it'd be a great opportunity to use a higher-order function here to deduplicate some of the boilerplate, something like:
import type { FnU } from "@thi.ng/api";
import type { FloatSym } from "@thi.ng/shader-ast";
/**
* Higher order function to wrap a given easing function body as proper
* shader-ast function
*/
const defEasing = (fn: FnU<FloatSym>) => defn(F, null, [F], fn);
...we could then rewrite/simplify all of the fns like so:
export const easeInSine = defEasing((x) => [ret(sub(FLOAT1, cos(mul(x, HALF_PI))))]);
etc.
good suggestion, I will update the PR
Thank you & much appreciated! Hope it's not too much effort...
Made updates. But had to add explicit return type for a fn:
const defEasing = (fn: Fn<FloatSym, ScopeBody>) => defn(F, null, [F], fn);
Because defn has a problem of function overload. I'll show on screenshots:
With explicit return type works fine:
Yeah, so sorry, that was my bad (forgot about the type!) - Fn<FloatSym,ScopeBody>
works, but could also have used the alias FnBody1<"float">
:
Please don't worry about updating it, it's fine as is... You already did enough here (thank you again!) and I might update it quickly myself (just to help with any (hypothetical) future refactoring of shader-ast in general)
🎉
Adding easing functions based on the discussion in issues.