public override double GetValue(double x, double y)
{
//Place input coordinates on triangular grid.
double squishOffset = (x + y) * SQUISH_CONSTANT;
double xs = x + squishOffset;
double ys = y + squishOffset;
//Floor to get base coordinate of containing square/rhombus.
int xsb = fastFloor(xs);
int ysb = fastFloor(ys);
//Skew out to get actual coordinates of rhombus origin. We'll need these later.
double stretchOffset = (xsb + ysb) * STRETCH_CONSTANT;
double xb = xsb + stretchOffset;
double yb = ysb + stretchOffset;
//Positions relative to origin point.
double dx = x - xb;
double dy = y - yb;
//Compute grid coordinates relative to rhombus origin.
double xins = xs - xsb;
double yins = ys - ysb;
double value;
if (xins > yins) { //We're inside the x>y triangle of the rhombus
//Get our 12 surrounding vertex values
//Using type "byte" works here because type "byte" in Java is signed
short yp;
yp = perm[(ysb - 1) & 0xFF];
byte h1 = (byte)perm[(yp + xsb - 1) & 0xFF]; //(-1,-1)
byte h2 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0,-1)
byte h3 = (byte)perm[(yp + xsb + 1) & 0xFF]; //( 1,-1)
yp = perm[(ysb + 0) & 0xFF];
byte h4 = (byte)perm[(yp + xsb - 1) & 0xFF]; //(-1, 0)
byte h5 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0, 0)
byte h6 = (byte)perm[(yp + xsb + 1) & 0xFF]; //( 1, 0)
byte h7 = (byte)perm[(yp + xsb + 2) & 0xFF]; //( 2, 0)
yp = perm[(ysb + 1) & 0xFF];
byte h8 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0, 1)
byte h9 = (byte)perm[(yp + xsb + 1) & 0xFF]; //( 1, 1)
byte h10 = (byte)perm[(yp + xsb + 2) & 0xFF];//( 2, 1)
yp = perm[(ysb + 2) & 0xFF];
byte h11 = (byte)perm[(yp + xsb + 1) & 0xFF];//( 1, 2)
byte h12 = (byte)perm[(yp + xsb + 2) & 0xFF];//( 2, 2)
value = kernels(dx, dy, h1, h2, h3,
h4, h5, h6, h7, h8, h9, h10, h11, h12);
} else { //We're inside the y>x triangle of the rhombus
//Get our 12 surrounding vertex values
//Using type "byte" works here because type "byte" in Java is signed
short yp;
yp = perm[(ysb - 1) & 0xFF];
byte h1 = (byte)perm[(yp + xsb - 1) & 0xFF]; //(-1,-1)
byte h4 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0,-1)
yp = perm[(ysb + 0) & 0xFF];
byte h2 = (byte)perm[(yp + xsb - 1) & 0xFF]; //(-1, 0)
byte h5 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0, 0)
byte h8 = (byte)perm[(yp + xsb + 1) & 0xFF]; //( 1, 0)
yp = perm[(ysb + 1) & 0xFF];
byte h3 = (byte)perm[(yp + xsb - 1) & 0xFF]; //(-1, 1)
byte h6 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0, 1)
byte h9 = (byte)perm[(yp + xsb + 1) & 0xFF]; //( 1, 1)
byte h11 = (byte)perm[(yp + xsb + 2) & 0xFF];//( 2, 1)
yp = perm[(ysb + 2) & 0xFF];
byte h7 = (byte)perm[(yp + xsb + 0) & 0xFF]; //( 0, 2)
byte h10 = (byte)perm[(yp + xsb + 1) & 0xFF];//( 1, 2)
byte h12 = (byte)perm[(yp + xsb + 2) & 0xFF];//( 2, 2)
value = kernels(dy, dx, h1, h2, h3,
h4, h5, h6, h7, h8, h9, h10, h11, h12);
}
return value / NORM_CONSTANT;
}