mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 06:40:12 +00:00
Replace Math with FastMath for improved performance.
FastMath is a drop in replacement for the native Java math class with improved performance and fall backs to the native Java math class if necessary. https://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/util/FastMath.html This requires further testing and might cause chunk borders due the FastMath giving slightly different results than the native Java math class. I also added .idea/Terra.iml to the .gitignore
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.procgen.math;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
/**
|
||||
* oh yeah
|
||||
*/
|
||||
@@ -111,7 +113,7 @@ public class Vector2 implements Cloneable {
|
||||
* @return length
|
||||
*/
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
return FastMath.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +132,7 @@ public class Vector2 implements Cloneable {
|
||||
* @return Distance between vectors
|
||||
*/
|
||||
public double distance(Vector2 other) {
|
||||
return Math.sqrt(distanceSquared(other));
|
||||
return FastMath.sqrt(distanceSquared(other));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.procgen.pixel;
|
||||
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -11,8 +12,8 @@ public class Rectangle extends Polygon {
|
||||
private final Vector2 max;
|
||||
|
||||
public Rectangle(Vector2 min, Vector2 max) {
|
||||
this.max = new Vector2(Math.min(min.getX(), max.getX()), Math.min(min.getZ(), max.getZ()));
|
||||
this.min = new Vector2(Math.max(min.getX(), max.getX()), Math.max(min.getZ(), max.getZ()));
|
||||
this.max = new Vector2(FastMath.min(min.getX(), max.getX()), FastMath.min(min.getZ(), max.getZ()));
|
||||
this.min = new Vector2(FastMath.max(min.getX(), max.getX()), FastMath.max(min.getZ(), max.getZ()));
|
||||
}
|
||||
|
||||
public Rectangle(Vector2 center, double xRadius, double zRadius) {
|
||||
|
||||
Reference in New Issue
Block a user