-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first part of porting libs/ code to typescript
- Loading branch information
Showing
41 changed files
with
448 additions
and
284 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'react' | ||
|
||
declare module 'react' { | ||
interface CSSProperties { | ||
[key: `--${string}`]: string | number | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,58 +1,32 @@ | ||
// maths.ts | ||
|
||
// Function type declarations | ||
type ClampFunction = (min: number, input: number, max: number) => number | ||
type MapRangeFunction = ( | ||
in_min: number, | ||
in_max: number, | ||
input: number, | ||
out_min: number, | ||
out_max: number | ||
) => number | ||
type LerpFunction = (start: number, end: number, amt: number) => number | ||
type TruncateFunction = (value: number, decimals: number) => number | ||
type ModuloFunction = (n: number, d: number) => number | ||
|
||
// Interface for the Maths object | ||
interface Maths { | ||
lerp: LerpFunction | ||
clamp: ClampFunction | ||
mapRange: MapRangeFunction | ||
truncate: TruncateFunction | ||
modulo: ModuloFunction | ||
} | ||
|
||
// Function implementations | ||
const clamp: ClampFunction = (min, input, max) => { | ||
function clamp(min: number, input: number, max: number) { | ||
return Math.max(min, Math.min(input, max)) | ||
} | ||
|
||
const mapRange: MapRangeFunction = ( | ||
in_min, | ||
in_max, | ||
input, | ||
out_min, | ||
out_max | ||
) => { | ||
return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min | ||
function mapRange( | ||
inMin: number, | ||
inMax: number, | ||
input: number, | ||
outMin: number, | ||
outMax: number | ||
) { | ||
return ((input - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin | ||
} | ||
|
||
const lerp: LerpFunction = (start, end, amt) => { | ||
return (1 - amt) * start + amt * end | ||
function lerp(start: number, end: number, amount: number) { | ||
return (1 - amount) * start + amount * end | ||
} | ||
|
||
const truncate: TruncateFunction = (value, decimals) => { | ||
function truncate(value: number, decimals: number) { | ||
return Number.parseFloat(value.toFixed(decimals)) | ||
} | ||
|
||
const modulo: ModuloFunction = (n, d) => { | ||
function modulo(n: number, d: number) { | ||
if (d === 0) return n | ||
if (d < 0) return Number.NaN | ||
return ((n % d) + d) % d | ||
} | ||
|
||
// Maths object | ||
const Maths: Maths = { lerp, clamp, mapRange, truncate, modulo } | ||
const Maths = { lerp, clamp, mapRange, truncate, modulo } | ||
|
||
export { clamp, lerp, mapRange, modulo, truncate } | ||
export default Maths |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.