Livery Editor – Utils
Math and conversion utilities shared across the livery editor modules.
Math and conversion utilities shared across the livery editor modules.
Overview
ui_liveryEditor_utils provides common math helpers used throughout the livery editor - angle conversions, rounding, coordinate extraction, range cycling, and action map resolution.
Extension path: lua/ge/extensions/ui/liveryEditor/utils.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
convertRadiansToDegrees | (radians) → number | Converts radians to degrees. |
convertDegreesToRadians | (degrees) → number | Converts degrees to radians with 14-decimal precision. |
getBaseDegreesValue | (value) → number | Normalises a degree value to 0–360 range. |
roundAndTruncateDecimal | (number, decimals) → number | Rounds to the specified decimal places (default 1). |
getXYCoordinates | (decalPos, coordinates) → {x, y} | Extracts X/Y from a decal position based on camera coordinate mapping. |
cycleRange | (value, min, max) → number | Wraps a value within [min, max) using modulo. |
getActionMapNameByTool | (tool) → string | Maps a tool constant to its action map name. |
Internals
Angle Conversion
local convertRadiansToDegrees = function(radians)
return radians * (180 / math.pi)
end
local convertDegreesToRadians = function(degrees)
local radians = degrees * (math.pi / 180)
return tonumber(string.format("%.14f", radians))
endThe radians-to-degrees conversion preserves full precision. Degrees-to-radians truncates to 14 decimal places to avoid floating-point drift.
Rounding
local roundAndTruncateDecimal = function(number, decimals)
decimals = decimals or 1
local scale = 10 ^ decimals
return math.ceil(number * scale - 0.5) / scale
endUses ceiling-minus-half for symmetric rounding (round-half-up behaviour).
Cycle Range
local cycleRange = function(value, min, max)
value = value % max
if value < min then
value = value + max
end
return value
endUsed for wrapping rotation degrees: cycleRange(370, 0, 360) → 10.
Coordinate Extraction
getXYCoordinates reads from a decalPos vector using camera-defined axis indices, allowing the same code to work regardless of camera orientation.
How It Works
- Transform modules call
convertRadiansToDegrees/convertDegreesToRadiansfor UI display roundAndTruncateDecimalkeeps displayed values clean (e.g., 0.001 precision for position)cycleRangeensures rotation values stay within 0–360getActionMapNameByToolresolves tool names to action map identifiers for input binding
Example Usage
local utils = extensions.ui_liveryEditor_utils
-- Convert rotation for display
local degrees = utils.convertRadiansToDegrees(1.5708) -- ~90.0
-- Round for UI
local rounded = utils.roundAndTruncateDecimal(0.12345, 2) -- 0.12
-- Wrap rotation
local wrapped = utils.cycleRange(-10, 0, 360) -- 350Additional Exports
The following exports are available but not yet documented in detail:
M.convertDegreesToRadiansM.convertRadiansToDegreesM.cycleRangeM.getActionMapNameByToolM.getBaseDegreesValueM.getXYCoordinatesM.roundAndTruncateDecimal