Remove duplicate code
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user