Class MathUtils
- Since:
- 1.0
- Author:
- LazyWizard
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic floatclamp(float toClamp, float min, float max) Clamps aFloat, ensuring it falls within a given range.static intclamp(int toClamp, int min, int max) Clamps anInteger, ensuring it falls within a given range.static floatclampAngle(float angle) Clamps an angle within 360 degrees (ex: 400 degrees becomes 40 degrees).static booleanequals(float a, float b) Tests for near-equality of floating point numbers.static floatgetDistance(SectorEntityToken token1, SectorEntityToken token2) Returns the distance between twoSectorEntityTokens, taking interaction radii into account.static floatgetDistance(SectorEntityToken token, Vector2f loc) Returns the distance between aSectorEntityTokenand aVector2f, taking interaction radius into account.static floatgetDistance(CombatEntityAPI entity1, CombatEntityAPI entity2) Returns the distance between twoCombatEntityAPIs, taking collision radii into account.static floatgetDistance(CombatEntityAPI entity, Vector2f loc) Returns the distance between aCombatEntityAPIand aVector2f, taking collision radius into account.static floatgetDistance(Vector2f loc1, Vector2f loc2) Returns the distance between twoVector2fs.static floatgetDistanceSquared(SectorEntityToken token1, SectorEntityToken token2) Returns the distance squared between twoSectorEntityTokens, taking interaction radii into account.static floatgetDistanceSquared(SectorEntityToken token, Vector2f loc) Returns the distance squared between aSectorEntityTokenand aVector2f, taking interaction radius into account.static floatgetDistanceSquared(CombatEntityAPI entity1, CombatEntityAPI entity2) Returns the distance squared between twoCombatEntityAPIs, taking collision radii into account.static floatgetDistanceSquared(CombatEntityAPI entity, Vector2f loc) Returns the distance squared between aCombatEntityAPIand aVector2f, taking collision radius into account.static floatgetDistanceSquared(Vector2f loc1, Vector2f loc2) Returns the distance squared between twoVector2fs (avoids a costly sqrt()).getEquidistantPointsInsideCircle(Vector2f center, float radius, float spaceBetweenPoints) static Vector2fgetMidpoint(Vector2f point1, Vector2f point2) Returns the point exactly between two other points.static Vector2fgetNearestPointOnLine(Vector2f source, Vector2f lineStart, Vector2f lineEnd) Given a point and a line, returns the nearest point on said line to that point.static Vector2fReturns a point along the circumference of a circle at the given angle.static Vector2fgetPointOnCircumference(Vector2f center, float radius, float angle) Returns a point along the circumference of a circle at the given angle.getPointsAlongCircumference(Vector2f center, float radius, int numPoints, float angleOffset) Returns an evenly distributedListof points along a circle's circumference.static RandomReturns the random number generator used by LazyLib's methods.static floatgetRandomNumberInRange(float min, float max) Returns a random float within a given range.static intgetRandomNumberInRange(int min, int max) Returns a random integer within a given range.static Vector2fgetRandomPointInCircle(Vector2f center, float radius) Returns a random point inside of a circle with uniform distribution.static Vector2fgetRandomPointInCone(Vector2f center, float radius, float minAngle, float maxAngle) Returns a random point inside of a circular sector (2d cone) with uniform distribution.static Vector2fgetRandomPointOnCircumference(Vector2f center, float radius) Returns a random point along the circumference of a circle.static Vector2fgetRandomPointOnLine(Vector2f lineStart, Vector2f lineEnd) Returns a random point along the line between twoVector2fs.static floatgetShortestRotation(float currAngle, float destAngle) Returns the direction and length of the quickest rotation between two angles.static booleanisPointOnLine(Vector2f point, Vector2f lineStart, Vector2f lineEnd) Check if a point is along the line between twoVector2fs.static booleanisPointWithinCircle(Vector2f point, Vector2f center, float radius) Checks whether a point is on or within the bounds of a circle.static booleanisWithinRange(SectorEntityToken token1, SectorEntityToken token2, float range) Check if twoSectorEntityTokens are within a certain distance of each other, taking interaction radii into account.static booleanisWithinRange(SectorEntityToken token, Vector2f loc, float range) Check if aSectorEntityTokenis within a certain distance of a location, taking interaction radius into account.static booleanisWithinRange(CombatEntityAPI entity1, CombatEntityAPI entity2, float range) Check if twoCombatEntityAPIs are within a certain distance of each other, taking collision radii into account.static booleanisWithinRange(CombatEntityAPI entity, Vector2f loc, float range) Check if aCombatEntityAPIis within a certain distance of a location, taking collision radius into account.static booleanisWithinRange(Vector2f loc1, Vector2f loc2, float range) Check if two objects are within a certain distance of each other.
-
Field Details
-
FPI
public static final float FPI- See Also:
-
FTAU
public static final float FTAU- See Also:
-
-
Method Details
-
getDistance
Returns the distance between twoSectorEntityTokens, taking interaction radii into account.- Since:
- 1.0
- See Also:
-
getDistance
Returns the distance between aSectorEntityTokenand aVector2f, taking interaction radius into account.- Since:
- 1.1
- See Also:
-
getDistance
Returns the distance between twoCombatEntityAPIs, taking collision radii into account.- Since:
- 1.0
- See Also:
-
getDistance
Returns the distance between aCombatEntityAPIand aVector2f, taking collision radius into account.- Since:
- 1.0
- See Also:
-
getDistance
Returns the distance between twoVector2fs.For comparing distances, it is vastly more efficient to use
getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f).- Returns:
- The distance between the two vectors.
- Since:
- 1.0
-
getDistanceSquared
Returns the distance squared between twoSectorEntityTokens, taking interaction radii into account.With the addition of collision radius checking, there's no way to avoid calculating the square root.
getDistance(SectorEntityToken, SectorEntityToken)will be just as efficient.- Since:
- 1.0
- See Also:
-
getDistanceSquared
Returns the distance squared between aSectorEntityTokenand aVector2f, taking interaction radius into account.With the addition of collision radius checking, there's no way to avoid calculating the square root.
getDistance(SectorEntityToken, Vector2f)will be just as efficient.- Since:
- 1.1
- See Also:
-
getDistanceSquared
Returns the distance squared between twoCombatEntityAPIs, taking collision radii into account.With the addition of collision radius checking, there's no way to avoid calculating the square root.
getDistance(CombatEntityAPI, CombatEntityAPI)will be just as efficient.- Since:
- 1.0
- See Also:
-
getDistanceSquared
Returns the distance squared between aCombatEntityAPIand aVector2f, taking collision radius into account.With the addition of collision radius checking, there's no way to avoid calculating the square root.
getDistance(CombatEntityAPI, Vector2f)will be just as efficient.- Since:
- 1.0
- See Also:
-
getDistanceSquared
Returns the distance squared between twoVector2fs (avoids a costly sqrt()).When comparing distances, use this function instead of
getDistance(Vector2f, Vector2f).- Returns:
- The distance squared between the two vectors.
- Since:
- 1.0
-
isWithinRange
public static boolean isWithinRange(SectorEntityToken token1, SectorEntityToken token2, float range) Check if twoSectorEntityTokens are within a certain distance of each other, taking interaction radii into account.This is vastly more efficient than comparisons using
getDistance(SectorEntityToken, SectorEntityToken), and should be used whenever possible.- Parameters:
token1- The firstSectorEntityTokento check.token2- The secondSectorEntityTokento check.range- The minimum distance betweentoken1andtoken2.- Returns:
- Whether
token1is withinrangesu oftoken2. - Since:
- 1.8
-
isWithinRange
Check if aSectorEntityTokenis within a certain distance of a location, taking interaction radius into account.This is vastly more efficient than comparisons using
getDistance(SectorEntityToken, Vector2f), and should be used whenever possible.- Parameters:
token- TheSectorEntityTokento check.loc- TheVector2fto check.range- The minimum distance betweentokenandloc.- Returns:
- Whether
tokenis withinrangesu ofloc. - Since:
- 1.8
-
isWithinRange
Check if twoCombatEntityAPIs are within a certain distance of each other, taking collision radii into account.This is vastly more efficient than comparisons using
getDistance(CombatEntityAPI, CombatEntityAPI), and should be used whenever possible.- Parameters:
entity1- The firstCombatEntityAPIto check.entity2- The secondCombatEntityAPIto check.range- The minimum distance betweenentity1andentity2.- Returns:
- Whether
entity1is withinrangesu ofentity2. - Since:
- 1.8
-
isWithinRange
Check if aCombatEntityAPIis within a certain distance of a location, taking collision radius into account.This is vastly more efficient than comparisons using
getDistance(CombatEntityAPI, Vector2f), and should be used whenever possible.- Parameters:
entity- TheCombatEntityAPIto check.loc- TheVector2fto check.range- The minimum distance betweenentityandloc.- Returns:
- Whether
entityis withinrangesu ofloc. - Since:
- 1.8
-
isWithinRange
Check if two objects are within a certain distance of each other. -
clampAngle
public static float clampAngle(float angle) Clamps an angle within 360 degrees (ex: 400 degrees becomes 40 degrees).- Parameters:
angle- The angle to be clamped.- Returns:
- A value between 0 and 360 degrees.
- Since:
- 1.2
-
clamp
public static float clamp(float toClamp, float min, float max) Clamps aFloat, ensuring it falls within a given range.- Parameters:
toClamp- TheFloatto be clamped.min- The minimum value you wish the return value to hold.max- The maximum value you wish the return value to hold.- Returns:
toClampif it falls betweenminandmax,minif it falls below, ormaxif it falls above.- Since:
- 2.3
-
clamp
public static int clamp(int toClamp, int min, int max) Clamps anInteger, ensuring it falls within a given range.- Parameters:
toClamp- TheIntegerto be clamped.min- The minimum value you wish the return value to hold.max- The maximum value you wish the return value to hold.- Returns:
toClampif it falls betweenminandmax,minif it falls below, ormaxif it falls above.- Since:
- 2.3
-
getShortestRotation
public static float getShortestRotation(float currAngle, float destAngle) Returns the direction and length of the quickest rotation between two angles.- Parameters:
currAngle- The current facing.destAngle- The facing to rotate towards.- Returns:
- The shortest distance between the two angles, in degrees.
- Since:
- 1.7
-
getMidpoint
Returns the point exactly between two other points.- Parameters:
point1- The first point.point2- The second point.- Returns:
- A
Vector2fat the midpoint of the line betweenpoint1andpoint2. - Since:
- 1.9
-
getPointOnCircumference
public static Vector2f getPointOnCircumference(@Nullable Vector2f center, float radius, float angle) Returns a point along the circumference of a circle at the given angle.- Parameters:
center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.angle- The angle, in degrees, to get the point at.- Returns:
- A
Vector2fat [@code angle} degrees along the circumference of the given circle. - Since:
- 1.0
-
getPoint
Returns a point along the circumference of a circle at the given angle. Provided as an alias forgetPointOnCircumference(Vector2f, float, float).- Parameters:
center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.angle- The angle, in degrees, to get the point at.- Returns:
- A
Vector2fatangledegrees along the circumference of the given circle. - Since:
- 2.0
- See Also:
-
getRandomPointOnCircumference
Returns a random point along the circumference of a circle.- Parameters:
center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.- Returns:
- A random point along the circumference of the given circle.
- Since:
- 1.0
- See Also:
-
getRandomPointInCircle
Returns a random point inside of a circle with uniform distribution.- Parameters:
center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.- Returns:
- A random point inside of the given circle.
- Since:
- 1.0
-
getRandomPointInCone
public static Vector2f getRandomPointInCone(@Nullable Vector2f center, float radius, float minAngle, float maxAngle) Returns a random point inside of a circular sector (2d cone) with uniform distribution.- Parameters:
center- The center point of the cone (can be null for a 0, 0 origin).radius- The radius of the cone.minAngle- The minimum angular bounds.maxAngle- The maximum angular bounds.- Returns:
- A random point inside of the given circular sector.
- Since:
- 1.7
-
getRandomPointOnLine
Returns a random point along the line between twoVector2fs.- Parameters:
lineStart- The starting point of the line.lineEnd- The end point of the line.- Returns:
- A random
Vector2falong the line betweenlineStartandlineEnd. - Since:
- 1.6
-
getPointsAlongCircumference
public static List<Vector2f> getPointsAlongCircumference(@Nullable Vector2f center, float radius, int numPoints, float angleOffset) Returns an evenly distributedListof points along a circle's circumference.- Parameters:
center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.numPoints- How many points to generate.angleOffset- The offset angle of the initial point.- Returns:
- A
ListofVector2fs that are evenly distributed along the circle's circumference. - Since:
- 1.0
-
isPointWithinCircle
Checks whether a point is on or within the bounds of a circle.- Parameters:
point- TheVector2fto check.center- The center point of the circle (can be null for a 0, 0 origin).radius- The radius of the circle.- Returns:
trueifpointis on or within the circle,falseotherwise.- Since:
- 1.0
-
isPointOnLine
Check if a point is along the line between twoVector2fs. Accurate to within 1/100 of a unit.- Parameters:
point- The point to check.lineStart- The starting point of the line.lineEnd- The end point of the line.- Returns:
trueif the point is along the line,falseotherwise.- Since:
- 1.6
-
getNearestPointOnLine
Given a point and a line, returns the nearest point on said line to that point.- Parameters:
source- The point to test distance from.lineStart- The start point of the line to check.lineEnd- The end point of the line to check.- Returns:
- The point on the line between
lineStartandlineEndnearest tosource. - Since:
- 2.3
-
getEquidistantPointsInsideCircle
public static List<Vector2f> getEquidistantPointsInsideCircle(@Nullable Vector2f center, float radius, float spaceBetweenPoints) -
getRandomNumberInRange
public static float getRandomNumberInRange(float min, float max) Returns a random float within a given range.- Parameters:
min- The minimum value to select.max- The maximum value to select.- Returns:
- A random
Floatbetweenminandmax. - Since:
- 1.4
-
getRandomNumberInRange
public static int getRandomNumberInRange(int min, int max) Returns a random integer within a given range.- Parameters:
min- The minimum value to select.max- The maximum value to select (inclusive).- Returns:
- A random
Integerbetweenminandmax, inclusive. - Since:
- 2.0
-
equals
public static boolean equals(float a, float b) Tests for near-equality of floating point numbers.- Parameters:
a- The first float to compare.b- The second float to compare.- Returns:
trueifaandbare within 99.99999% of each other,falseotherwise.
-
getRandom
Returns the random number generator used by LazyLib's methods. Useful for seed manipulation or to avoid instantiating your own.- Returns:
- The
Randominstance used by LazyLib. - Since:
- 1.5
-