8 lines
174 B
JavaScript
8 lines
174 B
JavaScript
|
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};
|
||
|
}
|