mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-08 08:21:50 +01:00
Misc fix + more tests (#1511)
This commit is contained in:
parent
88dd901438
commit
d496fcfe4a
@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* This class performs ray tracing and iterates along blocks on a line
|
||||
@ -43,6 +44,8 @@ public class BlockIterator implements Iterator<Point> {
|
||||
this.start = start.add(0, yOffset, 0);
|
||||
this.end = start.add(0, yOffset, 0).add(direction.normalize().mul(maxDistance)).apply(Vec.Operator.FLOOR);
|
||||
|
||||
if (this.direction.isZero()) this.foundEnd = true;
|
||||
|
||||
signums[0] = (short) Math.signum(direction.x());
|
||||
signums[1] = (short) Math.signum(direction.y());
|
||||
signums[2] = (short) Math.signum(direction.z());
|
||||
@ -152,6 +155,8 @@ public class BlockIterator implements Iterator<Point> {
|
||||
|
||||
@Override
|
||||
public Point next() {
|
||||
if (foundEnd) throw new NoSuchElementException();
|
||||
|
||||
// If we have entries in the extra points queue, return those first
|
||||
var res = extraPoints.isEmpty() ? updateClosest() : extraPoints.poll();
|
||||
// If we have reached the end, set the flag
|
||||
|
@ -74,6 +74,33 @@ public class BlockIteratorTest {
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroVelocity() {
|
||||
Vec s = new Vec(0, 0, 0);
|
||||
Vec e = new Vec(0, 0, 0);
|
||||
BlockIterator iterator = new BlockIterator(s, e, 0, 4);
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExactEnd() {
|
||||
Vec s = new Vec(0.5, 0, 0.5);
|
||||
Vec e = new Vec(0, 1, 0);
|
||||
BlockIterator iterator = new BlockIterator(s, e, 0, 1);
|
||||
assertEquals(new Vec(0, 0, 0), iterator.next());
|
||||
assertEquals(new Vec(0, 1, 0), iterator.next());
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameEnd() {
|
||||
Vec s = new Vec(0.5, 0, 0.5);
|
||||
Vec e = new Vec(0, 1, 0);
|
||||
BlockIterator iterator = new BlockIterator(s, e, 0, 0.5);
|
||||
assertEquals(new Vec(0, 0, 0), iterator.next());
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3dExtraCollection() {
|
||||
Vec s = new Vec(0.1, 0.1, 0.1);
|
||||
|
Loading…
Reference in New Issue
Block a user