diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-18 19:36:36 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:21:22 +0200 |
commit | 48934ff63ee14d4759eda36512af87361dd915dd (patch) | |
tree | f7a80115eacfee7b6871040a87f5fb0087098ea8 /test-client/util.ts | |
parent | 6ec47d729509db83eaeb6a9d855ce2483d70f227 (diff) | |
download | hurrycurry-48934ff63ee14d4759eda36512af87361dd915dd.tar hurrycurry-48934ff63ee14d4759eda36512af87361dd915dd.tar.bz2 hurrycurry-48934ff63ee14d4759eda36512af87361dd915dd.tar.zst |
remodel game.
Diffstat (limited to 'test-client/util.ts')
-rw-r--r-- | test-client/util.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test-client/util.ts b/test-client/util.ts index baebc61e..23679974 100644 --- a/test-client/util.ts +++ b/test-client/util.ts @@ -21,3 +21,16 @@ 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 } } + +export function aabb_circle_distance( + min_x: number, + min_y: number, + max_x: number, + max_y: number, + px: number, + py: number +): number { + const dx = px - Math.max(min_x, Math.min(max_x, px)) + const dy = py - Math.max(min_y, Math.min(max_y, py)) + return Math.sqrt(dx * dx + dy * dy) +} |