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

Is this a mistake in grad()? #5

Open
akriegman opened this issue Mar 31, 2020 · 2 comments
Open

Is this a mistake in grad()? #5

akriegman opened this issue Mar 31, 2020 · 2 comments
Assignees
Labels

Comments

@akriegman
Copy link

I either found a mistake in the code or there's something I don't understand here:

static float grad(int32_t hash, float x, float y) {
    const int32_t h = hash & 0x3F;  // Convert low 3 bits of hash code
    const float u = h < 4 ? x : y;  // into 8 simple gradient directions,
    const float v = h < 4 ? y : x;
    return ((h & 1) ? -u : u) + ((h & 2) ? -2.0f * v : 2.0f * v); // and compute the dot product with (x,y).
}

in this case isn't h the low 6 bits of hash, and isn't h < 4 false most of the time?

@SRombauts SRombauts self-assigned this Mar 31, 2020
@SRombauts SRombauts added the bug label Mar 31, 2020
@SRombauts
Copy link
Owner

Yes, it has been years but I see that the code isn't in sync with the comment so I'll have to fix and test, and also read back thé reference code

@devoh747
Copy link

Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants