mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
55bc7365f1
498 files changed
+54571
-1345
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.iris.probe.fidelity.ColumnSurvey;
|
||||
import art.arcane.iris.probe.fidelity.FidelityChunk;
|
||||
import art.arcane.iris.probe.fidelity.FidelityColumn;
|
||||
import art.arcane.iris.probe.fidelity.FidelityStats;
|
||||
import art.arcane.iris.probe.fidelity.IrisEngineColumnSource;
|
||||
import art.arcane.iris.probe.fidelity.IrisEngineFidelitySource;
|
||||
import art.arcane.iris.probe.fidelity.SurveyWindow;
|
||||
import art.arcane.iris.testsupport.IrisRuntimeState;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public final class IrisEngineColumnSourceTest {
|
||||
@AfterClass
|
||||
public static void releaseRuntime() {
|
||||
IrisRuntimeState.reset();
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
public void columnsMatchTheGeneratedChunkSurface() throws Exception {
|
||||
URL resource = IrisEngineColumnSourceTest.class.getResource("/seed-cohesion");
|
||||
assertNotNull(resource);
|
||||
File pack = new File(resource.toURI());
|
||||
try (RealPackProbeSupport.Workspace workspace = RealPackProbeSupport.openWorkspace(pack, "cohesion", "[fidelity]");
|
||||
RealPackProbeSupport.EngineSession session = workspace.openEngine(1337L, false, "fidelity");
|
||||
IrisEngineColumnSource columns = new IrisEngineColumnSource(session.engine());
|
||||
IrisEngineFidelitySource chunks = new IrisEngineFidelitySource(session.engine())) {
|
||||
for (int chunkX = -1; chunkX <= 0; chunkX++) {
|
||||
for (int chunkZ = -1; chunkZ <= 0; chunkZ++) {
|
||||
assertChunkMatches(columns, chunks, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
FidelityStats stats = ColumnSurvey.scan(columns, new SurveyWindow(0, 0, 64, 8), 2);
|
||||
|
||||
assertEquals(64L, stats.columns());
|
||||
assertEquals(64L, stats.heightColumns());
|
||||
assertEquals(0L, stats.fluidColumns());
|
||||
assertEquals(Map.of("terrain", 64L), stats.biomeColumns());
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertChunkMatches(IrisEngineColumnSource columns, IrisEngineFidelitySource chunks, int chunkX, int chunkZ) throws Exception {
|
||||
FidelityChunk chunk = chunks.sample(chunkX, chunkZ);
|
||||
for (int x = 0; x < 16; x += 3) {
|
||||
for (int z = 0; z < 16; z += 3) {
|
||||
FidelityColumn column = columns.column((chunkX << 4) + x, (chunkZ << 4) + z);
|
||||
int surface = chunk.surfaceY(x, z);
|
||||
assertEquals("column " + x + "," + z + " of chunk " + chunkX + "," + chunkZ, surface, column.terrainY());
|
||||
assertEquals(chunk.surfaceBiome(x, z), column.biome());
|
||||
assertFalse(column.wet());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.iris.probe.fidelity.FidelityChunk;
|
||||
import art.arcane.iris.probe.fidelity.FidelityComparison;
|
||||
import art.arcane.iris.probe.fidelity.FidelityReport;
|
||||
import art.arcane.iris.probe.fidelity.FidelitySampling;
|
||||
import art.arcane.iris.probe.fidelity.FidelitySamples;
|
||||
import art.arcane.iris.probe.fidelity.FidelityScanner;
|
||||
import art.arcane.iris.probe.fidelity.FidelityStats;
|
||||
import art.arcane.iris.probe.fidelity.FidelityThresholds;
|
||||
import art.arcane.iris.probe.fidelity.IrisEngineFidelitySource;
|
||||
import art.arcane.iris.testsupport.IrisRuntimeState;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class IrisEngineFidelitySourceTest {
|
||||
@AfterClass
|
||||
public static void releaseRuntime() {
|
||||
IrisRuntimeState.reset();
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
public void realPackChunksScanIntoComparableStats() throws Exception {
|
||||
URL resource = IrisEngineFidelitySourceTest.class.getResource("/seed-cohesion");
|
||||
assertNotNull(resource);
|
||||
File pack = new File(resource.toURI());
|
||||
try (RealPackProbeSupport.Workspace workspace = RealPackProbeSupport.openWorkspace(pack, "cohesion", "[fidelity]");
|
||||
RealPackProbeSupport.EngineSession session = workspace.openEngine(1337L, false, "fidelity");
|
||||
IrisEngineFidelitySource source = new IrisEngineFidelitySource(session.engine())) {
|
||||
FidelityStats stats = FidelityScanner.scan(source, 0, 0, 1, 4, 2);
|
||||
|
||||
assertEquals(0, source.minY());
|
||||
assertEquals(64, source.maxY());
|
||||
assertEquals(144L, stats.columns());
|
||||
assertEquals(144L, stats.heightColumns());
|
||||
assertEquals(Map.of("terrain", 144L), stats.biomeColumns());
|
||||
assertEquals(144L, stats.blockColumns());
|
||||
assertTrue(stats.wallSolidVoxels() > 0L);
|
||||
assertTrue(stats.wallVoxels() <= stats.wallSolidVoxels());
|
||||
double median = stats.heightQuantile(0.5D);
|
||||
assertTrue("median " + median, median >= 20.0D && median < 40.0D);
|
||||
FidelitySamples samples = new FidelitySamples(stats, stats, new FidelitySampling("chunks", 48, 4, List.of(1337L), stats.columns()));
|
||||
FidelityReport report = FidelityComparison.compare(samples, samples, FidelityThresholds.defaults());
|
||||
assertTrue(report.toJson(), report.passed());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
public void volumetricOverhangsAreTerrainVoidsAndRockIsTerrainMass() throws Exception {
|
||||
URL resource = IrisEngineFidelitySourceTest.class.getResource("/terrain3d-pack");
|
||||
assertNotNull(resource);
|
||||
File pack = new File(resource.toURI());
|
||||
try (RealPackProbeSupport.Workspace workspace = RealPackProbeSupport.openWorkspace(pack, "terrain3d", "[fidelity]");
|
||||
RealPackProbeSupport.EngineSession session = workspace.openEngine(1337L, false, "fidelity-voids");
|
||||
IrisEngineFidelitySource source = new IrisEngineFidelitySource(session.engine())) {
|
||||
FidelityChunk chunk = source.sample(0, 0);
|
||||
long voids = 0L;
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = source.minY(); y < chunk.surfaceY(x, z); y++) {
|
||||
boolean air = chunk.block(x, y, z).endsWith("air");
|
||||
assertEquals(x + "," + y + "," + z, !air, chunk.terrainMass(x, y, z));
|
||||
if (air) {
|
||||
voids++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(voids > 0L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BiomeShareReportTest {
|
||||
@Test
|
||||
public void tableListsEverySeedDeltaWithThePassingCount() {
|
||||
BiomeShareReport report = report();
|
||||
|
||||
List<String> lines = report.toTable().lines().toList();
|
||||
|
||||
assertTrue(lines.toString(), lines.contains(String.format(Locale.ROOT, "%-18s %10s %10s %8s", "seed", "1337", "1338", "passing")));
|
||||
assertTrue(lines.toString(), lines.contains(String.format(Locale.ROOT, "%-18s %10.4f %10.4f %8s", "biome.share.forest", 0.5D, 0.05D, "1/2")));
|
||||
assertTrue(lines.toString(), lines.contains(String.format(Locale.ROOT, "%-18s %10s %10.4f %8s", "biome.share.desert", "-", 0.0D, "1/1")));
|
||||
assertEquals("overall FAIL: 0 of 1 metrics passed", lines.getLast());
|
||||
assertFalse(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonCarriesTheMeanAndEverySeed() {
|
||||
JsonObject json = JsonParser.parseString(report().toJson()).getAsJsonObject();
|
||||
|
||||
assertFalse(json.get("passed").getAsBoolean());
|
||||
JsonObject mean = json.getAsJsonObject("mean");
|
||||
assertEquals("biome.share.forest", mean.getAsJsonArray("metrics").get(0).getAsJsonObject().get("name").getAsString());
|
||||
JsonArray seeds = json.getAsJsonArray("seeds");
|
||||
assertEquals(2, seeds.size());
|
||||
assertEquals(1337L, seeds.get(0).getAsJsonObject().get("seed").getAsLong());
|
||||
assertEquals(1, seeds.get(0).getAsJsonObject().getAsJsonArray("metrics").size());
|
||||
JsonObject passing = json.getAsJsonObject("seedsPassing").getAsJsonObject("biome.share.forest");
|
||||
assertEquals(1, passing.get("passing").getAsInt());
|
||||
assertEquals(2, passing.get("compared").getAsInt());
|
||||
JsonObject desert = json.getAsJsonObject("shares").getAsJsonObject("desert");
|
||||
assertEquals(0.05D, desert.get("iris").getAsDouble(), 0.0D);
|
||||
assertEquals(0.01D, desert.get("export").getAsDouble(), 0.0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportNeedsAtLeastOneSeed() {
|
||||
FidelityReport mean = new FidelityReport(List.of(), List.of(), List.of());
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new BiomeShareReport(mean, new TreeMap<>(), Map.of(), Map.of()));
|
||||
}
|
||||
|
||||
private static BiomeShareReport report() {
|
||||
FidelityReport mean = new FidelityReport(List.of(new FidelityMetric("biome.share.forest", 0.5D, 0.4D, 0.2D, false)), List.of(), List.of());
|
||||
SortedMap<Long, FidelityReport> seeds = new TreeMap<>();
|
||||
seeds.put(1337L, new FidelityReport(List.of(new FidelityMetric("biome.share.forest", 0.5D, 0.25D, 0.5D, false)), List.of(), List.of()));
|
||||
seeds.put(1338L, new FidelityReport(List.of(
|
||||
new FidelityMetric("biome.share.forest", 0.5D, 0.525D, 0.05D, true),
|
||||
new FidelityMetric("biome.share.desert", 0.1D, 0.1D, 0.0D, true)), List.of(), List.of()));
|
||||
return new BiomeShareReport(mean, seeds, Map.of("forest", 0.5D, "desert", 0.05D), Map.of("forest", 0.4D, "desert", 0.01D));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BiomeTypesTest {
|
||||
@Test
|
||||
public void childrenInheritTheListTypeOfTheirParent() {
|
||||
IrisRegion region = region(List.of("plains"), List.of("ocean"), List.of("beach"));
|
||||
Map<String, IrisBiome> biomes = Map.of(
|
||||
"plains", biome("meadow"),
|
||||
"meadow", biome("plains"),
|
||||
"ocean", biome("reef"),
|
||||
"reef", biome(),
|
||||
"beach", biome());
|
||||
|
||||
Map<String, String> types = BiomeTypes.of(List.of(region), biomes::get);
|
||||
|
||||
assertEquals(Map.of("plains", "land", "meadow", "land", "ocean", "sea", "reef", "sea", "beach", "shore"), types);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomesListedUnderSeveralTypesJoinThem() {
|
||||
IrisRegion first = region(List.of("plains"), List.of(), List.of());
|
||||
IrisRegion second = region(List.of(), List.of("plains"), List.of("missing"));
|
||||
|
||||
Map<String, String> types = BiomeTypes.of(List.of(first, second), key -> key.equals("plains") ? biome() : null);
|
||||
|
||||
assertEquals(Map.of("plains", "land+sea", "missing", "shore"), types);
|
||||
}
|
||||
|
||||
private static IrisRegion region(List<String> land, List<String> sea, List<String> shore) {
|
||||
return new IrisRegion().setLandBiomes(new KList<>(land)).setSeaBiomes(new KList<>(sea)).setShoreBiomes(new KList<>(shore));
|
||||
}
|
||||
|
||||
private static IrisBiome biome(String... children) {
|
||||
return new IrisBiome().setChildren(new KList<>(List.of(children)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveWallsTest {
|
||||
private static final int MIN_Y = -64;
|
||||
|
||||
@Test
|
||||
public void solidBesideCaveAirIsAWall() {
|
||||
SyntheticFidelityChunk chunk = new SyntheticFidelityChunk(MIN_Y).surface(64).caves(-20, 0, 4);
|
||||
|
||||
assertTrue(CaveWalls.besideCave(chunk, 4, -10, 7));
|
||||
assertFalse(CaveWalls.besideCave(chunk, 5, -10, 7));
|
||||
assertFalse(CaveWalls.besideCave(chunk, 4, 5, 7));
|
||||
assertFalse(CaveWalls.besideCave(chunk, 4, -21, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fluidFilledCavesHaveWalls() {
|
||||
SyntheticFidelityChunk chunk = new SyntheticFidelityChunk(MIN_Y).surface(64).lavaPool(-64, -56, 4);
|
||||
|
||||
assertTrue(CaveWalls.besideCave(chunk, 4, -60, 7));
|
||||
assertFalse(CaveWalls.besideCave(chunk, 4, -50, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkCornersOnlyReadNeighboursInsideTheChunk() {
|
||||
assertTrue(CaveWalls.besideCave(new SyntheticFidelityChunk(MIN_Y).surface(64).caves(-20, 0, 15), 15, -10, 0));
|
||||
assertFalse(CaveWalls.besideCave(new SyntheticFidelityChunk(MIN_Y).surface(64), 15, -10, 15));
|
||||
assertFalse(CaveWalls.besideCave(new SyntheticFidelityChunk(MIN_Y).surface(64), 0, -10, 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ColumnSurveyTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surveyVisitsEveryStrideCellCentreOnce() {
|
||||
SplitSource source = new SplitSource(null);
|
||||
|
||||
FidelityStats stats = ColumnSurvey.scan(source, new SurveyWindow(1000, -2000, 512, 128), 3);
|
||||
|
||||
assertEquals(16L, stats.columns());
|
||||
assertEquals(16, source.visited().size());
|
||||
assertTrue(source.visited().toString(), source.visited().contains(1000 - 256 + 64 + "," + (-2000 - 256 + 64)));
|
||||
assertTrue(source.visited().toString(), source.visited().contains(1000 + 128 + 64 + "," + (-2000 + 128 + 64)));
|
||||
assertEquals(Map.of("land", 8L, "sea", 8L), stats.biomeColumns());
|
||||
assertEquals(16L, stats.heightColumns());
|
||||
assertEquals(0.5D, stats.landFraction(), 0.0D);
|
||||
assertEquals(30.0D, stats.heightQuantile(0.25D), 0.0D);
|
||||
assertEquals(80.0D, stats.heightQuantile(0.75D), 0.0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedColumnFailsTheSurveyWithItsCause() {
|
||||
IllegalStateException broken = new IllegalStateException("sampler closed");
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> ColumnSurvey.scan(new SplitSource(broken), new SurveyWindow(0, 0, 64, 16), 2));
|
||||
|
||||
assertSame(broken, failure.getCause());
|
||||
}
|
||||
|
||||
private record SplitSource(RuntimeException failure, Set<String> visited) implements ColumnSource {
|
||||
private SplitSource(RuntimeException failure) {
|
||||
this(failure, ConcurrentHashMap.newKeySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "synthetic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return MIN_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxY() {
|
||||
return MAX_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FidelityColumn column(int x, int z) {
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
visited.add(x + "," + z);
|
||||
return x < 1000 ? new FidelityColumn("sea", 30, true) : new FidelityColumn("land", 80, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FidelityComparisonTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
private static final double RANGE = MAX_Y - MIN_Y;
|
||||
|
||||
@Test
|
||||
public void identicalStatsPass() {
|
||||
FidelityReport report = compare(varied(), varied());
|
||||
|
||||
assertTrue(report.passed());
|
||||
for (FidelityMetric metric : report.metrics()) {
|
||||
assertEquals(metric.name(), 0.0D, metric.delta(), 1.0E-12D);
|
||||
assertTrue(metric.name(), metric.pass());
|
||||
}
|
||||
assertEquals(0.5D, metric(report, "biome.share.plains").iris(), 1.0E-12D);
|
||||
assertEquals(40.0D, metric(report, "height.p10").iris(), 0.0D);
|
||||
assertEquals(0.5D, metric(report, "height.landFraction").iris(), 1.0E-12D);
|
||||
assertEquals(0.125D, metric(report, "cave.band.-48").iris(), 1.0E-12D);
|
||||
assertEquals(93_750.0D, metric(report, "decoration.columnsPerKm2").iris(), 1.0E-6D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeShareBeyondThresholdFails() {
|
||||
FidelityStats iris = stats(chunk().biomes("plains", "forest", 8));
|
||||
FidelityStats export = stats(chunk().biomes("plains", "forest", 12));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
FidelityMetric distance = metric(report, "biome.totalVariation");
|
||||
assertEquals(0.25D, distance.delta(), 1.0E-12D);
|
||||
assertFalse(distance.pass());
|
||||
FidelityMetric forest = metric(report, "biome.share.forest");
|
||||
assertEquals(0.5D, forest.iris(), 1.0E-12D);
|
||||
assertEquals(0.25D, forest.export(), 1.0E-12D);
|
||||
assertEquals(0.5D, forest.delta(), 1.0E-12D);
|
||||
assertFalse(forest.pass());
|
||||
assertTrue(metric(report, "height.p50").pass());
|
||||
assertFalse(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomesBelowTwoPercentAreOnlyCoveredByTotalVariation() {
|
||||
FidelityStats iris = new FidelityStats(MIN_Y, MAX_Y);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
iris.accept(chunk().biomes("plains", "plains", 16), 1);
|
||||
}
|
||||
iris.accept(chunk().biomes("swamp", "plains", 1), 1);
|
||||
FidelityStats export = new FidelityStats(MIN_Y, MAX_Y);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
export.accept(chunk().biomes("plains", "plains", 16), 1);
|
||||
}
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
assertNull(metric(report, "biome.share.swamp"));
|
||||
assertEquals(0.00625D, metric(report, "biome.totalVariation").delta(), 1.0E-12D);
|
||||
assertTrue(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heightQuantileDeltaNormalisedByRange() {
|
||||
FidelityStats iris = stats(chunk().surface(64));
|
||||
|
||||
FidelityReport close = compare(iris, stats(chunk().surface(94)));
|
||||
FidelityMetric closeMedian = metric(close, "height.p50");
|
||||
assertEquals(64.0D, closeMedian.iris(), 0.0D);
|
||||
assertEquals(94.0D, closeMedian.export(), 0.0D);
|
||||
assertEquals(30.0D / RANGE, closeMedian.delta(), 1.0E-12D);
|
||||
assertTrue(closeMedian.pass());
|
||||
|
||||
FidelityReport far = compare(iris, stats(chunk().surface(112)));
|
||||
FidelityMetric farMedian = metric(far, "height.p50");
|
||||
assertEquals(48.0D / RANGE, farMedian.delta(), 1.0E-12D);
|
||||
assertFalse(farMedian.pass());
|
||||
assertFalse(metric(far, "height.p10").pass());
|
||||
assertFalse(metric(far, "height.p90").pass());
|
||||
assertFalse(far.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landFractionUsesHeightThreshold() {
|
||||
FidelityStats iris = stats(chunk().surface(64), chunk().surface(64));
|
||||
FidelityStats export = stats(chunk().surface(64), chunk().surface(60).sea(62));
|
||||
|
||||
FidelityMetric land = metric(compare(iris, export), "height.landFraction");
|
||||
|
||||
assertEquals(1.0D, land.iris(), 0.0D);
|
||||
assertEquals(0.5D, land.export(), 0.0D);
|
||||
assertEquals(0.5D, land.delta(), 0.0D);
|
||||
assertFalse(land.pass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caveBandDeltaFails() {
|
||||
FidelityStats iris = stats(chunk().surface(64).caves(0, 16, 2));
|
||||
FidelityStats export = stats(chunk().surface(64).caves(0, 16, 8));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
FidelityMetric band = metric(report, "cave.band.0");
|
||||
assertEquals(0.125D, band.iris(), 1.0E-12D);
|
||||
assertEquals(0.5D, band.export(), 1.0E-12D);
|
||||
assertEquals(0.375D, band.delta(), 1.0E-12D);
|
||||
assertFalse(band.pass());
|
||||
assertTrue(metric(report, "cave.band.-64").pass());
|
||||
assertNull(metric(report, "cave.band.64"));
|
||||
assertFalse(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void terrainVoidBandsAreJudgedApartFromCaveBands() {
|
||||
FidelityStats iris = stats(chunk().surface(100).overhang(4, 80, 96).caves(0, 16, 4));
|
||||
FidelityStats export = stats(chunk().surface(100).caves(0, 16, 4));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
FidelityMetric caves = metric(report, "cave.band.80");
|
||||
assertEquals(0.0D, caves.iris(), 0.0D);
|
||||
assertEquals(0.0D, caves.export(), 0.0D);
|
||||
assertTrue(caves.pass());
|
||||
assertTrue(metric(report, "cave.band.0").pass());
|
||||
FidelityMetric voids = metric(report, "void.band.80");
|
||||
assertEquals(0.25D, voids.iris(), 1.0E-12D);
|
||||
assertEquals(0.0D, voids.export(), 0.0D);
|
||||
assertEquals(0.25D, voids.delta(), 1.0E-12D);
|
||||
assertFalse(voids.pass());
|
||||
assertNull(metric(report, "void.band.0"));
|
||||
assertFalse(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voidBandsUseTheCaveBandThreshold() {
|
||||
FidelityStats iris = stats(chunk().surface(100).overhang(4, 80, 96));
|
||||
FidelityStats export = stats(chunk().surface(100).overhang(2, 80, 96));
|
||||
|
||||
FidelityMetric voids = metric(compare(iris, export), "void.band.80");
|
||||
|
||||
assertEquals(0.125D, voids.delta(), 1.0E-12D);
|
||||
assertEquals(voids.delta() <= FidelityThresholds.defaults().caveBand(), voids.pass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thinVoidBandsAreObservedNotJudged() {
|
||||
FidelityStats iris = stats(chunk().surface(66).overhang(16, 64, 66));
|
||||
FidelityStats export = stats(chunk().surface(66));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
assertNull(metric(report, "void.band.64"));
|
||||
FidelityObservation thin = observation(report, "void.band.64");
|
||||
assertTrue(thin.iris() > 0.0D);
|
||||
assertEquals(0.0D, thin.export(), 0.0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decorationDensityUsesRelativeError() {
|
||||
FidelityStats iris = stats(chunk().trees(4, 5));
|
||||
|
||||
FidelityMetric dense = metric(compare(iris, stats(chunk().trees(8, 5))),
|
||||
"decoration.columnsPerKm2");
|
||||
assertEquals(1.0D, dense.delta(), 1.0E-12D);
|
||||
assertFalse(dense.pass());
|
||||
|
||||
FidelityReport noiseOnly = compare(iris, stats(chunk().trees(8, 5).noBlocks()));
|
||||
assertNull(metric(noiseOnly, "decoration.columnsPerKm2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallShareUsesRelativeError() {
|
||||
FidelityStats iris = stats(chunk().surface(64).caves(-20, 0, 4).walls(1));
|
||||
|
||||
FidelityMetric same = metric(compare(iris, stats(chunk().surface(64).caves(-20, 0, 4).walls(1))), "cave.wallShare");
|
||||
assertEquals(280.0D / 24_248.0D, same.iris(), 1.0E-12D);
|
||||
assertEquals(0.0D, same.delta(), 0.0D);
|
||||
assertTrue(same.pass());
|
||||
|
||||
FidelityMetric thick = metric(compare(iris, stats(chunk().surface(64).caves(-20, 0, 4).walls(3))), "cave.wallShare");
|
||||
assertEquals(840.0D / 24_248.0D, thick.export(), 1.0E-12D);
|
||||
assertEquals(2.0D, thick.delta(), 1.0E-12D);
|
||||
assertFalse(thick.pass());
|
||||
|
||||
assertNull(metric(compare(iris, stats(chunk().surface(64).caves(-20, 0, 4))), "cave.wallShare"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentHeightRangesAreRejected() {
|
||||
FidelityStats shallow = new FidelityStats(0, 256);
|
||||
shallow.accept(new SyntheticFidelityChunk(0), 1);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> compare(varied(), shallow));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportJsonListsEveryMetric() {
|
||||
FidelityStats iris = stats(chunk().surface(64));
|
||||
FidelityReport report = compare(iris, stats(chunk().surface(112)));
|
||||
|
||||
JsonObject json = JsonParser.parseString(report.toJson()).getAsJsonObject();
|
||||
|
||||
assertFalse(json.get("passed").getAsBoolean());
|
||||
assertEquals(report.metrics().size(), json.getAsJsonArray("metrics").size());
|
||||
JsonObject first = json.getAsJsonArray("metrics").get(0).getAsJsonObject();
|
||||
assertEquals(report.metrics().getFirst().name(), first.get("name").getAsString());
|
||||
assertEquals(report.metrics().getFirst().pass(), first.get("pass").getAsBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thinCaveBandsAreObservedNotJudged() {
|
||||
FidelityStats iris = stats(chunk().surface(66).caves(64, 66, 16));
|
||||
FidelityStats export = stats(chunk().surface(66));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
assertNull(metric(report, "cave.band.64"));
|
||||
assertTrue(metric(report, "cave.band.48").pass());
|
||||
FidelityObservation thin = observation(report, "cave.band.64");
|
||||
assertTrue(thin.iris() > 0.0D);
|
||||
assertEquals(0.0D, thin.export(), 0.0D);
|
||||
assertTrue(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepLavaShareIsObservedNotJudged() {
|
||||
FidelityStats iris = stats(chunk().surface(64).caves(-64, -56, 4));
|
||||
FidelityStats export = stats(chunk().surface(64).lavaPool(-64, -56, 4));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
FidelityObservation lava = report.observations().getFirst();
|
||||
assertEquals("cave.lavaShare.belowY-54", lava.name());
|
||||
assertEquals(0.0D, lava.iris(), 0.0D);
|
||||
assertEquals(0.2D, lava.export(), 1.0E-12D);
|
||||
assertNull(metric(report, "cave.lavaShare.belowY-54"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneBlockWallShareIsObservedNotJudged() {
|
||||
FidelityStats iris = stats(chunk().surface(64).caves(-20, 0, 4).walls(1));
|
||||
FidelityStats export = stats(chunk().surface(64).caves(-20, 0, 4).walls(3));
|
||||
|
||||
FidelityReport report = compare(iris, export);
|
||||
|
||||
FidelityObservation oneBlock = observation(report, "cave.wallShare.oneBlock");
|
||||
assertEquals(280.0D / 24_248.0D, oneBlock.iris(), 1.0E-12D);
|
||||
assertEquals(280.0D / 24_248.0D, oneBlock.export(), 1.0E-12D);
|
||||
assertNull(metric(report, "cave.wallShare.oneBlock"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyReportDoesNotPass() {
|
||||
assertFalse(new FidelityReport(List.of(), List.of(), List.of()).passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surfaceMetricsComeFromColumnsAndSubsurfaceMetricsFromChunks() {
|
||||
FidelityStats columns = stats(chunk().biomes("plains", "forest", 8).surface(70));
|
||||
FidelityStats exportColumns = stats(chunk().biomes("plains", "forest", 8).surface(70));
|
||||
FidelityStats chunks = stats(chunk().biomes("desert", "desert", 16).surface(20).caves(0, 16, 2).trees(3, 5));
|
||||
FidelityStats exportChunks = stats(chunk().biomes("ocean", "ocean", 16).surface(90).caves(0, 16, 2).trees(3, 5));
|
||||
|
||||
FidelityReport report = FidelityComparison.compare(
|
||||
new FidelitySamples(columns, exportColumns, sampling("columns")),
|
||||
new FidelitySamples(chunks, exportChunks, sampling("chunks")),
|
||||
FidelityThresholds.defaults());
|
||||
|
||||
assertTrue(report.toTable(), report.passed());
|
||||
assertEquals(0.5D, metric(report, "biome.share.plains").iris(), 1.0E-12D);
|
||||
assertNull(metric(report, "biome.share.desert"));
|
||||
assertEquals(70.0D, metric(report, "height.p50").export(), 0.0D);
|
||||
assertEquals(0.125D, metric(report, "cave.band.0").export(), 1.0E-12D);
|
||||
assertEquals(List.of("columns", "chunks"), report.sampling().stream().map(FidelitySampling::scope).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeSharesAreJudgedOnTheMeanOverEverySeed() {
|
||||
FidelitySamples first = seed(1337L, columns("plains", 8, "forest", 8), columns("plains", 12, "forest", 4));
|
||||
FidelitySamples second = seed(1338L, columns("plains", 8, "forest", 8), columns("plains", 4, "forest", 12));
|
||||
|
||||
BiomeShareReport report = FidelityComparison.compareBiomeShares(List.of(first, second), Map.of(), FidelityThresholds.defaults());
|
||||
|
||||
FidelityMetric forest = metric(report.mean(), "biome.share.forest");
|
||||
assertEquals(0.5D, forest.iris(), 1.0E-12D);
|
||||
assertEquals(0.5D, forest.export(), 1.0E-12D);
|
||||
assertTrue(forest.pass());
|
||||
assertEquals(0.0D, metric(report.mean(), "biome.totalVariation").delta(), 1.0E-12D);
|
||||
assertTrue(report.toTable(), report.passed());
|
||||
assertEquals(0.25D, metric(report.seeds().get(1337L), "biome.share.forest").export(), 1.0E-12D);
|
||||
assertFalse(metric(report.seeds().get(1338L), "biome.share.forest").pass());
|
||||
assertEquals(0, report.seedsPassing("biome.share.forest"));
|
||||
assertEquals(2, report.seedsCompared("biome.share.forest"));
|
||||
assertNull(metric(report.mean(), "height.p50"));
|
||||
FidelitySampling sampling = report.mean().sampling().getFirst();
|
||||
assertEquals(List.of(1337L, 1338L), sampling.seeds());
|
||||
assertEquals(32L, sampling.columns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void meanSharesWeighEverySeedEqually() {
|
||||
FidelitySamples small = seed(1337L, columns("plains", 4, "forest", 0), columns("plains", 4, "forest", 0));
|
||||
FidelitySamples large = seed(1338L, columns("plains", 0, "forest", 12), columns("plains", 6, "forest", 6));
|
||||
|
||||
BiomeShareReport report = FidelityComparison.compareBiomeShares(List.of(small, large), Map.of(), FidelityThresholds.defaults());
|
||||
|
||||
FidelityMetric plains = metric(report.mean(), "biome.share.plains");
|
||||
assertEquals(0.5D, plains.iris(), 1.0E-12D);
|
||||
assertEquals(0.75D, plains.export(), 1.0E-12D);
|
||||
assertFalse(plains.pass());
|
||||
assertFalse(report.passed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeTypeSharesAreObservedWithoutAffectingTheVerdict() {
|
||||
FidelitySamples first = seed(1337L, columns("plains", 6, "ocean", 4, "beach", 2), columns("plains", 6, "ocean", 5, "beach", 1));
|
||||
FidelitySamples second = seed(1338L, columns("plains", 6, "ocean", 4, "beach", 2), columns("plains", 6, "ocean", 4, "beach", 2));
|
||||
Map<String, String> types = Map.of("plains", "land", "ocean", "sea", "beach", "shore");
|
||||
|
||||
BiomeShareReport report = FidelityComparison.compareBiomeShares(List.of(first, second), types, FidelityThresholds.defaults());
|
||||
|
||||
FidelityObservation sea = observation(report.mean(), "biome.type.sea");
|
||||
assertEquals(4.0D / 12.0D, sea.iris(), 1.0E-12D);
|
||||
assertEquals(4.5D / 12.0D, sea.export(), 1.0E-12D);
|
||||
assertEquals(0.5D, observation(report.mean(), "biome.type.land").export(), 1.0E-12D);
|
||||
assertEquals(1.0D / 12.0D, observation(report.seeds().get(1337L), "biome.type.shore").export(), 1.0E-12D);
|
||||
assertEquals(0.5D, observation(report.mean(), "height.landFraction").iris(), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void meanSharesListEveryBiomeIncludingTheRareOnes() {
|
||||
FidelitySamples first = seed(1337L, columns("plains", 99, "swamp", 1), columns("plains", 100));
|
||||
FidelitySamples second = seed(1338L, columns("plains", 100), columns("plains", 98, "swamp", 2));
|
||||
|
||||
BiomeShareReport report = FidelityComparison.compareBiomeShares(List.of(first, second), Map.of(), FidelityThresholds.defaults());
|
||||
|
||||
assertNull(metric(report.mean(), "biome.share.swamp"));
|
||||
assertEquals(0.005D, report.irisShares().get("swamp"), 1.0E-12D);
|
||||
assertEquals(0.01D, report.exportShares().get("swamp"), 1.0E-12D);
|
||||
assertEquals(0.995D, report.irisShares().get("plains"), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeSharesNeedAtLeastOneSeed() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> FidelityComparison.compareBiomeShares(List.of(), Map.of(), FidelityThresholds.defaults()));
|
||||
}
|
||||
|
||||
private static FidelityStats varied() {
|
||||
return stats(chunk().biomes("plains", "forest", 8).caves(-48, -32, 4).trees(3, 5).surface(70),
|
||||
chunk().biomes("plains", "forest", 8).surface(40).sea(62));
|
||||
}
|
||||
|
||||
private static FidelityReport compare(FidelityStats iris, FidelityStats export) {
|
||||
return FidelityComparison.compare(new FidelitySamples(iris, export, sampling("columns")),
|
||||
new FidelitySamples(iris, export, sampling("chunks")), FidelityThresholds.defaults());
|
||||
}
|
||||
|
||||
private static FidelitySampling sampling(String scope) {
|
||||
return new FidelitySampling(scope, 16, 1, List.of(1337L), 256L);
|
||||
}
|
||||
|
||||
private static SyntheticFidelityChunk chunk() {
|
||||
return new SyntheticFidelityChunk(MIN_Y);
|
||||
}
|
||||
|
||||
private static FidelityStats stats(SyntheticFidelityChunk... chunks) {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
for (SyntheticFidelityChunk chunk : chunks) {
|
||||
stats.accept(chunk, 1);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
private static FidelitySamples seed(long seed, FidelityStats iris, FidelityStats export) {
|
||||
return new FidelitySamples(iris, export, new FidelitySampling("columns", 64, 16, List.of(seed), iris.columns()));
|
||||
}
|
||||
|
||||
private static FidelityStats columns(Object... biomesAndCounts) {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
for (int index = 0; index < biomesAndCounts.length; index += 2) {
|
||||
String biome = (String) biomesAndCounts[index];
|
||||
int count = (Integer) biomesAndCounts[index + 1];
|
||||
for (int column = 0; column < count; column++) {
|
||||
stats.accept(new FidelityColumn(biome, biome.equals("plains") ? 80 : 40, !biome.equals("plains")));
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
private static FidelityObservation observation(FidelityReport report, String name) {
|
||||
for (FidelityObservation observation : report.observations()) {
|
||||
if (observation.name().equals(name)) {
|
||||
return observation;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static FidelityMetric metric(FidelityReport report, String name) {
|
||||
for (FidelityMetric metric : report.metrics()) {
|
||||
if (metric.name().equals(name)) {
|
||||
return metric;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FidelityReportTest {
|
||||
@Test
|
||||
public void tableListsEveryMetricWithItsVerdict() {
|
||||
FidelityReport report = new FidelityReport(List.of(
|
||||
new FidelityMetric("biome.totalVariation", 0.0D, 0.03125D, 0.03125D, true),
|
||||
new FidelityMetric("height.p50", 64.0D, 80.0D, 0.041666D, false)), List.of(), List.of());
|
||||
|
||||
List<String> lines = report.toTable().lines().toList();
|
||||
|
||||
assertEquals(4, lines.size());
|
||||
assertTrue(lines.get(0), lines.get(0).startsWith("metric"));
|
||||
assertTrue(lines.get(1), lines.get(1).startsWith("biome.totalVariation"));
|
||||
assertTrue(lines.get(1), lines.get(1).contains("0.0313"));
|
||||
assertTrue(lines.get(1), lines.get(1).endsWith("PASS"));
|
||||
assertTrue(lines.get(2), lines.get(2).startsWith("height.p50"));
|
||||
assertTrue(lines.get(2), lines.get(2).contains("64.0000"));
|
||||
assertTrue(lines.get(2), lines.get(2).contains("80.0000"));
|
||||
assertTrue(lines.get(2), lines.get(2).endsWith("FAIL"));
|
||||
assertEquals("overall FAIL: 1 of 2 metrics passed", lines.get(3));
|
||||
assertEquals(lines.get(1).indexOf("PASS"), lines.get(2).indexOf("FAIL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passingReportEndsWithOverallPass() {
|
||||
FidelityReport report = new FidelityReport(List.of(new FidelityMetric("height.p10", 40.0D, 40.0D, 0.0D, true)), List.of(), List.of());
|
||||
|
||||
List<String> lines = report.toTable().lines().toList();
|
||||
|
||||
assertEquals("overall PASS: 1 of 1 metrics passed", lines.getLast());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void observationsAreListedWithoutAffectingTheVerdict() {
|
||||
FidelityReport report = new FidelityReport(List.of(new FidelityMetric("height.p10", 40.0D, 40.0D, 0.0D, true)), List.of(),
|
||||
List.of(new FidelityObservation("cave.lavaShare.belowY-54", 0.01D, 0.5D)));
|
||||
|
||||
List<String> lines = report.toTable().lines().toList();
|
||||
JsonObject json = JsonParser.parseString(report.toJson()).getAsJsonObject();
|
||||
|
||||
assertTrue(report.passed());
|
||||
assertTrue(lines.toString(), lines.stream().anyMatch(line -> line.startsWith("cave.lavaShare.belowY-54") && line.endsWith("INFO")));
|
||||
assertEquals("overall PASS: 1 of 1 metrics passed", lines.getLast());
|
||||
JsonObject observation = json.getAsJsonArray("observations").get(0).getAsJsonObject();
|
||||
assertEquals("cave.lavaShare.belowY-54", observation.get("name").getAsString());
|
||||
assertEquals(0.5D, observation.get("export").getAsDouble(), 0.0D);
|
||||
assertFalse(observation.has("pass"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void samplingIsListedInTheTableAndJson() {
|
||||
FidelityReport report = new FidelityReport(List.of(new FidelityMetric("height.p10", 40.0D, 40.0D, 0.0D, true)),
|
||||
List.of(new FidelitySampling("columns", 65536, 256, List.of(1337L, 1338L), 65536L)), List.of());
|
||||
|
||||
List<String> lines = report.toTable().lines().toList();
|
||||
JsonObject sampling = JsonParser.parseString(report.toJson()).getAsJsonObject().getAsJsonArray("sampling").get(0).getAsJsonObject();
|
||||
|
||||
assertEquals("sampling columns window=65536 stride=256 seeds=[1337, 1338] columns=65536", lines.getFirst());
|
||||
assertTrue(lines.get(1), lines.get(1).startsWith("metric"));
|
||||
assertEquals("columns", sampling.get("scope").getAsString());
|
||||
assertEquals(65536, sampling.get("windowBlocks").getAsInt());
|
||||
assertEquals(256, sampling.get("strideBlocks").getAsInt());
|
||||
assertEquals(2, sampling.getAsJsonArray("seeds").size());
|
||||
assertEquals(65536L, sampling.get("columns").getAsLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyReportFailsInTheTable() {
|
||||
List<String> lines = new FidelityReport(List.of(), List.of(), List.of()).toTable().lines().toList();
|
||||
|
||||
assertEquals("overall FAIL: no metrics were compared", lines.getLast());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class FidelityScannerTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scanMergesEveryChunkOfTheSpiral() {
|
||||
FidelityStats stats = FidelityScanner.scan(new BandedSource(null), 10, -4, 1, 4, 3);
|
||||
|
||||
assertEquals(144L, stats.columns());
|
||||
assertEquals(Map.of("plains", 128L, "forest", 16L), stats.biomeColumns());
|
||||
assertEquals(144L, stats.heightColumns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedChunkFailsTheScanWithItsCause() {
|
||||
IllegalStateException broken = new IllegalStateException("region missing");
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> FidelityScanner.scan(new BandedSource(broken), 0, 0, 1, 4, 2));
|
||||
|
||||
assertSame(broken, failure.getCause());
|
||||
}
|
||||
|
||||
private record BandedSource(RuntimeException failure) implements FidelitySource {
|
||||
@Override
|
||||
public String label() {
|
||||
return "synthetic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return MIN_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxY() {
|
||||
return MAX_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FidelityChunk sample(int chunkX, int chunkZ) {
|
||||
if (failure != null && chunkX == 1 && chunkZ == 1) {
|
||||
throw failure;
|
||||
}
|
||||
String biome = chunkX == 10 && chunkZ == -4 ? "forest" : "plains";
|
||||
return new SyntheticFidelityChunk(MIN_Y).biomes(biome, biome, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class FidelityStatsTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
|
||||
@Test
|
||||
public void strideSamplingCounts() {
|
||||
int[] strides = {1, 3, 4, 16};
|
||||
long[] expected = {256L, 36L, 16L, 1L};
|
||||
for (int i = 0; i < strides.length; i++) {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
stats.accept(chunk(), strides[i]);
|
||||
assertEquals(expected[i], stats.columns());
|
||||
assertEquals(expected[i], stats.heightColumns());
|
||||
assertEquals(expected[i], stats.blockColumns());
|
||||
assertEquals(expected[i], stats.biomeColumns().values().stream().mapToLong(Long::longValue).sum());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strideOutsideChunkIsRejected() {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
assertThrows(IllegalArgumentException.class, () -> stats.accept(chunk(), 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> stats.accept(chunk(), 17));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeIsAssociative() {
|
||||
FidelityStats a = stats(chunk().surface(40).biomes("plains", "forest", 4).caves(-20, 0, 3).walls(2));
|
||||
FidelityStats b = stats(chunk().surface(40).sea(62).biomes("ocean", "ocean", 16).overhang(3, 20, 30));
|
||||
FidelityStats c = stats(chunk().surface(90).trees(5, 6).caves(-64, -30, 16).lavaPool(-64, -60, 3).noBlocks());
|
||||
|
||||
FidelityStats left = a.merge(b).merge(c);
|
||||
FidelityStats right = a.merge(b.merge(c));
|
||||
FidelityStats combined = new FidelityStats(MIN_Y, MAX_Y);
|
||||
combined.accept(chunk().surface(40).biomes("plains", "forest", 4).caves(-20, 0, 3).walls(2), 1);
|
||||
combined.accept(chunk().surface(40).sea(62).biomes("ocean", "ocean", 16).overhang(3, 20, 30), 1);
|
||||
combined.accept(chunk().surface(90).trees(5, 6).caves(-64, -30, 16).lavaPool(-64, -60, 3).noBlocks(), 1);
|
||||
|
||||
assertSameStats(left, right);
|
||||
assertSameStats(left, combined);
|
||||
assertSameStats(a, stats(chunk().surface(40).biomes("plains", "forest", 4).caves(-20, 0, 3).walls(2)));
|
||||
assertEquals(768L, left.columns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void columnsCountBiomeHeightAndWater() {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
stats.accept(new FidelityColumn("plains", 70, false));
|
||||
stats.accept(new FidelityColumn("ocean", 20, true));
|
||||
stats.accept(new FidelityColumn(null, MIN_Y - 1, false));
|
||||
|
||||
assertEquals(3L, stats.columns());
|
||||
assertEquals(2L, stats.heightColumns());
|
||||
assertEquals(1L, stats.fluidColumns());
|
||||
assertEquals(0.5D, stats.landFraction(), 0.0D);
|
||||
assertEquals(20.0D, stats.heightQuantile(0.5D), 0.0D);
|
||||
assertEquals(70.0D, stats.heightQuantile(1.0D), 0.0D);
|
||||
assertEquals(Map.of("plains", 1L, "ocean", 1L), stats.biomeColumns());
|
||||
assertEquals(0L, stats.blockColumns());
|
||||
assertThrows(IllegalArgumentException.class, () -> stats.accept(new FidelityColumn("peak", MAX_Y, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRejectsDifferentHeightRanges() {
|
||||
FidelityStats overworld = new FidelityStats(MIN_Y, MAX_Y);
|
||||
FidelityStats shallow = new FidelityStats(0, 256);
|
||||
assertThrows(IllegalArgumentException.class, () -> overworld.merge(shallow));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decorationAboveTerrainIsCountedButNotMeasuredAsHeight() {
|
||||
FidelityStats stats = stats(chunk().surface(70).trees(4, 6));
|
||||
|
||||
assertEquals(70.0D, stats.heightQuantile(1.0D), 0.0D);
|
||||
assertEquals(64L, stats.decorationColumns());
|
||||
assertEquals(256L, stats.blockColumns());
|
||||
assertEquals(250_000.0D, stats.decorationPerSquareKilometre(), 1.0E-6D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noiseOnlyChunksSkipDecoration() {
|
||||
FidelityStats stats = stats(chunk().trees(4, 6).noBlocks());
|
||||
|
||||
assertEquals(0L, stats.blockColumns());
|
||||
assertEquals(0L, stats.decorationColumns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsurfaceOpenVoxelsAreSharedPerBand() {
|
||||
FidelityStats stats = stats(chunk().surface(64).caves(-64, -48, 4));
|
||||
|
||||
assertEquals(24, stats.bandCount());
|
||||
assertEquals(0.25D, stats.caveShare(0), 1.0E-12D);
|
||||
assertEquals(0.0D, stats.caveShare(1), 0.0D);
|
||||
assertEquals(0.0D, stats.voidShare(0), 0.0D);
|
||||
assertEquals(256L * 16L, stats.subsurfaceVoxels()[7]);
|
||||
assertEquals(0L, stats.subsurfaceVoxels()[8]);
|
||||
assertEquals(1.0D, stats.landFraction(), 0.0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snowCappedCanopyDoesNotRoofCaves() {
|
||||
FidelityStats stats = stats(chunk().surface(64).canopy(4, 90, "minecraft:snow"));
|
||||
|
||||
assertEquals(0L, sum(stats.caveVoxels()) + sum(stats.voidVoxels()));
|
||||
assertEquals(0L, stats.subsurfaceVoxels()[(80 - MIN_Y) / 16]);
|
||||
assertEquals(256L * 16L, stats.subsurfaceVoxels()[(48 - MIN_Y) / 16]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cavesUnderACanopyStillCount() {
|
||||
FidelityStats stats = stats(chunk().surface(64).caves(48, 64, 4).canopy(4, 90, "minecraft:snow"));
|
||||
|
||||
assertEquals(0.25D, stats.caveShare((48 - MIN_Y) / 16), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSpaceUnderAFloatingRoofIsATerrainVoid() {
|
||||
FidelityStats stats = stats(chunk().surface(64).roof(4, 90, 95));
|
||||
|
||||
int band = (80 - MIN_Y) / 16;
|
||||
assertEquals(64L * 15L, stats.subsurfaceVoxels()[band]);
|
||||
assertEquals(64L * 10L, stats.voidVoxels()[band]);
|
||||
assertEquals(0L, stats.caveVoxels()[band]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overhangsBelowTheTerrainTopAreVoidsAndCarvedSpaceIsCave() {
|
||||
FidelityStats stats = stats(chunk().surface(100).overhang(4, 80, 96).caves(0, 16, 8));
|
||||
|
||||
int overhangBand = (80 - MIN_Y) / 16;
|
||||
int caveBand = (0 - MIN_Y) / 16;
|
||||
assertEquals(0.25D, stats.voidShare(overhangBand), 1.0E-12D);
|
||||
assertEquals(0.0D, stats.caveShare(overhangBand), 0.0D);
|
||||
assertEquals(0.5D, stats.caveShare(caveBand), 1.0E-12D);
|
||||
assertEquals(0.0D, stats.voidShare(caveBand), 0.0D);
|
||||
assertEquals(256L * 16L, stats.subsurfaceVoxels()[overhangBand]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepLavaShareCoversSubsurfaceBelowTheLavaLine() {
|
||||
FidelityStats stats = stats(chunk().surface(64).lavaPool(-64, -56, 4).caves(-56, -40, 4));
|
||||
|
||||
assertEquals(256L * (FidelityStats.DEEP_LAVA_LINE - MIN_Y), stats.deepVoxels());
|
||||
assertEquals(4L * 16L * 8L, stats.deepLavaVoxels());
|
||||
assertEquals(0.2D, stats.deepLavaShare(), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallShareCountsSolidSubsurfaceVoxelsOfInteriorColumns() {
|
||||
FidelityStats stats = stats(chunk().surface(64).caves(-20, 0, 4).walls(1));
|
||||
|
||||
assertEquals(14L * 20L, stats.wallVoxels());
|
||||
assertEquals(42L * 108L + 154L * 128L, stats.wallSolidVoxels());
|
||||
assertEquals(280.0D / 24_248.0D, stats.wallShare(), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneBlockWallsCountSolidVoxelsBesideCaveAir() {
|
||||
FidelityStats stats = stats(chunk().surface(64).caves(-20, 0, 4).walls(3));
|
||||
|
||||
assertEquals(3L * 14L * 20L, stats.wallVoxels());
|
||||
assertEquals(14L * 20L, stats.oneBlockWallVoxels());
|
||||
assertEquals(280.0D / 24_248.0D, stats.oneBlockWallShare(), 1.0E-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunksWithoutWallsAddNoWallVoxels() {
|
||||
FidelityStats stats = stats(chunk().surface(64).caves(-20, 0, 4));
|
||||
|
||||
assertEquals(0L, stats.wallSolidVoxels());
|
||||
assertEquals(0L, stats.wallVoxels());
|
||||
assertEquals(0L, stats.oneBlockWallVoxels());
|
||||
assertThrows(IllegalStateException.class, stats::wallShare);
|
||||
assertThrows(IllegalStateException.class, stats::oneBlockWallShare);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submergedColumnsCountAsFluid() {
|
||||
FidelityStats stats = stats(chunk().surface(40).sea(62));
|
||||
|
||||
assertEquals(256L, stats.fluidColumns());
|
||||
assertEquals(0.0D, stats.landFraction(), 0.0D);
|
||||
assertEquals(40.0D, stats.heightQuantile(0.5D), 0.0D);
|
||||
}
|
||||
|
||||
private static long sum(long[] voxels) {
|
||||
long total = 0L;
|
||||
for (long count : voxels) {
|
||||
total += count;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private static SyntheticFidelityChunk chunk() {
|
||||
return new SyntheticFidelityChunk(MIN_Y);
|
||||
}
|
||||
|
||||
private static FidelityStats stats(SyntheticFidelityChunk chunk) {
|
||||
FidelityStats stats = new FidelityStats(MIN_Y, MAX_Y);
|
||||
stats.accept(chunk, 1);
|
||||
return stats;
|
||||
}
|
||||
|
||||
private static void assertSameStats(FidelityStats expected, FidelityStats actual) {
|
||||
assertEquals(expected.minY(), actual.minY());
|
||||
assertEquals(expected.maxY(), actual.maxY());
|
||||
assertEquals(expected.columns(), actual.columns());
|
||||
assertEquals(expected.heightColumns(), actual.heightColumns());
|
||||
assertEquals(expected.fluidColumns(), actual.fluidColumns());
|
||||
assertEquals(expected.blockColumns(), actual.blockColumns());
|
||||
assertEquals(expected.decorationColumns(), actual.decorationColumns());
|
||||
assertEquals(expected.riverColumns(), actual.riverColumns());
|
||||
assertEquals(expected.biomeColumns(), actual.biomeColumns());
|
||||
assertArrayEquals(expected.heightHistogram(), actual.heightHistogram());
|
||||
assertArrayEquals(expected.subsurfaceVoxels(), actual.subsurfaceVoxels());
|
||||
assertArrayEquals(expected.caveVoxels(), actual.caveVoxels());
|
||||
assertArrayEquals(expected.voidVoxels(), actual.voidVoxels());
|
||||
assertEquals(expected.deepVoxels(), actual.deepVoxels());
|
||||
assertEquals(expected.deepLavaVoxels(), actual.deepLavaVoxels());
|
||||
assertEquals(expected.wallSolidVoxels(), actual.wallSolidVoxels());
|
||||
assertEquals(expected.wallVoxels(), actual.wallVoxels());
|
||||
assertEquals(expected.oneBlockWallVoxels(), actual.oneBlockWallVoxels());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import art.arcane.volmlib.util.nbt.io.NBTSerializer;
|
||||
import art.arcane.volmlib.util.nbt.io.NamedTag;
|
||||
import art.arcane.volmlib.util.nbt.tag.CompoundTag;
|
||||
import art.arcane.volmlib.util.nbt.tag.ListTag;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class RegionFileFidelitySourceTest {
|
||||
private static final int CHUNK_X = 2;
|
||||
private static final int CHUNK_Z = -1;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void decodesPackedSectionsFromRegionFiles() throws Exception {
|
||||
Path regions = temporaryFolder.newFolder("region").toPath();
|
||||
writeRegion(regions.resolve("r.0.-1.mca"), chunk("minecraft:full"));
|
||||
|
||||
try (RegionFileFidelitySource source = new RegionFileFidelitySource(regions, -64, 320)) {
|
||||
FidelityChunk chunk = source.sample(CHUNK_X, CHUNK_Z);
|
||||
|
||||
assertEquals(-40, chunk.surfaceY(0, 0));
|
||||
assertEquals(-40, chunk.surfaceY(9, 3));
|
||||
assertTrue(chunk.fluid(0, -39, 0));
|
||||
assertFalse(chunk.fluid(9, -39, 0));
|
||||
assertTrue(chunk.open(9, -39, 0));
|
||||
assertTrue(chunk.open(0, -60, 0));
|
||||
assertFalse(chunk.open(1, -60, 0));
|
||||
assertEquals("minecraft:stone", chunk.block(15, -64, 15));
|
||||
assertEquals("minecraft:air", chunk.block(4, 100, 4));
|
||||
assertNull(chunk.surfaceBiome(0, 0));
|
||||
|
||||
FidelityStats stats = new FidelityStats(-64, 320);
|
||||
stats.accept(chunk, 1);
|
||||
assertEquals(128L, stats.fluidColumns());
|
||||
assertEquals(16L, stats.caveVoxels()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingChunkFails() throws Exception {
|
||||
Path regions = temporaryFolder.newFolder("region").toPath();
|
||||
writeRegion(regions.resolve("r.0.-1.mca"), chunk("minecraft:full"));
|
||||
|
||||
try (RegionFileFidelitySource source = new RegionFileFidelitySource(regions, -64, 320)) {
|
||||
assertThrows(IllegalStateException.class, () -> source.sample(CHUNK_X + 1, CHUNK_Z));
|
||||
assertThrows(IllegalStateException.class, () -> source.sample(40, 40));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void partiallyGeneratedChunkFails() throws Exception {
|
||||
Path regions = temporaryFolder.newFolder("region").toPath();
|
||||
writeRegion(regions.resolve("r.0.-1.mca"), chunk("minecraft:features"));
|
||||
|
||||
try (RegionFileFidelitySource source = new RegionFileFidelitySource(regions, -64, 320)) {
|
||||
assertThrows(IllegalStateException.class, () -> source.sample(CHUNK_X, CHUNK_Z));
|
||||
}
|
||||
}
|
||||
|
||||
private static CompoundTag chunk(String status) {
|
||||
CompoundTag root = new CompoundTag();
|
||||
root.putInt("DataVersion", 5023);
|
||||
root.putInt("xPos", CHUNK_X);
|
||||
root.putInt("zPos", CHUNK_Z);
|
||||
root.putInt("yPos", -4);
|
||||
root.putString("Status", status);
|
||||
ListTag<CompoundTag> sections = new ListTag<>(CompoundTag.class);
|
||||
sections.add(section(-4, List.of("minecraft:stone", "minecraft:air"), (int x, int localY, int z) -> localY == 4 && x == 0 ? 1 : 0));
|
||||
sections.add(section(-3, List.of("minecraft:stone", "minecraft:water", "minecraft:air"),
|
||||
(int x, int localY, int z) -> localY <= 8 ? 0 : x < 8 ? 1 : 2));
|
||||
sections.add(section(-2, List.of("minecraft:air"), (int x, int localY, int z) -> 0));
|
||||
root.put("sections", sections);
|
||||
return root;
|
||||
}
|
||||
|
||||
private static CompoundTag section(int sectionY, List<String> palette, VoxelPalette voxels) {
|
||||
CompoundTag section = new CompoundTag();
|
||||
section.putByte("Y", (byte) sectionY);
|
||||
CompoundTag blockStates = new CompoundTag();
|
||||
ListTag<CompoundTag> paletteTag = new ListTag<>(CompoundTag.class);
|
||||
for (String name : palette) {
|
||||
CompoundTag entry = new CompoundTag();
|
||||
entry.putString("Name", name);
|
||||
paletteTag.add(entry);
|
||||
}
|
||||
blockStates.put("palette", paletteTag);
|
||||
if (palette.size() > 1) {
|
||||
long[] data = new long[256];
|
||||
for (int index = 0; index < 4096; index++) {
|
||||
long value = voxels.index(index & 15, index >> 8, (index >> 4) & 15);
|
||||
data[index / 16] |= value << ((index % 16) * 4);
|
||||
}
|
||||
blockStates.putLongArray("data", data);
|
||||
}
|
||||
section.put("block_states", blockStates);
|
||||
return section;
|
||||
}
|
||||
|
||||
private static void writeRegion(Path file, CompoundTag chunk) throws IOException {
|
||||
ByteArrayOutputStream compressed = new ByteArrayOutputStream();
|
||||
try (DeflaterOutputStream out = new DeflaterOutputStream(compressed)) {
|
||||
new NBTSerializer(false).toStream(new NamedTag("", chunk), out);
|
||||
}
|
||||
byte[] payload = compressed.toByteArray();
|
||||
int sectors = (payload.length + 5 + 4095) / 4096;
|
||||
int index = (CHUNK_X & 31) + (CHUNK_Z & 31) * 32;
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file.toFile(), "rw")) {
|
||||
raf.setLength(8192L + sectors * 4096L);
|
||||
raf.seek(index * 4L);
|
||||
raf.writeInt((2 << 8) | sectors);
|
||||
raf.seek(8192L);
|
||||
raf.writeInt(payload.length + 1);
|
||||
raf.writeByte(2);
|
||||
raf.write(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface VoxelPalette {
|
||||
int index(int x, int localY, int z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class SurveyWindowTest {
|
||||
@Test
|
||||
public void coordinatesSitAtStrideCellCentres() {
|
||||
SurveyWindow window = new SurveyWindow(0, 0, 65536, 256);
|
||||
|
||||
assertEquals(256, window.perAxis());
|
||||
assertEquals(65536L, window.samples());
|
||||
assertEquals(-32768 + 128, window.coordinate(0, 0));
|
||||
assertEquals(32768 - 128, window.coordinate(0, 255));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void windowMustBeAPositiveMultipleOfTheStride() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new SurveyWindow(0, 0, 1000, 256));
|
||||
assertThrows(IllegalArgumentException.class, () -> new SurveyWindow(0, 0, 128, 256));
|
||||
assertThrows(IllegalArgumentException.class, () -> new SurveyWindow(0, 0, 256, 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package art.arcane.iris.probe.fidelity;
|
||||
|
||||
final class SyntheticFidelityChunk implements FidelityChunk {
|
||||
private static final int CANOPY_DEPTH = 3;
|
||||
|
||||
private final int minY;
|
||||
private int surfaceY = 64;
|
||||
private int seaLevel = Integer.MIN_VALUE;
|
||||
private int biomeSplit = 16;
|
||||
private String westBiome = "plains";
|
||||
private String eastBiome = "forest";
|
||||
private int caveMinY;
|
||||
private int caveMaxY;
|
||||
private int caveColumns;
|
||||
private int treeColumns;
|
||||
private int treeHeight;
|
||||
private int canopyColumns;
|
||||
private int canopyY;
|
||||
private String canopyCap;
|
||||
private int roofColumns;
|
||||
private int roofMinY;
|
||||
private int roofMaxY;
|
||||
private int lavaMinY;
|
||||
private int lavaMaxY;
|
||||
private int lavaColumns;
|
||||
private int wallThickness;
|
||||
private int overhangColumns;
|
||||
private int overhangMinY;
|
||||
private int overhangMaxY;
|
||||
private boolean blocks = true;
|
||||
|
||||
SyntheticFidelityChunk(int minY) {
|
||||
this.minY = minY;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk surface(int y) {
|
||||
surfaceY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk sea(int y) {
|
||||
seaLevel = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk biomes(String west, String east, int split) {
|
||||
westBiome = west;
|
||||
eastBiome = east;
|
||||
biomeSplit = split;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk caves(int fromY, int toY, int columns) {
|
||||
caveMinY = fromY;
|
||||
caveMaxY = toY;
|
||||
caveColumns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk trees(int columns, int height) {
|
||||
treeColumns = columns;
|
||||
treeHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk canopy(int columns, int leavesY, String cap) {
|
||||
canopyColumns = columns;
|
||||
canopyY = leavesY;
|
||||
canopyCap = cap;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk roof(int columns, int fromY, int toY) {
|
||||
roofColumns = columns;
|
||||
roofMinY = fromY;
|
||||
roofMaxY = toY;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk lavaPool(int fromY, int toY, int columns) {
|
||||
lavaMinY = fromY;
|
||||
lavaMaxY = toY;
|
||||
lavaColumns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk walls(int thickness) {
|
||||
wallThickness = thickness;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk overhang(int columns, int fromY, int toY) {
|
||||
overhangColumns = columns;
|
||||
overhangMinY = fromY;
|
||||
overhangMaxY = toY;
|
||||
return this;
|
||||
}
|
||||
|
||||
SyntheticFidelityChunk noBlocks() {
|
||||
blocks = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceY(int localX, int localZ) {
|
||||
if (localX < roofColumns) {
|
||||
return roofMaxY;
|
||||
}
|
||||
if (localX < canopyColumns) {
|
||||
return canopyY + CANOPY_DEPTH;
|
||||
}
|
||||
return localX < treeColumns ? surfaceY + treeHeight : surfaceY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String surfaceBiome(int localX, int localZ) {
|
||||
return localX < biomeSplit ? westBiome : eastBiome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open(int localX, int y, int localZ) {
|
||||
String id = id(localX, y, localZ);
|
||||
return id.equals("minecraft:air") || id.equals("minecraft:cave_air");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fluid(int localX, int y, int localZ) {
|
||||
String id = id(localX, y, localZ);
|
||||
return id.equals("minecraft:water") || id.equals("minecraft:lava");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String block(int localX, int y, int localZ) {
|
||||
return blocks ? id(localX, y, localZ) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean terrainMass(int localX, int y, int localZ) {
|
||||
return y <= surfaceY && !overhang(localX, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wallsKnown() {
|
||||
return wallThickness > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wall(int localX, int y, int localZ) {
|
||||
return localX >= caveColumns && localX < caveColumns + wallThickness && y >= caveMinY && y < caveMaxY;
|
||||
}
|
||||
|
||||
private String id(int localX, int y, int localZ) {
|
||||
if (y < minY) {
|
||||
return "minecraft:void_air";
|
||||
}
|
||||
if (y <= surfaceY) {
|
||||
if (localX < lavaColumns && y >= lavaMinY && y < lavaMaxY) {
|
||||
return "minecraft:lava";
|
||||
}
|
||||
if (overhang(localX, y)) {
|
||||
return "minecraft:air";
|
||||
}
|
||||
boolean cave = localX < caveColumns && y >= caveMinY && y < caveMaxY;
|
||||
return cave ? "minecraft:cave_air" : y == surfaceY ? "minecraft:grass_block" : "minecraft:stone";
|
||||
}
|
||||
if (localX < roofColumns && y >= roofMinY && y <= roofMaxY) {
|
||||
return "minecraft:stone";
|
||||
}
|
||||
if (localX < canopyColumns && y >= canopyY && y <= canopyY + CANOPY_DEPTH) {
|
||||
return y == canopyY + CANOPY_DEPTH ? canopyCap : "minecraft:spruce_leaves";
|
||||
}
|
||||
if (localX < treeColumns && y <= surfaceY + treeHeight) {
|
||||
return y == surfaceY + treeHeight ? "minecraft:oak_leaves" : "minecraft:oak_log";
|
||||
}
|
||||
if (y <= seaLevel) {
|
||||
return "minecraft:water";
|
||||
}
|
||||
return "minecraft:air";
|
||||
}
|
||||
|
||||
private boolean overhang(int localX, int y) {
|
||||
return localX < overhangColumns && y >= overhangMinY && y < overhangMaxY;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user