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
start
doubleThe start value for the interpolation.
control1
doubleControl point that defines the bezier curve.
control2
doubleControl point that defines the bezier curve.
end
doubleThe destination value for the interpolation.
t
doubleA 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
start
floatThe start value for the interpolation.
control1
floatControl point that defines the bezier curve.
control2
floatControl point that defines the bezier curve.
end
floatThe destination value for the interpolation.
t
floatA 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
start
doubleThe start value for the interpolation.
control1
doubleControl point that defines the bezier curve.
control2
doubleControl point that defines the bezier curve.
end
doubleThe destination value for the interpolation.
t
doubleA 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
start
floatThe start value for the interpolation.
control1
floatControl point that defines the bezier curve.
control2
floatControl point that defines the bezier curve.
end
floatThe destination value for the interpolation.
t
floatA 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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA 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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA 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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA 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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA 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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
doublepreT
doublepostT
double
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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
floatpreT
floatpostT
float
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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
doublepreT
doublepostT
double
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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
floatpreT
floatpostT
float
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
s
doubleThe value to ease.
curve
double0
is constant,1
is linear,0
to1
is ease-in,1
or 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
s
floatThe value to ease.
curve
float0
is constant,1
is linear,0
to1
is ease-in,1
or 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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
weight
doubleThe interpolated value.
Returns
- double
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weight
is betweenfrom
andto
(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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
weight
floatThe interpolated value.
Returns
- float
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weight
is betweenfrom
andto
(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
s
doubleThe 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
s
floatThe 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
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
weight
doubleA 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
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
weight
floatA 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
from
doubleThe start angle for interpolation.
to
doubleThe destination angle for interpolation.
weight
doubleA 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
from
floatThe start angle for interpolation.
to
floatThe destination angle for interpolation.
weight
floatA 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
from
doubleThe start value.
to
doubleThe value to move towards.
delta
doubleThe 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
value
doubleThe value to map.
inFrom
doubleThe start value for the input interpolation.
inTo
doubleThe destination value for the input interpolation.
outFrom
doubleThe start value for the output interpolation.
outTo
doubleThe 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
value
floatThe value to map.
inFrom
floatThe start value for the input interpolation.
inTo
floatThe destination value for the input interpolation.
outFrom
floatThe start value for the output interpolation.
outTo
floatThe 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
from
doubleThe start angle.
to
doubleThe angle to move towards.
delta
doubleThe 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
step
doubleThe input value.
Returns
- int
The position of the first non-zero digit.