Class Utils
-
- All Implemented Interfaces:
public final class Utils
-
-
Method Summary
Modifier and Type Method Description final IntegergetRed()final IntegergetGreen()final IntegergetBlue()final IntegergetAlpha()final static StringBuilderappend(StringBuilder $self, CharSequence c, Integer repeats)append the given CharSequence to this StringBuilder, repeated repeats times. final static Colorrgba(Float r, Float g, Float b, Float a)final static Colorrgba(Integer r, Integer g, Integer b, Float a)figma copy-paste accessor final static Colorrgba(Integer r, Integer g, Integer b)figma copy-paste accessor final static IntegerHSBtoRGB(Float hue, Float saturation, Float brightness)Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model. final static FloatArrayRGBtoHSB(Integer r, Integer g, Integer b, FloatArray out)Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model. final static ColortoColor(Integer $self)Takes an ARGB integer color and returns a Color object. final static DoubletoRadians(Double $self)final static Integergcd(Integer $self, Integer b)Calculate the greatest common denominator of two integers. final static Pair<Integer, Integer>simplifyRatio(Pair<Integer, Integer> $self)Simplify a ratio of two integers. final static Floatcl0(Float a, Float b)Returns the value closer to zero. final static Floatcl1(Float a, Float b)Returns the value closer to one. final static Integermin(Integer a, Integer b, Integer c)Returns the minimum value among three given ints. final static FloatArrayradii(Number $self)convert the given float into an array of 4 floats for radii. final static FloatArrayradii(Float topLeft, Float topRight, Float bottomLeft, Float bottomRight)convert the given floats into an array of 4 floats for radii. final static <T extends Any> Tstdout(T $self, Object arg)print the object to stdout, then return it. final static Array<Modifiers>fromModifierMerged(Short $self)final static BooleanhasModifier(Short $self, Modifiers mod)final static Shortmerge(Array<out Modifiers> $self)final static StringdropAt(String $self, Integer index, Integer amount)final static StringsubstringSafe(String $self, Integer fromIndex, Integer toIndex)safe substring function. final static Stringtruncate(String $self, Renderer renderer, Font font, Float fontSize, Float width, String limitText)Limit the given string to a width. final static Pair<String, String>substringToWidth(String $self, Renderer renderer, Font font, Float fontSize, Float width)take the given string and cut it to the length, returning a pair of the string cut to the length, and the remainder. final static IntegerlevenshteinDistance(String $self, String other)calculate the levenshtein distance between this string and the other string. final static ArrayList<String>wrap(String $self, Float maxWidth, Renderer renderer, Font font, Float fontSize)Wrap the given text to the given width, returning a list of lines. final static IntegerclosestToPoint(String $self, Renderer renderer, Font font, Float fontSize, Float x)Returns the closest character index from the given string to the given point x. -
-
Method Detail
-
append
final static StringBuilder append(StringBuilder $self, CharSequence c, Integer repeats)
append the given CharSequence to this StringBuilder, repeated repeats times.
This function is equivalent to doing sb
.append(c.repeat(repeats), but it uses an already existing StringBuilder.
-
HSBtoRGB
final static Integer HSBtoRGB(Float hue, Float saturation, Float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
The
saturationandbrightnesscomponents should be floating-point values between zero and one (numbers in the range 0.0-1.0). Thehuecomponent can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value that is the same format used by the method getARGB() This integer can be supplied as an argument to the toColor method that takes a single integer argument to create a Color.
- Parameters:
hue- the hue component of the colorsaturation- the saturation of the colorbrightness- the brightness of the color- Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.
-
RGBtoHSB
final static FloatArray RGBtoHSB(Integer r, Integer g, Integer b, FloatArray out)
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.
If the out argument is
null, then a new array is allocated to return the result. Otherwise, the method returns the array out, with the values put into that array.- Parameters:
r- the red component of the colorg- the green component of the colorb- the blue component of the colorout- the array used to return the three HSB values, ornull- Returns:
an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
- Since:
0.18.2
-
toColor
final static Color toColor(Integer $self)
Takes an ARGB integer color and returns a Color object.
-
gcd
final static Integer gcd(Integer $self, Integer b)
Calculate the greatest common denominator of two integers.
- Since:
0.18.4
-
simplifyRatio
final static Pair<Integer, Integer> simplifyRatio(Pair<Integer, Integer> $self)
Simplify a ratio of two integers.
- Since:
0.18.4
-
cl0
final static Float cl0(Float a, Float b)
Returns the value closer to zero.
If either value is
NaN, then the result isNaN.If
a == b, then the result isa.
-
cl1
final static Float cl1(Float a, Float b)
Returns the value closer to one.
If either value is
NaN, then the result isNaN.If
a == b, then the result isa.
-
min
final static Integer min(Integer a, Integer b, Integer c)
Returns the minimum value among three given ints.
- Parameters:
a- the first valueb- the second valuec- the third value- Returns:
the minimum value among a, b, and c
-
radii
final static FloatArray radii(Number $self)
convert the given float into an array of 4 floats for radii.
-
radii
final static FloatArray radii(Float topLeft, Float topRight, Float bottomLeft, Float bottomRight)
convert the given floats into an array of 4 floats for radii.
-
stdout
final static <T extends Any> T stdout(T $self, Object arg)
print the object to stdout, then return it.
-
fromModifierMerged
final static Array<Modifiers> fromModifierMerged(Short $self)
-
hasModifier
final static Boolean hasModifier(Short $self, Modifiers mod)
-
substringSafe
final static String substringSafe(String $self, Integer fromIndex, Integer toIndex)
safe substring function.
if fromIndex is negative, it will be set to 0
if toIndex is greater than the length of the string, or negative, it will be set to the length of the string
if fromIndex is greater than toIndex, they will be swapped, then substring'd as normal
-
truncate
final static String truncate(String $self, Renderer renderer, Font font, Float fontSize, Float width, String limitText)
Limit the given string to a width. If the string is too long, it will be cut to the width, and limitText will be appended to the end.
- Since:
0.22.0
-
substringToWidth
final static Pair<String, String> substringToWidth(String $self, Renderer renderer, Font font, Float fontSize, Float width)
take the given string and cut it to the length, returning a pair of the string cut to the length, and the remainder.
if the string fits within the width, the first string will be the entire string, and the second will be empty.
-
levenshteinDistance
final static Integer levenshteinDistance(String $self, String other)
calculate the levenshtein distance between this string and the other string.
- Since:
0.19.1
-
wrap
final static ArrayList<String> wrap(String $self, Float maxWidth, Renderer renderer, Font font, Float fontSize)
Wrap the given text to the given width, returning a list of lines.
-
closestToPoint
final static Integer closestToPoint(String $self, Renderer renderer, Font font, Float fontSize, Float x)
Returns the closest character index from the given string to the given point x.
- Returns:
the index of the character closest to the given point x, or
-1if it could not be found.- Since:
0.18.5
-
-
-
-