mirror of
https://github.com/photonstorm/phaser
synced 2024-12-20 18:14:13 +00:00
25 lines
348 B
JavaScript
25 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;
|
||
|
|
||
|
}
|