generated from ryanatkn/fuz_template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
248 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
/** | ||
* Does nothing when called. | ||
*/ | ||
export const noop: (...args: any[]) => any = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
|
||
/** | ||
* Async function that returns a resolved promise. | ||
*/ | ||
export const noop_async: (...args: any[]) => Promise<any> = () => resolved; | ||
|
||
/** | ||
* A singleton resolved `Promise`. | ||
*/ | ||
export const resolved = Promise.resolve(); | ||
|
||
/** | ||
* Returns the first arg. | ||
*/ | ||
export const identity = <T>(t: T): T => t; | ||
|
||
export type Lazy<T> = () => T; | ||
|
||
/** | ||
* Returns the result of calling `value` if it's a function, | ||
* otherwise it's like the `identity` function and passes it through. | ||
*/ | ||
export const lazy = <T>(value: T | Lazy<T>): T => | ||
typeof value === 'function' ? (value as any)() : value; | ||
typeof value === 'function' ? (value as any)() : value; // TODO rename? `call_if_function` something? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,91 @@ | ||
/** | ||
* Returns `n` bounded to `min` and `max`. | ||
*/ | ||
export const clamp = (n: number, min: number, max: number): number => | ||
Math.min(Math.max(n, min), max); | ||
|
||
/** | ||
* Linear interpolation between `a` and `b` by `amount`. | ||
*/ | ||
export const lerp = (a: number, b: number, amount: number): number => (1 - amount) * a + amount * b; | ||
|
||
/** | ||
* Returns a number clamped between `min` and `max`. | ||
*/ | ||
export const round = (n: number, decimals: number): number => { | ||
const mult = 10 ** decimals; | ||
return Math.round(n * mult) / mult; | ||
}; | ||
|
||
// golden ratio constants, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
/** | ||
* golden ratio/mean constants, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR = 1.618033988749895; | ||
/** | ||
* golden ratio/mean constants, `1/GR`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_i = 0.6180339887498948; | ||
/** | ||
* golden ratio/mean constants, `GR**2`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_2 = 2.618033988749895; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**2)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_2i = 0.38196601125010515; | ||
/** | ||
* golden ratio/mean constants, `GR**3`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_3 = 4.23606797749979; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**3)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_3i = 0.2360679774997897; | ||
/** | ||
* golden ratio/mean constants, `GR**4`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_4 = 6.854101966249686; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**4)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_4i = 0.14589803375031543; | ||
/** | ||
* golden ratio/mean constants, `GR**5`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_5 = 11.090169943749476; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**5)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_5i = 0.09016994374947422; | ||
/** | ||
* golden ratio/mean constants, `GR**6`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_6 = 17.944271909999163; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**6)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_6i = 0.0557280900008412; | ||
/** | ||
* golden ratio/mean constants, `GR**7`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_7 = 29.03444185374864; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**7)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_7i = 0.03444185374863302; | ||
/** | ||
* golden ratio/mean constants, `GR**8`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_8 = 46.978713763747805; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**8)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_8i = 0.02128623625220818; | ||
/** | ||
* golden ratio/mean constants, `GR**9`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_9 = 76.01315561749645; | ||
/** | ||
* golden ratio/mean constants, `1/(GR**9)`, useful for scaling: https://wikipedia.org/wiki/Golden_ratio | ||
*/ | ||
export const GR_9i = 0.013155617496424835; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.