Skybox { public int getColorForPoint(double x, double y, int px, int py, int plane, double brightness, ChunkMapper chunkMapper) { x /= 8.d; y /= 8.d; int cx = (int) x; int cy = (int) y; int centerChunkData = chunkData(px / 8, py / 8, plane, chunkMapper); if (centerChunkData == -1) { return 0; } double t = 0; double ty = 0; double tco = 0; double tcg = 0; int xmin = (int) (x - BLEND_RADIUS); int xmax = (int) Math.ceil(x + BLEND_RADIUS); int ymin = (int) (y - BLEND_RADIUS); int ymax = (int) Math.ceil(y + BLEND_RADIUS); for (int ucx = xmin; ucx < xmax; ucx++) { for (int ucy = ymin; ucy <= ymax; ucy++) { int val = chunkData(ucx, ucy, plane, chunkMapper); if (val == -1) { continue; } double sigma = ((val >>> 24) + .125) / 8.d; double minDist = 1 + (sigma * BLEND_DISTRIBUTION); double dxl = ucx - x; double dxh = dxl + 1.d; if (dxl < -minDist || dxl > minDist) { continue; } double dyl = ucy - y; double dyh = dyl + 1.d; if (dyl < -minDist || dyh > minDist) { continue; } double erfdivc = sigma * SQRT2; double m = (erf(dxl / erfdivc) - erf(dxh / erfdivc)) * (erf(dyl / erfdivc) - erf(dyh / erfdivc)); double vy = (val >>> 16 & 0xFF) / 255.d; double vco = (byte) (val >>> 8) / 128.d; double vcg = (byte) val / 128.d; ty += vy * m; tco += vco * m; tcg += vcg * m; t += m; } } byte ay = (byte) Math.min(Math.max(Math.round(ty / t * 255.d), 0), 255); byte aco = (byte) Math.min(Math.max(Math.round(tco * 128.d / t), -128), 127); byte acg = (byte) Math.min(Math.max(Math.round(tcg * 128.d / t), -128), 127); int g = (ay - (acg >> 1)) & 0xFF; int tmp = (g + acg) & 0xFF; int r = (tmp - (aco >> 1)) & 0xFF; int b = (r + aco) & 0xFF; float[] hsb = Color.RGBtoHSB(r, g, b, null); hsb[2] = (float) Math.pow(hsb[2], brightness); return 0xFFFFFF & Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]); } Skybox(InputStream is, String filename);  Skybox(Reader reader, String filename); int getColorForPoint(double x, double y, int px, int py, int plane, double brightness, ChunkMapper chunkMapper);  }
@Test public void testLoadSimple() throws IOException { Skybox skybox = new Skybox(CharSource.wrap("bounds 0 0 100 100 #00F Assert.assertEquals(0, skybox.getColorForPoint(0, 0, 0, 0, 0, 1, null)); int x = (99 * 64) + 32; int y = (99 * 64) + 32; Assert.assertEquals(0x0000FF, skybox.getColorForPoint(x, y, x, y, 0, 1, null)); }