Skip to content

Commit 1c248e6

Browse files
dmnsgnjwagner
authored andcommitted
feat: make sqrt constants
- performance: saves a few bytes when tested with terser - actually fix rollup annotation warning
1 parent d278637 commit 1c248e6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

simplex-noise.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ Better rank ordering method by Stefan Gustavson in 2012.
3030

3131
// these __PURE__ comments help uglifyjs with dead code removal
3232
//
33-
const F2 = 0.5 * (/*#__PURE__*/Math.sqrt(3.0) - 1.0);
34-
const G2 = (3.0 - /*#__PURE__*/Math.sqrt(3.0)) / 6.0;
33+
const SQRT3 = /*#__PURE__*/ Math.sqrt(3.0);
34+
const SQRT5 = /*#__PURE__*/ Math.sqrt(5.0);
35+
const F2 = 0.5 * (SQRT3 - 1.0);
36+
const G2 = (3.0 - SQRT3) / 6.0;
3537
const F3 = 1.0 / 3.0;
3638
const G3 = 1.0 / 6.0;
37-
const F4 = (/*#__PURE__*/Math.sqrt(5.0) - 1.0) / 4.0;
38-
const G4 = (5.0 - /*#__PURE__*/Math.sqrt(5.0)) / 20.0;
39+
const F4 = (SQRT5 - 1.0) / 4.0;
40+
const G4 = (5.0 - SQRT5) / 20.0;
3941

4042
// I'm really not sure why this | 0 (basically a coercion to int)
4143
// is making this faster but I get ~5 million ops/sec more on the

0 commit comments

Comments
 (0)