Ejemplo n.º 1
0
        static OpenSimplex2F()
        {
            LOOKUP_2D   = new LatticePoint2D[4];
            LOOKUP_3D   = new LatticePoint3D[8];
            VERTICES_4D = new LatticePoint4D[16];

            LOOKUP_2D[0] = new LatticePoint2D(1, 0);
            LOOKUP_2D[1] = new LatticePoint2D(0, 0);
            LOOKUP_2D[2] = new LatticePoint2D(1, 1);
            LOOKUP_2D[3] = new LatticePoint2D(0, 1);

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, k1, i2, j2, k2;
                i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1;
                i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1;

                // The two points within this octant, one from each of the two cubic half-lattices.
                LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
                LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);

                // Each single step away on the first half-lattice.
                LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0);
                LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0);
                LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0);

                // Each single step away on the second half-lattice.
                LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1);
                LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1);
                LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1);

                // First two are guaranteed.
                c0.NextOnFailure = c0.NextOnSuccess = c1;
                c1.NextOnFailure = c1.NextOnSuccess = c2;

                // Once we find one on the first half-lattice, the rest are out.
                // In addition, knowing c2 rules out c5.
                c2.NextOnFailure = c3; c2.NextOnSuccess = c6;
                c3.NextOnFailure = c4; c3.NextOnSuccess = c5;
                c4.NextOnFailure = c4.NextOnSuccess = c5;

                // Once we find one on the second half-lattice, the rest are out.
                c5.NextOnFailure = c6; c5.NextOnSuccess = null;
                c6.NextOnFailure = c7; c6.NextOnSuccess = null;
                c7.NextOnFailure = c7.NextOnSuccess = null;

                LOOKUP_3D[i] = c0;
            }

            for (int i = 0; i < 16; i++)
            {
                VERTICES_4D[i] = new LatticePoint4D((i >> 0) & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1);
            }

            GRADIENTS_2D = new Grad2[PSIZE];
            Grad2[] grad2 =
            {
                new Grad2(0.130526192220052,    0.99144486137381),
                new Grad2(0.38268343236509,    0.923879532511287),
                new Grad2(0.608761429008721,   0.793353340291235),
                new Grad2(0.793353340291235,   0.608761429008721),
                new Grad2(0.923879532511287,    0.38268343236509),
                new Grad2(0.99144486137381,    0.130526192220051),
                new Grad2(0.99144486137381,   -0.130526192220051),
                new Grad2(0.923879532511287,   -0.38268343236509),
                new Grad2(0.793353340291235,   -0.60876142900872),
                new Grad2(0.608761429008721,  -0.793353340291235),
                new Grad2(0.38268343236509,   -0.923879532511287),
                new Grad2(0.130526192220052,   -0.99144486137381),
                new Grad2(-0.130526192220052,  -0.99144486137381),
                new Grad2(-0.38268343236509,  -0.923879532511287),
                new Grad2(-0.608761429008721, -0.793353340291235),
                new Grad2(-0.793353340291235, -0.608761429008721),
                new Grad2(-0.923879532511287,  -0.38268343236509),
                new Grad2(-0.99144486137381,  -0.130526192220052),
                new Grad2(-0.99144486137381,   0.130526192220051),
                new Grad2(-0.923879532511287,   0.38268343236509),
                new Grad2(-0.793353340291235,  0.608761429008721),
                new Grad2(-0.608761429008721,  0.793353340291235),
                new Grad2(-0.38268343236509,   0.923879532511287),
                new Grad2(-0.130526192220052, 0.99144486137381)
            };
            for (int i = 0; i < grad2.Length; i++)
            {
                grad2[i].dx /= N2; grad2[i].dy /= N2;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_2D[i] = grad2[i % grad2.Length];
            }

            GRADIENTS_3D = new Grad3[PSIZE];
            Grad3[] grad3 =
            {
                new Grad3(-2.22474487139,           -2.22474487139,                -1.0),
                new Grad3(-2.22474487139,           -2.22474487139,                 1.0),
                new Grad3(-3.0862664687972017, -1.1721513422464978,                 0.0),
                new Grad3(-1.1721513422464978, -3.0862664687972017,                 0.0),
                new Grad3(-2.22474487139,                     -1.0,      -2.22474487139),
                new Grad3(-2.22474487139,                      1.0,      -2.22474487139),
                new Grad3(-1.1721513422464978,                 0.0, -3.0862664687972017),
                new Grad3(-3.0862664687972017,                 0.0, -1.1721513422464978),
                new Grad3(-2.22474487139,                     -1.0,       2.22474487139),
                new Grad3(-2.22474487139,                      1.0,       2.22474487139),
                new Grad3(-3.0862664687972017,                 0.0,  1.1721513422464978),
                new Grad3(-1.1721513422464978,                 0.0,  3.0862664687972017),
                new Grad3(-2.22474487139,            2.22474487139,                -1.0),
                new Grad3(-2.22474487139,            2.22474487139,                 1.0),
                new Grad3(-1.1721513422464978,  3.0862664687972017,                 0.0),
                new Grad3(-3.0862664687972017,  1.1721513422464978,                 0.0),
                new Grad3(-1.0,                     -2.22474487139,      -2.22474487139),
                new Grad3(1.0,                      -2.22474487139,      -2.22474487139),
                new Grad3(0.0,                 -3.0862664687972017, -1.1721513422464978),
                new Grad3(0.0,                 -1.1721513422464978, -3.0862664687972017),
                new Grad3(-1.0,                     -2.22474487139,       2.22474487139),
                new Grad3(1.0,                      -2.22474487139,       2.22474487139),
                new Grad3(0.0,                 -1.1721513422464978,  3.0862664687972017),
                new Grad3(0.0,                 -3.0862664687972017,  1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,      -2.22474487139),
                new Grad3(1.0,                       2.22474487139,      -2.22474487139),
                new Grad3(0.0,                  1.1721513422464978, -3.0862664687972017),
                new Grad3(0.0,                  3.0862664687972017, -1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,       2.22474487139),
                new Grad3(1.0,                       2.22474487139,       2.22474487139),
                new Grad3(0.0,                  3.0862664687972017,  1.1721513422464978),
                new Grad3(0.0,                  1.1721513422464978,  3.0862664687972017),
                new Grad3(2.22474487139,            -2.22474487139,                -1.0),
                new Grad3(2.22474487139,            -2.22474487139,                 1.0),
                new Grad3(1.1721513422464978,  -3.0862664687972017,                 0.0),
                new Grad3(3.0862664687972017,  -1.1721513422464978,                 0.0),
                new Grad3(2.22474487139,                      -1.0,      -2.22474487139),
                new Grad3(2.22474487139,                       1.0,      -2.22474487139),
                new Grad3(3.0862664687972017,                  0.0, -1.1721513422464978),
                new Grad3(1.1721513422464978,                  0.0, -3.0862664687972017),
                new Grad3(2.22474487139,                      -1.0,       2.22474487139),
                new Grad3(2.22474487139,                       1.0,       2.22474487139),
                new Grad3(1.1721513422464978,                  0.0,  3.0862664687972017),
                new Grad3(3.0862664687972017,                  0.0,  1.1721513422464978),
                new Grad3(2.22474487139,             2.22474487139,                -1.0),
                new Grad3(2.22474487139,             2.22474487139,                 1.0),
                new Grad3(3.0862664687972017,   1.1721513422464978,                 0.0),
                new Grad3(1.1721513422464978,   3.0862664687972017, 0.0)
            };
            for (int i = 0; i < grad3.Length; i++)
            {
                grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_3D[i] = grad3[i % grad3.Length];
            }

            GRADIENTS_4D = new Grad4[PSIZE];
            Grad4[] grad4 =
            {
                new Grad4(-0.753341017856078,     -0.37968289875261624,  -0.37968289875261624,  -0.37968289875261624),
                new Grad4(-0.7821684431180708,     -0.4321472685365301,   -0.4321472685365301,   0.12128480194602098),
                new Grad4(-0.7821684431180708,     -0.4321472685365301,   0.12128480194602098,   -0.4321472685365301),
                new Grad4(-0.7821684431180708,     0.12128480194602098,   -0.4321472685365301,   -0.4321472685365301),
                new Grad4(-0.8586508742123365,      -0.508629699630796,  0.044802370851755174,  0.044802370851755174),
                new Grad4(-0.8586508742123365,    0.044802370851755174,    -0.508629699630796,  0.044802370851755174),
                new Grad4(-0.8586508742123365,    0.044802370851755174,  0.044802370851755174,    -0.508629699630796),
                new Grad4(-0.9982828964265062,    -0.03381941603233842,  -0.03381941603233842,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,     -0.753341017856078,  -0.37968289875261624,  -0.37968289875261624),
                new Grad4(-0.4321472685365301,     -0.7821684431180708,   -0.4321472685365301,   0.12128480194602098),
                new Grad4(-0.4321472685365301,     -0.7821684431180708,   0.12128480194602098,   -0.4321472685365301),
                new Grad4(0.12128480194602098,     -0.7821684431180708,   -0.4321472685365301,   -0.4321472685365301),
                new Grad4(-0.508629699630796,      -0.8586508742123365,  0.044802370851755174,  0.044802370851755174),
                new Grad4(0.044802370851755174,    -0.8586508742123365,    -0.508629699630796,  0.044802370851755174),
                new Grad4(0.044802370851755174,    -0.8586508742123365,  0.044802370851755174,    -0.508629699630796),
                new Grad4(-0.03381941603233842,    -0.9982828964265062,  -0.03381941603233842,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,   -0.37968289875261624,    -0.753341017856078,  -0.37968289875261624),
                new Grad4(-0.4321472685365301,     -0.4321472685365301,   -0.7821684431180708,   0.12128480194602098),
                new Grad4(-0.4321472685365301,     0.12128480194602098,   -0.7821684431180708,   -0.4321472685365301),
                new Grad4(0.12128480194602098,     -0.4321472685365301,   -0.7821684431180708,   -0.4321472685365301),
                new Grad4(-0.508629699630796,     0.044802370851755174,   -0.8586508742123365,  0.044802370851755174),
                new Grad4(0.044802370851755174,     -0.508629699630796,   -0.8586508742123365,  0.044802370851755174),
                new Grad4(0.044802370851755174,   0.044802370851755174,   -0.8586508742123365,    -0.508629699630796),
                new Grad4(-0.03381941603233842,   -0.03381941603233842,   -0.9982828964265062,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,   -0.37968289875261624,  -0.37968289875261624,    -0.753341017856078),
                new Grad4(-0.4321472685365301,     -0.4321472685365301,   0.12128480194602098,   -0.7821684431180708),
                new Grad4(-0.4321472685365301,     0.12128480194602098,   -0.4321472685365301,   -0.7821684431180708),
                new Grad4(0.12128480194602098,     -0.4321472685365301,   -0.4321472685365301,   -0.7821684431180708),
                new Grad4(-0.508629699630796,     0.044802370851755174,  0.044802370851755174,   -0.8586508742123365),
                new Grad4(0.044802370851755174,     -0.508629699630796,  0.044802370851755174,   -0.8586508742123365),
                new Grad4(0.044802370851755174,   0.044802370851755174,    -0.508629699630796,   -0.8586508742123365),
                new Grad4(-0.03381941603233842,   -0.03381941603233842,  -0.03381941603233842,   -0.9982828964265062),
                new Grad4(-0.6740059517812944,     -0.3239847771997537,   -0.3239847771997537,    0.5794684678643381),
                new Grad4(-0.7504883828755602,     -0.4004672082940195,   0.15296486218853164,    0.5029860367700724),
                new Grad4(-0.7504883828755602,     0.15296486218853164,   -0.4004672082940195,    0.5029860367700724),
                new Grad4(-0.8828161875373585,     0.08164729285680945,   0.08164729285680945,    0.4553054119602712),
                new Grad4(-0.4553054119602712,    -0.08164729285680945,  -0.08164729285680945,    0.8828161875373585),
                new Grad4(-0.5029860367700724,    -0.15296486218853164,    0.4004672082940195,    0.7504883828755602),
                new Grad4(-0.5029860367700724,      0.4004672082940195,  -0.15296486218853164,    0.7504883828755602),
                new Grad4(-0.5794684678643381,      0.3239847771997537,    0.3239847771997537,    0.6740059517812944),
                new Grad4(-0.3239847771997537,     -0.6740059517812944,   -0.3239847771997537,    0.5794684678643381),
                new Grad4(-0.4004672082940195,     -0.7504883828755602,   0.15296486218853164,    0.5029860367700724),
                new Grad4(0.15296486218853164,     -0.7504883828755602,   -0.4004672082940195,    0.5029860367700724),
                new Grad4(0.08164729285680945,     -0.8828161875373585,   0.08164729285680945,    0.4553054119602712),
                new Grad4(-0.08164729285680945,    -0.4553054119602712,  -0.08164729285680945,    0.8828161875373585),
                new Grad4(-0.15296486218853164,    -0.5029860367700724,    0.4004672082940195,    0.7504883828755602),
                new Grad4(0.4004672082940195,      -0.5029860367700724,  -0.15296486218853164,    0.7504883828755602),
                new Grad4(0.3239847771997537,      -0.5794684678643381,    0.3239847771997537,    0.6740059517812944),
                new Grad4(-0.3239847771997537,     -0.3239847771997537,   -0.6740059517812944,    0.5794684678643381),
                new Grad4(-0.4004672082940195,     0.15296486218853164,   -0.7504883828755602,    0.5029860367700724),
                new Grad4(0.15296486218853164,     -0.4004672082940195,   -0.7504883828755602,    0.5029860367700724),
                new Grad4(0.08164729285680945,     0.08164729285680945,   -0.8828161875373585,    0.4553054119602712),
                new Grad4(-0.08164729285680945,   -0.08164729285680945,   -0.4553054119602712,    0.8828161875373585),
                new Grad4(-0.15296486218853164,     0.4004672082940195,   -0.5029860367700724,    0.7504883828755602),
                new Grad4(0.4004672082940195,     -0.15296486218853164,   -0.5029860367700724,    0.7504883828755602),
                new Grad4(0.3239847771997537,       0.3239847771997537,   -0.5794684678643381,    0.6740059517812944),
                new Grad4(-0.6740059517812944,     -0.3239847771997537,    0.5794684678643381,   -0.3239847771997537),
                new Grad4(-0.7504883828755602,     -0.4004672082940195,    0.5029860367700724,   0.15296486218853164),
                new Grad4(-0.7504883828755602,     0.15296486218853164,    0.5029860367700724,   -0.4004672082940195),
                new Grad4(-0.8828161875373585,     0.08164729285680945,    0.4553054119602712,   0.08164729285680945),
                new Grad4(-0.4553054119602712,    -0.08164729285680945,    0.8828161875373585,  -0.08164729285680945),
                new Grad4(-0.5029860367700724,    -0.15296486218853164,    0.7504883828755602,    0.4004672082940195),
                new Grad4(-0.5029860367700724,      0.4004672082940195,    0.7504883828755602,  -0.15296486218853164),
                new Grad4(-0.5794684678643381,      0.3239847771997537,    0.6740059517812944,    0.3239847771997537),
                new Grad4(-0.3239847771997537,     -0.6740059517812944,    0.5794684678643381,   -0.3239847771997537),
                new Grad4(-0.4004672082940195,     -0.7504883828755602,    0.5029860367700724,   0.15296486218853164),
                new Grad4(0.15296486218853164,     -0.7504883828755602,    0.5029860367700724,   -0.4004672082940195),
                new Grad4(0.08164729285680945,     -0.8828161875373585,    0.4553054119602712,   0.08164729285680945),
                new Grad4(-0.08164729285680945,    -0.4553054119602712,    0.8828161875373585,  -0.08164729285680945),
                new Grad4(-0.15296486218853164,    -0.5029860367700724,    0.7504883828755602,    0.4004672082940195),
                new Grad4(0.4004672082940195,      -0.5029860367700724,    0.7504883828755602,  -0.15296486218853164),
                new Grad4(0.3239847771997537,      -0.5794684678643381,    0.6740059517812944,    0.3239847771997537),
                new Grad4(-0.3239847771997537,     -0.3239847771997537,    0.5794684678643381,   -0.6740059517812944),
                new Grad4(-0.4004672082940195,     0.15296486218853164,    0.5029860367700724,   -0.7504883828755602),
                new Grad4(0.15296486218853164,     -0.4004672082940195,    0.5029860367700724,   -0.7504883828755602),
                new Grad4(0.08164729285680945,     0.08164729285680945,    0.4553054119602712,   -0.8828161875373585),
                new Grad4(-0.08164729285680945,   -0.08164729285680945,    0.8828161875373585,   -0.4553054119602712),
                new Grad4(-0.15296486218853164,     0.4004672082940195,    0.7504883828755602,   -0.5029860367700724),
                new Grad4(0.4004672082940195,     -0.15296486218853164,    0.7504883828755602,   -0.5029860367700724),
                new Grad4(0.3239847771997537,       0.3239847771997537,    0.6740059517812944,   -0.5794684678643381),
                new Grad4(-0.6740059517812944,      0.5794684678643381,   -0.3239847771997537,   -0.3239847771997537),
                new Grad4(-0.7504883828755602,      0.5029860367700724,   -0.4004672082940195,   0.15296486218853164),
                new Grad4(-0.7504883828755602,      0.5029860367700724,   0.15296486218853164,   -0.4004672082940195),
                new Grad4(-0.8828161875373585,      0.4553054119602712,   0.08164729285680945,   0.08164729285680945),
                new Grad4(-0.4553054119602712,      0.8828161875373585,  -0.08164729285680945,  -0.08164729285680945),
                new Grad4(-0.5029860367700724,      0.7504883828755602,  -0.15296486218853164,    0.4004672082940195),
                new Grad4(-0.5029860367700724,      0.7504883828755602,    0.4004672082940195,  -0.15296486218853164),
                new Grad4(-0.5794684678643381,      0.6740059517812944,    0.3239847771997537,    0.3239847771997537),
                new Grad4(-0.3239847771997537,      0.5794684678643381,   -0.6740059517812944,   -0.3239847771997537),
                new Grad4(-0.4004672082940195,      0.5029860367700724,   -0.7504883828755602,   0.15296486218853164),
                new Grad4(0.15296486218853164,      0.5029860367700724,   -0.7504883828755602,   -0.4004672082940195),
                new Grad4(0.08164729285680945,      0.4553054119602712,   -0.8828161875373585,   0.08164729285680945),
                new Grad4(-0.08164729285680945,     0.8828161875373585,   -0.4553054119602712,  -0.08164729285680945),
                new Grad4(-0.15296486218853164,     0.7504883828755602,   -0.5029860367700724,    0.4004672082940195),
                new Grad4(0.4004672082940195,       0.7504883828755602,   -0.5029860367700724,  -0.15296486218853164),
                new Grad4(0.3239847771997537,       0.6740059517812944,   -0.5794684678643381,    0.3239847771997537),
                new Grad4(-0.3239847771997537,      0.5794684678643381,   -0.3239847771997537,   -0.6740059517812944),
                new Grad4(-0.4004672082940195,      0.5029860367700724,   0.15296486218853164,   -0.7504883828755602),
                new Grad4(0.15296486218853164,      0.5029860367700724,   -0.4004672082940195,   -0.7504883828755602),
                new Grad4(0.08164729285680945,      0.4553054119602712,   0.08164729285680945,   -0.8828161875373585),
                new Grad4(-0.08164729285680945,     0.8828161875373585,  -0.08164729285680945,   -0.4553054119602712),
                new Grad4(-0.15296486218853164,     0.7504883828755602,    0.4004672082940195,   -0.5029860367700724),
                new Grad4(0.4004672082940195,       0.7504883828755602,  -0.15296486218853164,   -0.5029860367700724),
                new Grad4(0.3239847771997537,       0.6740059517812944,    0.3239847771997537,   -0.5794684678643381),
                new Grad4(0.5794684678643381,      -0.6740059517812944,   -0.3239847771997537,   -0.3239847771997537),
                new Grad4(0.5029860367700724,      -0.7504883828755602,   -0.4004672082940195,   0.15296486218853164),
                new Grad4(0.5029860367700724,      -0.7504883828755602,   0.15296486218853164,   -0.4004672082940195),
                new Grad4(0.4553054119602712,      -0.8828161875373585,   0.08164729285680945,   0.08164729285680945),
                new Grad4(0.8828161875373585,      -0.4553054119602712,  -0.08164729285680945,  -0.08164729285680945),
                new Grad4(0.7504883828755602,      -0.5029860367700724,  -0.15296486218853164,    0.4004672082940195),
                new Grad4(0.7504883828755602,      -0.5029860367700724,    0.4004672082940195,  -0.15296486218853164),
                new Grad4(0.6740059517812944,      -0.5794684678643381,    0.3239847771997537,    0.3239847771997537),
                new Grad4(0.5794684678643381,      -0.3239847771997537,   -0.6740059517812944,   -0.3239847771997537),
                new Grad4(0.5029860367700724,      -0.4004672082940195,   -0.7504883828755602,   0.15296486218853164),
                new Grad4(0.5029860367700724,      0.15296486218853164,   -0.7504883828755602,   -0.4004672082940195),
                new Grad4(0.4553054119602712,      0.08164729285680945,   -0.8828161875373585,   0.08164729285680945),
                new Grad4(0.8828161875373585,     -0.08164729285680945,   -0.4553054119602712,  -0.08164729285680945),
                new Grad4(0.7504883828755602,     -0.15296486218853164,   -0.5029860367700724,    0.4004672082940195),
                new Grad4(0.7504883828755602,       0.4004672082940195,   -0.5029860367700724,  -0.15296486218853164),
                new Grad4(0.6740059517812944,       0.3239847771997537,   -0.5794684678643381,    0.3239847771997537),
                new Grad4(0.5794684678643381,      -0.3239847771997537,   -0.3239847771997537,   -0.6740059517812944),
                new Grad4(0.5029860367700724,      -0.4004672082940195,   0.15296486218853164,   -0.7504883828755602),
                new Grad4(0.5029860367700724,      0.15296486218853164,   -0.4004672082940195,   -0.7504883828755602),
                new Grad4(0.4553054119602712,      0.08164729285680945,   0.08164729285680945,   -0.8828161875373585),
                new Grad4(0.8828161875373585,     -0.08164729285680945,  -0.08164729285680945,   -0.4553054119602712),
                new Grad4(0.7504883828755602,     -0.15296486218853164,    0.4004672082940195,   -0.5029860367700724),
                new Grad4(0.7504883828755602,       0.4004672082940195,  -0.15296486218853164,   -0.5029860367700724),
                new Grad4(0.6740059517812944,       0.3239847771997537,    0.3239847771997537,   -0.5794684678643381),
                new Grad4(0.03381941603233842,     0.03381941603233842,   0.03381941603233842,    0.9982828964265062),
                new Grad4(-0.044802370851755174, -0.044802370851755174,     0.508629699630796,    0.8586508742123365),
                new Grad4(-0.044802370851755174,     0.508629699630796, -0.044802370851755174,    0.8586508742123365),
                new Grad4(-0.12128480194602098,     0.4321472685365301,    0.4321472685365301,    0.7821684431180708),
                new Grad4(0.508629699630796,     -0.044802370851755174, -0.044802370851755174,    0.8586508742123365),
                new Grad4(0.4321472685365301,     -0.12128480194602098,    0.4321472685365301,    0.7821684431180708),
                new Grad4(0.4321472685365301,       0.4321472685365301,  -0.12128480194602098,    0.7821684431180708),
                new Grad4(0.37968289875261624,     0.37968289875261624,   0.37968289875261624,     0.753341017856078),
                new Grad4(0.03381941603233842,     0.03381941603233842,    0.9982828964265062,   0.03381941603233842),
                new Grad4(-0.044802370851755174,  0.044802370851755174,    0.8586508742123365,     0.508629699630796),
                new Grad4(-0.044802370851755174,     0.508629699630796,    0.8586508742123365, -0.044802370851755174),
                new Grad4(-0.12128480194602098,     0.4321472685365301,    0.7821684431180708,    0.4321472685365301),
                new Grad4(0.508629699630796,     -0.044802370851755174,    0.8586508742123365, -0.044802370851755174),
                new Grad4(0.4321472685365301,     -0.12128480194602098,    0.7821684431180708,    0.4321472685365301),
                new Grad4(0.4321472685365301,       0.4321472685365301,    0.7821684431180708,  -0.12128480194602098),
                new Grad4(0.37968289875261624,     0.37968289875261624,     0.753341017856078,   0.37968289875261624),
                new Grad4(0.03381941603233842,      0.9982828964265062,   0.03381941603233842,   0.03381941603233842),
                new Grad4(-0.044802370851755174,    0.8586508742123365, -0.044802370851755174,     0.508629699630796),
                new Grad4(-0.044802370851755174,    0.8586508742123365,     0.508629699630796, -0.044802370851755174),
                new Grad4(-0.12128480194602098,     0.7821684431180708,    0.4321472685365301,    0.4321472685365301),
                new Grad4(0.508629699630796,        0.8586508742123365, -0.044802370851755174, -0.044802370851755174),
                new Grad4(0.4321472685365301,       0.7821684431180708,  -0.12128480194602098,    0.4321472685365301),
                new Grad4(0.4321472685365301,       0.7821684431180708,    0.4321472685365301,  -0.12128480194602098),
                new Grad4(0.37968289875261624,       0.753341017856078,   0.37968289875261624,   0.37968289875261624),
                new Grad4(0.9982828964265062,      0.03381941603233842,   0.03381941603233842,   0.03381941603233842),
                new Grad4(0.8586508742123365,    -0.044802370851755174, -0.044802370851755174,     0.508629699630796),
                new Grad4(0.8586508742123365,    -0.044802370851755174,     0.508629699630796, -0.044802370851755174),
                new Grad4(0.7821684431180708,     -0.12128480194602098,    0.4321472685365301,    0.4321472685365301),
                new Grad4(0.8586508742123365,        0.508629699630796, -0.044802370851755174, -0.044802370851755174),
                new Grad4(0.7821684431180708,       0.4321472685365301,  -0.12128480194602098,    0.4321472685365301),
                new Grad4(0.7821684431180708,       0.4321472685365301,    0.4321472685365301,  -0.12128480194602098),
                new Grad4(0.753341017856078,       0.37968289875261624,   0.37968289875261624, 0.37968289875261624)
            };
            for (int i = 0; i < grad4.Length; i++)
            {
                grad4[i].dx /= N4; grad4[i].dy /= N4; grad4[i].dz /= N4; grad4[i].dw /= N4;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_4D[i] = grad4[i % grad4.Length];
            }
        }
