Class MathUtil

java.lang.Object
com.palmergames.util.MathUtil

public class MathUtil extends Object
  • Constructor Details

    • MathUtil

      public MathUtil()
  • Method Details

    • sqr

      public static double sqr(double a)
      Compute the square of a number. NOTE: This function does not perform any safe-checks against overflow / underflow.
      Parameters:
      a - Number to square
      Returns:
      Square of the parameter passed in.
    • distanceSquared

      public static double distanceSquared(double a, double b)
      Compute the pythagorean square distance based on the formula a^2 + b^2 = c^2.
      Parameters:
      a - Length of an axis
      b - Length of an axis
      Returns:
      The distance squared between two axis (which is c^2)
    • distance

      public static double distance(double a, double b)
      Compute the shortest distance between two perpendicular lines.
      Parameters:
      a - Length of a line
      b - Length of another line
      Returns:
      the shortest distance between two lines
    • distance

      public static double distance(double x1, double x2, double y1, double y2)
      Compute the shortest distance between two points in a 2d grid. Uses pythagorean formula.
      Parameters:
      x1 - X-coord of point 1
      x2 - X-coord of point 2
      y1 - Y-coord of point 1
      y2 - Y-coord of point 2
      Returns:
      shortest distance between two points.
    • distance

      public static double distance(Coord coord1, Coord coord2)
    • getDoubleOrThrow

      public static double getDoubleOrThrow(String input) throws TownyException
      Throws:
      TownyException
    • getIntOrThrow

      public static int getIntOrThrow(String input) throws TownyException
      Throws:
      TownyException
    • getPositiveIntOrThrow

      public static int getPositiveIntOrThrow(String input) throws TownyException
      Throws:
      TownyException