aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts10
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) : [];
}