Add validation to FullDataArray and SingleColumnData

This commit is contained in:
James Seibel
2023-06-17 21:00:35 -05:00
parent b7ca6dbd87
commit 122e24ad6d
2 changed files with 17 additions and 1 deletions
@@ -143,7 +143,20 @@ public class FullDataArrayAccessor implements IFullDataAccessor
@Override
public SingleColumnFullDataAccessor get(int index) { return this.get(index / this.width, index % this.width); }
@Override
public SingleColumnFullDataAccessor get(int relativeX, int relativeZ) { return new SingleColumnFullDataAccessor(this.mapping, this.dataArrays, relativeX * this.width + relativeZ + this.offset); }
public SingleColumnFullDataAccessor get(int relativeX, int relativeZ)
{
int dataArrayIndex = (relativeX * this.width) + relativeZ + this.offset;
if (dataArrayIndex >= this.dataArrays.length)
{
LodUtil.assertNotReach(
"FullDataArrayAccessor.get() called with a relative position that is outside the data source. \n" +
"source width: ["+this.width+"] source offset: ["+this.offset+"]\n" +
"given relative pos X: ["+relativeX+"] Z: ["+relativeZ+"]\n" +
"dataArrays.length: ["+this.dataArrays.length+"] dataArrayIndex: ["+dataArrayIndex+"].");
}
return new SingleColumnFullDataAccessor(this.mapping, this.dataArrays, dataArrayIndex);
}
@Override
public int width() { return this.width; }
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.dataObjects.fullData.accessor;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
/**
* Represents a single column of Full LOD data.
@@ -27,6 +28,8 @@ public class SingleColumnFullDataAccessor implements IFullDataAccessor
this.dataArrays = dataArrays;
this.dataArrayIndex = dataArrayIndex;
this.mapping = mapping;
LodUtil.assertTrue(this.dataArrayIndex < this.dataArrays.length, "dataArrays.length ["+this.dataArrays.length+"] is less than the dataArrayIndex ["+this.dataArrayIndex+"].");
}