mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
create GeometryUtil
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public final class GeometryUtil {
|
||||
private GeometryUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static void sphere(Vector3Int origin, int radius, Consumer<Vector3Int> action) {
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int y = -radius; y <= radius; y++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
if(x * x + y * y + z * z <= radius * radius) {
|
||||
action.accept(Vector3Int.of(origin, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cube(Vector3Int origin, int radius, Consumer<Vector3Int> action) {
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int y = -radius; y <= radius; y++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
action.accept(Vector3Int.of(origin, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,10 @@ public class Vector3Int {
|
||||
return new Vector3Int(x, y, z);
|
||||
}
|
||||
|
||||
public static Vector3Int of(Vector3Int origin, int x, int y, int z) {
|
||||
return new Vector3Int(origin.x + x, origin.y + y, origin.z + z);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user