Correct rounding bevhaviour for Vector3 -> BlockVector3

- fixes #512
Dieser Commit ist enthalten in:
dordsor21 2021-01-10 20:49:38 +00:00
Ursprung 0b727d9760
Commit ae6a1f1be4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
3 geänderte Dateien mit 13 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,7 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.brush.visualization.VisualExtent;
import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.mask.IdMask;
import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; import com.boydti.fawe.object.visitor.DFSRecursiveVisitor;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.tool.brush.Brush; 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.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MathUtils;
import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.interpolation.Node; import com.sk89q.worldedit.math.interpolation.Node;
@ -195,15 +197,15 @@ public class SplineBrush implements Brush, ResettableTool {
if (det_max == det_x) { if (det_max == det_x) {
double a = (xz * yz - xy * zz) / det_x; double a = (xz * yz - xy * zz) / det_x;
double b = (xy * yz - xz * yy) / 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) { } else if (det_max == det_y) {
double a = (yz * xz - xy * zz) / det_y; double a = (yz * xz - xy * zz) / det_y;
double b = (xy * xz - yz * xx) / 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 { } else {
double a = (yz * xy - xz * yy) / det_z; double a = (yz * xy - xz * yy) / det_z;
double b = (xz * xy - yz * xx) / 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(); return dir.normalize();
} }

Datei anzeigen

@ -84,15 +84,15 @@ public abstract class Vector3 {
} }
public int getBlockX() { public int getBlockX() {
return MathMan.roundInt(getX()); return (int) MathUtils.roundHalfUp(getX());
} }
public int getBlockY() { public int getBlockY() {
return MathMan.roundInt(getY()); return (int) MathUtils.roundHalfUp(getY());
} }
public int getBlockZ() { public int getBlockZ() {
return MathMan.roundInt(getZ()); return (int) MathUtils.roundHalfUp(getZ());
} }
public MutableVector3 setComponents(Vector3 other) { public MutableVector3 setComponents(Vector3 other) {
@ -595,7 +595,8 @@ public abstract class Vector3 {
* @return a new {@code BlockVector} * @return a new {@code BlockVector}
*/ */
public static BlockVector3 toBlockPoint(double x, double y, double z) { 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);
} }
/** /**

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util; package com.sk89q.worldedit.util;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
@ -79,7 +80,8 @@ public enum Direction {
} }
Direction(Vector3 vector, int flags, int left, int right) { 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.direction = vector.normalize();
this.flags = flags; this.flags = flags;
this.left = left; this.left = left;