Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Calculations

        public Calculations()
    • 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 number
        max - 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 bound
        upper - 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 distribution
        shape - 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 distribution
        sigma - 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 population
        numberOfSuccesses - the number of successes in the population
        sampleSize - 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 distribution
        scale - 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 point
        y1 - the y-coordinate of the first point
        x2 - the x-coordinate of the second point
        y2 - 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 tile
        b - 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 rectangle
        y - the y-coordinate of the top left corner of the rectangle
        width - the width of the rectangle
        height - 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 corner
        y - the y-coordinate of the rectangle's top-left corner
        width - the width of the rectangle
        height - 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 polygon
        N - 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 Rectangle
        b - the second Rectangle
        Returns:
        true if b is contained within a, false otherwise