silphius/app/util/math.js

8 lines
174 B
JavaScript
Raw Normal View History

2024-07-02 08:05:36 -05:00
export function normalizeVector({x, y}) {
if (0 === y && 0 === x) {
return {x: 0, y: 0};
}
const k = 1 / Math.sqrt(x * x + y * y);
return {x: x * k, y: y * k};
}