Skip to content

Commit

Permalink
perf(vectors): update standardize()
Browse files Browse the repository at this point in the history
- avoid final multiply if mag=0
  • Loading branch information
postspectacular committed Aug 30, 2021
1 parent 3817d65 commit e87b979
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vectors/src/standardize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ import { mulN } from "./muln";
export const standardize = (out: Vec | null, a: ReadonlyVec) => {
out = center(out, a);
const m = magSq(out);
return mulN(null, out, m > 0 ? 1 / Math.sqrt(m / (out.length - 1)) : 0);
return m > 0 ? mulN(null, out, 1 / Math.sqrt(m / (out.length - 1))) : out;
};

0 comments on commit e87b979

Please sign in to comment.