changed comment style to javadocs

This commit is contained in:
Bella 2020-03-31 17:05:52 -04:00
parent 455b745f3d
commit 83c5d7e62d
No known key found for this signature in database
GPG Key ID: 815562EA23BFE344
1 changed files with 49 additions and 14 deletions

View File

@ -6,14 +6,32 @@ import net.minecraft.util.math.Vec3d;
import java.util.ArrayList;
import java.util.List;
/**
* Utilities for managing and transforming blockPos positions
*
* @author Qther / Vonr
*/
public class VectorUtil {
// Gets distance between vecA and vecB
/**
* Gets distance between two vectors
*
* @param vecA First Vector
* @param vecB Second Vector
* @return the distance between two vectors
*/
public static double getDistance(Vec3d vecA, Vec3d vecB) {
return Math.sqrt(Math.pow(vecA.x - vecB.x, 2) + Math.pow(vecA.y - vecB.y, 2) + Math.pow(vecA.z - vecB.z, 2));
}
// Gets vectors between two given vectors (startVec and destinationVec) every (distance between the given vectors) / steps
/**
* Gets vectors between two given vectors (startVec and destinationVec) every (distance between the given vectors) / steps
*
* @param startVec Beginning vector
* @param destinationVec Ending vector
* @param steps distance between given vectors
* @return all vectors between startVec and destinationVec divided by steps
*/
public static ArrayList<Vec3d> extendVec(Vec3d startVec, Vec3d destinationVec, int steps) {
ArrayList<Vec3d> returnList = new ArrayList<>(steps + 1);
double stepDistance = getDistance(startVec, destinationVec) / steps;
@ -25,14 +43,29 @@ public class VectorUtil {
return returnList;
}
// Returns vector based on startVec that is moved towards destinationVec by distance
// Returns
/**
* Moves a vector towards a destination based on distance
*
* @param startVec Starting vector
* @param destinationVec returned vector
* @param distance distance to move startVec by
* @return vector based on startVec that is moved towards destinationVec by distance
*/
public static Vec3d advanceVec(Vec3d startVec, Vec3d destinationVec, double distance) {
Vec3d advanceDirection = destinationVec.subtract(startVec).normalize();
if (destinationVec.distanceTo(startVec) < distance) return destinationVec;
return advanceDirection.scale(distance);
}
// Get all rounded block positions inside a 3-dimensional area between pos1 and pos2.
/**
* Get all rounded block positions inside a 3-dimensional area between pos1 and pos2.
*
* @param pos1 Starting vector
* @param pos2 Ending vector
* @return rounded block positions inside a 3d area between pos1 and pos2
*/
public static ArrayList<BlockPos> getBlockPositionsInArea(Vec3d pos1, Vec3d pos2) {
int minX = (int) Math.round(Math.min(pos1.x, pos2.x));
int maxX = (int) Math.round(Math.max(pos1.x, pos2.x));
@ -43,18 +76,16 @@ public class VectorUtil {
int minZ = (int) Math.round(Math.min(pos1.z, pos2.z));
int maxZ = (int) Math.round(Math.max(pos1.z, pos2.z));
ArrayList<BlockPos> returnList = new ArrayList<>((maxX - minX) * (maxY - minY) * (maxZ - minZ));
for (int x = minX; x < maxX; x++) {
for (int y = minY; y < maxY; y++) {
for (int z = minZ; z < maxZ; z++) { returnList.add(new BlockPos(x, y, z)); }
}
}
return returnList;
return (ArrayList<BlockPos>) getBlockPos(minX, maxX, minY, maxY, minZ, maxZ);
}
// Get all rounded block positions inside a 3-dimensional area between pos1 and pos2.
/**
* Get all block positions inside a 3d area between pos1 and pos2
*
* @param pos1 Starting blockPos
* @param pos2 Ending blockPos
* @return block positions inside a 3d area between pos1 and pos2
*/
public static List<BlockPos> getBlockPositionsInArea(BlockPos pos1, BlockPos pos2) {
int minX = Math.min(pos1.x, pos2.x);
int maxX = Math.max(pos1.x, pos2.x);
@ -65,6 +96,10 @@ public class VectorUtil {
int minZ = Math.min(pos1.z, pos2.z);
int maxZ = Math.max(pos1.z, pos2.z);
return getBlockPos(minX, maxX, minY, maxY, minZ, maxZ);
}
private static List<BlockPos> getBlockPos(int minX, int maxX, int minY, int maxY, int minZ, int maxZ) {
ArrayList<BlockPos> returnList = new ArrayList<>((maxX - minX) * (maxY - minY) * (maxZ - minZ));
for (int x = minX; x < maxX; x++) {