Files
CrunkLord420 f6a660f692 init
2021-08-11 08:47:58 -07:00

1259 lines
63 KiB
HolyC

#ifndef SIMPLEX_HC
#define SIMPLEX_HC
#define PSIZE 2048
#define PMASK 2047
#define GRAD2_LEN 24
#define GRAD3_LEN 48
#define GRAD4_LEN 160
#define N2 0.05481866495625118
#define N3 0.2781926117527186
#define N4 0.11127401889945551
class Grad4 {
F64 dx;
F64 dy;
F64 dz;
F64 dw;
};
class LatticePoint2D {
I32 xsv;
I32 ysv;
F64 dx;
F64 dy;
};
class LatticePoint3D {
F64 dxr;
F64 dyr;
F64 dzr;
I32 xrv;
I32 yrv;
I32 zrv;
LatticePoint3D *nextOnFailure;
LatticePoint3D *nextOnSuccess;
};
class LatticePoint4D {
I32 xsv;
I32 ysv;
I32 zsv;
I32 wsv;
F64 dx;
F64 dy;
F64 dz;
F64 dw;
};
I16 perm[PSIZE];
CD2 permGrad2[PSIZE];
CD3 permGrad3[PSIZE];
Grad4 permGrad4[PSIZE];
I16 source[PSIZE];
CD2 GRADIENTS_2D[PSIZE];
CD3 GRADIENTS_3D[PSIZE];
Grad4 GRADIENTS_4D[PSIZE];
CD2 grad2[GRAD2_LEN] = {
{ 0.130526192220052, 0.99144486137381},
{ 0.38268343236509, 0.923879532511287},
{ 0.608761429008721, 0.793353340291235},
{ 0.793353340291235, 0.608761429008721},
{ 0.923879532511287, 0.38268343236509},
{ 0.99144486137381, 0.130526192220051},
{ 0.99144486137381, -0.130526192220051},
{ 0.923879532511287, -0.38268343236509},
{ 0.793353340291235, -0.60876142900872},
{ 0.608761429008721, -0.793353340291235},
{ 0.38268343236509, -0.923879532511287},
{ 0.130526192220052, -0.99144486137381},
{-0.130526192220052, -0.99144486137381},
{-0.38268343236509, -0.923879532511287},
{-0.608761429008721, -0.793353340291235},
{-0.793353340291235, -0.608761429008721},
{-0.923879532511287, -0.38268343236509},
{-0.99144486137381, -0.130526192220052},
{-0.99144486137381, 0.130526192220051},
{-0.923879532511287, 0.38268343236509},
{-0.793353340291235, 0.608761429008721},
{-0.608761429008721, 0.793353340291235},
{-0.38268343236509, 0.923879532511287},
{-0.130526192220052, 0.99144486137381}
};
CD3 grad3[GRAD3_LEN] = {
{-2.22474487139, -2.22474487139, -1.0},
{-2.22474487139, -2.22474487139, 1.0},
{-3.0862664687972017, -1.1721513422464978, 0.0},
{-1.1721513422464978, -3.0862664687972017, 0.0},
{-2.22474487139, -1.0, -2.22474487139},
{-2.22474487139, 1.0, -2.22474487139},
{-1.1721513422464978, 0.0, -3.0862664687972017},
{-3.0862664687972017, 0.0, -1.1721513422464978},
{-2.22474487139, -1.0, 2.22474487139},
{-2.22474487139, 1.0, 2.22474487139},
{-3.0862664687972017, 0.0, 1.1721513422464978},
{-1.1721513422464978, 0.0, 3.0862664687972017},
{-2.22474487139, 2.22474487139, -1.0},
{-2.22474487139, 2.22474487139, 1.0},
{-1.1721513422464978, 3.0862664687972017, 0.0},
{-3.0862664687972017, 1.1721513422464978, 0.0},
{-1.0, -2.22474487139, -2.22474487139},
{ 1.0, -2.22474487139, -2.22474487139},
{ 0.0, -3.0862664687972017, -1.1721513422464978},
{ 0.0, -1.1721513422464978, -3.0862664687972017},
{-1.0, -2.22474487139, 2.22474487139},
{ 1.0, -2.22474487139, 2.22474487139},
{ 0.0, -1.1721513422464978, 3.0862664687972017},
{ 0.0, -3.0862664687972017, 1.1721513422464978},
{-1.0, 2.22474487139, -2.22474487139},
{ 1.0, 2.22474487139, -2.22474487139},
{ 0.0, 1.1721513422464978, -3.0862664687972017},
{ 0.0, 3.0862664687972017, -1.1721513422464978},
{-1.0, 2.22474487139, 2.22474487139},
{ 1.0, 2.22474487139, 2.22474487139},
{ 0.0, 3.0862664687972017, 1.1721513422464978},
{ 0.0, 1.1721513422464978, 3.0862664687972017},
{ 2.22474487139, -2.22474487139, -1.0},
{ 2.22474487139, -2.22474487139, 1.0},
{ 1.1721513422464978, -3.0862664687972017, 0.0},
{ 3.0862664687972017, -1.1721513422464978, 0.0},
{ 2.22474487139, -1.0, -2.22474487139},
{ 2.22474487139, 1.0, -2.22474487139},
{ 3.0862664687972017, 0.0, -1.1721513422464978},
{ 1.1721513422464978, 0.0, -3.0862664687972017},
{ 2.22474487139, -1.0, 2.22474487139},
{ 2.22474487139, 1.0, 2.22474487139},
{ 1.1721513422464978, 0.0, 3.0862664687972017},
{ 3.0862664687972017, 0.0, 1.1721513422464978},
{ 2.22474487139, 2.22474487139, -1.0},
{ 2.22474487139, 2.22474487139, 1.0},
{ 3.0862664687972017, 1.1721513422464978, 0.0},
{ 1.1721513422464978, 3.0862664687972017, 0.0}
};
Grad4 grad4[GRAD4_LEN] = {
{-0.753341017856078, -0.37968289875261624, -0.37968289875261624, -0.37968289875261624},
{-0.7821684431180708, -0.4321472685365301, -0.4321472685365301, 0.12128480194602098},
{-0.7821684431180708, -0.4321472685365301, 0.12128480194602098, -0.4321472685365301},
{-0.7821684431180708, 0.12128480194602098, -0.4321472685365301, -0.4321472685365301},
{-0.8586508742123365, -0.508629699630796, 0.044802370851755174, 0.044802370851755174},
{-0.8586508742123365, 0.044802370851755174, -0.508629699630796, 0.044802370851755174},
{-0.8586508742123365, 0.044802370851755174, 0.044802370851755174, -0.508629699630796},
{-0.9982828964265062, -0.03381941603233842, -0.03381941603233842, -0.03381941603233842},
{-0.37968289875261624, -0.753341017856078, -0.37968289875261624, -0.37968289875261624},
{-0.4321472685365301, -0.7821684431180708, -0.4321472685365301, 0.12128480194602098},
{-0.4321472685365301, -0.7821684431180708, 0.12128480194602098, -0.4321472685365301},
{ 0.12128480194602098, -0.7821684431180708, -0.4321472685365301, -0.4321472685365301},
{-0.508629699630796, -0.8586508742123365, 0.044802370851755174, 0.044802370851755174},
{ 0.044802370851755174, -0.8586508742123365, -0.508629699630796, 0.044802370851755174},
{ 0.044802370851755174, -0.8586508742123365, 0.044802370851755174, -0.508629699630796},
{-0.03381941603233842, -0.9982828964265062, -0.03381941603233842, -0.03381941603233842},
{-0.37968289875261624, -0.37968289875261624, -0.753341017856078, -0.37968289875261624},
{-0.4321472685365301, -0.4321472685365301, -0.7821684431180708, 0.12128480194602098},
{-0.4321472685365301, 0.12128480194602098, -0.7821684431180708, -0.4321472685365301},
{ 0.12128480194602098, -0.4321472685365301, -0.7821684431180708, -0.4321472685365301},
{-0.508629699630796, 0.044802370851755174, -0.8586508742123365, 0.044802370851755174},
{ 0.044802370851755174, -0.508629699630796, -0.8586508742123365, 0.044802370851755174},
{ 0.044802370851755174, 0.044802370851755174, -0.8586508742123365, -0.508629699630796},
{-0.03381941603233842, -0.03381941603233842, -0.9982828964265062, -0.03381941603233842},
{-0.37968289875261624, -0.37968289875261624, -0.37968289875261624, -0.753341017856078},
{-0.4321472685365301, -0.4321472685365301, 0.12128480194602098, -0.7821684431180708},
{-0.4321472685365301, 0.12128480194602098, -0.4321472685365301, -0.7821684431180708},
{ 0.12128480194602098, -0.4321472685365301, -0.4321472685365301, -0.7821684431180708},
{-0.508629699630796, 0.044802370851755174, 0.044802370851755174, -0.8586508742123365},
{ 0.044802370851755174, -0.508629699630796, 0.044802370851755174, -0.8586508742123365},
{ 0.044802370851755174, 0.044802370851755174, -0.508629699630796, -0.8586508742123365},
{-0.03381941603233842, -0.03381941603233842, -0.03381941603233842, -0.9982828964265062},
{-0.6740059517812944, -0.3239847771997537, -0.3239847771997537, 0.5794684678643381},
{-0.7504883828755602, -0.4004672082940195, 0.15296486218853164, 0.5029860367700724},
{-0.7504883828755602, 0.15296486218853164, -0.4004672082940195, 0.5029860367700724},
{-0.8828161875373585, 0.08164729285680945, 0.08164729285680945, 0.4553054119602712},
{-0.4553054119602712, -0.08164729285680945, -0.08164729285680945, 0.8828161875373585},
{-0.5029860367700724, -0.15296486218853164, 0.4004672082940195, 0.7504883828755602},
{-0.5029860367700724, 0.4004672082940195, -0.15296486218853164, 0.7504883828755602},
{-0.5794684678643381, 0.3239847771997537, 0.3239847771997537, 0.6740059517812944},
{-0.3239847771997537, -0.6740059517812944, -0.3239847771997537, 0.5794684678643381},
{-0.4004672082940195, -0.7504883828755602, 0.15296486218853164, 0.5029860367700724},
{ 0.15296486218853164, -0.7504883828755602, -0.4004672082940195, 0.5029860367700724},
{ 0.08164729285680945, -0.8828161875373585, 0.08164729285680945, 0.4553054119602712},
{-0.08164729285680945, -0.4553054119602712, -0.08164729285680945, 0.8828161875373585},
{-0.15296486218853164, -0.5029860367700724, 0.4004672082940195, 0.7504883828755602},
{ 0.4004672082940195, -0.5029860367700724, -0.15296486218853164, 0.7504883828755602},
{ 0.3239847771997537, -0.5794684678643381, 0.3239847771997537, 0.6740059517812944},
{-0.3239847771997537, -0.3239847771997537, -0.6740059517812944, 0.5794684678643381},
{-0.4004672082940195, 0.15296486218853164, -0.7504883828755602, 0.5029860367700724},
{ 0.15296486218853164, -0.4004672082940195, -0.7504883828755602, 0.5029860367700724},
{ 0.08164729285680945, 0.08164729285680945, -0.8828161875373585, 0.4553054119602712},
{-0.08164729285680945, -0.08164729285680945, -0.4553054119602712, 0.8828161875373585},
{-0.15296486218853164, 0.4004672082940195, -0.5029860367700724, 0.7504883828755602},
{ 0.4004672082940195, -0.15296486218853164, -0.5029860367700724, 0.7504883828755602},
{ 0.3239847771997537, 0.3239847771997537, -0.5794684678643381, 0.6740059517812944},
{-0.6740059517812944, -0.3239847771997537, 0.5794684678643381, -0.3239847771997537},
{-0.7504883828755602, -0.4004672082940195, 0.5029860367700724, 0.15296486218853164},
{-0.7504883828755602, 0.15296486218853164, 0.5029860367700724, -0.4004672082940195},
{-0.8828161875373585, 0.08164729285680945, 0.4553054119602712, 0.08164729285680945},
{-0.4553054119602712, -0.08164729285680945, 0.8828161875373585, -0.08164729285680945},
{-0.5029860367700724, -0.15296486218853164, 0.7504883828755602, 0.4004672082940195},
{-0.5029860367700724, 0.4004672082940195, 0.7504883828755602, -0.15296486218853164},
{-0.5794684678643381, 0.3239847771997537, 0.6740059517812944, 0.3239847771997537},
{-0.3239847771997537, -0.6740059517812944, 0.5794684678643381, -0.3239847771997537},
{-0.4004672082940195, -0.7504883828755602, 0.5029860367700724, 0.15296486218853164},
{ 0.15296486218853164, -0.7504883828755602, 0.5029860367700724, -0.4004672082940195},
{ 0.08164729285680945, -0.8828161875373585, 0.4553054119602712, 0.08164729285680945},
{-0.08164729285680945, -0.4553054119602712, 0.8828161875373585, -0.08164729285680945},
{-0.15296486218853164, -0.5029860367700724, 0.7504883828755602, 0.4004672082940195},
{ 0.4004672082940195, -0.5029860367700724, 0.7504883828755602, -0.15296486218853164},
{ 0.3239847771997537, -0.5794684678643381, 0.6740059517812944, 0.3239847771997537},
{-0.3239847771997537, -0.3239847771997537, 0.5794684678643381, -0.6740059517812944},
{-0.4004672082940195, 0.15296486218853164, 0.5029860367700724, -0.7504883828755602},
{ 0.15296486218853164, -0.4004672082940195, 0.5029860367700724, -0.7504883828755602},
{ 0.08164729285680945, 0.08164729285680945, 0.4553054119602712, -0.8828161875373585},
{-0.08164729285680945, -0.08164729285680945, 0.8828161875373585, -0.4553054119602712},
{-0.15296486218853164, 0.4004672082940195, 0.7504883828755602, -0.5029860367700724},
{ 0.4004672082940195, -0.15296486218853164, 0.7504883828755602, -0.5029860367700724},
{ 0.3239847771997537, 0.3239847771997537, 0.6740059517812944, -0.5794684678643381},
{-0.6740059517812944, 0.5794684678643381, -0.3239847771997537, -0.3239847771997537},
{-0.7504883828755602, 0.5029860367700724, -0.4004672082940195, 0.15296486218853164},
{-0.7504883828755602, 0.5029860367700724, 0.15296486218853164, -0.4004672082940195},
{-0.8828161875373585, 0.4553054119602712, 0.08164729285680945, 0.08164729285680945},
{-0.4553054119602712, 0.8828161875373585, -0.08164729285680945, -0.08164729285680945},
{-0.5029860367700724, 0.7504883828755602, -0.15296486218853164, 0.4004672082940195},
{-0.5029860367700724, 0.7504883828755602, 0.4004672082940195, -0.15296486218853164},
{-0.5794684678643381, 0.6740059517812944, 0.3239847771997537, 0.3239847771997537},
{-0.3239847771997537, 0.5794684678643381, -0.6740059517812944, -0.3239847771997537},
{-0.4004672082940195, 0.5029860367700724, -0.7504883828755602, 0.15296486218853164},
{ 0.15296486218853164, 0.5029860367700724, -0.7504883828755602, -0.4004672082940195},
{ 0.08164729285680945, 0.4553054119602712, -0.8828161875373585, 0.08164729285680945},
{-0.08164729285680945, 0.8828161875373585, -0.4553054119602712, -0.08164729285680945},
{-0.15296486218853164, 0.7504883828755602, -0.5029860367700724, 0.4004672082940195},
{ 0.4004672082940195, 0.7504883828755602, -0.5029860367700724, -0.15296486218853164},
{ 0.3239847771997537, 0.6740059517812944, -0.5794684678643381, 0.3239847771997537},
{-0.3239847771997537, 0.5794684678643381, -0.3239847771997537, -0.6740059517812944},
{-0.4004672082940195, 0.5029860367700724, 0.15296486218853164, -0.7504883828755602},
{ 0.15296486218853164, 0.5029860367700724, -0.4004672082940195, -0.7504883828755602},
{ 0.08164729285680945, 0.4553054119602712, 0.08164729285680945, -0.8828161875373585},
{-0.08164729285680945, 0.8828161875373585, -0.08164729285680945, -0.4553054119602712},
{-0.15296486218853164, 0.7504883828755602, 0.4004672082940195, -0.5029860367700724},
{ 0.4004672082940195, 0.7504883828755602, -0.15296486218853164, -0.5029860367700724},
{ 0.3239847771997537, 0.6740059517812944, 0.3239847771997537, -0.5794684678643381},
{ 0.5794684678643381, -0.6740059517812944, -0.3239847771997537, -0.3239847771997537},
{ 0.5029860367700724, -0.7504883828755602, -0.4004672082940195, 0.15296486218853164},
{ 0.5029860367700724, -0.7504883828755602, 0.15296486218853164, -0.4004672082940195},
{ 0.4553054119602712, -0.8828161875373585, 0.08164729285680945, 0.08164729285680945},
{ 0.8828161875373585, -0.4553054119602712, -0.08164729285680945, -0.08164729285680945},
{ 0.7504883828755602, -0.5029860367700724, -0.15296486218853164, 0.4004672082940195},
{ 0.7504883828755602, -0.5029860367700724, 0.4004672082940195, -0.15296486218853164},
{ 0.6740059517812944, -0.5794684678643381, 0.3239847771997537, 0.3239847771997537},
{ 0.5794684678643381, -0.3239847771997537, -0.6740059517812944, -0.3239847771997537},
{ 0.5029860367700724, -0.4004672082940195, -0.7504883828755602, 0.15296486218853164},
{ 0.5029860367700724, 0.15296486218853164, -0.7504883828755602, -0.4004672082940195},
{ 0.4553054119602712, 0.08164729285680945, -0.8828161875373585, 0.08164729285680945},
{ 0.8828161875373585, -0.08164729285680945, -0.4553054119602712, -0.08164729285680945},
{ 0.7504883828755602, -0.15296486218853164, -0.5029860367700724, 0.4004672082940195},
{ 0.7504883828755602, 0.4004672082940195, -0.5029860367700724, -0.15296486218853164},
{ 0.6740059517812944, 0.3239847771997537, -0.5794684678643381, 0.3239847771997537},
{ 0.5794684678643381, -0.3239847771997537, -0.3239847771997537, -0.6740059517812944},
{ 0.5029860367700724, -0.4004672082940195, 0.15296486218853164, -0.7504883828755602},
{ 0.5029860367700724, 0.15296486218853164, -0.4004672082940195, -0.7504883828755602},
{ 0.4553054119602712, 0.08164729285680945, 0.08164729285680945, -0.8828161875373585},
{ 0.8828161875373585, -0.08164729285680945, -0.08164729285680945, -0.4553054119602712},
{ 0.7504883828755602, -0.15296486218853164, 0.4004672082940195, -0.5029860367700724},
{ 0.7504883828755602, 0.4004672082940195, -0.15296486218853164, -0.5029860367700724},
{ 0.6740059517812944, 0.3239847771997537, 0.3239847771997537, -0.5794684678643381},
{ 0.03381941603233842, 0.03381941603233842, 0.03381941603233842, 0.9982828964265062},
{-0.044802370851755174, -0.044802370851755174, 0.508629699630796, 0.8586508742123365},
{-0.044802370851755174, 0.508629699630796, -0.044802370851755174, 0.8586508742123365},
{-0.12128480194602098, 0.4321472685365301, 0.4321472685365301, 0.7821684431180708},
{ 0.508629699630796, -0.044802370851755174, -0.044802370851755174, 0.8586508742123365},
{ 0.4321472685365301, -0.12128480194602098, 0.4321472685365301, 0.7821684431180708},
{ 0.4321472685365301, 0.4321472685365301, -0.12128480194602098, 0.7821684431180708},
{ 0.37968289875261624, 0.37968289875261624, 0.37968289875261624, 0.753341017856078},
{ 0.03381941603233842, 0.03381941603233842, 0.9982828964265062, 0.03381941603233842},
{-0.044802370851755174, 0.044802370851755174, 0.8586508742123365, 0.508629699630796},
{-0.044802370851755174, 0.508629699630796, 0.8586508742123365, -0.044802370851755174},
{-0.12128480194602098, 0.4321472685365301, 0.7821684431180708, 0.4321472685365301},
{ 0.508629699630796, -0.044802370851755174, 0.8586508742123365, -0.044802370851755174},
{ 0.4321472685365301, -0.12128480194602098, 0.7821684431180708, 0.4321472685365301},
{ 0.4321472685365301, 0.4321472685365301, 0.7821684431180708, -0.12128480194602098},
{ 0.37968289875261624, 0.37968289875261624, 0.753341017856078, 0.37968289875261624},
{ 0.03381941603233842, 0.9982828964265062, 0.03381941603233842, 0.03381941603233842},
{-0.044802370851755174, 0.8586508742123365, -0.044802370851755174, 0.508629699630796},
{-0.044802370851755174, 0.8586508742123365, 0.508629699630796, -0.044802370851755174},
{-0.12128480194602098, 0.7821684431180708, 0.4321472685365301, 0.4321472685365301},
{ 0.508629699630796, 0.8586508742123365, -0.044802370851755174, -0.044802370851755174},
{ 0.4321472685365301, 0.7821684431180708, -0.12128480194602098, 0.4321472685365301},
{ 0.4321472685365301, 0.7821684431180708, 0.4321472685365301, -0.12128480194602098},
{ 0.37968289875261624, 0.753341017856078, 0.37968289875261624, 0.37968289875261624},
{ 0.9982828964265062, 0.03381941603233842, 0.03381941603233842, 0.03381941603233842},
{ 0.8586508742123365, -0.044802370851755174, -0.044802370851755174, 0.508629699630796},
{ 0.8586508742123365, -0.044802370851755174, 0.508629699630796, -0.044802370851755174},
{ 0.7821684431180708, -0.12128480194602098, 0.4321472685365301, 0.4321472685365301},
{ 0.8586508742123365, 0.508629699630796, -0.044802370851755174, -0.044802370851755174},
{ 0.7821684431180708, 0.4321472685365301, -0.12128480194602098, 0.4321472685365301},
{ 0.7821684431180708, 0.4321472685365301, 0.4321472685365301, -0.12128480194602098},
{ 0.753341017856078, 0.37968289875261624, 0.37968289875261624, 0.37968289875261624}
};
LatticePoint2D LOOKUP_2D[8*4];
LatticePoint3D LOOKUP_3D[8*14];
U8 LOOKUP_4DLens[256] = {20,15,16,17,15,16,12,15,16,12,10,14,17,15,14,17,15,16,12,15,16,14,14,13,12,14,11,12,15,13,12,14,16,12,10,14,12,14,11,12,10,11,10,13,14,12,13,15,17,15,14,17,15,13,12,14,14,12,13,15,17,14,15,17,15,16,12,15,16,14,14,13,12,14,11,12,15,13,12,14,16,14,14,13,14,16,16,10,14,16,19,11,13,10,11,10,12,14,11,12,14,16,19,11,11,19,13,14,12,11,14,13,15,13,12,14,13,10,11,10,12,11,14,13,14,10,13,13,16,12,10,14,12,14,11,12,10,11,10,13,14,12,13,15,12,14,11,12,14,16,19,11,11,19,13,14,12,11,14,13,10,11,10,13,11,19,13,14,10,13,16,14,13,14,14,16,14,12,13,15,12,11,14,13,13,14,14,16,15,13,16,15,17,15,14,17,15,13,12,14,14,12,13,15,17,14,15,17,15,13,12,14,13,10,11,10,12,11,14,13,14,10,13,13,14,12,13,15,12,11,14,13,13,14,14,16,15,13,16,15,17,14,15,17,14,10,13,13,15,13,16,15,17,13,15,20};
LatticePoint4D L40[20];
LatticePoint4D L41[15];
LatticePoint4D L42[16];
LatticePoint4D L43[17];
LatticePoint4D L44[15];
LatticePoint4D L45[16];
LatticePoint4D L46[12];
LatticePoint4D L47[15];
LatticePoint4D L48[16];
LatticePoint4D L49[12];
LatticePoint4D L410[10];
LatticePoint4D L411[14];
LatticePoint4D L412[17];
LatticePoint4D L413[15];
LatticePoint4D L414[14];
LatticePoint4D L415[17];
LatticePoint4D L416[15];
LatticePoint4D L417[16];
LatticePoint4D L418[12];
LatticePoint4D L419[15];
LatticePoint4D L420[16];
LatticePoint4D L421[14];
LatticePoint4D L422[14];
LatticePoint4D L423[13];
LatticePoint4D L424[12];
LatticePoint4D L425[14];
LatticePoint4D L426[11];
LatticePoint4D L427[12];
LatticePoint4D L428[15];
LatticePoint4D L429[13];
LatticePoint4D L430[12];
LatticePoint4D L431[14];
LatticePoint4D L432[16];
LatticePoint4D L433[12];
LatticePoint4D L434[10];
LatticePoint4D L435[14];
LatticePoint4D L436[12];
LatticePoint4D L437[14];
LatticePoint4D L438[11];
LatticePoint4D L439[12];
LatticePoint4D L440[10];
LatticePoint4D L441[11];
LatticePoint4D L442[10];
LatticePoint4D L443[13];
LatticePoint4D L444[14];
LatticePoint4D L445[12];
LatticePoint4D L446[13];
LatticePoint4D L447[15];
LatticePoint4D L448[17];
LatticePoint4D L449[15];
LatticePoint4D L450[14];
LatticePoint4D L451[17];
LatticePoint4D L452[15];
LatticePoint4D L453[13];
LatticePoint4D L454[12];
LatticePoint4D L455[14];
LatticePoint4D L456[14];
LatticePoint4D L457[12];
LatticePoint4D L458[13];
LatticePoint4D L459[15];
LatticePoint4D L460[17];
LatticePoint4D L461[14];
LatticePoint4D L462[15];
LatticePoint4D L463[17];
LatticePoint4D L464[15];
LatticePoint4D L465[16];
LatticePoint4D L466[12];
LatticePoint4D L467[15];
LatticePoint4D L468[16];
LatticePoint4D L469[14];
LatticePoint4D L470[14];
LatticePoint4D L471[13];
LatticePoint4D L472[12];
LatticePoint4D L473[14];
LatticePoint4D L474[11];
LatticePoint4D L475[12];
LatticePoint4D L476[15];
LatticePoint4D L477[13];
LatticePoint4D L478[12];
LatticePoint4D L479[14];
LatticePoint4D L480[16];
LatticePoint4D L481[14];
LatticePoint4D L482[14];
LatticePoint4D L483[13];
LatticePoint4D L484[14];
LatticePoint4D L485[16];
LatticePoint4D L486[16];
LatticePoint4D L487[10];
LatticePoint4D L488[14];
LatticePoint4D L489[16];
LatticePoint4D L490[19];
LatticePoint4D L491[11];
LatticePoint4D L492[13];
LatticePoint4D L493[10];
LatticePoint4D L494[11];
LatticePoint4D L495[10];
LatticePoint4D L496[12];
LatticePoint4D L497[14];
LatticePoint4D L498[11];
LatticePoint4D L499[12];
LatticePoint4D L4100[14];
LatticePoint4D L4101[16];
LatticePoint4D L4102[19];
LatticePoint4D L4103[11];
LatticePoint4D L4104[11];
LatticePoint4D L4105[19];
LatticePoint4D L4106[13];
LatticePoint4D L4107[14];
LatticePoint4D L4108[12];
LatticePoint4D L4109[11];
LatticePoint4D L4110[14];
LatticePoint4D L4111[13];
LatticePoint4D L4112[15];
LatticePoint4D L4113[13];
LatticePoint4D L4114[12];
LatticePoint4D L4115[14];
LatticePoint4D L4116[13];
LatticePoint4D L4117[10];
LatticePoint4D L4118[11];
LatticePoint4D L4119[10];
LatticePoint4D L4120[12];
LatticePoint4D L4121[11];
LatticePoint4D L4122[14];
LatticePoint4D L4123[13];
LatticePoint4D L4124[14];
LatticePoint4D L4125[10];
LatticePoint4D L4126[13];
LatticePoint4D L4127[13];
LatticePoint4D L4128[16];
LatticePoint4D L4129[12];
LatticePoint4D L4130[10];
LatticePoint4D L4131[14];
LatticePoint4D L4132[12];
LatticePoint4D L4133[14];
LatticePoint4D L4134[11];
LatticePoint4D L4135[12];
LatticePoint4D L4136[10];
LatticePoint4D L4137[11];
LatticePoint4D L4138[10];
LatticePoint4D L4139[13];
LatticePoint4D L4140[14];
LatticePoint4D L4141[12];
LatticePoint4D L4142[13];
LatticePoint4D L4143[15];
LatticePoint4D L4144[12];
LatticePoint4D L4145[14];
LatticePoint4D L4146[11];
LatticePoint4D L4147[12];
LatticePoint4D L4148[14];
LatticePoint4D L4149[16];
LatticePoint4D L4150[19];
LatticePoint4D L4151[11];
LatticePoint4D L4152[11];
LatticePoint4D L4153[19];
LatticePoint4D L4154[13];
LatticePoint4D L4155[14];
LatticePoint4D L4156[12];
LatticePoint4D L4157[11];
LatticePoint4D L4158[14];
LatticePoint4D L4159[13];
LatticePoint4D L4160[10];
LatticePoint4D L4161[11];
LatticePoint4D L4162[10];
LatticePoint4D L4163[13];
LatticePoint4D L4164[11];
LatticePoint4D L4165[19];
LatticePoint4D L4166[13];
LatticePoint4D L4167[14];
LatticePoint4D L4168[10];
LatticePoint4D L4169[13];
LatticePoint4D L4170[16];
LatticePoint4D L4171[14];
LatticePoint4D L4172[13];
LatticePoint4D L4173[14];
LatticePoint4D L4174[14];
LatticePoint4D L4175[16];
LatticePoint4D L4176[14];
LatticePoint4D L4177[12];
LatticePoint4D L4178[13];
LatticePoint4D L4179[15];
LatticePoint4D L4180[12];
LatticePoint4D L4181[11];
LatticePoint4D L4182[14];
LatticePoint4D L4183[13];
LatticePoint4D L4184[13];
LatticePoint4D L4185[14];
LatticePoint4D L4186[14];
LatticePoint4D L4187[16];
LatticePoint4D L4188[15];
LatticePoint4D L4189[13];
LatticePoint4D L4190[16];
LatticePoint4D L4191[15];
LatticePoint4D L4192[17];
LatticePoint4D L4193[15];
LatticePoint4D L4194[14];
LatticePoint4D L4195[17];
LatticePoint4D L4196[15];
LatticePoint4D L4197[13];
LatticePoint4D L4198[12];
LatticePoint4D L4199[14];
LatticePoint4D L4200[14];
LatticePoint4D L4201[12];
LatticePoint4D L4202[13];
LatticePoint4D L4203[15];
LatticePoint4D L4204[17];
LatticePoint4D L4205[14];
LatticePoint4D L4206[15];
LatticePoint4D L4207[17];
LatticePoint4D L4208[15];
LatticePoint4D L4209[13];
LatticePoint4D L4210[12];
LatticePoint4D L4211[14];
LatticePoint4D L4212[13];
LatticePoint4D L4213[10];
LatticePoint4D L4214[11];
LatticePoint4D L4215[10];
LatticePoint4D L4216[12];
LatticePoint4D L4217[11];
LatticePoint4D L4218[14];
LatticePoint4D L4219[13];
LatticePoint4D L4220[14];
LatticePoint4D L4221[10];
LatticePoint4D L4222[13];
LatticePoint4D L4223[13];
LatticePoint4D L4224[14];
LatticePoint4D L4225[12];
LatticePoint4D L4226[13];
LatticePoint4D L4227[15];
LatticePoint4D L4228[12];
LatticePoint4D L4229[11];
LatticePoint4D L4230[14];
LatticePoint4D L4231[13];
LatticePoint4D L4232[13];
LatticePoint4D L4233[14];
LatticePoint4D L4234[14];
LatticePoint4D L4235[16];
LatticePoint4D L4236[15];
LatticePoint4D L4237[13];
LatticePoint4D L4238[16];
LatticePoint4D L4239[15];
LatticePoint4D L4240[17];
LatticePoint4D L4241[14];
LatticePoint4D L4242[15];
LatticePoint4D L4243[17];
LatticePoint4D L4244[14];
LatticePoint4D L4245[10];
LatticePoint4D L4246[13];
LatticePoint4D L4247[13];
LatticePoint4D L4248[15];
LatticePoint4D L4249[13];
LatticePoint4D L4250[16];
LatticePoint4D L4251[15];
LatticePoint4D L4252[17];
LatticePoint4D L4253[13];
LatticePoint4D L4254[15];
LatticePoint4D L4255[20];
LatticePoint4D *LOOKUP_4D[256] = {L40,L41,L42,L43,L44,L45,L46,L47,L48,L49,L410,L411,L412,L413,L414,L415,L416,L417,L418,L419,L420,L421,L422,L423,L424,L425,L426,L427,L428,L429,L430,L431,L432,L433,L434,L435,L436,L437,L438,L439,L440,L441,L442,L443,L444,L445,L446,L447,L448,L449,L450,L451,L452,L453,L454,L455,L456,L457,L458,L459,L460,L461,L462,L463,L464,L465,L466,L467,L468,L469,L470,L471,L472,L473,L474,L475,L476,L477,L478,L479,L480,L481,L482,L483,L484,L485,L486,L487,L488,L489,L490,L491,L492,L493,L494,L495,L496,L497,L498,L499,L4100,L4101,L4102,L4103,L4104,L4105,L4106,L4107,L4108,L4109,L4110,L4111,L4112,L4113,L4114,L4115,L4116,L4117,L4118,L4119,L4120,L4121,L4122,L4123,L4124,L4125,L4126,L4127,L4128,L4129,L4130,L4131,L4132,L4133,L4134,L4135,L4136,L4137,L4138,L4139,L4140,L4141,L4142,L4143,L4144,L4145,L4146,L4147,L4148,L4149,L4150,L4151,L4152,L4153,L4154,L4155,L4156,L4157,L4158,L4159,L4160,L4161,L4162,L4163,L4164,L4165,L4166,L4167,L4168,L4169,L4170,L4171,L4172,L4173,L4174,L4175,L4176,L4177,L4178,L4179,L4180,L4181,L4182,L4183,L4184,L4185,L4186,L4187,L4188,L4189,L4190,L4191,L4192,L4193,L4194,L4195,L4196,L4197,L4198,L4199,L4200,L4201,L4202,L4203,L4204,L4205,L4206,L4207,L4208,L4209,L4210,L4211,L4212,L4213,L4214,L4215,L4216,L4217,L4218,L4219,L4220,L4221,L4222,L4223,L4224,L4225,L4226,L4227,L4228,L4229,L4230,L4231,L4232,L4233,L4234,L4235,L4236,L4237,L4238,L4239,L4240,L4241,L4242,L4243,L4244,L4245,L4246,L4247,L4248,L4249,L4250,L4251,L4252,L4253,L4254,L4255};
U8 L4DP0[20] = {21,69,81,84,85,86,89,90,101,102,105,106,149,150,153,154,165,166,169,170};
U8 L4DP1[15] = {21,69,81,85,86,89,90,101,102,106,149,150,154,166,170};
U8 L4DP2[16] = {1,5,17,21,65,69,81,85,86,90,102,106,150,154,166,170};
U8 L4DP3[17] = {1,21,22,69,70,81,82,85,86,90,102,106,150,154,166,170,171};
U8 L4DP4[15] = {21,69,84,85,86,89,90,101,105,106,149,153,154,169,170};
U8 L4DP5[16] = {5,21,69,85,86,89,90,101,102,105,106,149,150,153,154,170};
U8 L4DP6[12] = {5,21,69,85,86,89,90,102,106,150,154,170};
U8 L4DP7[15] = {5,21,22,69,70,85,86,89,90,102,106,150,154,170,171};
U8 L4DP8[16] = {4,5,20,21,68,69,84,85,89,90,105,106,153,154,169,170};
U8 L4DP9[12] = {5,21,69,85,86,89,90,105,106,153,154,170};
U8 L4DP10[10] = {5,21,69,85,86,89,90,106,154,170};
U8 L4DP11[14] = {5,21,22,69,70,85,86,89,90,91,106,154,170,171};
U8 L4DP12[17] = {4,21,25,69,73,84,85,88,89,90,105,106,153,154,169,170,174};
U8 L4DP13[15] = {5,21,25,69,73,85,86,89,90,105,106,153,154,170,174};
U8 L4DP14[14] = {5,21,25,69,73,85,86,89,90,94,106,154,170,174};
U8 L4DP15[17] = {5,21,26,69,74,85,86,89,90,91,94,106,154,170,171,174,175};
U8 L4DP16[15] = {21,81,84,85,86,89,101,102,105,106,149,165,166,169,170};
U8 L4DP17[16] = {17,21,81,85,86,89,90,101,102,105,106,149,150,165,166,170};
U8 L4DP18[12] = {17,21,81,85,86,90,101,102,106,150,166,170};
U8 L4DP19[15] = {17,21,22,81,82,85,86,90,101,102,106,150,166,170,171};
U8 L4DP20[16] = {20,21,84,85,86,89,90,101,102,105,106,149,153,165,169,170};
U8 L4DP21[14] = {21,85,86,89,90,101,102,105,106,149,154,166,169,170};
U8 L4DP22[14] = {21,85,86,89,90,101,102,105,106,150,154,166,170,171};
U8 L4DP23[13] = {21,22,85,86,90,102,106,107,150,154,166,170,171};
U8 L4DP24[12] = {20,21,84,85,89,90,101,105,106,153,169,170};
U8 L4DP25[14] = {21,85,86,89,90,101,102,105,106,153,154,169,170,174};
U8 L4DP26[11] = {21,85,86,89,90,101,102,105,106,154,170};
U8 L4DP27[12] = {21,22,85,86,89,90,102,106,107,154,170,171};
U8 L4DP28[15] = {20,21,25,84,85,88,89,90,101,105,106,153,169,170,174};
U8 L4DP29[13] = {21,25,85,89,90,105,106,110,153,154,169,170,174};
U8 L4DP30[12] = {21,25,85,86,89,90,105,106,110,154,170,174};
U8 L4DP31[14] = {21,26,85,86,89,90,106,107,110,154,170,171,174,175};
U8 L4DP32[16] = {16,17,20,21,80,81,84,85,101,102,105,106,165,166,169,170};
U8 L4DP33[12] = {17,21,81,85,86,101,102,105,106,165,166,170};
U8 L4DP34[10] = {17,21,81,85,86,101,102,106,166,170};
U8 L4DP35[14] = {17,21,22,81,82,85,86,101,102,103,106,166,170,171};
U8 L4DP36[12] = {20,21,84,85,89,101,102,105,106,165,169,170};
U8 L4DP37[14] = {21,85,86,89,90,101,102,105,106,165,166,169,170,186};
U8 L4DP38[11] = {21,85,86,89,90,101,102,105,106,166,170};
U8 L4DP39[12] = {21,22,85,86,90,101,102,106,107,166,170,171};
U8 L4DP40[10] = {20,21,84,85,89,101,105,106,169,170};
U8 L4DP41[11] = {21,85,86,89,90,101,102,105,106,169,170};
U8 L4DP42[10] = {21,85,86,89,90,101,102,105,106,170};
U8 L4DP43[13] = {21,22,85,86,89,90,101,102,105,106,107,170,171};
U8 L4DP44[14] = {20,21,25,84,85,88,89,101,105,106,109,169,170,174};
U8 L4DP45[12] = {21,25,85,89,90,101,105,106,110,169,170,174};
U8 L4DP46[13] = {21,25,85,86,89,90,101,102,105,106,110,170,174};
U8 L4DP47[15] = {21,85,86,89,90,102,105,106,107,110,154,170,171,174,175};
U8 L4DP48[17] = {16,21,37,81,84,85,97,100,101,102,105,106,165,166,169,170,186};
U8 L4DP49[15] = {17,21,37,81,85,86,97,101,102,105,106,165,166,170,186};
U8 L4DP50[14] = {17,21,37,81,85,86,97,101,102,106,118,166,170,186};
U8 L4DP51[17] = {17,21,38,81,85,86,98,101,102,103,106,118,166,170,171,186,187};
U8 L4DP52[15] = {20,21,37,84,85,89,100,101,102,105,106,165,169,170,186};
U8 L4DP53[13] = {21,37,85,101,102,105,106,122,165,166,169,170,186};
U8 L4DP54[12] = {21,37,85,86,101,102,105,106,122,166,170,186};
U8 L4DP55[14] = {21,38,85,86,101,102,106,107,122,166,170,171,186,187};
U8 L4DP56[14] = {20,21,37,84,85,89,100,101,105,106,121,169,170,186};
U8 L4DP57[12] = {21,37,85,89,101,102,105,106,122,169,170,186};
U8 L4DP58[13] = {21,37,85,86,89,90,101,102,105,106,122,170,186};
U8 L4DP59[15] = {21,85,86,90,101,102,105,106,107,122,166,170,171,186,187};
U8 L4DP60[17] = {20,21,41,84,85,89,101,104,105,106,109,121,169,170,174,186,190};
U8 L4DP61[14] = {21,41,85,89,101,105,106,110,122,169,170,174,186,190};
U8 L4DP62[15] = {21,85,89,90,101,102,105,106,110,122,169,170,174,186,190};
U8 L4DP63[17] = {21,85,86,89,90,101,102,105,106,107,110,122,170,171,174,186,191};
U8 L4DP64[15] = {69,81,84,85,86,89,101,149,150,153,154,165,166,169,170};
U8 L4DP65[16] = {65,69,81,85,86,89,90,101,102,149,150,153,154,165,166,170};
U8 L4DP66[12] = {65,69,81,85,86,90,102,149,150,154,166,170};
U8 L4DP67[15] = {65,69,70,81,82,85,86,90,102,149,150,154,166,170,171};
U8 L4DP68[16] = {68,69,84,85,86,89,90,101,105,149,150,153,154,165,169,170};
U8 L4DP69[14] = {69,85,86,89,90,101,106,149,150,153,154,166,169,170};
U8 L4DP70[14] = {69,85,86,89,90,102,106,149,150,153,154,166,170,171};
U8 L4DP71[13] = {69,70,85,86,90,102,106,150,154,155,166,170,171};
U8 L4DP72[12] = {68,69,84,85,89,90,105,149,153,154,169,170};
U8 L4DP73[14] = {69,85,86,89,90,105,106,149,150,153,154,169,170,174};
U8 L4DP74[11] = {69,85,86,89,90,106,149,150,153,154,170};
U8 L4DP75[12] = {69,70,85,86,89,90,106,150,154,155,170,171};
U8 L4DP76[15] = {68,69,73,84,85,88,89,90,105,149,153,154,169,170,174};
U8 L4DP77[13] = {69,73,85,89,90,105,106,153,154,158,169,170,174};
U8 L4DP78[12] = {69,73,85,86,89,90,106,153,154,158,170,174};
U8 L4DP79[14] = {69,74,85,86,89,90,106,154,155,158,170,171,174,175};
U8 L4DP80[16] = {80,81,84,85,86,89,101,102,105,149,150,153,165,166,169,170};
U8 L4DP81[14] = {81,85,86,89,101,102,106,149,150,154,165,166,169,170};
U8 L4DP82[14] = {81,85,86,90,101,102,106,149,150,154,165,166,170,171};
U8 L4DP83[13] = {81,82,85,86,90,102,106,150,154,166,167,170,171};
U8 L4DP84[14] = {84,85,86,89,101,105,106,149,153,154,165,166,169,170};
U8 L4DP85[16] = {85,86,89,90,101,102,105,106,149,150,153,154,165,166,169,170};
U8 L4DP86[16] = {21,69,81,85,86,89,90,101,102,106,149,150,154,166,170,171};
U8 L4DP87[10] = {85,86,90,102,106,150,154,166,170,171};
U8 L4DP88[14] = {84,85,89,90,101,105,106,149,153,154,165,169,170,174};
U8 L4DP89[16] = {21,69,84,85,86,89,90,101,105,106,149,153,154,169,170,174};
U8 L4DP90[19] = {21,69,85,86,89,90,101,102,105,106,149,150,153,154,166,169,170,171,174};
U8 L4DP91[11] = {85,86,89,90,102,106,150,154,166,170,171};
U8 L4DP92[13] = {84,85,88,89,90,105,106,153,154,169,170,173,174};
U8 L4DP93[10] = {85,89,90,105,106,153,154,169,170,174};
U8 L4DP94[11] = {85,86,89,90,105,106,153,154,169,170,174};
U8 L4DP95[10] = {85,86,89,90,106,154,170,171,174,175};
U8 L4DP96[12] = {80,81,84,85,101,102,105,149,165,166,169,170};
U8 L4DP97[14] = {81,85,86,101,102,105,106,149,150,165,166,169,170,186};
U8 L4DP98[11] = {81,85,86,101,102,106,149,150,165,166,170};
U8 L4DP99[12] = {81,82,85,86,101,102,106,150,166,167,170,171};
U8 L4DP100[14] = {84,85,89,101,102,105,106,149,153,165,166,169,170,186};
U8 L4DP101[16] = {21,81,84,85,86,89,101,102,105,106,149,165,166,169,170,186};
U8 L4DP102[19] = {21,81,85,86,89,90,101,102,105,106,149,150,154,165,166,169,170,171,186};
U8 L4DP103[11] = {85,86,90,101,102,106,150,154,166,170,171};
U8 L4DP104[11] = {84,85,89,101,105,106,149,153,165,169,170};
U8 L4DP105[19] = {21,84,85,86,89,90,101,102,105,106,149,153,154,165,166,169,170,174,186};
U8 L4DP106[13] = {21,85,86,89,90,101,102,105,106,154,166,169,170};
U8 L4DP107[14] = {21,85,86,89,90,101,102,105,106,150,154,166,170,171};
U8 L4DP108[12] = {84,85,88,89,101,105,106,153,169,170,173,174};
U8 L4DP109[11] = {85,89,90,101,105,106,153,154,169,170,174};
U8 L4DP110[14] = {21,85,86,89,90,101,102,105,106,153,154,169,170,174};
U8 L4DP111[13] = {21,85,86,89,90,102,105,106,154,170,171,174,175};
U8 L4DP112[15] = {80,81,84,85,97,100,101,102,105,149,165,166,169,170,186};
U8 L4DP113[13] = {81,85,97,101,102,105,106,165,166,169,170,182,186};
U8 L4DP114[12] = {81,85,86,97,101,102,106,165,166,170,182,186};
U8 L4DP115[14] = {81,85,86,98,101,102,106,166,167,170,171,182,186,187};
U8 L4DP116[13] = {84,85,100,101,102,105,106,165,166,169,170,185,186};
U8 L4DP117[10] = {85,101,102,105,106,165,166,169,170,186};
U8 L4DP118[11] = {85,86,101,102,105,106,165,166,169,170,186};
U8 L4DP119[10] = {85,86,101,102,106,166,170,171,186,187};
U8 L4DP120[12] = {84,85,89,100,101,105,106,165,169,170,185,186};
U8 L4DP121[11] = {85,89,101,102,105,106,165,166,169,170,186};
U8 L4DP122[14] = {21,85,86,89,90,101,102,105,106,165,166,169,170,186};
U8 L4DP123[13] = {21,85,86,90,101,102,105,106,166,170,171,186,187};
U8 L4DP124[14] = {84,85,89,101,104,105,106,169,170,173,174,185,186,190};
U8 L4DP125[10] = {85,89,101,105,106,169,170,174,186,190};
U8 L4DP126[13] = {21,85,89,90,101,102,105,106,169,170,174,186,190};
U8 L4DP127[13] = {85,86,89,90,101,102,105,106,170,171,174,186,191};
U8 L4DP128[16] = {64,65,68,69,80,81,84,85,149,150,153,154,165,166,169,170};
U8 L4DP129[12] = {65,69,81,85,86,149,150,153,154,165,166,170};
U8 L4DP130[10] = {65,69,81,85,86,149,150,154,166,170};
U8 L4DP131[14] = {65,69,70,81,82,85,86,149,150,151,154,166,170,171};
U8 L4DP132[12] = {68,69,84,85,89,149,150,153,154,165,169,170};
U8 L4DP133[14] = {69,85,86,89,90,149,150,153,154,165,166,169,170,234};
U8 L4DP134[11] = {69,85,86,89,90,149,150,153,154,166,170};
U8 L4DP135[12] = {69,70,85,86,90,149,150,154,155,166,170,171};
U8 L4DP136[10] = {68,69,84,85,89,149,153,154,169,170};
U8 L4DP137[11] = {69,85,86,89,90,149,150,153,154,169,170};
U8 L4DP138[10] = {69,85,86,89,90,149,150,153,154,170};
U8 L4DP139[13] = {69,70,85,86,89,90,149,150,153,154,155,170,171};
U8 L4DP140[14] = {68,69,73,84,85,88,89,149,153,154,157,169,170,174};
U8 L4DP141[12] = {69,73,85,89,90,149,153,154,158,169,170,174};
U8 L4DP142[13] = {69,73,85,86,89,90,149,150,153,154,158,170,174};
U8 L4DP143[15] = {69,85,86,89,90,106,150,153,154,155,158,170,171,174,175};
U8 L4DP144[12] = {80,81,84,85,101,149,150,153,165,166,169,170};
U8 L4DP145[14] = {81,85,86,101,102,149,150,153,154,165,166,169,170,234};
U8 L4DP146[11] = {81,85,86,101,102,149,150,154,165,166,170};
U8 L4DP147[12] = {81,82,85,86,102,149,150,154,166,167,170,171};
U8 L4DP148[14] = {84,85,89,101,105,149,150,153,154,165,166,169,170,234};
U8 L4DP149[16] = {69,81,84,85,86,89,101,149,150,153,154,165,166,169,170,234};
U8 L4DP150[19] = {69,81,85,86,89,90,101,102,106,149,150,153,154,165,166,169,170,171,234};
U8 L4DP151[11] = {85,86,90,102,106,149,150,154,166,170,171};
U8 L4DP152[11] = {84,85,89,101,105,149,153,154,165,169,170};
U8 L4DP153[19] = {69,84,85,86,89,90,101,105,106,149,150,153,154,165,166,169,170,174,234};
U8 L4DP154[13] = {69,85,86,89,90,106,149,150,153,154,166,169,170};
U8 L4DP155[14] = {69,85,86,89,90,102,106,149,150,153,154,166,170,171};
U8 L4DP156[12] = {84,85,88,89,105,149,153,154,169,170,173,174};
U8 L4DP157[11] = {85,89,90,105,106,149,153,154,169,170,174};
U8 L4DP158[14] = {69,85,86,89,90,105,106,149,150,153,154,169,170,174};
U8 L4DP159[13] = {69,85,86,89,90,106,150,153,154,170,171,174,175};
U8 L4DP160[10] = {80,81,84,85,101,149,165,166,169,170};
U8 L4DP161[11] = {81,85,86,101,102,149,150,165,166,169,170};
U8 L4DP162[10] = {81,85,86,101,102,149,150,165,166,170};
U8 L4DP163[13] = {81,82,85,86,101,102,149,150,165,166,167,170,171};
U8 L4DP164[11] = {84,85,89,101,105,149,153,165,166,169,170};
U8 L4DP165[19] = {81,84,85,86,89,101,102,105,106,149,150,153,154,165,166,169,170,186,234};
U8 L4DP166[13] = {81,85,86,101,102,106,149,150,154,165,166,169,170};
U8 L4DP167[14] = {81,85,86,90,101,102,106,149,150,154,165,166,170,171};
U8 L4DP168[10] = {84,85,89,101,105,149,153,165,169,170};
U8 L4DP169[13] = {84,85,89,101,105,106,149,153,154,165,166,169,170};
U8 L4DP170[16] = {85,86,89,90,101,102,105,106,149,150,153,154,165,166,169,170};
U8 L4DP171[14] = {85,86,89,90,101,102,106,149,150,154,166,169,170,171};
U8 L4DP172[13] = {84,85,88,89,101,105,149,153,165,169,170,173,174};
U8 L4DP173[14] = {84,85,89,90,101,105,106,149,153,154,165,169,170,174};
U8 L4DP174[14] = {85,86,89,90,101,105,106,149,153,154,166,169,170,174};
U8 L4DP175[16] = {85,86,89,90,102,105,106,150,153,154,166,169,170,171,174,175};
U8 L4DP176[14] = {80,81,84,85,97,100,101,149,165,166,169,170,181,186};
U8 L4DP177[12] = {81,85,97,101,102,149,165,166,169,170,182,186};
U8 L4DP178[13] = {81,85,86,97,101,102,149,150,165,166,170,182,186};
U8 L4DP179[15] = {81,85,86,101,102,106,150,165,166,167,170,171,182,186,187};
U8 L4DP180[12] = {84,85,100,101,105,149,165,166,169,170,185,186};
U8 L4DP181[11] = {85,101,102,105,106,149,165,166,169,170,186};
U8 L4DP182[14] = {81,85,86,101,102,105,106,149,150,165,166,169,170,186};
U8 L4DP183[13] = {81,85,86,101,102,106,150,165,166,170,171,186,187};
U8 L4DP184[13] = {84,85,89,100,101,105,149,153,165,169,170,185,186};
U8 L4DP185[14] = {84,85,89,101,102,105,106,149,153,165,166,169,170,186};
U8 L4DP186[14] = {85,86,89,101,102,105,106,149,154,165,166,169,170,186};
U8 L4DP187[16] = {85,86,90,101,102,105,106,150,154,165,166,169,170,171,186,187};
U8 L4DP188[15] = {84,85,89,101,105,106,153,165,169,170,173,174,185,186,190};
U8 L4DP189[13] = {84,85,89,101,105,106,153,165,169,170,174,186,190};
U8 L4DP190[16] = {85,89,90,101,102,105,106,153,154,165,166,169,170,174,186,190};
U8 L4DP191[15] = {85,86,89,90,101,102,105,106,154,166,169,170,171,174,186};
U8 L4DP192[17] = {64,69,81,84,85,133,145,148,149,150,153,154,165,166,169,170,234};
U8 L4DP193[15] = {65,69,81,85,86,133,145,149,150,153,154,165,166,170,234};
U8 L4DP194[14] = {65,69,81,85,86,133,145,149,150,154,166,170,214,234};
U8 L4DP195[17] = {65,69,81,85,86,134,146,149,150,151,154,166,170,171,214,234,235};
U8 L4DP196[15] = {68,69,84,85,89,133,148,149,150,153,154,165,169,170,234};
U8 L4DP197[13] = {69,85,133,149,150,153,154,165,166,169,170,218,234};
U8 L4DP198[12] = {69,85,86,133,149,150,153,154,166,170,218,234};
U8 L4DP199[14] = {69,85,86,134,149,150,154,155,166,170,171,218,234,235};
U8 L4DP200[14] = {68,69,84,85,89,133,148,149,153,154,169,170,217,234};
U8 L4DP201[12] = {69,85,89,133,149,150,153,154,169,170,218,234};
U8 L4DP202[13] = {69,85,86,89,90,133,149,150,153,154,170,218,234};
U8 L4DP203[15] = {69,85,86,90,149,150,153,154,155,166,170,171,218,234,235};
U8 L4DP204[17] = {68,69,84,85,89,137,149,152,153,154,157,169,170,174,217,234,238};
U8 L4DP205[14] = {69,85,89,137,149,153,154,158,169,170,174,218,234,238};
U8 L4DP206[15] = {69,85,89,90,149,150,153,154,158,169,170,174,218,234,238};
U8 L4DP207[17] = {69,85,86,89,90,149,150,153,154,155,158,170,171,174,218,234,239};
U8 L4DP208[15] = {80,81,84,85,101,145,148,149,150,153,165,166,169,170,234};
U8 L4DP209[13] = {81,85,145,149,150,153,154,165,166,169,170,230,234};
U8 L4DP210[12] = {81,85,86,145,149,150,154,165,166,170,230,234};
U8 L4DP211[14] = {81,85,86,146,149,150,154,166,167,170,171,230,234,235};
U8 L4DP212[13] = {84,85,148,149,150,153,154,165,166,169,170,233,234};
U8 L4DP213[10] = {85,149,150,153,154,165,166,169,170,234};
U8 L4DP214[11] = {85,86,149,150,153,154,165,166,169,170,234};
U8 L4DP215[10] = {85,86,149,150,154,166,170,171,234,235};
U8 L4DP216[12] = {84,85,89,148,149,153,154,165,169,170,233,234};
U8 L4DP217[11] = {85,89,149,150,153,154,165,166,169,170,234};
U8 L4DP218[14] = {69,85,86,89,90,149,150,153,154,165,166,169,170,234};
U8 L4DP219[13] = {69,85,86,90,149,150,153,154,166,170,171,234,235};
U8 L4DP220[14] = {84,85,89,149,152,153,154,169,170,173,174,233,234,238};
U8 L4DP221[10] = {85,89,149,153,154,169,170,174,234,238};
U8 L4DP222[13] = {69,85,89,90,149,150,153,154,169,170,174,234,238};
U8 L4DP223[13] = {85,86,89,90,149,150,153,154,170,171,174,234,239};
U8 L4DP224[14] = {80,81,84,85,101,145,148,149,165,166,169,170,229,234};
U8 L4DP225[12] = {81,85,101,145,149,150,165,166,169,170,230,234};
U8 L4DP226[13] = {81,85,86,101,102,145,149,150,165,166,170,230,234};
U8 L4DP227[15] = {81,85,86,102,149,150,154,165,166,167,170,171,230,234,235};
U8 L4DP228[12] = {84,85,101,148,149,153,165,166,169,170,233,234};
U8 L4DP229[11] = {85,101,149,150,153,154,165,166,169,170,234};
U8 L4DP230[14] = {81,85,86,101,102,149,150,153,154,165,166,169,170,234};
U8 L4DP231[13] = {81,85,86,102,149,150,154,165,166,170,171,234,235};
U8 L4DP232[13] = {84,85,89,101,105,148,149,153,165,169,170,233,234};
U8 L4DP233[14] = {84,85,89,101,105,149,150,153,154,165,166,169,170,234};
U8 L4DP234[14] = {85,86,89,101,106,149,150,153,154,165,166,169,170,234};
U8 L4DP235[16] = {85,86,90,102,106,149,150,153,154,165,166,169,170,171,234,235};
U8 L4DP236[15] = {84,85,89,105,149,153,154,165,169,170,173,174,233,234,238};
U8 L4DP237[13] = {84,85,89,105,149,153,154,165,169,170,174,234,238};
U8 L4DP238[16] = {85,89,90,105,106,149,150,153,154,165,166,169,170,174,234,238};
U8 L4DP239[15] = {85,86,89,90,106,149,150,153,154,166,169,170,171,174,234};
U8 L4DP240[17] = {80,81,84,85,101,149,161,164,165,166,169,170,181,186,229,234,250};
U8 L4DP241[14] = {81,85,101,149,161,165,166,169,170,182,186,230,234,250};
U8 L4DP242[15] = {81,85,101,102,149,150,165,166,169,170,182,186,230,234,250};
U8 L4DP243[17] = {81,85,86,101,102,149,150,165,166,167,170,171,182,186,230,234,251};
U8 L4DP244[14] = {84,85,101,149,164,165,166,169,170,185,186,233,234,250};
U8 L4DP245[10] = {85,101,149,165,166,169,170,186,234,250};
U8 L4DP246[13] = {81,85,101,102,149,150,165,166,169,170,186,234,250};
U8 L4DP247[13] = {85,86,101,102,149,150,165,166,170,171,186,234,251};
U8 L4DP248[15] = {84,85,101,105,149,153,165,166,169,170,185,186,233,234,250};
U8 L4DP249[13] = {84,85,101,105,149,153,165,166,169,170,186,234,250};
U8 L4DP250[16] = {85,101,102,105,106,149,150,153,154,165,166,169,170,186,234,250};
U8 L4DP251[15] = {85,86,101,102,106,149,150,154,165,166,169,170,171,186,234};
U8 L4DP252[17] = {84,85,89,101,105,149,153,165,169,170,173,174,185,186,233,234,254};
U8 L4DP253[13] = {85,89,101,105,149,153,165,169,170,174,186,234,254};
U8 L4DP254[15] = {85,89,101,105,106,149,153,154,165,166,169,170,174,186,234};
U8 L4DP255[20] = {85,86,89,90,101,102,105,106,149,150,153,154,165,166,169,170,171,174,186,234};
U8 *lookup4DPregen[256] = {L4DP0,L4DP1,L4DP2,L4DP3,L4DP4,L4DP5,L4DP6,L4DP7,L4DP8,L4DP9,L4DP10,L4DP11,L4DP12,L4DP13,L4DP14,L4DP15,L4DP16,L4DP17,L4DP18,L4DP19,L4DP20,L4DP21,L4DP22,L4DP23,L4DP24,L4DP25,L4DP26,L4DP27,L4DP28,L4DP29,L4DP30,L4DP31,L4DP32,L4DP33,L4DP34,L4DP35,L4DP36,L4DP37,L4DP38,L4DP39,L4DP40,L4DP41,L4DP42,L4DP43,L4DP44,L4DP45,L4DP46,L4DP47,L4DP48,L4DP49,L4DP50,L4DP51,L4DP52,L4DP53,L4DP54,L4DP55,L4DP56,L4DP57,L4DP58,L4DP59,L4DP60,L4DP61,L4DP62,L4DP63,L4DP64,L4DP65,L4DP66,L4DP67,L4DP68,L4DP69,L4DP70,L4DP71,L4DP72,L4DP73,L4DP74,L4DP75,L4DP76,L4DP77,L4DP78,L4DP79,L4DP80,L4DP81,L4DP82,L4DP83,L4DP84,L4DP85,L4DP86,L4DP87,L4DP88,L4DP89,L4DP90,L4DP91,L4DP92,L4DP93,L4DP94,L4DP95,L4DP96,L4DP97,L4DP98,L4DP99,L4DP100,L4DP101,L4DP102,L4DP103,L4DP104,L4DP105,L4DP106,L4DP107,L4DP108,L4DP109,L4DP110,L4DP111,L4DP112,L4DP113,L4DP114,L4DP115,L4DP116,L4DP117,L4DP118,L4DP119,L4DP120,L4DP121,L4DP122,L4DP123,L4DP124,L4DP125,L4DP126,L4DP127,L4DP128,L4DP129,L4DP130,L4DP131,L4DP132,L4DP133,L4DP134,L4DP135,L4DP136,L4DP137,L4DP138,L4DP139,L4DP140,L4DP141,L4DP142,L4DP143,L4DP144,L4DP145,L4DP146,L4DP147,L4DP148,L4DP149,L4DP150,L4DP151,L4DP152,L4DP153,L4DP154,L4DP155,L4DP156,L4DP157,L4DP158,L4DP159,L4DP160,L4DP161,L4DP162,L4DP163,L4DP164,L4DP165,L4DP166,L4DP167,L4DP168,L4DP169,L4DP170,L4DP171,L4DP172,L4DP173,L4DP174,L4DP175,L4DP176,L4DP177,L4DP178,L4DP179,L4DP180,L4DP181,L4DP182,L4DP183,L4DP184,L4DP185,L4DP186,L4DP187,L4DP188,L4DP189,L4DP190,L4DP191,L4DP192,L4DP193,L4DP194,L4DP195,L4DP196,L4DP197,L4DP198,L4DP199,L4DP200,L4DP201,L4DP202,L4DP203,L4DP204,L4DP205,L4DP206,L4DP207,L4DP208,L4DP209,L4DP210,L4DP211,L4DP212,L4DP213,L4DP214,L4DP215,L4DP216,L4DP217,L4DP218,L4DP219,L4DP220,L4DP221,L4DP222,L4DP223,L4DP224,L4DP225,L4DP226,L4DP227,L4DP228,L4DP229,L4DP230,L4DP231,L4DP232,L4DP233,L4DP234,L4DP235,L4DP236,L4DP237,L4DP238,L4DP239,L4DP240,L4DP241,L4DP242,L4DP243,L4DP244,L4DP245,L4DP246,L4DP247,L4DP248,L4DP249,L4DP250,L4DP251,L4DP252,L4DP253,L4DP254,L4DP255};
U0 NewLatticePoint2D(LatticePoint2D *point, I32 xsv, I32 ysv) {
point->xsv = xsv;
point->ysv = ysv;
F64 ssv = (xsv + ysv) * -0.211324865405187;
point->dx = -xsv - ssv;
point->dy = -ysv - ssv;
}
U0 NewLatticePoint3D(LatticePoint3D *point, I32 xrv, I32 yrv, I32 zrv, I32 lattice) {
point->dxr = -xrv + lattice * 0.5;
point->dyr = -yrv + lattice * 0.5;
point->dzr = -zrv + lattice * 0.5;
point->xrv = xrv + lattice * 1024;
point->yrv = yrv + lattice * 1024;
point->zrv = zrv + lattice * 1024;
}
U0 NewLatticePoint4D(LatticePoint4D *point, I32 xsv, I32 ysv, I32 zsv, I32 wsv) {
point->xsv = xsv; point->ysv = ysv; point->zsv = zsv; point->wsv = wsv;
F64 ssv = (xsv + ysv + zsv + wsv) * -0.138196601125011;
point->dx = -xsv - ssv;
point->dy = -ysv - ssv;
point->dz = -zsv - ssv;
point->dw = -wsv - ssv;
}
I64 fastFloor(F64 x) {
I64 xi = ToI64(x);
if (x < xi)
return xi-1;
return xi;
}
public U0 OpenSimplex2SInit() {
I64 i;
// Init 2D Gradient
for (i=0; i<GRAD2_LEN; i++) {
grad2[i].x /= N2; grad2[i].y /= N2;
}
for (i=0; i<PSIZE; i++) {
MemCpy(&GRADIENTS_2D[i], &grad2[i%GRAD2_LEN], sizeof(CD2));
}
// Init 3D Gradient
for (i=0; i<GRAD3_LEN; i++) {
grad3[i].x /= N3; grad3[i].y /= N3; grad3[i].z /= N3;
}
for (i=0; i<PSIZE; i++) {
MemCpy(&GRADIENTS_3D[i], &grad3[i%GRAD3_LEN], sizeof(CD3));
}
// Init 4D Gradient
for (i=0; i<GRAD4_LEN; i++) {
grad4[i].dx /= N4; grad4[i].dy /= N4; grad4[i].dz /= N4; grad4[i].dw /= N4;
}
for (i=0; i<PSIZE; i++) {
MemCpy(&GRADIENTS_4D[i], &grad4[i%GRAD4_LEN], sizeof(Grad4));
}
// Init 2D Lattice
I64 i1, j1, i2, j2;
for (i=0; i<8; i++) {
if ((i & 1) == 0) {
if (i&2 == 0) { i1 = -1; j1 = 0; } else { i1 = 1; j1 = 0; }
if (i&4 == 0) { i2 = 0; j2 = -1; } else { i2 = 0; j2 = 1; }
} else {
if (i&2 != 0) { i1 = 2; j1 = 1; } else { i1 = 0; j1 = 1; }
if (i&4 != 0) { i2 = 1; j2 = 2; } else { i2 = 1; j2 = 0; }
}
NewLatticePoint2D(&LOOKUP_2D[i*4+0], 0, 0);
NewLatticePoint2D(&LOOKUP_2D[i*4+1], 1, 1);
NewLatticePoint2D(&LOOKUP_2D[i*4+2], i1, j1);
NewLatticePoint2D(&LOOKUP_2D[i*4+3], i2, j2);
}
// Init 3D Lattice
for (i=0; i<8; i++) {
I64 k1, 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 *c1,*c2,*c3,*c4,*c5,*c6,*c7,*c8,*c9,*cA,*cB,*cC,*cD;
NewLatticePoint3D(&LOOKUP_3D[i*14], i1, j1, k1, 0);
NewLatticePoint3D(&LOOKUP_3D[i*14+1], i1 + i2, j1 + j2, k1 + k2, 1);
// (1, 0, 0) vs (0, 1, 1) away from octant.
NewLatticePoint3D(&LOOKUP_3D[i*14+2], i1 ^ 1, j1, k1, 0);
NewLatticePoint3D(&LOOKUP_3D[i*14+3], i1, j1 ^ 1, k1 ^ 1, 0);
// (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice.
NewLatticePoint3D(&LOOKUP_3D[i*14+4], i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1);
NewLatticePoint3D(&LOOKUP_3D[i*14+5], i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1);
// (0, 1, 0) vs (1, 0, 1) away from octant.
NewLatticePoint3D(&LOOKUP_3D[i*14+6], i1, j1 ^ 1, k1, 0);
NewLatticePoint3D(&LOOKUP_3D[i*14+7], i1 ^ 1, j1, k1 ^ 1, 0);
// (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice.
NewLatticePoint3D(&LOOKUP_3D[i*14+8], i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1);
NewLatticePoint3D(&LOOKUP_3D[i*14+9], i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1);
// (0, 0, 1) vs (1, 1, 0) away from octant.
NewLatticePoint3D(&LOOKUP_3D[i*14+10], i1, j1, k1 ^ 1, 0);
NewLatticePoint3D(&LOOKUP_3D[i*14+11], i1 ^ 1, j1 ^ 1, k1, 0);
// (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice.
NewLatticePoint3D(&LOOKUP_3D[i*14+12], i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1);
NewLatticePoint3D(&LOOKUP_3D[i*14+13], i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1);
// First two points are guaranteed.
LOOKUP_3D[i*14].nextOnFailure = LOOKUP_3D[i*14].nextOnSuccess = &LOOKUP_3D[i*14+1];
LOOKUP_3D[i*14+1].nextOnFailure = LOOKUP_3D[i*14+1].nextOnSuccess = &LOOKUP_3D[i*14+2];
// If c2 is in range, then we know c3 and c4 are not.
LOOKUP_3D[i*14+2].nextOnFailure = &LOOKUP_3D[i*14+3];
LOOKUP_3D[i*14+2].nextOnSuccess = &LOOKUP_3D[i*14+5];
LOOKUP_3D[i*14+3].nextOnFailure = &LOOKUP_3D[i*14+4];
LOOKUP_3D[i*14+3].nextOnSuccess = &LOOKUP_3D[i*14+4];
// If c4 is in range, then we know c5 is not.
LOOKUP_3D[i*14+4].nextOnFailure = &LOOKUP_3D[i*14+5];
LOOKUP_3D[i*14+4].nextOnSuccess = &LOOKUP_3D[i*14+6];
LOOKUP_3D[i*14+5].nextOnFailure = &LOOKUP_3D[i*14+6];
LOOKUP_3D[i*14+5].nextOnSuccess = &LOOKUP_3D[i*14+6];
// If c6 is in range, then we know c7 and c8 are not.
LOOKUP_3D[i*14+6].nextOnFailure = &LOOKUP_3D[i*14+7];
LOOKUP_3D[i*14+6].nextOnSuccess = &LOOKUP_3D[i*14+9];
LOOKUP_3D[i*14+7].nextOnFailure = &LOOKUP_3D[i*14+8];
LOOKUP_3D[i*14+7].nextOnSuccess = &LOOKUP_3D[i*14+8];
// If c8 is in range, then we know c9 is not.
LOOKUP_3D[i*14+8].nextOnFailure = &LOOKUP_3D[i*14+9];
LOOKUP_3D[i*14+8].nextOnSuccess = &LOOKUP_3D[i*14+10];
LOOKUP_3D[i*14+9].nextOnFailure = &LOOKUP_3D[i*14+10];
LOOKUP_3D[i*14+9].nextOnSuccess = &LOOKUP_3D[i*14+10];
// If cA is in range, then we know cB and cC are not.
LOOKUP_3D[i*14+10].nextOnFailure = &LOOKUP_3D[i*14+11];
LOOKUP_3D[i*14+10].nextOnSuccess = &LOOKUP_3D[i*14+13];
LOOKUP_3D[i*14+11].nextOnFailure = &LOOKUP_3D[i*14+12];
LOOKUP_3D[i*14+11].nextOnSuccess = &LOOKUP_3D[i*14+12];
// If cC is in range, then we know cD is not.
LOOKUP_3D[i*14+12].nextOnFailure = &LOOKUP_3D[i*14+13];
LOOKUP_3D[i*14+12].nextOnSuccess = NULL;
LOOKUP_3D[i*14+13].nextOnFailure = NULL;
LOOKUP_3D[i*14+13].nextOnSuccess = NULL;
}
// Init 4D Lattice
LatticePoint4D latticePoints[256];
for (i=0; i<256; i++) {
I32 cx = i>>0 & 3 - 1;
I32 cy = i>>2 & 3 - 1;
I32 cz = i>>4 & 3 - 1;
I32 cw = i>>6 & 3 - 1;
NewLatticePoint4D(&latticePoints[i], cx, cy, cz, cw);
}
for (i=0; i<256; i++) {
I64 j;
for (j=0; j<LOOKUP_4DLens[i]; j++) {
MemCpy(&LOOKUP_4D[i][j], &latticePoints[lookup4DPregen[i][j]], sizeof(LatticePoint4D));
}
}
}
public U0 OpenSimplex2S(F64 seed) {
I64 i;
for (i=0; i<PSIZE; i++)
source[i] = i;
for (i=PSIZE-1; i>=0; i--) {
seed = seed(I64) * 6364136223846793005 + 1442695040888963407;
// I64 r = ToI64(seed + 31) % (i + 1);
I64 r = (seed + 31) % (i + 1);
if (r < 0)
r += (i + 1);
perm[i] = source[r];
MemCpy(&permGrad2[i], &GRADIENTS_2D[perm[i]], sizeof(CD2));
MemCpy(&permGrad3[i], &GRADIENTS_3D[perm[i]], sizeof(CD3));
MemCpy(&permGrad4[i], &GRADIENTS_4D[perm[i]], sizeof(Grad4));
source[r] = source[i];
}
}
/**
* 2D SuperSimplex noise base.
* Lookup table implementation inspired by DigitalShadow.
*/
F64 noise2_Base(F64 xs, F64 ys) {
F64 value = 0;
// Get base points and offsets
I64 xsb = fastFloor(xs), ysb = fastFloor(ys);
F64 xsi = xs - xsb, ysi = ys - ysb;
// Index to point list
I64 a = xsi + ysi;
I64 index = (a << 2) | ToI64(xsi - ysi / 2 + 1 - a / 2.0) << 3 | ToI64(ysi - xsi / 2 + 1 - a / 2.0) << 4;
F64 ssi = (xsi + ysi) * -0.211324865405187;
F64 xi = xsi + ssi, yi = ysi + ssi;
// Point contributions
I64 i;
for (i=0; i<4; i++) {
LatticePoint2D c;
MemCpy(&c, &LOOKUP_2D[index+i], sizeof(LatticePoint2D));
F64 dx = xi + c.dx, dy = yi + c.dy;
F64 attn = 2.0 / 3.0 - dx * dx - dy * dy;
if (attn <= 0) goto nextNoise2Base;
I64 pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK;
CD2 grad;
MemCpy(&grad, &permGrad2[perm[pxm] ^ pym], sizeof(CD2));
F64 extrapolation = grad.x * dx + grad.y * dy;
attn *= attn;
value += attn * attn * extrapolation;
nextNoise2Base:
}
return value;
}
/**
* 2D SuperSimplex noise, standard lattice orientation.
*/
public F64 noise2(F64 x, F64 y) {
// Get points for A2* lattice
F64 s = 0.366025403784439 * (x + y);
F64 xs = x + s, ys = y + s;
return noise2_Base(xs, ys);
}
/**
* 2D SuperSimplex noise, with Y pointing down the main diagonal.
* Might be better for a 2D sandbox style game, where Y is vertical.
* Probably slightly less optimal for heightmaps or continent maps.
*/
public F64 noise2_XBeforeY(F64 x, F64 y) {
// Skew transform and rotation baked into one.
F64 xx = x * 0.7071067811865476;
F64 yy = y * 1.224744871380249;
return noise2_Base(yy + xx, yy - xx);
}
/**
* Generate overlapping cubic lattices for 3D Re-oriented BCC noise.
* Lookup table implementation inspired by DigitalShadow.
* It was actually faster to narrow down the points in the loop itself,
* than to build up the index with enough info to isolate 8 points.
*/
F64 noise3_BCC(F64 xr, F64 yr, F64 zr) {
// Get base and offsets inside cube of first lattice.
I64 xrb = fastFloor(xr), yrb = fastFloor(yr), zrb = fastFloor(zr);
F64 xri = xr - xrb, yri = yr - yrb, zri = zr - zrb;
// Identify which octant of the cube we're in. This determines which cell
// in the other cubic lattice we're in, and also narrows down one point on each.
I64 xht = xri + 0.5, yht = yri + 0.5, zht = zri + 0.5;
I64 index = (xht << 0) | (yht << 1) | (zht << 2);
// Point contributions
F64 value = 0;
LatticePoint3D *c = &LOOKUP_3D[index*14];
while (c != NULL) {
F64 dxr = xri + c->dxr, dyr = yri + c->dyr, dzr = zri + c->dzr;
F64 attn = 0.75 - dxr * dxr - dyr * dyr - dzr * dzr;
if (attn < 0) {
c = c->nextOnFailure;
} else {
I64 pxm = (xrb + c->xrv) & PMASK, pym = (yrb + c->yrv) & PMASK, pzm = (zrb + c->zrv) & PMASK;
CD3 grad;
MemCpy(&grad, &permGrad3[perm[perm[pxm] ^ pym] ^ pzm], sizeof(CD3));
F64 extrapolation = grad.x * dxr + grad.y * dyr + grad.z * dzr;
attn *= attn;
value += attn * attn * extrapolation;
c = c->nextOnSuccess;
}
}
return value;
}
/**
* 3D Re-oriented 8-point BCC noise, classic orientation
* Proper substitute for what 3D SuperSimplex would be,
* in light of Forbidden Formulae.
* Use noise3_XYBeforeZ or noise3_XZBeforeY instead, wherever appropriate.
*/
public F64 noise3_Classic(F64 x, F64 y, F64 z) {
// Re-orient the cubic lattices via rotation, to produce the expected look on cardinal planar slices.
// If texturing objects that don't tend to have cardinal plane faces, you could even remove this.
// Orthonormal rotation. Not a skew transform.
F64 r = (2.0 / 3.0) * (x + y + z);
F64 xr = r - x, yr = r - y, zr = r - z;
// Evaluate both lattices to form a BCC lattice.
return noise3_BCC(xr, yr, zr);
}
/**
* 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Y).
* Recommended for 3D terrain and time-varied animations.
* The Z coordinate should always be the "different" coordinate in your use case.
* If Y is vertical in world coordinates, call noise3_XYBeforeZ(x, z, Y) or use noise3_XZBeforeY.
* If Z is vertical in world coordinates, call noise3_XYBeforeZ(x, y, Z).
* For a time varied animation, call noise3_XYBeforeZ(x, y, T).
*/
public F64 noise3_XYBeforeZ(F64 x, F64 y, F64 z) {
// Re-orient the cubic lattices without skewing, to make X and Y triangular like 2D.
// Orthonormal rotation. Not a skew transform.
F64 xy = x + y;
F64 s2 = xy * -0.211324865405187;
F64 zz = z * 0.577350269189626;
F64 xr = x + s2 - zz, yr = y + s2 - zz;
F64 zr = xy * 0.577350269189626 + zz;
// Evaluate both lattices to form a BCC lattice.
return noise3_BCC(xr, yr, zr);
}
/**
* 3D Re-oriented 8-point BCC noise, with better visual isotropy in (X, Z).
* Recommended for 3D terrain and time-varied animations.
* The Y coordinate should always be the "different" coordinate in your use case.
* If Y is vertical in world coordinates, call noise3_XZBeforeY(x, Y, z).
* If Z is vertical in world coordinates, call noise3_XZBeforeY(x, Z, y) or use noise3_XYBeforeZ.
* For a time varied animation, call noise3_XZBeforeY(x, T, y) or use noise3_XYBeforeZ.
*/
public F64 noise3_XZBeforeY(F64 x, F64 y, F64 z) {
// Re-orient the cubic lattices without skewing, to make X and Z triangular like 2D.
// Orthonormal rotation. Not a skew transform.
F64 xz = x + z;
F64 s2 = xz * -0.211324865405187;
F64 yy = y * 0.577350269189626;
F64 xr = x + s2 - yy; F64 zr = z + s2 - yy;
F64 yr = xz * 0.577350269189626 + yy;
// Evaluate both lattices to form a BCC lattice.
return noise3_BCC(xr, yr, zr);
}
/**
* 4D SuperSimplex noise base.
* Using ultra-simple 4x4x4x4 lookup partitioning.
* This isn't as elegant or SIMD/GPU/etc. portable as other approaches,
* but it does compete performance-wise with optimized OpenSimplex1.
*/
F64 noise4_Base(F64 xs, F64 ys, F64 zs, F64 ws) {
F64 value = 0;
// Get base points and offsets
I64 xsb = fastFloor(xs), ysb = fastFloor(ys), zsb = fastFloor(zs), wsb = fastFloor(ws);
F64 xsi = xs - xsb, ysi = ys - ysb, zsi = zs - zsb, wsi = ws - wsb;
// Unskewed offsets
F64 ssi = (xsi + ysi + zsi + wsi) * -0.138196601125011;
F64 xi = xsi + ssi, yi = ysi + ssi, zi = zsi + ssi, wi = wsi + ssi;
I64 index = ((fastFloor(xs * 4) & 3) << 0)
| ((fastFloor(ys * 4) & 3) << 2)
| ((fastFloor(zs * 4) & 3) << 4)
| ((fastFloor(ws * 4) & 3) << 6);
// Point contributions
I64 i;
for (i=0; i<LOOKUP_4DLens[index]; i++) {
F64 dx = xi + LOOKUP_4D[index][i].dx, dy = yi + LOOKUP_4D[index][i].dy, dz = zi + LOOKUP_4D[index][i].dz, dw = wi + LOOKUP_4D[index][i].dw;
F64 attn = 0.8 - dx * dx - dy * dy - dz * dz - dw * dw;
if (attn > 0) {
attn *= attn;
I32 pxm = (xsb + LOOKUP_4D[index][i].xsv) & PMASK, pym = (ysb + LOOKUP_4D[index][i].ysv) & PMASK;
I32 pzm = (zsb + LOOKUP_4D[index][i].zsv) & PMASK, pwm = (wsb + LOOKUP_4D[index][i].wsv) & PMASK;
Grad4 grad;
MemCpy(&grad, &permGrad4[perm[perm[perm[pxm] ^ pym] ^ pzm] ^ pwm], sizeof(Grad4));
F64 extrapolation = grad.dx * dx + grad.dy * dy + grad.dz * dz + grad.dw * dw;
value += attn * attn * extrapolation;
}
}
return value;
}
/**
* 4D SuperSimplex noise, classic lattice orientation.
*/
public F64 noise4_Classic(F64 x, F64 y, F64 z, F64 w) {
// Get points for A4 lattice
F64 s = 0.309016994374947 * (x + y + z + w);
F64 xs = x + s, ys = y + s, zs = z + s, ws = w + s;
return noise4_Base(xs, ys, zs, ws);
}
/**
* 4D SuperSimplex noise, with XY and ZW forming orthogonal triangular-based planes.
* Recommended for 3D terrain, where X and Y (or Z and W) are horizontal.
* Recommended for noise(x, y, sin(time), cos(time)) trick.
*/
public F64 noise4_XYBeforeZW(F64 x, F64 y, F64 z, F64 w) {
F64 s2 = (x + y) * -0.28522513987434876941 + (z + w) * 0.83897065470611435718;
F64 t2 = (z + w) * 0.21939749883706435719 + (x + y) * -0.48214856493302476942;
F64 xs = x + s2, ys = y + s2, zs = z + t2, ws = w + t2;
return noise4_Base(xs, ys, zs, ws);
}
/**
* 4D SuperSimplex noise, with XZ and YW forming orthogonal triangular-based planes.
* Recommended for 3D terrain, where X and Z (or Y and W) are horizontal.
*/
public F64 noise4_XZBeforeYW(F64 x, F64 y, F64 z, F64 w) {
F64 s2 = (x + z) * -0.28522513987434876941 + (y + w) * 0.83897065470611435718;
F64 t2 = (y + w) * 0.21939749883706435719 + (x + z) * -0.48214856493302476942;
F64 xs = x + s2, ys = y + t2, zs = z + s2, ws = w + t2;
return noise4_Base(xs, ys, zs, ws);
}
/**
* 4D SuperSimplex noise, with XYZ oriented like noise3_Classic,
* and W for an extra degree of freedom.
* Recommended for time-varied animations which texture a 3D object (W=time)
*/
public F64 noise4_XYZBeforeW(F64 x, F64 y, F64 z, F64 w) {
F64 xyz = x + y + z;
F64 ww = w * 1.118033988749894;
F64 s2 = xyz * -0.16666666666666666 + ww;
F64 xs = x + s2, ys = y + s2, zs = z + s2, ws = -0.5 * xyz + ww;
return noise4_Base(xs, ys, zs, ws);
}
#endif