Copy paste/merge FAWE classes to this WorldEdit fork

- so certain people can look at the diff and complain about my sloppy code :(

Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
Jesse Boyd
2018-08-13 00:03:07 +10:00
parent a920c77cb8
commit a629d15c74
994 changed files with 117583 additions and 10745 deletions

View File

@ -63,14 +63,14 @@ public final class MathUtils {
dInt += 360;
}
switch (dInt) {
case 0:
return 1.0;
case 90:
return 0.0;
case 180:
return -1.0;
case 270:
return 0.0;
case 0:
return 1.0;
case 90:
return 0.0;
case 180:
return -1.0;
case 270:
return 0.0;
}
}
return Math.cos(Math.toRadians(degrees));
@ -92,14 +92,14 @@ public final class MathUtils {
dInt += 360;
}
switch (dInt) {
case 0:
return 0.0;
case 90:
return 1.0;
case 180:
return 0.0;
case 270:
return -1.0;
case 0:
return 0.0;
case 90:
return 1.0;
case 180:
return 0.0;
case 270:
return -1.0;
}
}
return Math.sin(Math.toRadians(degrees));
@ -117,4 +117,4 @@ public final class MathUtils {
public static double roundHalfUp(double value) {
return Math.signum(value) * Math.round(Math.abs(value));
}
}
}

View File

