use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.
the class ShapePatternsTester method testSphereEquality.
/**
* Ensure that (for the same implicit size sphere) SPHERE, SPHERE_HALF, SPHERE_QUARTER, and SPHERE_EIGHTH all
* generate the same sphere.
*
* @param size an eighth of the size of the entire sphere.
*/
@Theory
public void testSphereEquality(BlockPos size) {
BlockPos fullSize = new BlockPos(size.getX() * 2, size.getY() * 2, size.getZ() * 2);
System.out.println("Testing spheres for equality in " + StringUtilBC.blockPosToString(fullSize));
IStatementParameter[] fullParams = new IStatementParameter[] { //
PatternParameterHollow.HOLLOW };
IFilledTemplate filledTemplateFull = createFilledTemplate(fullSize);
Assert.assertTrue(BCBuildersStatements.PATTERN_SPHERE.fillTemplate(filledTemplateFull, fullParams));
System.out.println("Full:\n" + filledTemplateFull);
// Test halfs
for (EnumFacing face : EnumFacing.VALUES) {
BlockPos halfSize = VecUtil.replaceValue(fullSize, face.getAxis(), VecUtil.getValue(size, face.getAxis()));
IStatementParameter[] params = new IStatementParameter[] { //
PatternParameterHollow.HOLLOW, //
PatternParameterFacing.get(face) };
IFilledTemplate filledTemplateHalf = createFilledTemplate(halfSize);
Assert.assertTrue(BCBuildersStatements.PATTERN_HEMI_SPHERE.fillTemplate(filledTemplateHalf, params));
System.out.println("Half:\n" + filledTemplateHalf);
int dx = face == EnumFacing.WEST ? filledTemplateHalf.getSize().getX() : 0;
int dy = face == EnumFacing.DOWN ? filledTemplateHalf.getSize().getY() : 0;
int dz = face == EnumFacing.NORTH ? filledTemplateHalf.getSize().getZ() : 0;
for (int z = 0; z <= filledTemplateHalf.getMax().getZ(); z++) {
for (int y = 0; y <= filledTemplateHalf.getMax().getY(); y++) {
for (int x = 0; x <= filledTemplateHalf.getMax().getX(); x++) {
if (filledTemplateFull.get(x + dx, y + dy, z + dz) != filledTemplateHalf.get(x, y, z)) {
Assert.fail(String.format("Half sphere[%s] didn't match full sphere at (%s, %s, %s)", face, x, y, z));
}
}
}
}
}
// TODO: Test quarters
}
use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.
the class ShapePatternsTester method testTinyTemplate.
@Theory
public void testTinyTemplate(IFillerPatternShape pattern, BlockPos size) {
System.out.print("Testing pattern " + pattern.getUniqueTag() + " in " + StringUtilBC.blockPosToString(size));
try {
IStatementParameter[] params = new IStatementParameter[pattern.maxParameters()];
for (int i = 0; i < params.length; i++) {
params[i] = pattern.createParameter(i);
}
IFilledTemplate filledTemplate = createFilledTemplate(size);
boolean b = pattern.fillTemplate(filledTemplate, params);
if (pattern == BCBuildersStatements.PATTERN_NONE) {
Assert.assertFalse(b);
} else {
Assert.assertTrue(b);
}
System.out.println(" -> success");
} catch (Throwable t) {
System.out.println(" -> fail");
throw t;
}
}
use of buildcraft.api.filler.IFilledTemplate in project BuildCraft by BuildCraft.
the class ShapePatternsTester method createFilledTemplate.
private IFilledTemplate createFilledTemplate(BlockPos size) {
Template template = new Template();
template.size = size;
template.offset = BlockPos.ORIGIN;
template.data = new BitSet(Snapshot.getDataSize(size));
return template.getFilledTemplate();
}
Aggregations