diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-03 13:33:37 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-03 13:33:37 -0400 |
commit | 9e77f980e7704999ef0a1c1845d660bccb13ff8a (patch) | |
tree | 14ca0da5915e4382a7bcb15f7d0b241941c8291f /src/Utils.ts | |
parent | 1be63695875c9242fba43d580465e8765cf3991d (diff) | |
parent | 202e994515392892676f8f080852db1e32b8dbd3 (diff) |
Merge branch 'master' into nathan-starter
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index 3af057d82..23ae38bdb 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -3,6 +3,11 @@ import * as uuid from 'uuid'; export function clamp(n: number, lower: number, upper: number) { return Math.max(lower, Math.min(upper, n)); } + +export function ptDistance(p1: { x: number; y: number }, p2: { x: number; y: number }) { + return Math.sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2); +} + export namespace Utils { export function GuestID() { return '__guest__'; @@ -206,6 +211,11 @@ export type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; export type Predicate<K, V> = (entry: [K, V]) => boolean; +/** + * creates a list of numbers ordered from 0 to 'num' + * @param num range of numbers + * @returns list of values from 0 to num -1 + */ export function numberRange(num: number) { return num > 0 && num < 1000 ? Array.from(Array(num)).map((v, i) => i) : []; } |