diff --git a/paper-api/src/main/java/org/bukkit/util/BoundingBox.java b/paper-api/src/main/java/org/bukkit/util/BoundingBox.java index e5c7826afe..01f80020b1 100644 --- a/paper-api/src/main/java/org/bukkit/util/BoundingBox.java +++ b/paper-api/src/main/java/org/bukkit/util/BoundingBox.java @@ -844,12 +844,14 @@ public class BoundingBox implements Cloneable, ConfigurationSerializable { double startZ = start.getZ(); // ray direction: - Vector dir = direction.clone().normalize(); + Vector dir = direction.clone().normalizeZeros().normalize(); double dirX = dir.getX(); double dirY = dir.getY(); double dirZ = dir.getZ(); // saving a few divisions below: + // Note: If one of the direction vector components is 0.0, these + // divisions result in infinity. But this is not a problem. double divX = 1.0D / dirX; double divY = 1.0D / dirY; double divZ = 1.0D / dirZ; diff --git a/paper-api/src/main/java/org/bukkit/util/Vector.java b/paper-api/src/main/java/org/bukkit/util/Vector.java index 143579bb30..bdfb9623b7 100644 --- a/paper-api/src/main/java/org/bukkit/util/Vector.java +++ b/paper-api/src/main/java/org/bukkit/util/Vector.java @@ -365,6 +365,19 @@ public class Vector implements Cloneable, ConfigurationSerializable { return this; } + /** + * Converts each component of value -0.0 to 0.0. + * + * @return This vector. + */ + @NotNull + Vector normalizeZeros() { + if (x == -0.0D) x = 0.0D; + if (y == -0.0D) y = 0.0D; + if (z == -0.0D) z = 0.0D; + return this; + } + /** * Returns whether this vector is in an axis-aligned bounding box. *