From aa63f886ec1589c8088c8569374e8f4fb50090c2 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 17 Oct 2010 15:17:24 -0700 Subject: [PATCH] Fixed floating point inaccuracy error with getBlock#(), fixed //rotate. --- src/CuboidClipboard.java | 26 ++++++++++++++------------ src/com/sk89q/worldedit/Vector.java | 6 +++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/CuboidClipboard.java b/src/CuboidClipboard.java index 019c10973..48c94251e 100644 --- a/src/CuboidClipboard.java +++ b/src/CuboidClipboard.java @@ -118,20 +118,20 @@ public class CuboidClipboard { int width = getWidth(); int length = getLength(); int height = getHeight(); - int newWidth = angle % 180 == 0 ? width : length; - int newLength = angle % 180 == 0 ? length : width; Vector sizeRotated = size.transform2D(angle, 0, 0, 0, 0); - int shiftX = sizeRotated.getX() < 0 ? newWidth - 1 : 0; - int shiftZ = sizeRotated.getZ() < 0 ? newLength - 1: 0; + int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0; + int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0; - BaseBlock newData[][][] = new BaseBlock[newWidth][getHeight()][newLength]; + BaseBlock newData[][][] = new BaseBlock + [Math.abs(sizeRotated.getBlockX())] + [Math.abs(sizeRotated.getBlockY())] + [Math.abs(sizeRotated.getBlockZ())]; for (int x = 0; x < width; x++) { for (int z = 0; z < length; z++) { - int newX = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0) - .getBlockX(); - int newZ = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0) - .getBlockZ(); + Vector v = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0); + int newX = v.getBlockX(); + int newZ = v.getBlockZ(); for (int y = 0; y < height; y++) { newData[shiftX + newX][y][shiftZ + newZ] = data[x][y][z]; } @@ -139,9 +139,11 @@ public class CuboidClipboard { } data = newData; - size = new Vector(newWidth, getHeight(), newLength); + size = new Vector(Math.abs(sizeRotated.getBlockX()), + Math.abs(sizeRotated.getBlockY()), + Math.abs(sizeRotated.getBlockZ())); offset = offset.transform2D(angle, 0, 0, 0, 0) - .subtract(shiftX, 0, shiftZ); + .subtract(shiftX, 0, shiftZ);; } /** @@ -188,7 +190,7 @@ public class CuboidClipboard { for (int z = 0; z < size.getBlockZ(); z++) { if (noAir && data[x][y][z].isAir()) continue; - + editSession.setBlock(new Vector(x, y, z).add(pos), data[x][y][z]); } diff --git a/src/com/sk89q/worldedit/Vector.java b/src/com/sk89q/worldedit/Vector.java index ba59bca57..1a92b1a43 100644 --- a/src/com/sk89q/worldedit/Vector.java +++ b/src/com/sk89q/worldedit/Vector.java @@ -96,7 +96,7 @@ public class Vector { * @return the x */ public int getBlockX() { - return (int)x; + return (int)Math.round(x); } /** @@ -110,7 +110,7 @@ public class Vector { * @return the y */ public int getBlockY() { - return (int)y; + return (int)Math.round(y); } /** @@ -124,7 +124,7 @@ public class Vector { * @return the z */ public int getBlockZ() { - return (int)z; + return (int)Math.round(z); } /**