Remove duplicate code

This commit is contained in:
2026-10-13 11:57:43 -03:00
parent dfc6a6d77b
commit 5165698fe3
50 changed files with 307 additions and 812 deletions
+14
View File
@@ -38,6 +38,20 @@ export function distance_point_rectangle(px: number, py: number, sqx: number, sq
return Math.sqrt(dx * dx + dy * dy);
}
// -pi to pi
export function wrap_angle(angle: number) {
angle %= Math.PI * 2;
if (angle >= Math.PI) angle -= Math.PI * 2;
if (angle < -Math.PI) angle += Math.PI * 2;
return angle;
}
// the hex sha-256 of bytes
export async function sha256(bytes: Uint8Array<ArrayBuffer>): Promise<string> {
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
}
export function distance_point_point(ax: number, ay: number, az: number, bx: number, by: number, bz: number) {
const dx = ax - bx;
const dy = ay - by;