]> git.localhorst.tv Git - blank.git/commitdiff
test stability of worley noise generator
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 10 Nov 2016 11:49:21 +0000 (12:49 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 10 Nov 2016 11:49:21 +0000 (12:49 +0100)
tst/rand/StabilityTest.cpp
tst/rand/StabilityTest.hpp

index 579433752bfc779f03512248e02deb15c5bd8062..4aab3eba000b55ccd2a5c89bfefc8773c8ce2d19 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "rand/GaloisLFSR.hpp"
 #include "rand/SimplexNoise.hpp"
+#include "rand/WorleyNoise.hpp"
 
 #include <cstdint>
 #include <string>
@@ -251,6 +252,27 @@ void StabilityTest::testSimplex() {
        Assert(noise, glm::vec3(-1.0f, -1.0f, -1.0f),  0.0f);
 }
 
+void StabilityTest::testWorley() {
+       WorleyNoise noise(0);
+
+       Assert(noise, glm::vec3(0.0f, 0.0f, 0.0f), -0.117765009403229f);
+       Assert(noise, glm::vec3(0.0f, 0.0f, 1.0f), -0.209876894950867f);
+       Assert(noise, glm::vec3(0.0f, 1.0f, 0.0f), -0.290086328983307f);
+       Assert(noise, glm::vec3(0.0f, 1.0f, 1.0f), -0.332393705844879f);
+       Assert(noise, glm::vec3(1.0f, 0.0f, 0.0f), -0.621925830841064f);
+       Assert(noise, glm::vec3(1.0f, 0.0f, 1.0f), -0.338455379009247f);
+       Assert(noise, glm::vec3(1.0f, 1.0f, 0.0f), -0.386664032936096f);
+       Assert(noise, glm::vec3(1.0f, 1.0f, 1.0f), -0.533940434455872f);
+
+       Assert(noise, glm::vec3( 0.0f,  0.0f, -1.0f), -0.425480604171753f);
+       Assert(noise, glm::vec3( 0.0f, -1.0f,  0.0f), -0.189745843410492f);
+       Assert(noise, glm::vec3( 0.0f, -1.0f, -1.0f), -0.30408102273941f);
+       Assert(noise, glm::vec3(-1.0f,  0.0f,  0.0f), -0.618566155433655f);
+       Assert(noise, glm::vec3(-1.0f,  0.0f, -1.0f), -0.060045599937439f);
+       Assert(noise, glm::vec3(-1.0f, -1.0f,  0.0f), -0.366827547550201f);
+       Assert(noise, glm::vec3(-1.0f, -1.0f, -1.0f), -0.575981974601746f);
+}
+
 void StabilityTest::Assert(
        const SimplexNoise &noise,
        const glm::vec3 &position,
@@ -264,5 +286,18 @@ void StabilityTest::Assert(
        );
 }
 
+void StabilityTest::Assert(
+       const WorleyNoise &noise,
+       const glm::vec3 &position,
+       float expected
+) {
+       stringstream msg;
+       msg << "unexpected worley noise value at " << position;
+       CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+               msg.str(),
+               expected, noise(position), numeric_limits<float>::epsilon()
+       );
+}
+
 }
 }
index b2ee1aefba1718c99a908da3637f6a622216518a..acc6741fb13f2f8141f95ed294f9a81f34726fae 100644 (file)
@@ -10,6 +10,7 @@
 namespace blank {
 
 class SimplexNoise;
+class WorleyNoise;
 
 namespace test {
 
@@ -20,6 +21,7 @@ CPPUNIT_TEST_SUITE(StabilityTest);
 
 CPPUNIT_TEST(testRNG);
 CPPUNIT_TEST(testSimplex);
+CPPUNIT_TEST(testWorley);
 
 CPPUNIT_TEST_SUITE_END();
 
@@ -29,12 +31,18 @@ public:
 
        void testRNG();
        void testSimplex();
+       void testWorley();
 
        static void Assert(
                const SimplexNoise &noise,
                const glm::vec3 &position,
                float expected);
 
+       static void Assert(
+               const WorleyNoise &noise,
+               const glm::vec3 &position,
+               float expected);
+
 };
 
 }