A collection of extension methods for Floats
Usage:
- use this extension by adding this where you normally import modules:
using zero.extensions.FloatExt;
- now you can use any of these functions on different arrays:
100.get_random(50); // gets a float between 50 and 100
- or use all of the extensions in this library by adding:
using zero.extensions.Tools;
Static methods
staticinlineclamp (n:Float, min:Float, max:Float):Float
Clamps input value between the minimum and maximum values. ex. 120.clamp(0, 100) = 100
* @param n input value
* @param min minimum value
* @param max maximum value
* @return Float
staticinlinecycle (n:Float, min:Float, max:Float):Float
Loops input value through a range of minimum and maximum values. ex. 150.cycle(0, 100) = 50
* @param n input value
* @param min minimum value (beginning) of cycle
* @param max maximum value (end) of cycle
* @return Float
staticinlinedeg_to_rad (deg:Float):Float
Returns the radian equivalent to the input degree. ex. 180.deg_to_rad() == Math.PI = true
* @param deg input degree
* @return Float
staticinlinedegrees_between (a1:Float, a2:Float):Float
Returns the degrees between two angles. ex. 20.degrees_between(-20) = 40
* @param a1 first angle in degrees
* @param a2 second angle in degrees
* @return Float
staticinlineget_random (def_max:Float, min:Float = 0, ?max:Float):Float
gets a random number from a range of numbers. ex. 10.get_random() = a number between 0 and 10
* @param def_max input value is the assumed (default) maximum number in the desired range
* @param min the minimum number in the desired range
* @param max overrides input number for the maximum number in the desired range (input number is ignored)
* @return Float
staticinlineget_relative_degree (n:Float):Float
Returns a degree between 0 and 360. ex. (-10).get_relative_degree() = 350
* @param n input angle
* @return Float
staticinlinehalf (n:Float):Float
returns half of the input
* @param n input float
* @return Float return n * 0.5
staticinlinelerp (t:Float, a:Float, b:Float):Float
linear interpolation. ex. 2.lerp(0, 100) = 200;
* @param t input value
* @param a lerp range first index
* @param b lerp range second index
* @return Float
staticinlinemap (t:Float, a0:Float, b0:Float, a1:Float, b1:Float):Float
Maps a value from one range of values to another, ex: 1.map(0, 2, 20, 30) = 25
* @param t input value
* @param a0 0 index for first range
* @param b0 1 index for first range
* @param a1 0 index for second range
* @param a1 1 index for second range
* @return Float
staticinlinenorm (t:Float, a:Float, b:Float):Float
returns a norm value t of a through b. ex. 10.norm(0, 100) = 0.1
* @param t input value
* @param a norm range first index
* @param b norm range second index
* @return Float
staticinlinenormalize (n:Float, places:Int):Float
returns input value with removed decimal places after places input. ex. 1.135908.normalize(2) = 1.14
* @param n input value
* @param places how many places
* @return Float
staticinlinequarter (n:Float):Float
returns quarter of the input
* @param n input float
* @return Float return n * 0.25
staticinlinerad_to_deg (rad:Float):Float
Returns the degree equivalent to the input radian. ex. Math.PI.rad_to_deg() = 180
* @param rad input radian
* @return Float
staticinlinesign_of (n:Float):Int
returns the sign (-1, 0, 1) of a number
* @param n input value
* @return Int
staticinlinesnap_to_grid (n:Float, grid_size:Float, offset:Float = 0, floor:Bool = false):Float
snaps value n to a grid. ex. 21.snap_to_grid(10) = 20
* @param n input value
* @param grid_size the size of the grid
* @param offset the offset of the grid
* @param floor whether or not to use Math.floor() or Math.round(), default false (Math.round())
* @return Float
staticinlineto_color (n:Float):Color
Converts an 0xRRGGBBAA Int to a float array suitable for passing to shaders
Parameters:
n | input value |
---|
Returns:
Color
staticinlineto_int (n:Float):Int
returns an Int in the place of a Float. ex. 10.1.to_int() = 10
* @param n input Float
* @return Int
staticinlinetranslate_to_nearest_angle (a1:Float, a2:Float):Float
Returns a degree that has the same relative angle as the input angle, but is closest to the second angle. ex. 350.translate_to_nearest_angle(10) = 20
Parameters:
a1 | input angle in degrees |
---|---|
a2 | second angle in degrees |
Returns:
Float
staticinlinevector_from_angle (a:Float, len:Float):Vec2
returns a Vector describing a vector of given angle and length. ex. 270.vector_from_angle(100) == new Vector(0, -100) = true
* @param a the angle in degrees of desired vector
* @param len the length of the desired vector
* @return Vector