Skip to content

Commit

Permalink
improve consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless authored Oct 31, 2017
1 parent 8ce7ed4 commit 158ad52
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions PerlinNoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ namespace siv

std::int32_t p[512];

double fade(double t) const noexcept
static double Fade(double t) noexcept
{
return t * t * t * (t * (t * 6 - 15) + 10);
}

double lerp(double t, double a, double b) const noexcept
static double Lerp(double t, double a, double b) noexcept
{
return a + t * (b - a);
}

double grad(std::int32_t hash, double x, double y, double z) const noexcept
static double Grad(std::int32_t hash, double x, double y, double z) noexcept
{
const std::int32_t h = hash & 15;
const double u = h < 8 ? x : y;
Expand All @@ -66,7 +66,7 @@ namespace siv

void reseed(std::uint32_t seed)
{
for (std::int32_t i = 0; i < 256; ++i)
for (size_t i = 0; i < 256; ++i)
{
p[i] = i;
}
Expand Down Expand Up @@ -99,21 +99,21 @@ namespace siv
y -= std::floor(y);
z -= std::floor(z);

const double u = fade(x);
const double v = fade(y);
const double w = fade(z);

const int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z;
const int B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;

return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z),
grad(p[BA], x - 1, y, z)),
lerp(u, grad(p[AB], x, y - 1, z),
grad(p[BB], x - 1, y - 1, z))),
lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1),
grad(p[BA + 1], x - 1, y, z - 1)),
lerp(u, grad(p[AB + 1], x, y - 1, z - 1),
grad(p[BB + 1], x - 1, y - 1, z - 1))));
const double u = Fade(x);
const double v = Fade(y);
const double w = Fade(z);

const std::int32_t A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z;
const std::int32_t B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;

return Lerp(w, Lerp(v, Lerp(u, Grad(p[AA], x, y, z),
Grad(p[BA], x - 1, y, z)),
Lerp(u, Grad(p[AB], x, y - 1, z),
Grad(p[BB], x - 1, y - 1, z))),
Lerp(v, Lerp(u, Grad(p[AA + 1], x, y, z - 1),
Grad(p[BA + 1], x - 1, y, z - 1)),
Lerp(u, Grad(p[AB + 1], x, y - 1, z - 1),
Grad(p[BB + 1], x - 1, y - 1, z - 1))));
}

double octaveNoise(double x, std::int32_t octaves) const
Expand Down

0 comments on commit 158ad52

Please sign in to comment.