Skip to content

Commit

Permalink
feat(math): add minMax()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 24, 2023
1 parent 06b0e38 commit 76ca59d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/math/src/interval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FnN, FnN2, FnN3, FnN4, FnU3 } from "@thi.ng/api";
import type { FnN, FnN2, FnN3, FnN4, FnU2, FnU3 } from "@thi.ng/api";

/**
* Clamps value `x` to given closed interval.
Expand Down Expand Up @@ -37,6 +37,15 @@ export const clamp11: FnN = (x) => (x < -1 ? -1 : x > 1 ? 1 : x);
*/
export const clamp05: FnN = (x) => (x < 0 ? 0 : x > 0.5 ? 0.5 : x);

/**
* Returns 2-tuple of [min(x,y), max(x,y)].
*
* @param x
* @param y
*/
export const minMax: FnU2<number, [number, number]> = (x, y) =>
x < y ? [x, y] : [y, x];

/**
* Folds `x` back inside closed [min..max] interval. Also see
* {@link wrapOnce}.
Expand Down

0 comments on commit 76ca59d

Please sign in to comment.