From 07e80bf84759a48b46c764189846920d59ee98f1 Mon Sep 17 00:00:00 2001 From: munrocket Date: Wed, 2 Jun 2021 13:03:10 +0400 Subject: [PATCH] Optimize angle(v1, v2) --- src/vec3.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/vec3.js b/src/vec3.js index d4c72dd0..98262d3d 100644 --- a/src/vec3.js +++ b/src/vec3.js @@ -675,9 +675,7 @@ export function angle(a, b) { bx = b[0], by = b[1], bz = b[2], - mag1 = Math.sqrt(ax * ax + ay * ay + az * az), - mag2 = Math.sqrt(bx * bx + by * by + bz * bz), - mag = mag1 * mag2, + mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz)), cosine = mag && dot(a, b) / mag; return Math.acos(Math.min(Math.max(cosine, -1), 1)); }