Ejemplo n.º 2
0
        /**
         * 4D OpenSimplex2F noise base.
         * Current implementation not fully optimized by lookup tables.
         * But still comes out slightly ahead of Gustavson's Simplex in tests.
         */
        private double noise4_Base(double xs, double ys, double zs, double ws)
        {
            double value = 0;

            // Get base points and offsets
            int    xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws);
            double xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb;

            // If we're in the lower half, flip so we can repeat the code for the upper half. We'll flip back later.
            double siSum       = xsi + ysi + zsi + wsi;
            double ssi         = siSum * 0.309016994374947; // Prep for vertex contributions.
            bool   inLowerHalf = (siSum < 2);

            if (inLowerHalf)
            {
                xsi   = 1 - xsi; ysi = 1 - ysi; zsi = 1 - zsi; wsi = 1 - wsi;
                siSum = 4 - siSum;
            }

            // Consider opposing vertex pairs of the octahedron formed by the central cross-section of the stretched tesseract
            double aabb = xsi + ysi - zsi - wsi, abab = xsi - ysi + zsi - wsi, abba = xsi - ysi - zsi + wsi;
            double aabbScore = Math.Abs(aabb), ababScore = Math.Abs(abab), abbaScore = Math.Abs(abba);

            // Find the closest point on the stretched tesseract as if it were the upper half
            int    vertexIndex, via, vib;
            double asi, bsi;

            if (aabbScore > ababScore && aabbScore > abbaScore)
            {
                if (aabb > 0)
                {
                    asi = zsi; bsi = wsi; vertexIndex = 0b0011; via = 0b0111; vib = 0b1011;
                }
                else
                {
                    asi = xsi; bsi = ysi; vertexIndex = 0b1100; via = 0b1101; vib = 0b1110;
                }
            }
            else if (ababScore > abbaScore)
            {
                if (abab > 0)
                {
                    asi = ysi; bsi = wsi; vertexIndex = 0b0101; via = 0b0111; vib = 0b1101;
                }
                else
                {
                    asi = xsi; bsi = zsi; vertexIndex = 0b1010; via = 0b1011; vib = 0b1110;
                }
            }
            else
            {
                if (abba > 0)
                {
                    asi = ysi; bsi = zsi; vertexIndex = 0b1001; via = 0b1011; vib = 0b1101;
                }
                else
                {
                    asi = xsi; bsi = wsi; vertexIndex = 0b0110; via = 0b0111; vib = 0b1110;
                }
            }
            if (bsi > asi)
            {
                via = vib;
                double temp = bsi;
                bsi = asi;
                asi = temp;
            }
            if (siSum + asi > 3)
            {
                vertexIndex = via;
                if (siSum + bsi > 4)
                {
                    vertexIndex = 0b1111;
                }
            }

            // Now flip back if we're actually in the lower half.
            if (inLowerHalf)
            {
                xsi          = 1 - xsi; ysi = 1 - ysi; zsi = 1 - zsi; wsi = 1 - wsi;
                vertexIndex ^= 0b1111;
            }

            // Five points to add, total, from five copies of the A4 lattice.
            for (int i = 0; i < 5; i++)
            {
                // Update xsb/etc. and add the lattice point's contribution.
                LatticePoint4D c = VERTICES_4D[vertexIndex];
                xsb += c.xsv; ysb += c.ysv; zsb += c.zsv; wsb += c.wsv;
                double xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi;
                double dx = xi + c.dx, dy = yi + c.dy, dz = zi + c.dz, dw = wi + c.dw;
                double attn = 0.5 - dx * dx - dy * dy - dz * dz - dw * dw;
                if (attn > 0)
                {
                    int    pxm = xsb & PMASK, pym = ysb & PMASK, pzm = zsb & PMASK, pwm = wsb & PMASK;
                    Grad4  grad   = permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm];
                    double ramped = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw;

                    attn  *= attn;
                    value += attn * attn * ramped;
                }

                // Maybe this helps the compiler/JVM/LLVM/etc. know we can end the loop here. Maybe not.
                if (i == 4)
                {
                    break;
                }

                // Update the relative skewed coordinates to reference the vertex we just added.
                // Rather, reference its counterpart on the lattice copy that is shifted down by
                // the vector <-0.2, -0.2, -0.2, -0.2>
                xsi += c.xsi; ysi += c.ysi; zsi += c.zsi; wsi += c.wsi;
                ssi += c.ssiDelta;

                // Next point is the closest vertex on the 4-simplex whose base vertex is the aforementioned vertex.
                double score0 = 1.0 + ssi * (-1.0 / 0.309016994374947); // Seems slightly faster than 1.0-xsi-ysi-zsi-wsi
                vertexIndex = 0b0000;
                if (xsi >= ysi && xsi >= zsi && xsi >= wsi && xsi >= score0)
                {
                    vertexIndex = 0b0001;
                }
                else if (ysi > xsi && ysi >= zsi && ysi >= wsi && ysi >= score0)
                {
                    vertexIndex = 0b0010;
                }
                else if (zsi > xsi && zsi > ysi && zsi >= wsi && zsi >= score0)
                {
                    vertexIndex = 0b0100;
                }
                else if (wsi > xsi && wsi > ysi && wsi > zsi && wsi >= score0)
                {
                    vertexIndex = 0b1000;
                }
            }

            return(value);
        }