Package org.texastorque.torquelib.util
Class TorqueMath
java.lang.Object
org.texastorque.torquelib.util.TorqueMath
A static class of useful math utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final double
Takes the average of a list of numbers.static final <T> double
average
(List<T> list, ToDoubleFunction<T> function) Takes the average of the mapped functional outputs on a list of objects.static final double
constrain
(double n, double a) Return contrained value n between a and -astatic final double
constrain
(double n, double a, double b) Return contrained value n between a and bstatic final boolean
constrained
(double n, double a, double b) Check if a number is inside of a certain bounds (inclusive).static final double
linearConstraint
(double requestedSpeed, double currentPosition, double minPosition, double maxPosition) Returns either requestedSpeed or zero depending on if it will keep currentPosition between minPosition and maxPosition.static final void
static final double
powPreserveSign
(double a, double b) Power with sign the sign of a.static final boolean
prime
(long n) Check if an integer (as a long) is prime or not.static final long
random
(long high) This method will return an integer (as a long) in the range [1, high].static final long
random
(long low, long high) This method will return an integer (as a long) in the range [low, high].static final double[]
range
(double min, double max) Returns an array with range of [min, max] and steps of 1.static final double[]
range
(double min, double max, double increment) Returns an array with range of [min, max] and steps of increment.static final double
round
(double num, long dec) Round number to a place value.static final double
scaledLinearDeadband
(double value, double scale) Scaled linear deadbandstatic final double
scaledPowerDeadband
(double value, double roundness, double scale) Scaled linear deadbandstatic final double
scaledQuadraticDeadband
(double value, double scale) Scaled linear deadbandstatic final boolean
toleranced
(double x, double t) Check if a number is within a tolerance of 0.static final boolean
toleranced
(double x, double y, double t) Check if a number is within a tolerance of another number.static final boolean
toleranced
(double x, double y, double u, double l) Check if a number is within a tolerance of another number with independent sides.static final boolean
toleranced2
(double x, double y, double t) Another approach to 3 param toleranced, the one used in 2 param toleranced.
-
Method Details
-
constrain
public static final double constrain(double n, double a) Return contrained value n between a and -a- Parameters:
n
- Value to be constraineda
- Value to constrain by- Returns:
- The constrained value of n
-
constrain
public static final double constrain(double n, double a, double b) Return contrained value n between a and b- Parameters:
n
- Value to be constraineda
- Value to constrain the value over, the minimum valueb
- Value to constrain the value under, the maximum value- Returns:
- The constrained value of n
-
powPreserveSign
public static final double powPreserveSign(double a, double b) Power with sign the sign of a.- Parameters:
a
- The baseb
- The exponent- Returns:
- power with the sign of a.
-
scaledLinearDeadband
public static final double scaledLinearDeadband(double value, double scale) Scaled linear deadband- Parameters:
value
- Value to be deadbandedscale
- The minimum value
-
scaledPowerDeadband
public static final double scaledPowerDeadband(double value, double roundness, double scale) Scaled linear deadband- Parameters:
value
- Value to be deadbandedroundness
- The roundness (exponent) of the deadbandscale
- The minimum value
-
scaledQuadraticDeadband
public static final double scaledQuadraticDeadband(double value, double scale) Scaled linear deadband- Parameters:
valye
- Value to be deadbandedscale
- The minimum value
-
round
public static final double round(double num, long dec) Round number to a place value.- Parameters:
num
- Number to round.dec
- Place value (decimal places) to round to.- Returns:
- The rounded number
-
prime
public static final boolean prime(long n) Check if an integer (as a long) is prime or not.- Parameters:
params
- The number to check for prime.- Returns:
- If the numbers if prime or not.
-
constrained
public static final boolean constrained(double n, double a, double b) Check if a number is inside of a certain bounds (inclusive).- Parameters:
n
- The number to check.a
- The lower bound.b
- The upper bound.- Returns:
- If the number is inside the bounds.
-
toleranced
public static final boolean toleranced(double x, double t) Check if a number is within a tolerance of 0.- Parameters:
x
- One number.t
- The tolerance.- Returns:
- If the numbers are within tolerance.
-
toleranced
public static final boolean toleranced(double x, double y, double t) Check if a number is within a tolerance of another number.- Parameters:
x
- One number.y
- The other number.t
- The tolerance.- Returns:
- If the numbers are within tolerance.
-
toleranced2
public static final boolean toleranced2(double x, double y, double t) Another approach to 3 param toleranced, the one used in 2 param toleranced. Should do the same thing?- Parameters:
x
- One number.y
- The other number.t
- The tolerance.- Returns:
- If the numbers are within tolerance.
-
toleranced
public static final boolean toleranced(double x, double y, double u, double l) Check if a number is within a tolerance of another number with independent sides.- Parameters:
x
- One number.y
- The other number.u
- The upper tolerance.l
- The lower tolerance.- Returns:
- If the numbers are within tolerance.
-
linearConstraint
public static final double linearConstraint(double requestedSpeed, double currentPosition, double minPosition, double maxPosition) Returns either requestedSpeed or zero depending on if it will keep currentPosition between minPosition and maxPosition.- Parameters:
requestedSpeed
- The requested speed.currentPosition
- The current position.minPosition
- The minimum position.maxPosition
- The maximum position.- Returns:
- The desired speed.
-
range
public static final double[] range(double min, double max, double increment) Returns an array with range of [min, max] and steps of increment.- Parameters:
min
- Min value (inclusive).max
- Max value (inclusive).increment
- Step increment.- Returns:
- The array in range.
-
range
public static final double[] range(double min, double max) Returns an array with range of [min, max] and steps of 1.- Parameters:
min
- Min value (inclusive).max
- Max value (inclusive).- Returns:
- The array in range.
-
random
public static final long random(long high) This method will return an integer (as a long) in the range [1, high].- Parameters:
high
- The upper bound of range the number could be from.- Returns:
- The randomly generated number.
-
random
public static final long random(long low, long high) This method will return an integer (as a long) in the range [low, high].- Parameters:
low
- The lower bound range the number could be from.high
- The upper bound of range the number could be from.- Returns:
- The randomly generated number.
-
average
Takes the average of a list of numbers.- Parameters:
list
- The list of numbers.- Returns:
- The average of the list.
-
average
Takes the average of the mapped functional outputs on a list of objects.- Parameters:
list
- The list of numbers.function
- The function to generate the number.- Returns:
- The average of the list.
-
main
- Throws:
Exception
-