mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
#809: Throw a more clear error for BlockIterators with zero direction, add Vector#isZero()
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
parent
e17edb7785
commit
d6d7c1a64f
3 changed files with 25 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.bukkit.util;
|
||||
|
||||
import static org.bukkit.util.NumberConversions.*;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.bukkit.Location;
|
||||
|
@ -53,6 +54,11 @@ public class BlockIterator implements Iterator<Block> {
|
|||
*
|
||||
*/
|
||||
public BlockIterator(@NotNull World world, @NotNull Vector start, @NotNull Vector direction, double yOffset, int maxDistance) {
|
||||
Preconditions.checkArgument(world != null, "world must not be null");
|
||||
Preconditions.checkArgument(start != null, "start must not be null");
|
||||
Preconditions.checkArgument(direction != null, "direction must not be null");
|
||||
Preconditions.checkArgument(!direction.isZero(), "direction must have at least one non-zero component");
|
||||
|
||||
this.world = world;
|
||||
this.maxDistance = maxDistance;
|
||||
|
||||
|
|
|
@ -365,6 +365,15 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not each component of this vector is equal to 0.
|
||||
*
|
||||
* @return true if equal to zero, false if at least one component is non-zero
|
||||
*/
|
||||
public boolean isZero() {
|
||||
return x == 0 && y == 0 && z == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts each component of value <code>-0.0</code> to <code>0.0</code>.
|
||||
*
|
||||
|
|
|
@ -122,4 +122,14 @@ public class VectorTest {
|
|||
|
||||
assertTrue(Double.isFinite(a.angle(b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsZero() {
|
||||
assertTrue(new Vector().isZero());
|
||||
assertTrue(new Vector(0, 0, 0).isZero());
|
||||
|
||||
Vector vector = new Vector(1, 2, 3);
|
||||
vector.zero();
|
||||
assertTrue(vector.isZero());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue