Refactor (1)

This commit is contained in:
2025-09-19 18:54:12 +09:00
committed by cannorin
parent 6b15542c40
commit c3b1bf39a4
26 changed files with 1684 additions and 105 deletions

View File

@@ -0,0 +1,28 @@
export type Vector = {
x: number;
y: number;
};
export type Radian = number;
export const degree = (value: number) => ((value / 180) * Math.PI) as Radian;
export const sub = (v1: Vector, v2: Vector) =>
({
x: v1.x - v2.x,
y: v1.y - v2.y,
}) as Vector;
export const add = (v1: Vector, v2: Vector) =>
({
x: v1.x + v2.x,
y: v1.y + v2.y,
}) as Vector;
export const theta = ({ x, y }: Vector) => Math.atan2(y, x) as Radian;
export const rotate = ({ x, y }: Vector, rad: Radian) =>
({
x: x * Math.cos(rad) - y * Math.sin(rad),
y: x * Math.sin(rad) + y * Math.cos(rad),
}) as Vector;