Skip to content

Commit

Permalink
Fixed floating point inaccuracy error with getBlock#(), fixed //rotate.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Oct 17, 2010
1 parent 383a475 commit aa63f88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/CuboidClipboard.java
Expand Up @@ -118,30 +118,32 @@ public void rotate2D(int angle) {
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];
}
}
}

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);;
}

/**
Expand Down Expand Up @@ -188,7 +190,7 @@ public void place(EditSession editSession, Vector pos, boolean noAir)
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]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/com/sk89q/worldedit/Vector.java
Expand Up @@ -96,7 +96,7 @@ public double getX() {
* @return the x
*/
public int getBlockX() {
return (int)x;
return (int)Math.round(x);
}

/**
Expand All @@ -110,7 +110,7 @@ public double getY() {
* @return the y
*/
public int getBlockY() {
return (int)y;
return (int)Math.round(y);
}

/**
Expand All @@ -124,7 +124,7 @@ public double getZ() {
* @return the z
*/
public int getBlockZ() {
return (int)z;
return (int)Math.round(z);
}

/**
Expand Down

0 comments on commit aa63f88

Please sign in to comment.