@ -1,41 +1,33 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.convolution;
import com.boydti.fawe.object.visitor.Fast2DIterator;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Regions;
import com.sk89q.worldedit.registry.state.PropertyGroup;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Iterator;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
/**
* Allows applications of Kernels onto the region's height map.
*
* <p>
* <p>Currently only used for smoothing (with a GaussianKernel)</p>.
*/
public class HeightMap {
private final boolean layers;
private int[] data;
private boolean[] invalid;
private int width;
private int height;
@ -46,9 +38,17 @@ public class HeightMap {
* Constructs the HeightMap
*
* @param session an edit session
* @param region the region
* @param region the region
*/
public HeightMap(EditSession session, Region region) {
this(session, region, false);
}
public HeightMap(EditSession session, Region region, boolean naturalOnly) {
this(session, region, naturalOnly, false);
}
public HeightMap(EditSession session, Region region, boolean naturalOnly, boolean layers) {
checkNotNull(session);
checkNotNull(region);
@ -58,29 +58,84 @@ public class HeightMap {
this.width = region.getWidth();
this.height = region.getLength();
this.layers = layers;
int minX = region.getMinimumPoint().getBlockX();
int minY = region.getMinimumPoint().getBlockY();
int minZ = region.getMinimumPoint().getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
// Store current heightmap data
data = new int[width * height];
for (int z = 0; z < height; ++z) {
for (int x = 0; x < width; ++x) {
data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY);
invalid = new boolean[data.length];
if (layers) {
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int bx = min.getBlockX();
int bz = min.getBlockZ();
Iterable<Vector2D> flat = Regions.asFlatRegion(region).asFlatRegion();
Iterator<Vector2D> iter = new Fast2DIterator(flat, session).iterator();
int layer = 0;
MutableBlockVector mutable = new MutableBlockVector();
while (iter.hasNext()) {
Vector2D pos = iter.next();
int x = pos.getBlockX();
int z = pos.getBlockZ();
layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY);
data[(z - bz) * width + (x - bx)] = layer;
}
} else {
// Store current heightmap data
int index = 0;
if (naturalOnly) {
for (int z = 0; z < height; ++z) {
for (int x = 0; x < width; ++x, index++) {
data[index] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY);
}
}
} else {
int yTmp = 255;
for (int z = 0; z < height; ++z) {
for (int x = 0; x < width; ++x, index++) {
yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
switch (yTmp) {
case Integer.MIN_VALUE:
yTmp = minY;
invalid[index] = true;
break;
case Integer.MAX_VALUE:
yTmp = maxY;
invalid[index] = true;
break;
}
data[index] = yTmp;
}
}
}
}
}
@Deprecated
public HeightMap(EditSession session, Region region, int[] data, boolean layers) {
this.session = session;
this.region = region;
this.width = region.getWidth();
this.height = region.getLength();
this.data = data;
this.layers = layers;
}
/**
* Apply the filter 'iterations' amount times.
*
* @param filter the filter
*
* @param filter the filter
* @param iterations the number of iterations
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException {
checkNotNull(filter);
@ -91,16 +146,86 @@ public class HeightMap {
newData = filter.filter(newData, width, height);
}
return apply(newData);
return layers ? applyLayers(newData) : apply(newData);
}
/**
* Apply a raw heightmap to the region
*
* @param data the data
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int applyLayers(int[] data) {
checkNotNull(data);
Vector minY = region.getMinimumPoint();
int originX = minY.getBlockX();
int originY = minY.getBlockY();
int originZ = minY.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BlockStateHolder fillerAir = EditSession.nullBlock;
int blocksChanged = 0;
BlockStateHolder tmpBlock = EditSession.nullBlock;
// Apply heightmap
int maxY4 = maxY << 4;
int index = 0;
for (int z = 0; z < height; ++z) {
int zr = z + originZ;
for (int x = 0; x < width; ++x) {
int curHeight = this.data[index];
if (this.invalid != null && this.invalid[index]) continue;
int newHeight = Math.min(maxY4, data[index++]);
int curBlock = (curHeight) >> 4;
int newBlock = (newHeight + 15) >> 4;
int xr = x + originX;
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
BlockStateHolder existing = session.getBlock(xr, curBlock, zr);
// Skip water/lava
if (existing.getBlockType().getMaterial().isMovementBlocker()) {
// Grow -- start from 1 below top replacing airblocks
for (int setY = newBlock - 1, getY = curBlock; setY >= curBlock; --setY, getY--) {
BlockStateHolder get = session.getBlock(xr, getY, zr);
if (get != EditSession.nullBlock) tmpBlock = get;
session.setBlock(xr, setY, zr, tmpBlock);
++blocksChanged;
}
int setData = newHeight & 15;
if (setData != 0) {
existing = PropertyGroup.LEVEL.set(existing, setData - 1);
session.setBlock(xr, newBlock, zr, existing);
++blocksChanged;
} else {
existing = PropertyGroup.LEVEL.set(existing, 15);
session.setBlock(xr, newBlock, zr, existing);
++blocksChanged;
}
}
} else if (curHeight > newHeight) {
// Fill rest with air
for (int y = newBlock + 1; y <= ((curHeight + 15) >> 4); ++y) {
session.setBlock(xr, y, zr, fillerAir);
++blocksChanged;
}
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
int setData = newHeight & 15;
BlockStateHolder existing = session.getBlock(xr, curBlock, zr);
if (setData != 0) {
existing = PropertyGroup.LEVEL.set(existing, setData - 1);
session.setBlock(xr, newBlock, zr, existing);
} else {
existing = PropertyGroup.LEVEL.set(existing, 15);
session.setBlock(xr, newBlock, zr, existing);
}
++blocksChanged;
}
}
}
return blocksChanged;
}
public int apply(int[] data) throws MaxChangedBlocksException {
checkNotNull(data);
@ -111,68 +236,60 @@ public class HeightMap {
int originZ = minY.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BlockState fillerAir = BlockTypes.AIR.getDefaultState();
BlockStateHolder fillerAir = EditSession.nullBlock;
int blocksChanged = 0;
// Apply heightmap
for (int z = 0; z < height; ++z) {
for (int x = 0; x < width; ++x) {
int index = z * width + x;
int curHeight = this.data[index];
BlockStateHolder tmpBlock = EditSession.nullBlock;
// Clamp newHeight within the selection area
// Apply heightmap
int index = 0;
for (int z = 0; z < height; ++z) {
int zr = z + originZ;
for (int x = 0; x < width; ++x, index++) {
int curHeight = this.data[index];
if (this.invalid != null && this.invalid[index]) continue;
int newHeight = Math.min(maxY, data[index]);
// Offset x,z to be 'real' coordinates
int xr = x + originX;
int zr = z + originZ;
// We are keeping the topmost blocks so take that in account for the scale
double scale = (double) (curHeight - originY) / (double) (newHeight - originY);
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
BlockState existing = session.getBlock(new Vector(xr, curHeight, zr));
BlockStateHolder existing = session.getBlock(xr, curHeight, zr);
// Skip water/lava
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
session.setBlock(new Vector(xr, newHeight, zr), existing);
++blocksChanged;
// Grow -- start from 1 below top replacing airblocks
for (int y = newHeight - 1 - originY; y >= 0; --y) {
int copyFrom = (int) (y * scale);
session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr)));
if (existing.getBlockType().getMaterial().isMovementBlocker()) {
int y0 = newHeight - 1;
for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) {
BlockStateHolder get = session.getBlock(xr, getY, zr);
if (get != EditSession.nullBlock) tmpBlock = get;
session.setBlock(xr, setY, zr, tmpBlock);
++blocksChanged;
}
}
} else if (curHeight > newHeight) {
// Shrink -- start from bottom
for (int y = 0; y < newHeight - originY; ++y) {
int copyFrom = (int) (y * scale);
session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr)));
session.setBlock(xr, newHeight, zr, existing);
++blocksChanged;
}
} else if (curHeight > newHeight) {
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
session.setBlock(new Vector(xr, newHeight, zr), session.getBlock(new Vector(xr, curHeight, zr)));
session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr));
++blocksChanged;
// Fill rest with air
for (int y = newHeight + 1; y <= curHeight; ++y) {
session.setBlock(new Vector(xr, y, zr), fillerAir);
session.setBlock(xr, y, zr, fillerAir);
++blocksChanged;
}
}
}
}
// Drop trees to the floor -- TODO
return blocksChanged;
}
public static Class<?> inject() {
return HeightMap.class;
}
}

View File

@ -21,16 +21,16 @@
package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A Kochanek-Bartels interpolation; continuous in the 2nd derivative.
*
* <p>
* <p>Supports {@link Node#tension tension}, {@link Node#bias bias} and
* {@link Node#continuity continuity} parameters per {@link Node}.</p>
*/
@ -82,14 +82,14 @@ public class KochanekBartelsInterpolation implements Interpolation {
}
// Kochanek-Bartels tangent coefficients
final double ta = (1-tensionA)*(1+biasA)*(1+continuityA)/2; // Factor for lhs of d[i]
final double tb = (1-tensionA)*(1-biasA)*(1-continuityA)/2; // Factor for rhs of d[i]
final double tc = (1-tensionB)*(1+biasB)*(1-continuityB)/2; // Factor for lhs of d[i+1]
final double td = (1-tensionB)*(1-biasB)*(1+continuityB)/2; // Factor for rhs of d[i+1]
final double ta = (1 - tensionA) * (1 + biasA) * (1 + continuityA) / 2; // Factor for lhs of d[i]
final double tb = (1 - tensionA) * (1 - biasA) * (1 - continuityA) / 2; // Factor for rhs of d[i]
final double tc = (1 - tensionB) * (1 + biasB) * (1 - continuityB) / 2; // Factor for lhs of d[i+1]
final double td = (1 - tensionB) * (1 - biasB) * (1 + continuityB) / 2; // Factor for rhs of d[i+1]
coeffA[i] = linearCombination(i, -ta, ta- tb-tc+2, tb+tc-td-2, td);
coeffB[i] = linearCombination(i, 2*ta, -2*ta+2*tb+tc-3, -2*tb-tc+td+3, -td);
coeffC[i] = linearCombination(i, -ta, ta- tb , tb , 0);
coeffA[i] = linearCombination(i, -ta, ta - tb - tc + 2, tb + tc - td - 2, td);
coeffB[i] = linearCombination(i, 2 * ta, -2 * ta + 2 * tb + tc - 3, -2 * tb - tc + td + 3, -td);
coeffC[i] = linearCombination(i, -ta, ta - tb, tb, 0);
//coeffD[i] = linearCombination(i, 0, 1, 0, 0);
coeffD[i] = retrieve(i); // this is an optimization
}
@ -101,15 +101,15 @@ public class KochanekBartelsInterpolation implements Interpolation {
* Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex.
*
* @param baseIndex node index
* @param f1 coefficient for baseIndex-1
* @param f2 coefficient for baseIndex
* @param f3 coefficient for baseIndex+1
* @param f4 coefficient for baseIndex+2
* @param f1 coefficient for baseIndex-1
* @param f2 coefficient for baseIndex
* @param f3 coefficient for baseIndex+1
* @param f4 coefficient for baseIndex+2
* @return linear combination of nodes[n-1..n+2] with f1..4
*/
private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
final Vector r1 = retrieve(baseIndex - 1).multiply(f1);
final Vector r2 = retrieve(baseIndex ).multiply(f2);
final Vector r2 = retrieve(baseIndex).multiply(f2);
final Vector r3 = retrieve(baseIndex + 1).multiply(f3);
final Vector r4 = retrieve(baseIndex + 2).multiply(f4);
@ -127,7 +127,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
return fastRetrieve(0);
if (index >= nodes.size())
return fastRetrieve(nodes.size()-1);
return fastRetrieve(nodes.size() - 1);
return fastRetrieve(index);
}
@ -136,6 +136,8 @@ public class KochanekBartelsInterpolation implements Interpolation {
return nodes.get(index).getPosition();
}
private Vector mutable = new Vector();
@Override
public Vector getPosition(double position) {
if (coeffA == null)
@ -154,7 +156,12 @@ public class KochanekBartelsInterpolation implements Interpolation {
final Vector c = coeffC[index];
final Vector d = coeffD[index];
return a.multiply(remainder).add(b).multiply(remainder).add(c).multiply(remainder).add(d);
double r2 = remainder * remainder;
double r3 = r2 * remainder;
mutable.mutX((a.getX() * r3 + b.getX() * r2 + c.getX() * remainder + d.getX()));
mutable.mutY((a.getY() * r3 + b.getY() * r2 + c.getY() * remainder + d.getY()));
mutable.mutZ((a.getZ() * r3 + b.getZ() * r2 + c.getZ() * remainder + d.getZ()));
return mutable;
}
@Override
@ -174,7 +181,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
final Vector b = coeffB[index];
final Vector c = coeffC[index];
return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling);
return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a.multiply(1.5 * index).subtract(b).multiply(2.0 * index)).add(c).multiply(scaling);
}
@Override
@ -202,19 +209,19 @@ public class KochanekBartelsInterpolation implements Interpolation {
*/
private double arcLengthRecursive(int indexLeft, double remainderLeft, int indexRight, double remainderRight) {
switch (indexRight - indexLeft) {
case 0:
return arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
case 0:
return arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
case 1:
// This case is merely a speed-up for a very common case
return
arcLengthRecursive(indexLeft, remainderLeft, 1.0) +
arcLengthRecursive(indexRight, 0.0, remainderRight);
case 1:
// This case is merely a speed-up for a very common case
return
arcLengthRecursive(indexLeft, remainderLeft, 1.0) +
arcLengthRecursive(indexRight, 0.0, remainderRight);
default:
return
arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) +
arcLengthRecursive(indexRight, 0.0, remainderRight);
default:
return
arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) +
arcLengthRecursive(indexRight, 0.0, remainderRight);
}
}
@ -226,9 +233,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
final int nPoints = 8;
double accum = a.multiply(remainderLeft).add(b).multiply(remainderLeft).add(c).length() / 2.0;
for (int i = 1; i < nPoints-1; ++i) {
for (int i = 1; i < nPoints - 1; ++i) {
double t = ((double) i) / nPoints;
t = (remainderRight-remainderLeft)*t + remainderLeft;
t = (remainderRight - remainderLeft) * t + remainderLeft;
accum += a.multiply(t).add(b).multiply(t).add(c).length();
}
@ -249,4 +256,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
return (int) Math.floor(position);
}
public static Class<?> inject() {
return KochanekBartelsInterpolation.class;
}
}

