Math

The Math library provides common math utilities.

Side: Shared

Functions

Round

Rounds a number to a given number of decimal places.

local rounded = Bridge.Math.Round(value, decimals)
-- Returns: number
ParameterTypeDescription
valuenumberNumber to round
decimalsnumberDecimal places (default 0)

Clamp

Clamps a value between a minimum and maximum.

local clamped = Bridge.Math.Clamp(value, min, max)
-- Returns: number
ParameterTypeDescription
valuenumberValue to clamp
minnumberMinimum bound
maxnumberMaximum bound

Lerp

Linearly interpolates between two values.

local result = Bridge.Math.Lerp(a, b, t)
-- Returns: number
ParameterTypeDescription
anumberStart value
bnumberEnd value
tnumberInterpolation factor (0.0 - 1.0)

InverseLerp

Returns the interpolation factor for a value between two bounds.

local t = Bridge.Math.InverseLerp(a, b, value)
-- Returns: number (0.0 - 1.0)
ParameterTypeDescription
anumberStart value
bnumberEnd value
valuenumberValue to find factor for

Remap

Remaps a value from one range to another.

local result = Bridge.Math.Remap(value, fromMin, fromMax, toMin, toMax)
-- Returns: number
ParameterTypeDescription
valuenumberInput value
fromMinnumberSource range minimum
fromMaxnumberSource range maximum
toMinnumberTarget range minimum
toMaxnumberTarget range maximum

GroupDigits

Formats a number with digit grouping (e.g. 1,000,000).

local str = Bridge.Math.GroupDigits(number)
-- Returns: string
ParameterTypeDescription
numbernumberNumber to format

InBoundary

Checks if a point is within a boundary defined by min/max vectors or polygon points.

local inside = Bridge.Math.InBoundary(point, boundary)
-- Returns: boolean
ParameterTypeDescription
pointvector3Position to check
boundarytableBoundary definition ({min, max} or {points, minZ, maxZ})