Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #5

Merged
merged 26 commits into from
Feb 5, 2024
Merged

V2 #5

merged 26 commits into from
Feb 5, 2024

Conversation

dmnsgn
Copy link
Member

@dmnsgn dmnsgn commented Mar 7, 2022

Changes:

  • feat: convert require to import and module.exports to exports
  • test: add missing test dependency tape and pex-geom
  • docs: convert test to esm
  • build: update dependencies (new seedrandom api and new breaking change simplex noise version)
  • refactor: move everything to index.js (Move Random namespace inside index #2)
  • feat: use Number.MAX_SAFE_INTEGER
  • test: update for recent pex-math and pex-geom
  • perf: remove intermediary const declaration in vec3InAABB
  • feat: use default argument values
  • feat: add FBM

TBD:

Closes #2
Closes #4

- convert require to import and module.exports to exports
- replace var/let with const
- use console.assert over assert
- add missing test dependency tape pex-geom
- remove Math.seedrandom and use new seedrandom global option

Closes #2

BREAKING CHANGE: switch to type module
- test with latest geom and math
@vorg
Copy link
Member

vorg commented Mar 7, 2022

About the random prng Replied on the issue #4

@github-pages github-pages bot temporarily deployed to github-pages May 5, 2022 14:38 Inactive
@github-pages github-pages bot temporarily deployed to github-pages May 5, 2022 14:42 Inactive
@github-pages github-pages bot temporarily deployed to github-pages May 5, 2022 15:23 Inactive
@github-pages github-pages bot temporarily deployed to github-pages July 6, 2022 12:56 Inactive
@github-pages github-pages bot temporarily deployed to github-pages August 1, 2022 08:20 Inactive
@github-pages github-pages bot temporarily deployed to github-pages August 1, 2022 08:25 Inactive
@github-pages github-pages bot temporarily deployed to github-pages September 7, 2022 10:11 Inactive
@dmnsgn
Copy link
Member Author

dmnsgn commented May 9, 2023

TODO @dmnsgn add some notes about:

  • Input coordinates bigger than 2^31 may not result in a noisy output anymore.
  • Similar seeds might not result in different values for the same position in noise (see test)

@vorg
Copy link
Member

vorg commented May 9, 2023

Did we change seedrandom compared to older versions? Is it their issue?

@dmnsgn
Copy link
Member Author

dmnsgn commented May 10, 2023

It is a seedrandom "standard ARC4 key scheduler cycles short keys" issue, we just never noticed as the test were always using the same 0/1 seeds:

pex-random/test/Random.js

Lines 245 to 247 in f199ef8

rnd.seed(0);
var r1 = rnd.noise2(x, y);
rnd.seed(1);

While I rewrote it to be i/i+1:

pex-random/test/index.js

Lines 339 to 341 in 9293bd2

random.seed(i);
const r1 = random.noise2(x, y);
random.seed(i + 1);

Test here

Update Random.js code to following and run node --test in v1:

var { describe, it } = require("node:test");
var assert = require("assert");
var rnd = require("../");

describe("Random", function () {
  describe("noise2(x, y)", function () {
    it("should return the different value for the same x,y", function () {
      for (var i = 0; i < 100; i++) {
        var x = 100 * Math.random();
        var y = 100 * Math.random();
        rnd.seed(i);
        var r1 = rnd.noise2(x, y);
        rnd.seed(i + 1);
        var r2 = rnd.noise2(x, y);
        assert.notEqual(r1, r2);
      }
    });
  });
});

@dmnsgn dmnsgn temporarily deployed to github-pages May 10, 2023 09:47 — with GitHub Pages Inactive
@dmnsgn dmnsgn temporarily deployed to github-pages May 12, 2023 15:04 — with GitHub Pages Inactive
@dmnsgn dmnsgn temporarily deployed to github-pages July 17, 2023 09:00 — with GitHub Pages Inactive
@dmnsgn dmnsgn temporarily deployed to github-pages August 29, 2023 08:05 — with GitHub Pages Inactive
@dmnsgn dmnsgn temporarily deployed to github-pages August 29, 2023 08:05 — with GitHub Pages Inactive
@dmnsgn dmnsgn temporarily deployed to github-pages August 30, 2023 11:50 — with GitHub Pages Inactive
@dmnsgn dmnsgn marked this pull request as ready for review February 5, 2024 15:44
@dmnsgn dmnsgn merged commit 35dc58e into master Feb 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid seek leaking by crating local prng Move Random namespace inside index
2 participants