Package com.palmergames.util
Class MathUtil
java.lang.Object
com.palmergames.util.MathUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
distance
(double a, double b) Compute the shortest distance between two perpendicular lines.static double
distance
(double x1, double x2, double y1, double y2) Compute the shortest distance between two points in a 2d grid.static double
static double
distanceSquared
(double a, double b) Compute the pythagorean square distance based on the formula a^2 + b^2 = c^2.static double
getDoubleOrThrow
(String input) static int
getIntOrThrow
(String input) static int
getPositiveIntOrThrow
(String input) static double
sqr
(double a) Compute the square of a number.
-
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 axisb
- 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 lineb
- 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 1x2
- X-coord of point 2y1
- Y-coord of point 1y2
- Y-coord of point 2- Returns:
- shortest distance between two points.
-
distance
-
getDoubleOrThrow
- Throws:
TownyException
-
getIntOrThrow
- Throws:
TownyException
-
getPositiveIntOrThrow
- Throws:
TownyException
-