Class Calculations
- java.lang.Object
-
- net.eternalclient.api.utilities.math.Calculations
-
public class Calculations extends java.lang.Object
Calculations class provides various static methods for performing calculations and generating random points based on different geometric shapes.
-
-
Constructor Summary
Constructors Constructor Description Calculations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
contains(java.awt.Rectangle a, java.awt.Rectangle b)
Checks if Rectangle b is completely contained within Rectangle a.static double
distanceBetween(int x1, int y1, int x2, int y2)
Calculates the euclidean distance between two points in 2D space.static double
distanceBetween(java.awt.Point a, java.awt.Point b)
Calculates the distance between two points.static double
distanceBetween(Positionable a, Positionable b)
Returns the distance between two tiles.static java.awt.Point
generateRandomGaussianPoint(int x, int y, int width, int height)
Generates a random point within the specified rectangle, using a Gaussian distribution.static java.awt.Point
generateRandomGaussianPoint(java.awt.Rectangle rectangle)
Generates a random point within the given rectangle using Gaussian distribution.static java.awt.Point
generateRandomPoint(int x, int y, int width, int height)
Generates a random point within the specified rectangle area.static java.awt.Point
generateRandomPoint(java.awt.Polygon polygon)
Generates a random point within the given polygon.static java.awt.Point
generateRandomPoint(java.awt.Polygon[] polygon)
Generates a random Point within the bounds of the given polygons and returns it.static java.awt.Point
generateRandomPoint(java.awt.Rectangle rectangle)
Generates a random point within the given rectangle.static java.awt.Point
generateRandomPoint(net.eternalclient.api.data.geometry.SimplePolygon polygon)
Generates a random point within the bounds of the given polygon.static java.awt.Point
getCenterOfPolygon(java.awt.Polygon pg)
Returns the center point of a polygon.static java.awt.Point
getCenterOfPolygon(net.eternalclient.api.data.geometry.SimplePolygon pg)
Calculates and returns the center point of a polygon.static org.apache.commons.math3.random.RandomDataGenerator
getGenerator()
static double
getPolygonArea(java.awt.Point[] polygon, int N)
Calculates the area of a polygon given its vertices.static double
nextGammaRandom(int shape, int scale)
Generates a random number from a gamma distribution with specified shape and scale.static double
nextGaussianRandom(double mean, double sigma)
Generates a random number from a Gaussian distribution with the specified mean and standard deviation.static double
nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
Generates a random number following the Hypergeometric distribution.static double
nextLogNormalDistributionRandom(double scale, double shape)
Generates a random number from a log-normal distribution with the given scale and shape parameters.static double
random(double lower, double upper)
Generates a random number between the specified lower and upper bounds.static int
random(int high)
Generates a random integer between 0 (inclusive) and the specified high value (exclusive).static int
random(int min, int max)
Generates a random integer between the specified minimum and maximum values.static long
random(long min, long max)
Generates a random long between the specified minimum and maximum values.static void
setRandomSeed(long seed)
Sets the random seed for the generator.
-
-
-
Method Detail
-
getGenerator
public static org.apache.commons.math3.random.RandomDataGenerator getGenerator()
-
setRandomSeed
public static void setRandomSeed(long seed)
Sets the random seed for the generator.- Parameters:
seed
- the seed to set for the random generator
-
random
public static int random(int high)
Generates a random integer between 0 (inclusive) and the specified high value (exclusive).- Parameters:
high
- the exclusive upper bound for the random integer- Returns:
- a random integer between 0 (inclusive) and high (exclusive)
-
random
public static int random(int min, int max)
Generates a random integer between the specified minimum and maximum values.- Parameters:
min
- the minimum value for the random numbermax
- the maximum value for the random number- Returns:
- a random integer between min and max (inclusive)
-
random
public static double random(double lower, double upper)
Generates a random number between the specified lower and upper bounds.- Parameters:
lower
- the lower boundupper
- the upper bound- Returns:
- a random number between the lower and upper bounds
-
random
public static long random(long min, long max)
Generates a random long between the specified minimum and maximum values.- Parameters:
min
- the minimum value of the range (inclusive)max
- the maximum value of the range (inclusive)- Returns:
- a randomly generated long between min and max (inclusive)
-
nextLogNormalDistributionRandom
public static double nextLogNormalDistributionRandom(double scale, double shape)
Generates a random number from a log-normal distribution with the given scale and shape parameters.- Parameters:
scale
- the scale parameter of the distributionshape
- the shape parameter of the distribution- Returns:
- a random number from the log-normal distribution
- Throws:
org.apache.commons.math3.exception.NotStrictlyPositiveException
- if scale or shape is not strictly positive
-
nextGaussianRandom
public static double nextGaussianRandom(double mean, double sigma)
Generates a random number from a Gaussian distribution with the specified mean and standard deviation.- Parameters:
mean
- the mean of the Gaussian distributionsigma
- the standard deviation of the Gaussian distribution- Returns:
- a random number from the Gaussian distribution with the specified mean and standard deviation
-
nextHypergeometricRandom
public static double nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
Generates a random number following the Hypergeometric distribution.- Parameters:
populationSize
- the size of the populationnumberOfSuccesses
- the number of successes in the populationsampleSize
- the size of the sample- Returns:
- a random number following the Hypergeometric distribution
-
nextGammaRandom
public static double nextGammaRandom(int shape, int scale)
Generates a random number from a gamma distribution with specified shape and scale.- Parameters:
shape
- the shape parameter of the gamma distributionscale
- the scale parameter of the gamma distribution- Returns:
- a random number from the gamma distribution with specified shape and scale
-
distanceBetween
public static double distanceBetween(int x1, int y1, int x2, int y2)
Calculates the euclidean distance between two points in 2D space.- Parameters:
x1
- the x-coordinate of the first pointy1
- the y-coordinate of the first pointx2
- the x-coordinate of the second pointy2
- the y-coordinate of the second point- Returns:
- the distance between the two points
-
distanceBetween
public static double distanceBetween(Positionable a, Positionable b)
Returns the distance between two tiles.- Parameters:
a
- the first tileb
- the second tile- Returns:
- the distance between the two tiles
-
distanceBetween
public static double distanceBetween(java.awt.Point a, java.awt.Point b)
Calculates the distance between two points.- Parameters:
a
- The first point.b
- The second point.- Returns:
- The distance between the two points.
-
generateRandomGaussianPoint
public static java.awt.Point generateRandomGaussianPoint(java.awt.Rectangle rectangle)
Generates a random point within the given rectangle using Gaussian distribution.- Parameters:
rectangle
- the rectangle within which the point will be generated- Returns:
- a random point within the rectangle, or (-1, -1) if the rectangle is null or has non-positive dimensions
-
generateRandomGaussianPoint
public static java.awt.Point generateRandomGaussianPoint(int x, int y, int width, int height)
Generates a random point within the specified rectangle, using a Gaussian distribution.- Parameters:
x
- the x-coordinate of the top left corner of the rectangley
- the y-coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangle- Returns:
- a random point within the rectangle if width and height are positive, otherwise (-1, -1)
-
generateRandomPoint
public static java.awt.Point generateRandomPoint(java.awt.Rectangle rectangle)
Generates a random point within the given rectangle.- Parameters:
rectangle
- the rectangle in which the random point will be generated- Returns:
- a random point within the rectangle, or (-1, -1) if the rectangle is null or has non-positive dimensions
-
generateRandomPoint
public static java.awt.Point generateRandomPoint(int x, int y, int width, int height)
Generates a random point within the specified rectangle area.- Parameters:
x
- the x-coordinate of the rectangle's top-left cornery
- the y-coordinate of the rectangle's top-left cornerwidth
- the width of the rectangleheight
- the height of the rectangle- Returns:
- a random point within the rectangle, or (-1, -1) if the rectangle has invalid dimensions
-
generateRandomPoint
public static java.awt.Point generateRandomPoint(net.eternalclient.api.data.geometry.SimplePolygon polygon)
Generates a random point within the bounds of the given polygon.- Parameters:
polygon
- the SimplePolygon object to generate the random point within- Returns:
- a random Point object within the polygon, or null if 20 attempts fail
-
getCenterOfPolygon
public static java.awt.Point getCenterOfPolygon(net.eternalclient.api.data.geometry.SimplePolygon pg)
Calculates and returns the center point of a polygon.- Parameters:
pg
- the simple polygon- Returns:
- the center point of the polygon
-
generateRandomPoint
public static java.awt.Point generateRandomPoint(java.awt.Polygon[] polygon)
Generates a random Point within the bounds of the given polygons and returns it.- Parameters:
polygon
- an array of polygons- Returns:
- a random Point within the polygons' bounds, or null if unable to generate a valid point after 20 attempts
-
generateRandomPoint
public static java.awt.Point generateRandomPoint(java.awt.Polygon polygon)
Generates a random point within the given polygon.- Parameters:
polygon
- the polygon to generate a random point within- Returns:
- a random point within the polygon, or null if unable to generate a point after 20 attempts
-
getCenterOfPolygon
public static java.awt.Point getCenterOfPolygon(java.awt.Polygon pg)
Returns the center point of a polygon.- Parameters:
pg
- the polygon input- Returns:
- the center point of the polygon
-
getPolygonArea
public static double getPolygonArea(java.awt.Point[] polygon, int N)
Calculates the area of a polygon given its vertices.- Parameters:
polygon
- an array of Point objects representing the vertices of the polygonN
- the number of vertices in the polygon- Returns:
- the area of the polygon
-
contains
public static boolean contains(java.awt.Rectangle a, java.awt.Rectangle b)
Checks if Rectangle b is completely contained within Rectangle a.- Parameters:
a
- the first Rectangleb
- the second Rectangle- Returns:
- true if b is contained within a, false otherwise
-
-