diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-17 03:46:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-17 03:46:01 +0200 |
commit | eabe0cff44921ea43f31340e12f20159ba5c381e (patch) | |
tree | d1dc24a189f3cf4ec13bcbab40977b3d8068f194 /test-client/util.ts | |
parent | 181d1c97e01f66b4a9415eec118d82cbce87346b (diff) | |
download | hurrycurry-eabe0cff44921ea43f31340e12f20159ba5c381e.tar hurrycurry-eabe0cff44921ea43f31340e12f20159ba5c381e.tar.bz2 hurrycurry-eabe0cff44921ea43f31340e12f20159ba5c381e.tar.zst |
can move items around. rejoin persistance seems okk
Diffstat (limited to 'test-client/util.ts')
-rw-r--r-- | test-client/util.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/test-client/util.ts b/test-client/util.ts index 99f0c013..6febac37 100644 --- a/test-client/util.ts +++ b/test-client/util.ts @@ -2,9 +2,22 @@ export interface V2 { x: number, y: number } export function length(p: V2): number { return Math.sqrt(p.x * p.x + p.y * p.y) } export function normalize_mut(p: V2) { const l = length(p); if (l == 0) return; p.x /= l; p.y /= l } export function normalize(p: V2): V2 { let l = length(p); if (l == 0) l = 1; return { x: p.x / l, y: p.y / l } } -export function lerp_v2_mut(current: V2, target: V2, dt: number) { +export function lerp_exp(current: number, target: number, dt: number): number { + return target + (current - target) * Math.exp(-dt) +} +export function lerp_v2(a: V2, b: V2, t: number): V2 { + return { + x: a.x * (1 - t) + b.x * t, + y: a.y * (1 - t) + b.y * t, + } +} +export function lerp_exp_v2_mut(current: V2, target: V2, dt: number) { current.x = target.x + (current.x - target.x) * Math.exp(-dt) current.y = target.y + (current.y - target.y) * Math.exp(-dt) } export function floor_v2(p: V2): V2 { return { x: Math.floor(p.x), y: Math.floor(p.y) } } export function ceil_v2(p: V2): V2 { return { x: Math.ceil(p.x), y: Math.ceil(p.y) } } +export function add_v2(p: V2, o: V2 | number) { + if (typeof o == "number") return { x: p.x + o, y: p.y + o } + else return { x: p.x + o.x, y: p.y + o.y } +}
\ No newline at end of file |