Math
Everything you need to know about the script.
Shared Functions
Round
local roundedValue = dLib.Math.Round(value, places)| Argument | Type | Description |
|---|---|---|
value | number | string | - |
places? | number | string | - |
| Returned Data | Type | Description |
|---|---|---|
roundedValue | number | - |
Clamp
Restricts a value within a specified range.
local clampedValue = dLib.Math.Clamp(value, min, max)| Argument | Type | Description |
|---|---|---|
value | number | string | The value to clamp. |
min | number | string | The minimum allowed value. |
max | number | string | The maximum allowed value. |
| Returned Data | Type | Description |
|---|---|---|
clampedValue | number | The clamped value. |
ToHex
Converts a number to a hexadecimal string.
local hexString = dLib.Math.ToHex(value)| Argument | Type | Description |
|---|---|---|
value | number | string | The number to convert. |
upper? | boolean | Whether to use uppercase letters. |
| Returned Data | Type | Description |
|---|---|---|
hexString | string | The hexadecimal string representation. |
HexToRGB
Converts a hexadecimal color string to RGB values.
local r, g, b = dLib.Math.HexToRGB(hex)| Argument | Type | Description |
|---|---|---|
hex | string | The hexadecimal color string (e.g., "#FF0000"). |
| Returned Data | Type | Description |
|---|---|---|
r | number | Red component (0-255). |
g | number | Green component (0-255). |
b | number | Blue component (0-255). |
HexToRGBA
Converts a hexadecimal color string to RGBA values.
local r, g, b, a = dLib.Math.HexToRGBA(hex)| Argument | Type | Description |
|---|---|---|
hex | string | The hexadecimal color string. |
| Returned Data | Type | Description |
|---|---|---|
r | number | Red component (0-255). |
g | number | Green component (0-255). |
b | number | Blue component (0-255). |
a | number | Alpha component (0-255). |
NormalToRotation
Converts a normal vector to a rotation.
local rotation = dLib.Math.NormalToRotation(normal)| Argument | Type | Description |
|---|---|---|
normal | vector3 | The normal vector. |
| Returned Data | Type | Description |
|---|---|---|
rotation | vector3 | The resulting rotation. |
ToVector
Tries to convert its argument to a vector3.
local vec = dLib.Math.ToVector(input)| Argument | Type | Description |
|---|---|---|
input | table | The table or object to convert to a vector. |
min? | number | Optional minimum value to clamp components. |
max? | number | Optional maximum value to clamp components. |
round? | boolean | Whether to round component values. |
| Returned Data | Type | Description |
|---|---|---|
vec | vector3 | The resulting vector. |
ToScalars
Converts a string into a set of scalar values.
local x, y, z = dLib.Math.ToScalars(input)| Argument | Type | Description |
|---|---|---|
input | string | The vector to decompose. |
min? | number | Optional minimum value to clamp components. |
max? | number | Optional maximum value to clamp components. |
round? | boolean | Whether to round component values. |
| Returned Data | Type | Description |
|---|---|---|
value | number | The set of scalar values. |
ParseNumber
Parses a string or value into a number.
local number = dLib.Math.ParseNumber(value, min, max, round)| Argument | Type | Description |
|---|---|---|
value | string | number | The value to parse. |
min? | number | Optional minimum value to clamp components. |
max? | number | Optional maximum value to clamp components. |
round? | boolean | Whether to round component values. |
| Returned Data | Type | Description |
|---|---|---|
number | number | The parsed number. |
Lerp
Linearly interpolates between two values based on a factor.
local result = dLib.Math.Lerp(start, finish, duration)| Argument | Type | Description |
|---|---|---|
start | number | The start value. |
finish | number | The end value. |
duration | number | The duration over which to interpolate over in milliseconds. |
| Returned Data | Type | Description |
|---|---|---|
result | number | The interpolated value. |
InverseLerp
Calculates the interpolation factor given a value between two points.
local t = dLib.Math.InverseLerp(start, finish, value)| Argument | Type | Description |
|---|---|---|
start | number | The start value. |
finish | number | The end value. |
value | number | The value between start and end. |
| Returned Data | Type | Description |
|---|---|---|
t | number | The calculated factor (0.0 to 1.0). |
Map
Maps a value from one range to another.
local mappedValue = dLib.Math.Map(value, inMin, inMax, outMin, outMax)| Argument | Type | Description |
|---|---|---|
value | number | The value to map. |
inMin | number | Input range minimum. |
inMax | number | Input range maximum. |
outMin | number | Output range minimum. |
outMax | number | Output range maximum. |
| Returned Data | Type | Description |
|---|---|---|
mappedValue | number | The mapped value. |
Deg2Rad
Converts degrees to radians.
local radians = dLib.Math.Deg2Rad(degrees)| Argument | Type | Description |
|---|---|---|
degrees | number | Angle in degrees. |
| Returned Data | Type | Description |
|---|---|---|
radians | number | Angle in radians. |
Rad2Deg
Converts radians to degrees.
local degrees = dLib.Math.Rad2Deg(radians)| Argument | Type | Description |
|---|---|---|
radians | number | Angle in radians. |
| Returned Data | Type | Description |
|---|---|---|
degrees | number | Angle in degrees. |
Sign
Returns the sign of a number (-1, 0, or 1).
local sign = dLib.Math.Sign(value)| Argument | Type | Description |
|---|---|---|
value | number | The number to check. |
| Returned Data | Type | Description |
|---|---|---|
sign | number | The sign of the number. |
AlmostEqual
Checks if two numbers are approximately equal.
local isEqual = dLib.Math.AlmostEqual(a, b, epsilon)| Argument | Type | Description |
|---|---|---|
a | number | First number. |
b | number | Second number. |
epsilon? | number | The tolerance (optional, default usually small). |
| Returned Data | Type | Description |
|---|---|---|
isEqual | boolean | True if equal within tolerance. |
Length2
Calculates the 2D length (magnitude) of a vector.
local length = dLib.Math.Length2(x, y)| Argument | Type | Description |
|---|---|---|
x | number | The x component. |
y | number | The y component. |
| Returned Data | Type | Description |
|---|---|---|
length | number | The 2D length. |
Length3
Calculates the 3D length (magnitude) of a vector.
local length = dLib.Math.Length3(x, y, z)| Argument | Type | Description |
|---|---|---|
x | number | The x component. |
y | number | The y component. |
z | number | The z component. |
| Returned Data | Type | Description |
|---|---|---|
length | number | The 3D length. |
Distance2D
Calculates the distance between two 2D points.
local distance = dLib.Math.Distance2D(x1, y1, x2, y2)| Argument | Type | Description |
|---|---|---|
x1 | number | X coordinate of the first point. |
y1 | number | Y coordinate of the first point. |
x2 | number | X coordinate of the second point. |
y2 | number | Y coordinate of the second point. |
| Returned Data | Type | Description |
|---|---|---|
distance | number | The distance between points. |
Distance3D
Calculates the distance between two 3D points.
local distance = dLib.Math.Distance3D(x1, y1, z1, x2, y2, z2)| Argument | Type | Description |
|---|---|---|
x1 | number | X coordinate of the first point. |
y1 | number | Y coordinate of the first point. |
z1 | number | Z coordinate of the first point. |
x2 | number | X coordinate of the second point. |
y2 | number | Y coordinate of the second point. |
z2 | number | Z coordinate of the second point. |
| Returned Data | Type | Description |
|---|---|---|
distance | number | The distance between points. |