mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-11 02:06:07 +00:00
Config refactoring, work on caverns, multi-level tree gen
This commit is contained in:
157
src/main/java/com/dfsek/terra/procgen/math/Vector2.java
Normal file
157
src/main/java/com/dfsek/terra/procgen/math/Vector2.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package com.dfsek.terra.procgen.math;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* oh yeah
|
||||
*/
|
||||
public class Vector2 implements Cloneable {
|
||||
private double x;
|
||||
private double z;
|
||||
|
||||
/**
|
||||
* Create a vector with a given X and Z component
|
||||
* @param x X component
|
||||
* @param z Z component
|
||||
*/
|
||||
public Vector2(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X component
|
||||
* @return X component
|
||||
*/
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z component
|
||||
* @return Z component
|
||||
*/
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply X and Z components by a value.
|
||||
* @param m Value to multiply
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 multiply(double m) {
|
||||
x*=m;
|
||||
z*=m;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide X and Z components by a value.
|
||||
* @param d Divisor
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 divide(double d) {
|
||||
x/=d;
|
||||
z/=d;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the squared length of this Vector
|
||||
* @return squared length
|
||||
*/
|
||||
public double lengthSquared() {
|
||||
return x*x+z*z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of this Vector
|
||||
* @return length
|
||||
*/
|
||||
public double length() {
|
||||
return Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this vector to another.
|
||||
* @param other Vector to add
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 add(Vector2 other) {
|
||||
x+=other.x;
|
||||
z+=other.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from this vector,
|
||||
* @param other Vector to subtract
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 subtract(Vector2 other) {
|
||||
x-=other.x;
|
||||
z-=other.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize this vector to length 1
|
||||
* @return Mutated vector, for chaining.
|
||||
*/
|
||||
public Vector2 normalize() {
|
||||
divide(length());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance from this vector to another.
|
||||
* @param other Another vector
|
||||
* @return Distance between vectors
|
||||
*/
|
||||
public double distance(Vector2 other) {
|
||||
return Math.sqrt(distanceSquared(other));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the squared distance between 2 vectors.
|
||||
* @param other Another vector
|
||||
* @return Squared distance
|
||||
*/
|
||||
public double distanceSquared(Vector2 other) {
|
||||
double dx = other.x - x;
|
||||
double dz = other.z - z;
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Vector2)) {
|
||||
return false;
|
||||
}
|
||||
Vector2 other = (Vector2) obj;
|
||||
return other.x == this.x && other.z == this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = 31 * hash + Double.hashCode(x);
|
||||
hash = 31 * hash + Double.hashCode(z);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2 clone() {
|
||||
try {
|
||||
return (Vector2) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.dfsek.terra.procgen.pixel;
|
||||
|
||||
public class Distribution {
|
||||
public Distribution(Rectangle bound, int numPoints, double minRad) {
|
||||
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/dfsek/terra/procgen/pixel/Polygon.java
Normal file
9
src/main/java/com/dfsek/terra/procgen/pixel/Polygon.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.procgen.pixel;
|
||||
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Polygon {
|
||||
public abstract Set<Vector2> getContainedPixels();
|
||||
}
|
||||
31
src/main/java/com/dfsek/terra/procgen/pixel/Rectangle.java
Normal file
31
src/main/java/com/dfsek/terra/procgen/pixel/Rectangle.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.procgen.pixel;
|
||||
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Rectangle extends Polygon {
|
||||
private Vector2 min;
|
||||
private 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()));;
|
||||
}
|
||||
public Rectangle(Vector2 center, double xRadius, double zRadius) {
|
||||
Vector2 rad = new Vector2(xRadius, zRadius);
|
||||
this.min = center.clone().subtract(rad);
|
||||
this.max = center.clone().add(rad);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Vector2> getContainedPixels() {
|
||||
Set<Vector2> pixels = new HashSet<>();
|
||||
for(int x = (int) min.getX(); x <= max.getX(); x++) {
|
||||
for(int z = (int) min.getZ(); z <= max.getZ(); z++) {
|
||||
pixels.add(new Vector2(x, z));
|
||||
}
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public abstract class VoxelGeometry {
|
||||
}
|
||||
|
||||
public void merge(VoxelGeometry other) {
|
||||
geometry.addAll(other.getGeometry());
|
||||
geometry.addAll(other.geometry);
|
||||
}
|
||||
public static VoxelGeometry getBlank() {
|
||||
return new VoxelGeometry() {};
|
||||
|
||||
Reference in New Issue
Block a user