From ae6a1f1be45994e726447b9faecb3818bbed4df5 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 10 Jan 2021 20:49:38 +0000 Subject: [PATCH] Correct rounding bevhaviour for Vector3 -> BlockVector3 - fixes #512 --- .../java/com/boydti/fawe/object/brush/SplineBrush.java | 8 +++++--- .../src/main/java/com/sk89q/worldedit/math/Vector3.java | 9 +++++---- .../main/java/com/sk89q/worldedit/util/Direction.java | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 8097f2104..8fd3fd55a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -4,6 +4,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; +import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; @@ -13,6 +14,7 @@ import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Node; @@ -195,15 +197,15 @@ public class SplineBrush implements Brush, ResettableTool { if (det_max == det_x) { double a = (xz * yz - xy * zz) / det_x; double b = (xy * yz - xz * yy) / det_x; - dir = BlockVector3.at(1.0, a, b); + dir = BlockVector3.at(1.0, (int) MathUtils.roundHalfUp(a), (int) MathUtils.roundHalfUp(b)); } else if (det_max == det_y) { double a = (yz * xz - xy * zz) / det_y; double b = (xy * xz - yz * xx) / det_y; - dir = BlockVector3.at(a, 1.0, b); + dir = BlockVector3.at((int) MathUtils.roundHalfUp(a), 1.0, (int) MathUtils.roundHalfUp(b)); } else { double a = (yz * xy - xz * yy) / det_z; double b = (xz * xy - yz * xx) / det_z; - dir = BlockVector3.at(a, b, 1.0); + dir = BlockVector3.at((int) MathUtils.roundHalfUp(a), (int) MathUtils.roundHalfUp(b), 1.0); } return dir.normalize(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java index 79469ae54..09f0387b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -84,15 +84,15 @@ public abstract class Vector3 { } public int getBlockX() { - return MathMan.roundInt(getX()); + return (int) MathUtils.roundHalfUp(getX()); } public int getBlockY() { - return MathMan.roundInt(getY()); + return (int) MathUtils.roundHalfUp(getY()); } public int getBlockZ() { - return MathMan.roundInt(getZ()); + return (int) MathUtils.roundHalfUp(getZ()); } public MutableVector3 setComponents(Vector3 other) { @@ -595,7 +595,8 @@ public abstract class Vector3 { * @return a new {@code BlockVector} */ public static BlockVector3 toBlockPoint(double x, double y, double z) { - return BlockVector3.at(x, y, z); + return BlockVector3.at(MathUtils.roundHalfUp(x), MathUtils.roundHalfUp(y), MathUtils.roundHalfUp(z)); + //return BlockVector3.at(x, y, z); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java index 35c259f31..05a29f2ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.util; +import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -79,7 +80,8 @@ public enum Direction { } Direction(Vector3 vector, int flags, int left, int right) { - this.blockPoint = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); + this.blockPoint = BlockVector3.at(MathMan.roundInt(Math.signum(vector.getX())), + MathMan.roundInt(Math.signum(vector.getY())), MathMan.roundInt(Math.signum(vector.getZ()))); this.direction = vector.normalize(); this.flags = flags; this.left = left;