View File

@ -21,12 +21,12 @@
package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Simple linear interpolation. Mainly used for testing.
*/

View File

@ -21,8 +21,6 @@
package com.sk89q.worldedit.math.interpolation;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import java.util.List;
@ -30,6 +28,8 @@ import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Reparametrises another interpolation function by arc length.
*

View File

@ -1,35 +1,21 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.transform;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.math.MathUtils;
import java.io.IOException;
import java.io.Serializable;
/**
* An affine transform.
*
* <p>
* <p>This class is from the
* <a href="http://geom-java.sourceforge.net/index.html">JavaGeom project</a>,
* which is licensed under LGPL v2.1.</p>
*/
public class AffineTransform implements Transform {
public class AffineTransform implements Transform, Serializable {
private transient MutableBlockVector mutable = new MutableBlockVector();
/**
* coefficients for x coordinate.
@ -147,12 +133,24 @@ public class AffineTransform implements Transform {
return new double[]{m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23};
}
public boolean isOffAxis() {
double[] c = coefficients();
for (int i = 0; i < c.length; i++) {
if ((i + 1) % 4 != 0) {
if (Math.abs(c[i]) != 1 && c[i] != 0) {
return true;
}
}
}
return false;
}
/**
* Computes the determinant of this transform. Can be zero.
*
* @return the determinant of the transform.
*/
private double determinant() {
public double determinant() {
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12)
+ m02 * (m10 * m21 - m20 * m11);
}
@ -165,17 +163,17 @@ public class AffineTransform implements Transform {
double det = this.determinant();
return new AffineTransform(
(m11 * m22 - m21 * m12) / det,
(m21 * m02 - m01 * m22) / det,
(m02 * m21 - m22 * m01) / det,
(m01 * m12 - m11 * m02) / det,
(m01 * (m22 * m13 - m12 * m23) + m02 * (m11 * m23 - m21 * m13)
- m03 * (m11 * m22 - m21 * m12)) / det,
(m20 * m12 - m10 * m22) / det,
(m12 * m20 - m22 * m10) / det,
(m00 * m22 - m20 * m02) / det,
(m10 * m02 - m00 * m12) / det,
(m02 * m10 - m12 * m00) / det,
(m00 * (m12 * m23 - m22 * m13) - m02 * (m10 * m23 - m20 * m13)
+ m03 * (m10 * m22 - m20 * m12)) / det,
(m10 * m21 - m20 * m11) / det,
(m20 * m01 - m00 * m21) / det,
(m01 * m20 - m21 * m00) / det,
(m00 * m11 - m10 * m01) / det,
(m00 * (m21 * m13 - m11 * m23) + m01 * (m10 * m23 - m20 * m13)
- m03 * (m10 * m21 - m20 * m11)) / det);
@ -288,10 +286,17 @@ public class AffineTransform implements Transform {
@Override
public Vector apply(Vector vector) {
// vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03
// vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13
// vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23
return new Vector(
vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
// mutable.mutX((vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03));
// mutable.mutY((vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13));
// mutable.mutZ((vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23));
// return mutable;
}
public AffineTransform combine(AffineTransform other) {
@ -300,7 +305,9 @@ public class AffineTransform implements Transform {
@Override
public Transform combine(Transform other) {
if (other instanceof AffineTransform) {
if (other instanceof Identity || other.isIdentity()) {
return this;
} else if (other instanceof AffineTransform) {
return concatenate((AffineTransform) other);
} else {
return new CombinedTransform(this, other);
@ -312,5 +319,12 @@ public class AffineTransform implements Transform {
return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
mutable = new MutableBlockVector();
}
}
public static Class<?> inject() {
return AffineTransform.class;
}
}

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.math.transform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.Vector;
import java.util.ArrayList;
@ -28,6 +26,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Combines several transforms in order.
*/

View File

@ -0,0 +1,41 @@
package com.sk89q.worldedit.math.transform;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
public class RoundedTransform implements Transform{
private final Transform transform;
private MutableBlockVector mutable = new MutableBlockVector();
public RoundedTransform(Transform transform) {
this.transform = transform;
}
@Override
public boolean isIdentity() {
return transform.isIdentity();
}
@Override
public Vector apply(Vector input) {
Vector val = transform.apply(input);
mutable.mutX((int) Math.floor(val.getX() + 0.5));
mutable.mutY((int) Math.floor(val.getY() + 0.5));
mutable.mutZ((int) Math.floor(val.getZ() + 0.5));
return mutable;
}
@Override
public RoundedTransform inverse() {
return new RoundedTransform(transform.inverse());
}
@Override
public RoundedTransform combine(Transform other) {
return new RoundedTransform(transform.combine(other));
}
public Transform getTransform() {
return transform;
}
}

View File

@ -19,10 +19,10 @@
package com.sk89q.worldedit.math.transform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.util.Location;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Various utility methods related to {@link Transform}s.
*/