Class Utils
public static class Utils
- Inheritance
-
Utils
- Inherited Members
Methods
AngleDifference(double, double)
Returns the difference between the two angles,
in range of -PI, PI.
When from and to are opposite,
returns -PI if from is smaller than to,
or PI otherwise.
public static double AngleDifference(double from, double to)
Parameters
Returns
- double
The difference between the two angles.
AngleDifference(float, float)
Returns the difference between the two angles,
in range of -PI, PI.
When from and to are opposite,
returns -PI if from is smaller than to,
or PI otherwise.
public static float AngleDifference(float from, float to)
Parameters
Returns
- float
The difference between the two angles.
Bezier(double, double, double, double, double)
Returns the point at the given t on a one-dimensional Bezier curve defined by
the given control1, control2, and end points.
public static double Bezier(double start, double control1, double control2, double end, double t)
Parameters
startdoubleThe start value for the interpolation.
control1doubleControl point that defines the bezier curve.
control2doubleControl point that defines the bezier curve.
enddoubleThe destination value for the interpolation.
tdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
Bezier(float, float, float, float, float)
Returns the point at the given t on a one-dimensional Bezier curve defined by
the given control1, control2, and end points.
public static float Bezier(float start, float control1, float control2, float end, float t)
Parameters
startfloatThe start value for the interpolation.
control1floatControl point that defines the bezier curve.
control2floatControl point that defines the bezier curve.
endfloatThe destination value for the interpolation.
tfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
BezierDerivative(double, double, double, double, double)
Returns the derivative at the given t on a one dimensional Bezier curve defined by
the given control1, control2, and end points.
public static double BezierDerivative(double start, double control1, double control2, double end, double t)
Parameters
startdoubleThe start value for the interpolation.
control1doubleControl point that defines the bezier curve.
control2doubleControl point that defines the bezier curve.
enddoubleThe destination value for the interpolation.
tdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
BezierDerivative(float, float, float, float, float)
Returns the derivative at the given t on a one dimensional Bezier curve defined by
the given control1, control2, and end points.
public static float BezierDerivative(float start, float control1, float control2, float end, float t)
Parameters
startfloatThe start value for the interpolation.
control1floatControl point that defines the bezier curve.
control2floatControl point that defines the bezier curve.
endfloatThe destination value for the interpolation.
tfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
Cubic(double, double, double, double, double)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
public static double Cubic(double from, double to, double pre, double post, double weight)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
predoubleThe value which before "from" value for interpolation.
postdoubleThe value which after "to" value for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
Cubic(float, float, float, float, float)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
public static float Cubic(float from, float to, float pre, float post, float weight)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
prefloatThe value which before "from" value for interpolation.
postfloatThe value which after "to" value for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
CubicAngle(double, double, double, double, double)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight with pre and post values.
See also LerpAngle(double, double, double).
public static double CubicAngle(double from, double to, double pre, double post, double weight)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
predoubleThe value which before "from" value for interpolation.
postdoubleThe value which after "to" value for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
CubicAngle(float, float, float, float, float)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight with pre and post values.
See also LerpAngle(float, float, float).
public static float CubicAngle(float from, float to, float pre, float post, float weight)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
prefloatThe value which before "from" value for interpolation.
postfloatThe value which after "to" value for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
CubicAngleInTime(double, double, double, double, double, double, double, double)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight with pre and post values.
See also LerpAngle(double, double, double).
It can perform smoother interpolation than
CubicAngle(double, double, double, double, double)
by the time values.
public static double CubicAngleInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
predoubleThe value which before "from" value for interpolation.
postdoubleThe value which after "to" value for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toTdoublepreTdoublepostTdouble
Returns
- double
The resulting value of the interpolation.
CubicAngleInTime(float, float, float, float, float, float, float, float)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight with pre and post values.
See also LerpAngle(float, float, float).
It can perform smoother interpolation than
CubicAngle(float, float, float, float, float)
by the time values.
public static float CubicAngleInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
prefloatThe value which before "from" value for interpolation.
postfloatThe value which after "to" value for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toTfloatpreTfloatpostTfloat
Returns
- float
The resulting value of the interpolation.
CubicInTime(double, double, double, double, double, double, double, double)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
It can perform smoother interpolation than
Cubic(double, double, double, double, double)
by the time values.
public static double CubicInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
predoubleThe value which before "from" value for interpolation.
postdoubleThe value which after "to" value for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toTdoublepreTdoublepostTdouble
Returns
- double
The resulting value of the interpolation.
CubicInTime(float, float, float, float, float, float, float, float)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
It can perform smoother interpolation than
Cubic(float, float, float, float, float)
by the time values.
public static float CubicInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
prefloatThe value which before "from" value for interpolation.
postfloatThe value which after "to" value for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toTfloatpreTfloatpostTfloat
Returns
- float
The resulting value of the interpolation.
Ease(double, double)
Easing function, based on exponent. The curve values are:
0 is constant, 1 is linear, 0 to 1 is ease-in, 1 or more is ease-out.
Negative values are in-out/out-in.
public static double Ease(double s, double curve)
Parameters
sdoubleThe value to ease.
curvedouble0is constant,1is linear,0to1is ease-in,1or more is ease-out.
Returns
- double
The eased value.
Ease(float, float)
Easing function, based on exponent. The curve values are:
0 is constant, 1 is linear, 0 to 1 is ease-in, 1 or more is ease-out.
Negative values are in-out/out-in.
public static float Ease(float s, float curve)
Parameters
sfloatThe value to ease.
curvefloat0is constant,1is linear,0to1is ease-in,1or more is ease-out.
Returns
- float
The eased value.
InverseLerp(double, double, double)
Returns a normalized value considering the given range. This is the opposite of Lerp(double, double, double).
public static double InverseLerp(double from, double to, double weight)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
weightdoubleThe interpolated value.
Returns
- double
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weightis betweenfromandto(inclusive).
InverseLerp(float, float, float)
Returns a normalized value considering the given range. This is the opposite of Lerp(float, float, float).
public static float InverseLerp(float from, float to, float weight)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
weightfloatThe interpolated value.
Returns
- float
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weightis betweenfromandto(inclusive).
IsEqualApprox(double, double)
Returns true if a and b are approximately equal
to each other.
The comparison is done using a tolerance calculation with Epsilon.
public static bool IsEqualApprox(double a, double b)
Parameters
Returns
IsEqualApprox(float, float)
Returns true if a and b are approximately equal
to each other.
The comparison is done using a tolerance calculation with Epsilon.
public static bool IsEqualApprox(float a, float b)
Parameters
Returns
IsEqualApprox(float, float, float)
Returns true if a and b are approximately equal
to each other.
The comparison is done using a tolerance calculation with Epsilon.
public static bool IsEqualApprox(float a, float b, float radius)
Parameters
Returns
IsZeroApprox(double)
Returns true if s is zero or almost zero.
The comparison is done using a tolerance calculation with Epsilon.
This method is faster than using IsEqualApprox(double, double) with one value as zero.
public static bool IsZeroApprox(double s)
Parameters
sdoubleThe value to check.
Returns
IsZeroApprox(float)
Returns true if s is zero or almost zero.
The comparison is done using a tolerance calculation with Epsilon.
This method is faster than using IsEqualApprox(float, float) with one value as zero.
public static bool IsZeroApprox(float s)
Parameters
sfloatThe value to check.
Returns
Lerp(double, double, double)
Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(double, double, double).
public static double Lerp(double from, double to, double weight)
Parameters
fromdoubleThe start value for interpolation.
todoubleThe destination value for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
Lerp(float, float, float)
Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(float, float, float).
public static float Lerp(float from, float to, float weight)
Parameters
fromfloatThe start value for interpolation.
tofloatThe destination value for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
LerpAngle(double, double, double)
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to Lerp(double, double, double), but interpolates correctly when the angles wrap around Tau.
public static double LerpAngle(double from, double to, double weight)
Parameters
fromdoubleThe start angle for interpolation.
todoubleThe destination angle for interpolation.
weightdoubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting angle of the interpolation.
LerpAngle(float, float, float)
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to Lerp(float, float, float), but interpolates correctly when the angles wrap around Tau.
public static float LerpAngle(float from, float to, float weight)
Parameters
fromfloatThe start angle for interpolation.
tofloatThe destination angle for interpolation.
weightfloatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting angle of the interpolation.
MoveToward(double, double, double)
Moves from toward to by the delta value.
Use a negative delta value to move away.
public static double MoveToward(double from, double to, double delta)
Parameters
fromdoubleThe start value.
todoubleThe value to move towards.
deltadoubleThe amount to move by.
Returns
- double
The value after moving.
MoveToward(float, float, float)
Moves from toward to by the delta value.
Use a negative delta value to move away.
public static float MoveToward(float from, float to, float delta)
Parameters
Returns
- float
The value after moving.
Remap(double, double, double, double, double)
Maps a value from [inFrom, inTo]
to [outFrom, outTo].
public static double Remap(double value, double inFrom, double inTo, double outFrom, double outTo)
Parameters
valuedoubleThe value to map.
inFromdoubleThe start value for the input interpolation.
inTodoubleThe destination value for the input interpolation.
outFromdoubleThe start value for the output interpolation.
outTodoubleThe destination value for the output interpolation.
Returns
- double
The resulting mapped value mapped.
Remap(float, float, float, float, float)
Maps a value from [inFrom, inTo]
to [outFrom, outTo].
public static float Remap(float value, float inFrom, float inTo, float outFrom, float outTo)
Parameters
valuefloatThe value to map.
inFromfloatThe start value for the input interpolation.
inTofloatThe destination value for the input interpolation.
outFromfloatThe start value for the output interpolation.
outTofloatThe destination value for the output interpolation.
Returns
- float
The resulting mapped value mapped.
RotateToward(double, double, double)
Rotates from toward to by the delta amount. Will not go past to.
Similar to MoveToward(double, double, double) but interpolates correctly when the angles wrap around Tau.
If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.
public static double RotateToward(double from, double to, double delta)
Parameters
fromdoubleThe start angle.
todoubleThe angle to move towards.
deltadoubleThe amount to move by.
Returns
- double
The angle after moving.
RotateToward(float, float, float)
Rotates from toward to by the delta amount. Will not go past to.
Similar to MoveToward(float, float, float) but interpolates correctly when the angles wrap around Tau.
If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.
public static float RotateToward(float from, float to, float delta)
Parameters
Returns
- float
The angle after moving.
Snapped(double, double)
Snaps float value s to a given step.
This can also be used to round a floating point number to an arbitrary number of decimals.
public static double Snapped(double s, double step)
Parameters
Returns
- double
The snapped value.
Snapped(float, float)
Snaps float value s to a given step.
This can also be used to round a floating point number to an arbitrary number of decimals.
public static float Snapped(float s, float step)
Parameters
Returns
- float
The snapped value.
StepDecimals(double)
Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
public static int StepDecimals(double step)
Parameters
stepdoubleThe input value.
Returns
- int
The position of the first non-zero digit.