Class Funcs
java.lang.Object
io.github.emcw.utils.Funcs
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
calcArea
(int[] X, int[] Z) static int
calcArea
(int[] X, int[] Z, int numPoints, int @NotNull ... divisor) collectAsMap
(@NotNull Stream<Map.Entry<String, T>> stream) static <T> List
<T> collectList
(Stream<T> stream, Boolean unique) static double
euclidean
(int x1, int x2, int z1, int z2) Calculates the straight-line distance between two locations, ignoring any obstacles or other factors.static double
Calculates the distance between two instances ofPoint2D
using Euclidean geometry.static int
manhattan
(int x1, int z1, int x2, int z2) Calculates the Manhattan (sometimes referred to as "taxi-cab") distance between two locations, which is the sum of the absolute differences of their X and Z coordinates.static int
Calculates the distance between two instances ofPoint2D
using Taxi-cab geometry.static int
midrange
(int[] ints) Applies the Midrange Formula to the input array, the result is then rounded to the nearest full integer.static <T> @NotNull Stream
<T> parallelStreamArr
(T[] arr) static <T> List
<T> removeListDuplicates
(@NotNull List<T> list) static int
roundToNearest16
(double value) static int
roundToNearest16
(int value) static boolean
static UUID
stringToFullUUID
(@NotNull String uuidStr) Ensures aUUID
is full (with hyphens) by inserting them at known points in the string.
If the given string is 36 characters (full uuid), it will use that one without inserting.static boolean
withinRadius
(int num, int[] args) static boolean
withinRadius
(Integer sourceCoord, Integer targetCoord, Integer radius)
-
Constructor Details
-
Funcs
public Funcs()
-
-
Method Details
-
collectAsMap
-
calcArea
public static int calcArea(int[] X, int[] Z) -
calcArea
public static int calcArea(int[] X, int[] Z, int numPoints, int @NotNull ... divisor) -
roundToNearest16
public static int roundToNearest16(int value) -
roundToNearest16
public static int roundToNearest16(double value) -
midrange
public static int midrange(int[] ints) Applies the Midrange Formula to the input array, the result is then rounded to the nearest full integer.- Parameters:
ints
- The input array of integers.- Returns:
- The resulting int (rounded).
-
euclidean
Calculates the distance between two instances ofPoint2D
using Euclidean geometry. Note that the order of parameters here does not matter, the distance will be the same.
See the underlying euclidean method for further info.- See Also:
-
euclidean
public static double euclidean(int x1, int x2, int z1, int z2) Calculates the straight-line distance between two locations, ignoring any obstacles or other factors. This allows for diagonal paths that may not be viable in reality, the result is best only in theory.
In Minecraft, this method is preferred in many cases over Manhattan distance. You can visit here to look at examples of when to use one over the other.- Parameters:
x1
- The X coordinate (left/right) of the first location.x2
- The position on the X axis (left/right) of the second location.z1
- The Z coordinate (up/down) of the first location.z2
- The position on the Z axis (up/down) of the second location.- Returns:
- The distance as a highly precise number.
-
manhattan
-
manhattan
public static int manhattan(int x1, int z1, int x2, int z2) Calculates the Manhattan (sometimes referred to as "taxi-cab") distance between two locations, which is the sum of the absolute differences of their X and Z coordinates.
This method only considers horizontal and vertical movements, not diagonal. This is usually the method to use when we want the result in blocks and precision is not required.- Parameters:
x1
- The position on the X axis (left/right) of the first location.z1
- The position on the Z axis (up/down) of the first location.x2
- The position on the X axis (left/right) of the second location.z2
- The position on the Z axis (up/down) of the second location.- See Also:
-
removeListDuplicates
-
collectList
-
parallelStreamArr
-
strArrHas
-
withinRadius
@Contract(pure=true) public static boolean withinRadius(int num, int[] args) -
withinRadius
-
stringToFullUUID
public static UUID stringToFullUUID(@NotNull @NotNull String uuidStr) throws IllegalArgumentException Ensures aUUID
is full (with hyphens) by inserting them at known points in the string.
If the given string is 36 characters (full uuid), it will use that one without inserting.- Parameters:
uuidStr
- A trimmed or full UUID in string representation.- Returns:
- A new
UUID
with hyphens inserted if not already. - Throws:
IllegalArgumentException
-