This commit is contained in:
dfsek
2021-01-09 02:25:48 -07:00
parent 67ffd91641
commit 141b4f86ae
5 changed files with 18 additions and 20 deletions

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.generation.math.Sampler;
import net.jafama.FastMath;
import java.util.List;
import java.util.Random;
/**
@@ -25,18 +26,18 @@ public final class MathUtil {
* @param numArray The array of numbers to calculate the standard deviation of.
* @return double - The standard deviation.
*/
public static double standardDeviation(double[] numArray) {
public static double standardDeviation(List<Number> numArray) {
double sum = 0.0, standardDeviation = 0.0;
int length = numArray.length;
int length = numArray.size();
for(double num : numArray) {
sum += num;
for(Number num : numArray) {
sum += num.doubleValue();
}
double mean = sum / length;
for(double num : numArray) {
standardDeviation += FastMath.pow(num - mean, 2);
for(Number num : numArray) {
standardDeviation += FastMath.pow2(num.doubleValue() - mean);
}
return FastMath.sqrt(standardDeviation / length);

View File

@@ -101,6 +101,10 @@ public class Vector3 implements Cloneable {
return FastMath.sqrt(lengthSquared());
}
public double inverseLength() {
return FastMath.invSqrtQuick(lengthSquared());
}
/**
* Returns if a vector is normalized
*
@@ -280,7 +284,7 @@ public class Vector3 implements Cloneable {
}
public Vector3 normalize() {
return this.multiply(1D / this.length());
return this.multiply(this.inverseLength());
}
public Vector3 subtract(int x, int y, int z) {

View File

@@ -5,13 +5,14 @@ import com.dfsek.terra.api.util.GlueList;
import net.jafama.FastMath;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
/**
* Class to record and hold all data for a single type of measurement performed by the profiler.
*/
public class Measurement {
private final List<Long> measurements;
private final List<Long> measurements = new LinkedList<>();
private final long desirable;
private final DataType type;
private long min = Long.MAX_VALUE;
@@ -26,7 +27,6 @@ public class Measurement {
public Measurement(long desirable, DataType type) {
this.desirable = desirable;
this.type = type;
measurements = new GlueList<>();
}
public void record(long value) {
@@ -67,7 +67,7 @@ public class Measurement {
}
public long average() {
BigInteger running = new BigInteger("0");
BigInteger running = BigInteger.valueOf(0);
List<Long> mTemp = new GlueList<>(measurements);
for(Long l : mTemp) {
running = running.add(BigInteger.valueOf(l));
@@ -77,12 +77,7 @@ public class Measurement {
}
public double getStdDev() {
List<Long> mTemp = new GlueList<>(measurements);
double[] vals = new double[mTemp.size()];
for(int i = 0; i < mTemp.size(); i++) {
vals[i] = mTemp.get(i);
}
return MathUtil.standardDeviation(vals);
return MathUtil.standardDeviation(new GlueList<>(measurements));
}
public int entries() {

View File

@@ -5,7 +5,6 @@ import com.dfsek.terra.api.math.voxel.Tube;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.structure.WorldEditUtil;
import com.dfsek.terra.bukkit.util.BukkitConversions;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.Location;
@@ -33,7 +32,7 @@ public class TubeCommand extends PlayerCommand {
LangUtil.send("command.geometry.tube.invalid-radius", new BukkitCommandSender(sender), args[0]);
return true;
}
Tube tube = new Tube(BukkitConversions.toTerraVector(l[0].toVector()), BukkitConversions.toTerraVector(l[1].toVector()), radius);
Tube tube = new Tube(BukkitAdapter.adapt(l[0].toVector()), BukkitAdapter.adapt(l[1].toVector()), radius);
for(Vector3 v : tube.getGeometry()) {
v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false);
}

View File

@@ -5,7 +5,6 @@ import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.bukkit.util.BukkitConversions;
import com.dfsek.terra.util.MaterialSet;
import org.bukkit.TreeType;
@@ -49,7 +48,7 @@ public class BukkitTree implements Tree {
@Override
public boolean plant(Location l, Random r) {
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitConversions.toBukkitLocation(l), delegate);
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitAdapter.adapt(l), delegate);
}
@Override