Apply editorconfig auto formatting
This commit is contained in:
@@ -13,4 +13,5 @@ public interface ISingletonTestOne extends IBindable
|
||||
public int getValue();
|
||||
|
||||
public int getDependentValue();
|
||||
|
||||
}
|
||||
|
||||
@@ -13,4 +13,5 @@ public interface ISingletonTestTwo extends IBindable
|
||||
public int getValue();
|
||||
|
||||
public int getDependentValue();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,5 @@ public class ConcreteSingletonTestBoth implements ISingletonTestOne, ISingletonT
|
||||
|
||||
@Override
|
||||
public int getDependentValue() { return -1; }
|
||||
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ public class LevelWrapperTest implements IDhApiLevelWrapper
|
||||
@Override
|
||||
public Object getWrappedMcObject() { return null; }
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public IDhApiDimensionTypeWrapper getDimensionType() { return null; }
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType() { return null; }
|
||||
|
||||
@Override
|
||||
@@ -30,7 +30,7 @@ public class LevelWrapperTest implements IDhApiLevelWrapper
|
||||
@Override
|
||||
public int getHeight() { return 0; }
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public int getMinHeight() { return IDhApiLevelWrapper.super.getMinHeight(); }
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ public class TestWorldGenerator implements IDhApiWorldGenerator
|
||||
//===================//
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
public void close() { }
|
||||
|
||||
@Override
|
||||
public boolean isBusy() { return false; }
|
||||
@@ -61,7 +61,7 @@ public class TestWorldGenerator implements IDhApiWorldGenerator
|
||||
public CompletableFuture<Void> generateChunks(int chunkPosMinX, int chunkPosMinZ, byte granularity, byte targetDataDetail, EDhApiDistantGeneratorMode maxGenerationStep, ExecutorService executorService, Consumer<Object[]> resultConsumer) { return null; }
|
||||
|
||||
@Override
|
||||
public void preGeneratorTaskStart() { }
|
||||
public void preGeneratorTaskStart() { }
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
package testItems.worldGeneratorInjection.objects;
|
||||
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||
|
||||
/**
|
||||
* Dummy test implementation object for world generator injection unit tests.
|
||||
*
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class WorldGeneratorTestPrimary extends TestWorldGenerator
|
||||
public static int PRIORITY = OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY + 5;
|
||||
public static final byte SMALLEST_DETAIL_LEVEL = 2;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getPriority() { return PRIORITY; }
|
||||
|
||||
@@ -37,18 +37,18 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Results (2023-5-20): <br>
|
||||
* 200 files <br><br>
|
||||
*
|
||||
*
|
||||
* <strong>uncompressed</strong> <br><br>
|
||||
*
|
||||
*
|
||||
* render data - ratio 1.0 (shocker :P) <br>
|
||||
* read time in - 784 ms, avg 3 ms/file <br>
|
||||
* write time in - 803 ms, avg 4 ms/file <br><br>
|
||||
*
|
||||
*
|
||||
* full data - ratio 1.0 <br>
|
||||
* read time in - 2,213 ms, avg 11 ms/file <br>
|
||||
* write time in - 1,753 ms, avg 8 ms/file <br><br><br>
|
||||
*
|
||||
*
|
||||
*
|
||||
* <strong>XZ</strong> <br><br>
|
||||
*
|
||||
* render data - ratio 0.1044 <br>
|
||||
@@ -58,8 +58,8 @@ import java.util.ArrayList;
|
||||
* full data - ratio 0.1123 <br>
|
||||
* read time in - 5,888 ms, avg 29 ms/file <br>
|
||||
* write time in - 79,675 ms, avg 398 ms/file <br><br><br>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* <strong>LZ4</strong> <br><br>
|
||||
*
|
||||
* render data - ratio 0.2933 <br>
|
||||
@@ -69,8 +69,8 @@ import java.util.ArrayList;
|
||||
* full data - ratio 0.3275 <br>
|
||||
* read time in - 1,964 ms, avg 9 ms/file <br>
|
||||
* write time in - 1,584 ms, avg 7 ms/file <br><br><br>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* <strong>Z Standard</strong> <br><br>
|
||||
*
|
||||
* render data - ratio 0.1791 <br>
|
||||
@@ -80,9 +80,9 @@ import java.util.ArrayList;
|
||||
* full data - ratio 0.2060 <br>
|
||||
* read time in - 14,754 ms, avg 73 ms/file <br>
|
||||
* write time in - 14,057 ms, avg 70 ms/file <br><br><br>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* <strong>Note:</strong>
|
||||
* In order to test the compressors that aren't currently in use: <br>
|
||||
* 1. Generate DH data and point the {@link CompressionTest#TEST_DIR} variable to the "Distant_Horizons" folder.
|
||||
@@ -106,7 +106,7 @@ public class CompressionTest
|
||||
|
||||
|
||||
|
||||
// @Test
|
||||
// @Test
|
||||
public void NoCompression()
|
||||
{
|
||||
String compressorName = "Uncompressed";
|
||||
@@ -115,13 +115,13 @@ public class CompressionTest
|
||||
CreateOutputStreamFunc createOutputStreamFunc = (outputStream) -> outputStream;
|
||||
|
||||
|
||||
System.out.println(compressorName+" testing render data");
|
||||
System.out.println(compressorName + " testing render data");
|
||||
this.testCompressor(compressorName, RENDER_DATA_PATH, createInputStreamFunc, createOutputStreamFunc);
|
||||
System.out.println(compressorName+" testing full data");
|
||||
System.out.println(compressorName + " testing full data");
|
||||
this.testCompressor(compressorName, FULL_DATA_PATH, createInputStreamFunc, createOutputStreamFunc);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// @Test
|
||||
public void Lz4()
|
||||
{
|
||||
String compressorName = "LZ4";
|
||||
@@ -130,12 +130,12 @@ public class CompressionTest
|
||||
CreateOutputStreamFunc createOutputStreamFunc = (outputStream) -> new LZ4FrameOutputStream(outputStream);
|
||||
|
||||
|
||||
System.out.println(compressorName+" testing render data");
|
||||
System.out.println(compressorName + " testing render data");
|
||||
this.testCompressor(compressorName, RENDER_DATA_PATH, createInputStreamFunc, createOutputStreamFunc);
|
||||
System.out.println(compressorName+" testing full data");
|
||||
System.out.println(compressorName + " testing full data");
|
||||
this.testCompressor(compressorName, FULL_DATA_PATH, createInputStreamFunc, createOutputStreamFunc);
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
// public void Zstandard()
|
||||
// {
|
||||
@@ -150,7 +150,7 @@ public class CompressionTest
|
||||
// System.out.println(compressorName+" testing full data");
|
||||
// this.testCompressor(compressorName, FULL_DATA_PATH, createInputStreamFunc, createOutputStreamFunc);
|
||||
// }
|
||||
|
||||
|
||||
// @Test
|
||||
// public void Xz()
|
||||
// {
|
||||
@@ -173,9 +173,18 @@ public class CompressionTest
|
||||
//=================//
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CreateInputStreamFunc { InputStream apply(InputStream inputStream) throws Exception; }
|
||||
public interface CreateInputStreamFunc
|
||||
{
|
||||
InputStream apply(InputStream inputStream) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CreateOutputStreamFunc { OutputStream apply(OutputStream outputStream) throws Exception; }
|
||||
public interface CreateOutputStreamFunc
|
||||
{
|
||||
OutputStream apply(OutputStream outputStream) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
private void testCompressor(
|
||||
String compressorName, String inputFolderPath,
|
||||
@@ -194,7 +203,7 @@ public class CompressionTest
|
||||
File[] inputFileArray = inputFolder.listFiles();
|
||||
Assert.assertNotNull(inputFileArray);
|
||||
|
||||
File compressedFolder = new File(inputFolderPath+"\\"+compressorName);
|
||||
File compressedFolder = new File(inputFolderPath + "\\" + compressorName);
|
||||
compressedFolder.delete();
|
||||
compressedFolder.mkdirs();
|
||||
|
||||
@@ -231,7 +240,8 @@ public class CompressionTest
|
||||
originalFileByteArray.add(nextByte);
|
||||
}
|
||||
}
|
||||
catch (EOFException e) { /* end of file reached */ }
|
||||
catch (EOFException e)
|
||||
{ /* end of file reached */ }
|
||||
}
|
||||
|
||||
|
||||
@@ -239,7 +249,7 @@ public class CompressionTest
|
||||
// compress file //
|
||||
long startWriteMsTime = System.currentTimeMillis();
|
||||
|
||||
File compressedFile = new File(inputFolderPath+"\\"+compressorName+"\\"+inputFile.getName());
|
||||
File compressedFile = new File(inputFolderPath + "\\" + compressorName + "\\" + inputFile.getName());
|
||||
compressedFile.delete();
|
||||
compressedFile.createNewFile();
|
||||
|
||||
@@ -278,7 +288,8 @@ public class CompressionTest
|
||||
compressedFileByteArray.add(nextByte);
|
||||
}
|
||||
}
|
||||
catch (EOFException e) { /* end of file reached */ }
|
||||
catch (EOFException e)
|
||||
{ /* end of file reached */ }
|
||||
}
|
||||
|
||||
long endReadMsTime = System.currentTimeMillis();
|
||||
@@ -289,7 +300,7 @@ public class CompressionTest
|
||||
Assert.assertEquals("byte array size mismatch", compressedFileByteArray.size(), originalFileByteArray.size());
|
||||
for (int i = 0; i < compressedFileByteArray.size(); i++)
|
||||
{
|
||||
Assert.assertEquals("array content mismatch at index ["+i+"]", compressedFileByteArray.get(i), originalFileByteArray.get(i));
|
||||
Assert.assertEquals("array content mismatch at index [" + i + "]", compressedFileByteArray.get(i), originalFileByteArray.get(i));
|
||||
}
|
||||
|
||||
|
||||
@@ -298,12 +309,12 @@ public class CompressionTest
|
||||
|
||||
|
||||
double compressionRatio = (totalCompressedFileSizeInBytes / (double) totalUncompressedFileSizeInBytes);
|
||||
String compressionRatioString = compressionRatio+"";
|
||||
compressionRatioString = compressionRatioString.substring(0, Math.min(6,compressionRatioString.length()));
|
||||
String compressionRatioString = compressionRatio + "";
|
||||
compressionRatioString = compressionRatioString.substring(0, Math.min(6, compressionRatioString.length()));
|
||||
|
||||
System.out.println("Uncompressed file size: ["+humanReadableByteCountSI(totalUncompressedFileSizeInBytes)+"] Compressed file size: ["+humanReadableByteCountSI(totalCompressedFileSizeInBytes)+"]. Compression ratio: ["+compressionRatioString+"].");
|
||||
System.out.println("Total read time in MS: ["+totalReadTimeInMs+"] Average read time per file: ["+(totalReadTimeInMs/processedFileCount)+"]");
|
||||
System.out.println("Total write time in MS: ["+totalWriteTimeInMs+"] Average write time per file: ["+(totalWriteTimeInMs/processedFileCount)+"]");
|
||||
System.out.println("Uncompressed file size: [" + humanReadableByteCountSI(totalUncompressedFileSizeInBytes) + "] Compressed file size: [" + humanReadableByteCountSI(totalCompressedFileSizeInBytes) + "]. Compression ratio: [" + compressionRatioString + "].");
|
||||
System.out.println("Total read time in MS: [" + totalReadTimeInMs + "] Average read time per file: [" + (totalReadTimeInMs / processedFileCount) + "]");
|
||||
System.out.println("Total write time in MS: [" + totalWriteTimeInMs + "] Average write time per file: [" + (totalWriteTimeInMs / processedFileCount) + "]");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -98,30 +98,38 @@ public class DependencyInjectorTest
|
||||
{
|
||||
OverrideInjector TEST_INJECTOR = new OverrideInjector(OverrideTestAssembly.getPackagePath(2));
|
||||
OverrideInjector CORE_INJECTOR = new OverrideInjector();
|
||||
|
||||
|
||||
|
||||
|
||||
// pre-dependency setup
|
||||
Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get(IOverrideTest.class));
|
||||
Assert.assertNull("Nothing should have been bound.", CORE_INJECTOR.get(IOverrideTest.class));
|
||||
|
||||
|
||||
|
||||
|
||||
// variables to use later
|
||||
IOverrideTest override;
|
||||
OverrideTestCore coreOverride = new OverrideTestCore();
|
||||
OverrideTestPrimary primaryOverride = new OverrideTestPrimary();
|
||||
|
||||
|
||||
|
||||
|
||||
// core override binding
|
||||
try { TEST_INJECTOR.bind(IOverrideTest.class, coreOverride); } catch (IllegalArgumentException e) { Assert.fail("Core override should be bindable for test package injector."); }
|
||||
|
||||
try
|
||||
{
|
||||
TEST_INJECTOR.bind(IOverrideTest.class, coreOverride);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
Assert.fail("Core override should be bindable for test package injector.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CORE_INJECTOR.bind(IOverrideTest.class, coreOverride);
|
||||
Assert.fail("Core override should not be bindable for core package injector.");
|
||||
}
|
||||
catch (IllegalArgumentException e) { /* this exception should be thrown */ }
|
||||
|
||||
|
||||
catch (IllegalArgumentException e)
|
||||
{ /* this exception should be thrown */ }
|
||||
|
||||
|
||||
// core override
|
||||
Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get(IOverrideTest.class));
|
||||
Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get(IOverrideTest.class));
|
||||
@@ -132,8 +140,8 @@ public class DependencyInjectorTest
|
||||
override = TEST_INJECTOR.get(IOverrideTest.class);
|
||||
Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.CORE_PRIORITY);
|
||||
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestCore.VALUE);
|
||||
|
||||
|
||||
|
||||
|
||||
// default override
|
||||
TEST_INJECTOR.bind(IOverrideTest.class, primaryOverride);
|
||||
// priority gets
|
||||
@@ -144,12 +152,12 @@ public class DependencyInjectorTest
|
||||
override = TEST_INJECTOR.get(IOverrideTest.class);
|
||||
Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideTestPrimary.PRIORITY);
|
||||
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestPrimary.VALUE);
|
||||
|
||||
|
||||
|
||||
|
||||
// in-line get
|
||||
// (make sure the returned type is correct and compiles, the actual value doesn't matter)
|
||||
TEST_INJECTOR.get(IOverrideTest.class).getValue();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +182,14 @@ public class DependencyInjectorTest
|
||||
|
||||
|
||||
// bind the core generator //
|
||||
try { TEST_INJECTOR.bind(boundLevel, coreLevelGenerator); } catch (IllegalArgumentException e) { Assert.fail("[" + coreLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector."); }
|
||||
try
|
||||
{
|
||||
TEST_INJECTOR.bind(boundLevel, coreLevelGenerator);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
Assert.fail("[" + coreLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector.");
|
||||
}
|
||||
|
||||
// validate the core generator was bound
|
||||
generator = TEST_INJECTOR.get(boundLevel);
|
||||
@@ -188,7 +203,14 @@ public class DependencyInjectorTest
|
||||
|
||||
|
||||
// bind the secondary generator //
|
||||
try { TEST_INJECTOR.bind(boundLevel, secondaryLevelGenerator); } catch (IllegalArgumentException e) { Assert.fail("[" + secondaryLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector."); }
|
||||
try
|
||||
{
|
||||
TEST_INJECTOR.bind(boundLevel, secondaryLevelGenerator);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
Assert.fail("[" + secondaryLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector.");
|
||||
}
|
||||
|
||||
// validate the secondary generator overrides the core generator
|
||||
generator = TEST_INJECTOR.get(boundLevel);
|
||||
@@ -202,7 +224,14 @@ public class DependencyInjectorTest
|
||||
|
||||
|
||||
// bind the primary generator //
|
||||
try { TEST_INJECTOR.bind(boundLevel, primaryLevelGenerator); } catch (IllegalArgumentException e) { Assert.fail("[" + primaryLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector."); }
|
||||
try
|
||||
{
|
||||
TEST_INJECTOR.bind(boundLevel, primaryLevelGenerator);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
Assert.fail("[" + primaryLevelGenerator.getClass().getSimpleName() + "] should be bindable for test package injector.");
|
||||
}
|
||||
|
||||
// validate the primary generator overrides both the core and secondary generator
|
||||
generator = TEST_INJECTOR.get(boundLevel);
|
||||
|
||||
@@ -29,36 +29,36 @@ public class DhSectionPosTest
|
||||
@Test
|
||||
public void ContainsPosTest()
|
||||
{
|
||||
DhSectionPos root = new DhSectionPos((byte)10, 0, 0);
|
||||
DhSectionPos child = new DhSectionPos((byte)9, 1, 1);
|
||||
DhSectionPos root = new DhSectionPos((byte) 10, 0, 0);
|
||||
DhSectionPos child = new DhSectionPos((byte) 9, 1, 1);
|
||||
|
||||
Assert.assertTrue("section pos contains fail", root.contains(child));
|
||||
Assert.assertFalse("section pos contains fail", child.contains(root));
|
||||
|
||||
|
||||
root = new DhSectionPos((byte)10, 1, 0);
|
||||
root = new DhSectionPos((byte) 10, 1, 0);
|
||||
|
||||
// out of bounds
|
||||
child = new DhSectionPos((byte)9, 0, 0);
|
||||
child = new DhSectionPos((byte) 9, 0, 0);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
child = new DhSectionPos((byte)9, 1, 1);
|
||||
child = new DhSectionPos((byte) 9, 1, 1);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
|
||||
// in bounds
|
||||
child = new DhSectionPos((byte)9, 2, 0);
|
||||
child = new DhSectionPos((byte) 9, 2, 0);
|
||||
Assert.assertTrue("position should be in bounds", root.contains(child));
|
||||
child = new DhSectionPos((byte)9, 3, 1);
|
||||
child = new DhSectionPos((byte) 9, 3, 1);
|
||||
Assert.assertTrue("position should be in bounds", root.contains(child));
|
||||
|
||||
// out of bounds
|
||||
child = new DhSectionPos((byte)9, 2, 2);
|
||||
child = new DhSectionPos((byte) 9, 2, 2);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
child = new DhSectionPos((byte)9, 3, 3);
|
||||
child = new DhSectionPos((byte) 9, 3, 3);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
|
||||
child = new DhSectionPos((byte)9, 4, 4);
|
||||
child = new DhSectionPos((byte) 9, 4, 4);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
child = new DhSectionPos((byte)9, 5, 5);
|
||||
child = new DhSectionPos((byte) 9, 5, 5);
|
||||
Assert.assertFalse("position should be out of bounds", root.contains(child));
|
||||
}
|
||||
|
||||
@@ -66,15 +66,15 @@ public class DhSectionPosTest
|
||||
public void ContainsAdjacentPosTest()
|
||||
{
|
||||
// neither should contain the other, they are single blocks that are next to each other
|
||||
DhSectionPos left = new DhSectionPos((byte)0, 4606, 0);
|
||||
DhSectionPos right = new DhSectionPos((byte)0, 4607, 0);
|
||||
DhSectionPos left = new DhSectionPos((byte) 0, 4606, 0);
|
||||
DhSectionPos right = new DhSectionPos((byte) 0, 4607, 0);
|
||||
Assert.assertFalse(left.contains(right));
|
||||
Assert.assertFalse(right.contains(left));
|
||||
|
||||
|
||||
// 512 block wide sections that are adjacent, but not overlapping
|
||||
left = new DhSectionPos((byte)9, 0, 0);
|
||||
right = new DhSectionPos((byte)9, 1, 0);
|
||||
left = new DhSectionPos((byte) 9, 0, 0);
|
||||
right = new DhSectionPos((byte) 9, 1, 0);
|
||||
Assert.assertFalse(left.contains(right));
|
||||
Assert.assertFalse(right.contains(left));
|
||||
|
||||
@@ -83,23 +83,23 @@ public class DhSectionPosTest
|
||||
@Test
|
||||
public void ParentPosTest()
|
||||
{
|
||||
DhSectionPos leaf = new DhSectionPos((byte)0, 0, 0);
|
||||
DhSectionPos convert = leaf.convertToDetailLevel((byte)1);
|
||||
DhSectionPos leaf = new DhSectionPos((byte) 0, 0, 0);
|
||||
DhSectionPos convert = leaf.convertToDetailLevel((byte) 1);
|
||||
DhSectionPos parent = leaf.getParentPos();
|
||||
Assert.assertEquals("get parent at 0,0 fail", convert, parent);
|
||||
|
||||
|
||||
leaf = new DhSectionPos((byte)0, 1, 1);
|
||||
convert = leaf.convertToDetailLevel((byte)1);
|
||||
leaf = new DhSectionPos((byte) 0, 1, 1);
|
||||
convert = leaf.convertToDetailLevel((byte) 1);
|
||||
parent = leaf.getParentPos();
|
||||
Assert.assertEquals("get parent at 1,1 fail", convert, parent);
|
||||
|
||||
|
||||
leaf = new DhSectionPos((byte)1, 2, 2);
|
||||
convert = leaf.convertToDetailLevel((byte)2);
|
||||
leaf = new DhSectionPos((byte) 1, 2, 2);
|
||||
convert = leaf.convertToDetailLevel((byte) 2);
|
||||
parent = leaf.getParentPos();
|
||||
Assert.assertEquals("parent upscale fail", convert, parent);
|
||||
convert = leaf.convertToDetailLevel((byte)0);
|
||||
convert = leaf.convertToDetailLevel((byte) 0);
|
||||
DhSectionPos childIndex = leaf.getChildByIndex(0);
|
||||
Assert.assertEquals("child detail fail", convert, childIndex);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class DhSectionPosTest
|
||||
@Test
|
||||
public void ChildPosTest()
|
||||
{
|
||||
DhSectionPos node = new DhSectionPos((byte)1, 2302, 0);
|
||||
DhSectionPos node = new DhSectionPos((byte) 1, 2302, 0);
|
||||
DhSectionPos nw = node.getChildByIndex(0);
|
||||
DhSectionPos sw = node.getChildByIndex(1);
|
||||
DhSectionPos ne = node.getChildByIndex(2);
|
||||
@@ -120,26 +120,26 @@ public class DhSectionPosTest
|
||||
Assert.assertNotEquals(ne, se);
|
||||
|
||||
// confirm each child has the correct value
|
||||
Assert.assertEquals(nw, new DhSectionPos((byte)0, 4604, 0));
|
||||
Assert.assertEquals(sw, new DhSectionPos((byte)0, 4605, 0));
|
||||
Assert.assertEquals(ne, new DhSectionPos((byte)0, 4604, 1));
|
||||
Assert.assertEquals(se, new DhSectionPos((byte)0, 4605, 1));
|
||||
Assert.assertEquals(nw, new DhSectionPos((byte) 0, 4604, 0));
|
||||
Assert.assertEquals(sw, new DhSectionPos((byte) 0, 4605, 0));
|
||||
Assert.assertEquals(ne, new DhSectionPos((byte) 0, 4604, 1));
|
||||
Assert.assertEquals(se, new DhSectionPos((byte) 0, 4605, 1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GetCenterTest()
|
||||
{
|
||||
DhSectionPos node = new DhSectionPos((byte)1, 2303, 0);
|
||||
DhSectionPos node = new DhSectionPos((byte) 1, 2303, 0);
|
||||
DhLodPos centerNode = node.getCenter();
|
||||
DhLodPos expectedCenterNode = new DhLodPos((byte)0, 4606,0);
|
||||
DhLodPos expectedCenterNode = new DhLodPos((byte) 0, 4606, 0);
|
||||
Assert.assertEquals("", expectedCenterNode, centerNode);
|
||||
|
||||
|
||||
|
||||
node = new DhSectionPos((byte)10, 0, 0); // 1024 blocks wide
|
||||
node = new DhSectionPos((byte) 10, 0, 0); // 1024 blocks wide
|
||||
centerNode = node.getCenter();
|
||||
expectedCenterNode = new DhLodPos((byte)0, 1024/2,1024/2);
|
||||
expectedCenterNode = new DhLodPos((byte) 0, 1024 / 2, 1024 / 2);
|
||||
Assert.assertEquals("", expectedCenterNode, centerNode);
|
||||
|
||||
}
|
||||
@@ -147,15 +147,15 @@ public class DhSectionPosTest
|
||||
@Test
|
||||
public void GetCenter2Test()
|
||||
{
|
||||
DhSectionPos parentNode = new DhSectionPos((byte)2, 1151, 0); // width 4 blocks
|
||||
DhSectionPos inputPos = new DhSectionPos((byte)0, 4606, 0); // width 1 block
|
||||
DhSectionPos parentNode = new DhSectionPos((byte) 2, 1151, 0); // width 4 blocks
|
||||
DhSectionPos inputPos = new DhSectionPos((byte) 0, 4606, 0); // width 1 block
|
||||
Assert.assertTrue(parentNode.contains(inputPos));
|
||||
|
||||
DhLodPos parentCenter = parentNode.getCenter();
|
||||
DhLodPos inputCenter = inputPos.getCenter();
|
||||
|
||||
Assert.assertEquals(new DhLodPos((byte)0, 4606, 2), parentCenter);
|
||||
Assert.assertEquals(new DhLodPos((byte)0, 4606, 0), inputCenter);
|
||||
Assert.assertEquals(new DhLodPos((byte) 0, 4606, 2), parentCenter);
|
||||
Assert.assertEquals(new DhLodPos((byte) 0, 4606, 0), inputCenter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This is just a quick demo to confirm the testing system is set up correctly.
|
||||
*
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-5
|
||||
*/
|
||||
|
||||
@@ -55,34 +55,34 @@ public class QuadTreeTest
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new LargeTestTree();
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), treeParams.getPositiveEdgeCenterPos(), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertTrue("Tree min/max detail level out of expected bounds: "+tree, tree.treeMaxDetailLevel >= 10 && tree.treeMinDetailLevel <= 10 - 4);
|
||||
Assert.assertTrue("Tree min/max detail level out of expected bounds: " + tree, tree.treeMaxDetailLevel >= 10 && tree.treeMinDetailLevel <= 10 - 4);
|
||||
|
||||
|
||||
// (pseudo) root node //
|
||||
testSet(tree, new DhSectionPos((byte)10, 0, 0), 0);
|
||||
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 0);
|
||||
|
||||
// first child (0,0) //
|
||||
testSet(tree, new DhSectionPos((byte)9, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte)9, 1, 0), 2);
|
||||
testSet(tree, new DhSectionPos((byte)9, 0, 1), 3);
|
||||
testSet(tree, new DhSectionPos((byte)9, 1, 1), 4);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 1, 0), 2);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 0, 1), 3);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 1, 1), 4);
|
||||
|
||||
// second child (0,0) (0,0) //
|
||||
testSet(tree, new DhSectionPos((byte)8, 0, 0), 5);
|
||||
testSet(tree, new DhSectionPos((byte)8, 1, 0), 6);
|
||||
testSet(tree, new DhSectionPos((byte)8, 0, 1), 7);
|
||||
testSet(tree, new DhSectionPos((byte)8, 1, 1), 8);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 0, 0), 5);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 1, 0), 6);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 0, 1), 7);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 1, 1), 8);
|
||||
// second child (0,0) (1,1) //
|
||||
testSet(tree, new DhSectionPos((byte)8, 2, 2), 9);
|
||||
testSet(tree, new DhSectionPos((byte)8, 3, 2), 10);
|
||||
testSet(tree, new DhSectionPos((byte)8, 2, 3), 11);
|
||||
testSet(tree, new DhSectionPos((byte)8, 3, 3), 12);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 2, 2), 9);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 3, 2), 10);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 2, 3), 11);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 3, 3), 12);
|
||||
|
||||
// third child (0,0) (1,0) (0,0) //
|
||||
testSet(tree, new DhSectionPos((byte)7, 5, 0), 9);
|
||||
testSet(tree, new DhSectionPos((byte)7, 6, 0), 10);
|
||||
testSet(tree, new DhSectionPos((byte)7, 5, 1), 11);
|
||||
testSet(tree, new DhSectionPos((byte)7, 6, 1), 12);
|
||||
testSet(tree, new DhSectionPos((byte) 7, 5, 0), 9);
|
||||
testSet(tree, new DhSectionPos((byte) 7, 6, 0), 10);
|
||||
testSet(tree, new DhSectionPos((byte) 7, 5, 1), 11);
|
||||
testSet(tree, new DhSectionPos((byte) 7, 6, 1), 12);
|
||||
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
// root node //
|
||||
testSet(tree, new DhSectionPos((byte)10, -1, -1), 0);
|
||||
testSet(tree, new DhSectionPos((byte) 10, -1, -1), 0);
|
||||
|
||||
// first child (-1,-1) //
|
||||
testSet(tree, new DhSectionPos((byte)9, -2, -1), 1);
|
||||
testSet(tree, new DhSectionPos((byte)9, -1, -1), 2);
|
||||
testSet(tree, new DhSectionPos((byte)9, -2, -2), 3);
|
||||
testSet(tree, new DhSectionPos((byte)9, -1, -2), 4);
|
||||
testSet(tree, new DhSectionPos((byte) 9, -2, -1), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 9, -1, -1), 2);
|
||||
testSet(tree, new DhSectionPos((byte) 9, -2, -2), 3);
|
||||
testSet(tree, new DhSectionPos((byte) 9, -1, -2), 4);
|
||||
|
||||
// TODO
|
||||
// // second child (-1,-1) (0,0) //
|
||||
@@ -126,41 +126,41 @@ public class QuadTreeTest
|
||||
public void OutOfBoundsQuadTreeTest()
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new LargeTestTree();
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0,0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
Assert.assertEquals("tree diameter incorrect", treeParams.getWidthInBlocks(), tree.diameterInBlocks());
|
||||
|
||||
|
||||
// wrong detail level on purpose, if the detail level was 0 (block) this should work
|
||||
DhSectionPos outOfBoundsPos = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2), 0);
|
||||
DhSectionPos outOfBoundsPos = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
|
||||
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
|
||||
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
|
||||
|
||||
|
||||
// out of bounds //
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2) + 1, 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) + 1, 0);
|
||||
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
|
||||
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
|
||||
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2), 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2), 0);
|
||||
testSet(tree, outOfBoundsPos, -1, IndexOutOfBoundsException.class);
|
||||
Assert.assertEquals("incorrect leaf node count", 0, tree.leafNodeCount());
|
||||
|
||||
|
||||
// in bounds //
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2)-1, 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 1, 0);
|
||||
testSet(tree, outOfBoundsPos, 0);
|
||||
Assert.assertEquals("incorrect leaf node count", 1, tree.leafNodeCount());
|
||||
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2)-3, 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 3, 0);
|
||||
testSet(tree, outOfBoundsPos, 0);
|
||||
Assert.assertEquals("incorrect leaf node count", 2, tree.leafNodeCount());
|
||||
|
||||
// TODO this position probably has trouble with getting the center.
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2)-2, 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 2, 0);
|
||||
testSet(tree, outOfBoundsPos, 0);
|
||||
Assert.assertEquals("incorrect leaf node count", 3, tree.leafNodeCount());
|
||||
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks()/2)-4, 0);
|
||||
outOfBoundsPos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (treeParams.getWidthInBlocks() / 2) - 4, 0);
|
||||
testSet(tree, outOfBoundsPos, 0);
|
||||
Assert.assertEquals("incorrect leaf node count", 4, tree.leafNodeCount());
|
||||
|
||||
@@ -169,19 +169,19 @@ public class QuadTreeTest
|
||||
public void outOfBoundsInTreeTest()
|
||||
{
|
||||
// very specific tree parameters to match test results
|
||||
QuadTree<Integer> tree = new QuadTree<>(512, new DhBlockPos2D(125, -516), (byte)6);
|
||||
QuadTree<Integer> tree = new QuadTree<>(512, new DhBlockPos2D(125, -516), (byte) 6);
|
||||
Assert.assertEquals("Test may need to be re-calculated for different max detail level.", 9, tree.treeMaxDetailLevel);
|
||||
|
||||
|
||||
DhSectionPos rootPos = new DhSectionPos((byte)9, 0, -1);
|
||||
DhSectionPos rootPos = new DhSectionPos((byte) 9, 0, -1);
|
||||
testSet(tree, rootPos, 1);
|
||||
|
||||
// pos is in tree, but out of range
|
||||
DhSectionPos midPos = new DhSectionPos((byte)8, 0, -1);
|
||||
DhSectionPos midPos = new DhSectionPos((byte) 8, 0, -1);
|
||||
testSet(tree, midPos, 2, IndexOutOfBoundsException.class);
|
||||
|
||||
// pos is in tree, but out of range
|
||||
DhSectionPos leafPos = new DhSectionPos((byte)7, 0, -2);
|
||||
DhSectionPos leafPos = new DhSectionPos((byte) 7, 0, -2);
|
||||
testSet(tree, leafPos, 3, IndexOutOfBoundsException.class);
|
||||
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
// (pseudo) root nodes //
|
||||
testSet(tree, new DhSectionPos((byte)10, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
|
||||
|
||||
// first child (0,0) //
|
||||
DhSectionPos nw = new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0);
|
||||
@@ -224,7 +224,7 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
// small move //
|
||||
DhBlockPos2D smallMoveBlockPos = new DhBlockPos2D(pseudoRootNodeWidthInBlocks*2, 0); // move enough that the original root nodes aren't touching the same grid squares they were before, but not far enough as to be garbage collected (TODO reword)
|
||||
DhBlockPos2D smallMoveBlockPos = new DhBlockPos2D(pseudoRootNodeWidthInBlocks * 2, 0); // move enough that the original root nodes aren't touching the same grid squares they were before, but not far enough as to be garbage collected (TODO reword)
|
||||
tree.setCenterBlockPos(smallMoveBlockPos);
|
||||
Assert.assertEquals("Tree center incorrect", smallMoveBlockPos, tree.getCenterBlockPos());
|
||||
|
||||
@@ -259,17 +259,17 @@ public class QuadTreeTest
|
||||
Assert.assertEquals("Tree center incorrect", DhBlockPos2D.ZERO, tree.getCenterBlockPos());
|
||||
|
||||
// on the negative X edge
|
||||
DhSectionPos edgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, -treeParams.getWidthInBlocks()/2, 0);
|
||||
DhSectionPos edgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, -treeParams.getWidthInBlocks() / 2, 0);
|
||||
testSet(tree, edgePos, 1);
|
||||
Assert.assertEquals("incorrect leaf node count", 1, tree.leafNodeCount());
|
||||
|
||||
// +1 root node from the negative X edge
|
||||
DhSectionPos adjacentEdgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (-treeParams.getWidthInBlocks()/2)+pseudoRootNodeWidthInBlocks, 0);
|
||||
DhSectionPos adjacentEdgePos = new DhSectionPos(LodUtil.BLOCK_DETAIL_LEVEL, (-treeParams.getWidthInBlocks() / 2) + pseudoRootNodeWidthInBlocks, 0);
|
||||
testSet(tree, adjacentEdgePos, 2);
|
||||
Assert.assertEquals("incorrect leaf node count", 2, tree.leafNodeCount());
|
||||
|
||||
// move so only the root nodes exactly on the X edge remain
|
||||
DhBlockPos2D edgeMoveBlockPos = new DhBlockPos2D(pseudoRootNodeWidthInBlocks - (treeParams.getWidthInRootNodes()*pseudoRootNodeWidthInBlocks), 0);
|
||||
DhBlockPos2D edgeMoveBlockPos = new DhBlockPos2D(pseudoRootNodeWidthInBlocks - (treeParams.getWidthInRootNodes() * pseudoRootNodeWidthInBlocks), 0);
|
||||
tree.setCenterBlockPos(edgeMoveBlockPos);
|
||||
Assert.assertEquals("Tree center incorrect", edgeMoveBlockPos, tree.getCenterBlockPos());
|
||||
Assert.assertEquals("incorrect leaf node count", 2, tree.leafNodeCount());
|
||||
@@ -284,14 +284,14 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
// (pseudo) root nodes //
|
||||
testSet(tree, new DhSectionPos((byte)10, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte)10, 1, 0), 2);
|
||||
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 10, 1, 0), 2);
|
||||
|
||||
// first child (0,0) //
|
||||
testSet(tree, new DhSectionPos((byte)9, 0, 0), 3);
|
||||
testSet(tree, new DhSectionPos((byte)9, 1, 0), 4);
|
||||
testSet(tree, new DhSectionPos((byte)9, 0, 1), 5);
|
||||
testSet(tree, new DhSectionPos((byte)9, 1, 1), 6);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 3);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 1, 0), 4);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 0, 1), 5);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 1, 1), 6);
|
||||
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ public class QuadTreeTest
|
||||
QuadNode<Integer> rootNode = tree.getNode(rootNodePosIterator.next());
|
||||
if (rootNode != null)
|
||||
{
|
||||
rootNodeCount++;
|
||||
rootNodeCount++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals("incorrect root count", 1, rootNodeCount);
|
||||
@@ -332,19 +332,19 @@ public class QuadTreeTest
|
||||
public void NewQuadTreeIterationTest()
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new LargeTestTree();
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte)10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
|
||||
rootNode.setValue(new DhSectionPos((byte)10, 0, 0), 0);
|
||||
rootNode.setValue(new DhSectionPos((byte) 10, 0, 0), 0);
|
||||
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 0, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 1, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 0, 1), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 1, 1), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 0, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 1, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 0, 1), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 1, 1), null);
|
||||
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 1), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 1), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), null);
|
||||
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ public class QuadTreeTest
|
||||
|
||||
if (!iteratedNodes.add(node))
|
||||
{
|
||||
Assert.fail("Iterator passed over the same node multiple times. Section Pos: "+node.sectionPos);
|
||||
Assert.fail("Iterator passed over the same node multiple times. Section Pos: " + node.sectionPos);
|
||||
}
|
||||
|
||||
totalNodeCount++;
|
||||
@@ -395,7 +395,7 @@ public class QuadTreeTest
|
||||
|
||||
if (!iteratedLeafNodes.add(node))
|
||||
{
|
||||
Assert.fail("Iterator passed over the same node multiple times. Section Pos: "+node.sectionPos);
|
||||
Assert.fail("Iterator passed over the same node multiple times. Section Pos: " + node.sectionPos);
|
||||
}
|
||||
|
||||
totalLeafCount++;
|
||||
@@ -561,21 +561,21 @@ public class QuadTreeTest
|
||||
public void TreeDetailLevelLimitTest()
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new MediumTestTree();
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte)8);
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte) 8);
|
||||
Assert.assertEquals("Test detail level's need to be adjusted. This isn't necessarily a failed test.", 10, tree.treeMaxDetailLevel);
|
||||
|
||||
// valid detail levels
|
||||
testSet(tree, new DhSectionPos((byte)10, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte)9, 0, 0), 2);
|
||||
testSet(tree, new DhSectionPos((byte)8, 0, 0), 3);
|
||||
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 9, 0, 0), 2);
|
||||
testSet(tree, new DhSectionPos((byte) 8, 0, 0), 3);
|
||||
|
||||
// detail level too low
|
||||
testSet(tree, new DhSectionPos((byte)7, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte)6, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte) 7, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte) 6, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
|
||||
// detail level too high
|
||||
testSet(tree, new DhSectionPos((byte)11, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte)12, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte) 11, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
testSet(tree, new DhSectionPos((byte) 12, 0, 0), -1, IndexOutOfBoundsException.class);
|
||||
|
||||
}
|
||||
|
||||
@@ -583,12 +583,12 @@ public class QuadTreeTest
|
||||
public void QuadNodeDetailLimitTest()
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new MediumTestTree();
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte)6);
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte) 6);
|
||||
Assert.assertEquals("Test detail level's need to be adjusted. This isn't necessarily a failed test.", 10, tree.treeMaxDetailLevel);
|
||||
|
||||
|
||||
// create the root node
|
||||
testSet(tree, new DhSectionPos((byte)10, 0, 0), 1);
|
||||
|
||||
testSet(tree, new DhSectionPos((byte) 10, 0, 0), 1);
|
||||
|
||||
|
||||
|
||||
AtomicInteger minimumDetailLevelReachedRef = new AtomicInteger(tree.treeMaxDetailLevel);
|
||||
@@ -649,7 +649,7 @@ public class QuadTreeTest
|
||||
DhSectionPos sectionPos = directChildIterator.next();
|
||||
QuadNode<Integer> childNode = node.getNode(sectionPos);
|
||||
|
||||
Assert.assertTrue("Child node recurred too low. Min detail level: "+minDetailLevel+", node detail level: "+childNode.sectionPos.sectionDetailLevel, childNode.sectionPos.sectionDetailLevel >= minDetailLevel);
|
||||
Assert.assertTrue("Child node recurred too low. Min detail level: " + minDetailLevel + ", node detail level: " + childNode.sectionPos.sectionDetailLevel, childNode.sectionPos.sectionDetailLevel >= minDetailLevel);
|
||||
recursivelyCreateNodeChildren(childNode, minDetailLevel, minimumDetailLevelReachedRef);
|
||||
|
||||
childNodesIterated = true;
|
||||
@@ -671,14 +671,14 @@ public class QuadTreeTest
|
||||
}
|
||||
if (childNodesIterated)
|
||||
{
|
||||
Assert.assertTrue("node children iterated below minimum detail level", node.sectionPos.sectionDetailLevel-1 >= minDetailLevel);
|
||||
Assert.assertTrue("node children iterated below minimum detail level", node.sectionPos.sectionDetailLevel - 1 >= minDetailLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quadNodeChildPositionIndexTest()
|
||||
{
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte)10, 0, 0), (byte)0);
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), (byte) 0);
|
||||
Iterator<DhSectionPos> directChildPosIterator = rootNode.getChildPosIterator();
|
||||
while (directChildPosIterator.hasNext())
|
||||
{
|
||||
@@ -694,7 +694,7 @@ public class QuadTreeTest
|
||||
{
|
||||
DhSectionPos childPos = rootNode.sectionPos.getChildByIndex(i);
|
||||
QuadNode<Integer> childNode = rootNode.getChildByIndex(i);
|
||||
Assert.assertEquals("child position not the same as "+DhSectionPos.class.getSimpleName()+"'s getChildByIndex()", childPos, childNode.sectionPos);
|
||||
Assert.assertEquals("child position not the same as " + DhSectionPos.class.getSimpleName() + "'s getChildByIndex()", childPos, childNode.sectionPos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -703,12 +703,12 @@ public class QuadTreeTest
|
||||
public void quadNodeChildPositionOutOfBoundsTest()
|
||||
{
|
||||
int treeWidthInBlocks = 64;
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeWidthInBlocks, new DhBlockPos2D(-2, 0), (byte)0);
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeWidthInBlocks, new DhBlockPos2D(-2, 0), (byte) 0);
|
||||
|
||||
|
||||
|
||||
// center root node
|
||||
DhSectionPos centerNodePos = new DhSectionPos((byte)1, 0, 0);
|
||||
DhSectionPos centerNodePos = new DhSectionPos((byte) 1, 0, 0);
|
||||
|
||||
// create node
|
||||
tree.setValue(centerNodePos, 0);
|
||||
@@ -727,7 +727,7 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
// edge root node
|
||||
DhSectionPos offsetNodePos = new DhSectionPos((byte)1, -17, -16);
|
||||
DhSectionPos offsetNodePos = new DhSectionPos((byte) 1, -17, -16);
|
||||
|
||||
// create node
|
||||
tree.setValue(offsetNodePos, 0);
|
||||
@@ -751,7 +751,7 @@ public class QuadTreeTest
|
||||
public void toStringTest()
|
||||
{
|
||||
AbstractTestTreeParams treeParams = new MediumTestTree();
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte)6);
|
||||
QuadTree<Integer> tree = new QuadTree<>(treeParams.getWidthInBlocks(), new DhBlockPos2D(0, 0), (byte) 6);
|
||||
|
||||
String treeString = tree.toString();
|
||||
Assert.assertNotNull(treeString);
|
||||
@@ -772,9 +772,9 @@ public class QuadTreeTest
|
||||
|
||||
|
||||
//
|
||||
testSet(tree, new DhSectionPos((byte)0, 0, 0), 1);
|
||||
testSet(tree, new DhSectionPos((byte) 0, 0, 0), 1);
|
||||
Assert.assertEquals(1, tree.count());
|
||||
tree.setCenterBlockPos(new DhBlockPos2D(treeWidth + (treeWidth/2), 0));
|
||||
tree.setCenterBlockPos(new DhBlockPos2D(treeWidth + (treeWidth / 2), 0));
|
||||
Assert.assertEquals(0, tree.count());
|
||||
|
||||
}
|
||||
@@ -783,21 +783,21 @@ public class QuadTreeTest
|
||||
//@Test
|
||||
public void autoDeleteNullQuadNodeChildTest()
|
||||
{
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte)10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
QuadNode<Integer> rootNode = new QuadNode<>(new DhSectionPos((byte) 10, 0, 0), LodUtil.BLOCK_DETAIL_LEVEL);
|
||||
|
||||
|
||||
rootNode.setValue(new DhSectionPos((byte)10, 0, 0), 0);
|
||||
rootNode.setValue(new DhSectionPos((byte) 10, 0, 0), 0);
|
||||
|
||||
DhSectionPos midNodePos = new DhSectionPos((byte)9, 0, 0);
|
||||
DhSectionPos midNodePos = new DhSectionPos((byte) 9, 0, 0);
|
||||
//rootNode.setValue(midNodePos, null); // holds detail 8
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 1, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 0, 1), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte)9, 1, 1), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 1, 0), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 0, 1), 1);
|
||||
rootNode.setValue(new DhSectionPos((byte) 9, 1, 1), 1);
|
||||
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 1), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 1), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), 2);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), 2);
|
||||
|
||||
|
||||
|
||||
@@ -810,12 +810,12 @@ public class QuadTreeTest
|
||||
// test removing nodes //
|
||||
|
||||
// remove two leaf nodes from the root
|
||||
DhSectionPos leafPos = new DhSectionPos((byte)9, 1, 1);
|
||||
DhSectionPos leafPos = new DhSectionPos((byte) 9, 1, 1);
|
||||
rootNode.setValue(leafPos, null);
|
||||
Assert.assertEquals(3, rootNode.getNonNullChildCount());
|
||||
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
|
||||
|
||||
leafPos = new DhSectionPos((byte)9, 0, 1);
|
||||
leafPos = new DhSectionPos((byte) 9, 0, 1);
|
||||
rootNode.setValue(leafPos, null);
|
||||
Assert.assertEquals(2, rootNode.getNonNullChildCount());
|
||||
Assert.assertNull("Node wasn't deleted", rootNode.getNode(leafPos));
|
||||
@@ -827,13 +827,13 @@ public class QuadTreeTest
|
||||
Assert.assertEquals(4, rootNode.getNode(midNodePos).getNonNullChildCount());
|
||||
|
||||
// remove all but one, mid-node should still be present
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 0), null);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 0, 1), null);
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 0), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 0), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 0, 1), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 0), null);
|
||||
Assert.assertEquals(1, rootNode.getNode(midNodePos).getNonNullChildCount());
|
||||
|
||||
// remove last mid-node child, mid-node should now be removed
|
||||
rootNode.setValue(new DhSectionPos((byte)8, 1, 1), null);
|
||||
rootNode.setValue(new DhSectionPos((byte) 8, 1, 1), null);
|
||||
Assert.assertNull("Mid node not deleted.", rootNode.getNode(midNodePos));
|
||||
Assert.assertEquals(3, rootNode.getNonNullChildCount());
|
||||
|
||||
@@ -860,7 +860,7 @@ public class QuadTreeTest
|
||||
if (expectedExceptionClass == null || e.getClass() != expectedExceptionClass)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Assert.fail("set failed "+pos+" with exception "+e.getClass()+", expected exception: "+expectedExceptionClass+". error: "+e.getMessage());
|
||||
Assert.fail("set failed " + pos + " with exception " + e.getClass() + ", expected exception: " + expectedExceptionClass + ". error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -875,14 +875,14 @@ public class QuadTreeTest
|
||||
try
|
||||
{
|
||||
Integer getResult = tree.getValue(pos);
|
||||
Assert.assertEquals("get failed "+pos, getValue, getResult);
|
||||
Assert.assertEquals("get failed " + pos, getValue, getResult);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (expectedExceptionClass == null || e.getClass() != expectedExceptionClass)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Assert.fail("get failed "+pos+" with exception "+e.getClass()+", expected exception: "+expectedExceptionClass+". error: "+e.getMessage());
|
||||
Assert.fail("get failed " + pos + " with exception " + e.getClass() + ", expected exception: " + expectedExceptionClass + ". error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -901,23 +901,27 @@ public class QuadTreeTest
|
||||
public int getWidthInRootNodes() { return MathUtil.log2(this.getWidthInBlocks()) + 2; }
|
||||
public byte getMaxDetailLevel() { return (byte) MathUtil.log2(this.getWidthInBlocks()); }
|
||||
/** @return the block pos so that the tree's negative corner lines up with (0,0) */
|
||||
public DhBlockPos2D getPositiveEdgeCenterPos() { return new DhBlockPos2D(BitShiftUtil.powerOfTwo(this.getMaxDetailLevel())/2, BitShiftUtil.powerOfTwo(this.getMaxDetailLevel())/2); }
|
||||
public DhBlockPos2D getPositiveEdgeCenterPos() { return new DhBlockPos2D(BitShiftUtil.powerOfTwo(this.getMaxDetailLevel()) / 2, BitShiftUtil.powerOfTwo(this.getMaxDetailLevel()) / 2); }
|
||||
|
||||
}
|
||||
|
||||
private static class LargeTestTree extends AbstractTestTreeParams
|
||||
{
|
||||
public int getWidthInBlocks() { return 8192; }
|
||||
|
||||
}
|
||||
|
||||
private static class MediumTestTree extends AbstractTestTreeParams
|
||||
{
|
||||
public int getWidthInBlocks() { return 1024; }
|
||||
|
||||
}
|
||||
|
||||
private static class TinyTestTree extends AbstractTestTreeParams
|
||||
{
|
||||
// top detail level = 6
|
||||
public int getWidthInBlocks() { return 32; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,21 +46,21 @@ public class RaycastingTest
|
||||
|
||||
// ray origin left of square
|
||||
double rayX = 0;
|
||||
testRay(false, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
// ray origin right of square
|
||||
rayX = 2.5;
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray points left - direction <-1,0>
|
||||
@@ -69,21 +69,21 @@ public class RaycastingTest
|
||||
|
||||
// ray origin left of square
|
||||
rayX = 0;
|
||||
testRay(false, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
// ray origin right of square
|
||||
rayX = 2.5;
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
}
|
||||
|
||||
@@ -105,28 +105,28 @@ public class RaycastingTest
|
||||
double rayY = 0;
|
||||
|
||||
// ray origin below square
|
||||
testRay(false, 0, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, 2.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin in square
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin above square
|
||||
rayY = 2.5;
|
||||
testRay(false, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
|
||||
@@ -138,28 +138,28 @@ public class RaycastingTest
|
||||
rayY = 0;
|
||||
|
||||
// ray origin below square
|
||||
testRay(false, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin in square
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin above square
|
||||
rayY = 2.5;
|
||||
testRay(false, 0, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, 2.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2.5, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
}
|
||||
|
||||
@@ -177,15 +177,15 @@ public class RaycastingTest
|
||||
// direction <0,0>
|
||||
double xDir = 0;
|
||||
double yDir = 0;
|
||||
testRay(false, 0, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 0.5, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, 2.5, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 2.5, 2.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, 3, 3, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
}
|
||||
|
||||
@@ -205,30 +205,30 @@ public class RaycastingTest
|
||||
|
||||
// ray origin bottom left of square
|
||||
double rayX = 0;
|
||||
testRay(false, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin in square
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, 1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, 2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin right of square
|
||||
rayX = 2.5;
|
||||
double rayY = (yDir/xDir) * rayX; // y = mx + b // where b is the constants defined below
|
||||
testRay(false, rayX, -0.5 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
double rayY = (yDir / xDir) * rayX; // y = mx + b // where b is the constants defined below
|
||||
testRay(false, rayX, -0.5 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 0.5 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1 + rayY, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
|
||||
@@ -242,21 +242,21 @@ public class RaycastingTest
|
||||
|
||||
// ray origin bottom left of square
|
||||
rayX = 0;
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin in square
|
||||
testRay(true, 1, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 1.5, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, 2, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
|
||||
@@ -271,21 +271,21 @@ public class RaycastingTest
|
||||
|
||||
// ray origin bottom left of square
|
||||
rayX = 0;
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, 1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, 0, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -0.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, rayX, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
testRay(false, rayX, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(false, rayX, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
// ray origin in square
|
||||
testRay(true, -1, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, -1.5, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, -2, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, -1, -1, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, -1.5, -1.5, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
testRay(true, -2, -2, xDir, yDir, squareMinX, squareMinY, squareWidth);
|
||||
|
||||
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public class RaycastingTest
|
||||
|
||||
private static String failMessage(double rayX, double rayY, double xDir, double yDir, double squareMinX, double squareMinY, double squareWidth)
|
||||
{
|
||||
return "ray: [" + rayX + ", " + rayY + "] <" + xDir + ", " + yDir + "> square: [" + squareMinX + ", " + squareMinY + "] - [" + (squareMinX+squareWidth) + ", " + (squareMinY+squareWidth) + "]";
|
||||
return "ray: [" + rayX + ", " + rayY + "] <" + xDir + ", " + yDir + "> square: [" + squareMinX + ", " + squareMinY + "] - [" + (squareMinX + squareWidth) + ", " + (squareMinY + squareWidth) + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,24 +75,24 @@ public class SquareIntersectTest
|
||||
@Test
|
||||
public void TestNonOverlappingSquares()
|
||||
{
|
||||
DhLodPos rect1Min = new DhLodPos((byte)0, 1, 1);
|
||||
DhLodPos rect1Min = new DhLodPos((byte) 0, 1, 1);
|
||||
int rect1Width = 2;
|
||||
|
||||
DhLodPos rect2Min = new DhLodPos((byte)0, 4, 4);
|
||||
DhLodPos rect2Min = new DhLodPos((byte) 0, 4, 4);
|
||||
int rect2Width = 2;
|
||||
|
||||
boolean result = DoSquaresOverlap(rect1Min, rect1Width, rect2Min, rect2Width);
|
||||
Assert.assertFalse(result);
|
||||
}
|
||||
|
||||
|
||||
// The third test case checks that two rectangles with different sizes and overlapping are detected as overlapping.
|
||||
@Test
|
||||
public void TestSquaresWithDifferentSizes()
|
||||
{
|
||||
DhLodPos rect1Min = new DhLodPos((byte)0, 1, 1);
|
||||
DhLodPos rect1Min = new DhLodPos((byte) 0, 1, 1);
|
||||
int rect1Width = 4;
|
||||
|
||||
DhLodPos rect2Min = new DhLodPos((byte)0, 3, 3);
|
||||
DhLodPos rect2Min = new DhLodPos((byte) 0, 3, 3);
|
||||
int rect2Width = 3;
|
||||
|
||||
boolean result = DoSquaresOverlap(rect1Min, rect1Width, rect2Min, rect2Width);
|
||||
@@ -103,10 +103,10 @@ public class SquareIntersectTest
|
||||
@Test
|
||||
public void TestOneRectangleContainsTheOther()
|
||||
{
|
||||
DhLodPos rect1Min = new DhLodPos((byte)0, 1, 1);
|
||||
DhLodPos rect1Min = new DhLodPos((byte) 0, 1, 1);
|
||||
int rect1Width = 9;
|
||||
|
||||
DhLodPos rect2Min = new DhLodPos((byte)0, 3, 3);
|
||||
DhLodPos rect2Min = new DhLodPos((byte) 0, 3, 3);
|
||||
int rect2Width = 3;
|
||||
|
||||
boolean result = DoSquaresOverlap(rect1Min, rect1Width, rect2Min, rect2Width);
|
||||
@@ -117,10 +117,10 @@ public class SquareIntersectTest
|
||||
@Test
|
||||
public void TestOneRectangleContainsTheOtherInverted()
|
||||
{
|
||||
DhLodPos rect1Min = new DhLodPos((byte)0, 3, 3);
|
||||
DhLodPos rect1Min = new DhLodPos((byte) 0, 3, 3);
|
||||
int rect1Width = 3;
|
||||
|
||||
DhLodPos rect2Min = new DhLodPos((byte)0, 1, 1);
|
||||
DhLodPos rect2Min = new DhLodPos((byte) 0, 1, 1);
|
||||
int rect2Width = 9;
|
||||
|
||||
boolean result = DoSquaresOverlap(rect1Min, rect1Width, rect2Min, rect2Width);
|
||||
|
||||
Reference in New Issue
Block a user