Skip to content

Commit

Permalink
test: more tests for voxel shape
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed May 18, 2024
1 parent 8fbce4f commit 272b4d4
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.allaymc.api.math.voxelshape;

import org.allaymc.api.block.data.BlockFace;
import org.joml.Vector3f;
import org.joml.primitives.AABBf;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* Allay Project 2023/9/2
Expand Down Expand Up @@ -41,8 +41,39 @@ void testCauldronShape() {

assertFalse(vs.intersectsPoint(0.5f, 0.5f, 0.5f));
assertTrue(vs.intersectsPoint(0.5f, 0.5f, 0.05f));
assertFalse(vs.intersectsPoint(new Vector3f(0.5f, 0.5f, 0.5f)));
assertTrue(vs.intersectsPoint(new Vector3f(0.5f, 0.5f, 0.05f)));

var aabb = new AABBf(0.2f, 0.2f, 0.2f, 0.8f, 0.8f, 0.8f);
assertFalse(vs.intersectsAABB(aabb));
}

@Test
void testTranslate() {
var vs = VoxelShape
.builder()
.solid(0, 0, 0, 1, 1, 1)
.vacancy(0.1f, 0.1f, 0.1f, 0.9f, 0.9f, 0.9f)
.build();
validateTranslateResult(vs.translate(1, 1, 1));
validateTranslateResult(vs.translate(new Vector3f(1, 1, 1)));
}

void validateTranslateResult(VoxelShape vs) {
var solid = vs.getSolids().iterator().next();
assertEquals(1, solid.minX());
assertEquals(1, solid.minY());
assertEquals(1, solid.minZ());
assertEquals(2, solid.maxX());
assertEquals(2, solid.maxY());
assertEquals(2, solid.maxZ());
var vacancy = vs.getVacancies().iterator().next();
assertEquals(1.1f, vacancy.minX());
assertEquals(1.1f, vacancy.minY());
assertEquals(1.1f, vacancy.minZ());
assertEquals(1.9f, vacancy.maxX());
assertEquals(1.9f, vacancy.maxY());
assertEquals(1.9f, vacancy.maxZ());

}
}

0 comments on commit 272b4d4

Please sign in to comment.