mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-10 04:28:35 +00:00
Upstream
This commit is contained in:
@ -117,34 +117,4 @@ public final class MathUtils {
|
||||
public static double roundHalfUp(double value) {
|
||||
return Math.signum(value) * Math.round(Math.abs(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the midpoint Vector3 of the two given Vector3's.
|
||||
*
|
||||
* @param first Vector3
|
||||
* @param second Vector3
|
||||
* @return midpoint Vector3
|
||||
*/
|
||||
public static Vector3 midpoint(Vector3 v1, Vector3 v2) {
|
||||
return Vector3.at(
|
||||
(v1.getX() + v2.getX()) / 2,
|
||||
(v1.getY() + v2.getY()) / 2,
|
||||
(v1.getZ() + v2.getZ()) / 2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the midpoint BlockVector3 of the two given BlockVector3's.
|
||||
*
|
||||
* @param first BlockVector3
|
||||
* @param second BlockVector3
|
||||
* @return midpoint BlockVector3
|
||||
*/
|
||||
public static BlockVector3 midpoint(BlockVector3 v1, BlockVector3 v2) {
|
||||
return BlockVector3.at(
|
||||
(v1.getBlockX() + v2.getBlockX()) / 2,
|
||||
(v1.getBlockY() + v2.getBlockY()) / 2,
|
||||
(v1.getBlockZ() + v2.getBlockZ()) / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,7 @@ package com.sk89q.worldedit.math;
|
||||
|
||||
public class MutableBlockVector2 extends BlockVector2 {
|
||||
|
||||
private static ThreadLocal<MutableBlockVector2> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector2>() {
|
||||
@Override
|
||||
protected MutableBlockVector2 initialValue() {
|
||||
return new MutableBlockVector2();
|
||||
}
|
||||
};
|
||||
private static ThreadLocal<MutableBlockVector2> MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector2());
|
||||
|
||||
public static MutableBlockVector2 get(int x, int z) {
|
||||
return MUTABLE_CACHE.get().setComponents(x, z);
|
||||
|
@ -2,12 +2,7 @@ package com.sk89q.worldedit.math;
|
||||
|
||||
public class MutableBlockVector3 extends BlockVector3 {
|
||||
|
||||
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector3>() {
|
||||
@Override
|
||||
protected MutableBlockVector3 initialValue() {
|
||||
return new MutableBlockVector3();
|
||||
}
|
||||
};
|
||||
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector3());
|
||||
|
||||
public static MutableBlockVector3 get(int x, int y, int z) {
|
||||
return MUTABLE_CACHE.get().setComponents(x, y, z);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MutableVector3 extends Vector3 {
|
||||
|
||||
public MutableVector3() {}
|
||||
|
@ -20,6 +20,8 @@
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import com.boydti.fawe.object.visitor.Fast2DIterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
@ -34,8 +36,6 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Allows applications of Kernels onto the region's height map.
|
||||
*
|
||||
@ -167,7 +167,6 @@ public class HeightMap {
|
||||
|
||||
BlockVector3 minY = region.getMinimumPoint();
|
||||
int originX = minY.getBlockX();
|
||||
int originY = minY.getBlockY();
|
||||
int originZ = minY.getBlockZ();
|
||||
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
@ -177,10 +176,10 @@ public class HeightMap {
|
||||
|
||||
BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
// Apply heightmap
|
||||
int maxY4 = maxY << 4;
|
||||
int index = 0;
|
||||
|
||||
// Apply heightmap
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
|
@ -22,21 +22,17 @@
|
||||
package com.sk89q.worldedit.math.interpolation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
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>
|
||||
*
|
||||
* <p>Supports Node#tension tension, Node#bias bias and
|
||||
* Node#continuity continuity parameters per {@link Node}.</p>
|
||||
*/
|
||||
public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
@ -48,7 +44,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
private double scaling;
|
||||
|
||||
public KochanekBartelsInterpolation() {
|
||||
setNodes(Collections.<Node>emptyList());
|
||||
setNodes(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,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
|
||||
}
|
||||
@ -105,10 +101,10 @@ 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 Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
|
||||
@ -116,6 +112,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final Vector3 r2 = retrieve(baseIndex ).multiply(f2);
|
||||
final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3);
|
||||
final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4);
|
||||
|
||||
return r1.add(r2).add(r3).add(r4);
|
||||
}
|
||||
|
||||
@ -130,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);
|
||||
}
|
||||
@ -184,7 +181,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final Vector3 b = coeffB[index];
|
||||
final Vector3 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
|
||||
@ -212,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,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();
|
||||
}
|
||||
|
||||
@ -259,5 +256,4 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
return (int) Math.floor(position);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class Node {
|
||||
private double continuity;
|
||||
|
||||
public Node() {
|
||||
this(Vector3.at(0, 0, 0));
|
||||
this(Vector3.ZERO);
|
||||
}
|
||||
|
||||
public Node(Node other) {
|
||||
|
@ -1,17 +1,34 @@
|
||||
/*
|
||||
* 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.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.MutableVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
@ -153,7 +170,7 @@ public class AffineTransform implements Transform, Serializable {
|
||||
*
|
||||
* @return the determinant of the transform.
|
||||
*/
|
||||
public double determinant() {
|
||||
private double determinant() {
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12)
|
||||
+ m02 * (m10 * m21 - m20 * m11);
|
||||
}
|
||||
@ -336,4 +353,4 @@ public class AffineTransform implements Transform, Serializable {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
public class RoundedTransform implements Transform{
|
||||
private final Transform transform;
|
||||
// private MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
public RoundedTransform(Transform transform) {
|
||||
this.transform = transform;
|
||||
@ -19,9 +17,6 @@ public class RoundedTransform implements Transform{
|
||||
@Override
|
||||
public Vector3 apply(Vector3 input) {
|
||||
Vector3 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 Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public final class Transforms {
|
||||
public static Location transform(Location location, Transform transform) {
|
||||
checkNotNull(location);
|
||||
checkNotNull(transform);
|
||||
return new Location(location.getExtent(), transform.apply(location), location.getDirection());
|
||||
return new Location(location.getExtent(), transform.apply(location.toVector()), location.getDirection());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user