mirror of
https://github.com/photonstorm/phaser
synced 2024-12-25 20:43:26 +00:00
24 lines
348 B
JavaScript
24 lines
348 B
JavaScript
let vec2 = Float32Array;
|
|
|
|
export default function (a, dst = new vec2(2)) {
|
|
|
|
const x = a[0];
|
|
const y = a[1];
|
|
const lsq = x * x + y * y;
|
|
|
|
if (lsq > 0)
|
|
{
|
|
const lr = 1 / Math.sqrt(lsq);
|
|
|
|
dst[0] = x * lr;
|
|
dst[1] = y * lr;
|
|
}
|
|
else
|
|
{
|
|
dst[0] = 0;
|
|
dst[1] = 0;
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|