class Floats
package thx
Floats
contains helper methods to work with Float
values.
Static variables
staticinline read onlyEPSILON:Float = 1e-9
Constant value employed to see if two Float
values are very close.
Static methods
staticangleDifference (a:Float, b:Float, turn:Float = 360.0):Float
Returns the angular distance between 2 angles.
staticcanParse (s:String):Bool
canParse
checks if a string value can be safely converted into a Float
value.
staticinline clamp (v:Float, min:Float, max:Float):Float
clamp
restricts a value within the specified range.
trace(1.3.clamp(0, 1)); // prints 1
trace(0.8.clamp(0, 1)); // prints 0.8
trace(-0.5.clamp(0, 1)); // prints 0.0
staticinline clampSym (v:Float, max:Float):Float
Like clamp but you only pass one argument (max
) that is used as the upper limit
and the opposite (additive inverse or -max
) as the lower limit.
staticinline compare (a:Float, b:Float):Int
It returns the comparison value (an integer number) between two float
values.
staticfloorTo (f:Float, decimals:Int):Float
Rounds a number down to the specified number of decimals.
staticinterpolate (f:Float, a:Float, b:Float):Float
interpolate
returns a value between a
and b
for any value of f
between 0 and 1.
staticinterpolateAngle (f:Float, a:Float, b:Float, turn:Float = 360):Float
Interpolates values in a polar coordinate system looking for the narrowest delta angle.
It can be either clock-wise or counter-clock-wise.
staticinterpolateAngleCCW (f:Float, a:Float, b:Float, turn:Float = 360):Float
Interpolates values in a polar coordinate system always in counter-clock-wise direction.
staticinterpolateAngleCW (f:Float, a:Float, b:Float, turn:Float = 360):Float
Interpolates values in a polar coordinate system always in clock-wise direction.
staticinterpolateAngleWidest (f:Float, a:Float, b:Float, turn:Float = 360):Float
Interpolates values in a polar coordinate system looking for the wideset delta angle.
It can be either clock-wise or counter-clock-wise.
staticinline nearEqualAngles (a:Float, b:Float, turn:Float = 360.0, tollerance:Float = EPSILON):Bool
Float numbers can sometime introduce tiny errors even for simple operations.
nearEqualAngles
compares two angles (default is 360deg) using a tiny
tollerance (last optional argument). By default the tollerance is defined as
EPSILON
.
staticnearEquals (a:Float, b:Float, tollerance:Float = EPSILON):Bool
Float numbers can sometime introduce tiny errors even for simple operations.
nearEquals
compares two floats using a tiny tollerance (last optional
argument). By default it is defined as EPSILON
.
staticinline nearZero (n:Float, tollerance:Float = EPSILON):Bool
nearZero
finds if the passed number is zero or very close to it. By default
EPSILON
is used as the tollerance value.
staticinline toFloat (s:String):Float
Alias for parse, mainly for disambiguation with other parses using mega Thx.
staticwrap (v:Float, min:Float, max:Float):Float
Passed two boundaries values (min
, max
), wrap
ensures that the passed value v
will
be included in the boundaries. If the value exceeds max
, the value is reduced by min
repeatedely until it falls within the range. Similar and inverted treatment is performed if
the value is below min
.
staticwrapCircular (v:Float, max:Float):Float
Similar to wrap
, it works for numbers between 0 and max
.