Created
February 27, 2023 02:42
-
-
Save imDaniX/8362f80fa516769dbbe10b612baaca16 to your computer and use it in GitHub Desktop.
Traversing edges of a cuboid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationUtils { | |
public static void traverseEdges(LocationConsumer consumer, Location aLoc, Location bLoc, double step) { | |
World world = aLoc.getWorld(); | |
double[] xArr = {Math.min(aLoc.getX(), bLoc.getX()), Math.max(aLoc.getX(), bLoc.getX())}; | |
double[] yArr = {Math.min(aLoc.getY(), bLoc.getY()), Math.max(aLoc.getY(), bLoc.getY())}; | |
double[] zArr = {Math.min(aLoc.getZ(), bLoc.getZ()), Math.max(aLoc.getZ(), bLoc.getZ())}; | |
for (double x = xArr[0]; x < xArr[1]; x += step) for (double y : yArr) for (double z : zArr) { | |
consumer.accept(world, x, y, z); | |
} | |
for (double y = yArr[0]; y < yArr[1]; y += step) for (double x : xArr) for (double z : zArr) { | |
consumer.accept(world, x, y, z); | |
} | |
for (double z = zArr[0]; z < zArr[1]; z += step) for (double y : yArr) for (double x : xArr) { | |
consumer.accept(world, x, y, z); | |
} | |
} | |
@FunctionalInterface | |
public interface LocationConsumer { | |
void accept(World world, double x, double y, double z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment