Skip to main content

MetricUnitDimensionUtils

Functions over dimensions: frozen tables of integer exponents by name, zero exponents left out, so a speed is { length = 1, time = -1 } and a plain number is {}. Any name is a dimension; time, length, memory, mass, temperature, angle, current, amount and luminousIntensity are the base dimensions MetricUnit has units for, and derived ones such as force and energy are products of those. The named combinations, such as "speed", are in MetricUnitKinds.

MetricUnitDimensionUtils.combine({ length = 1 }, { time = 1 }, -1) -- { length = 1, time = -1 }
MetricUnitDimensionUtils.describe({ length = 1, time = -1 }) -- "length/time"

Types​

Dimensions​

type Dimensions = {[string]: number}

Integer exponents keyed by dimension name, with zero exponents left out.

Properties​

NONE​

MetricUnitDimensionUtils.NONE: Dimensions

No dimensions: a plain number's, and what combine returns when every exponent cancels.

Functions​

combine​

MetricUnitDimensionUtils.combine(
sign: number--

1 or -1

) → Dimensions

The exponents of a plus sign times those of b: a product when sign is 1, a quotient when it is -1.

scale​

MetricUnitDimensionUtils.scale(
factor: number
) → Dimensions

The exponents of a times factor, erroring if any is not a whole number.

equal​

MetricUnitDimensionUtils.equal() → boolean

Whether a and b have the same exponents.

isDimensions​

MetricUnitDimensionUtils.isDimensions(value: any) → boolean

Whether value is a table of whole-number exponents keyed by name, none of them zero.

describe​

MetricUnitDimensionUtils.describe(dimensions: Dimensions) → string

A readable formula for dimensions: "time", "length/time", "1/time", "length^2" or "dimensionless".

Show raw api
{
    "functions": [
        {
            "name": "combine",
            "desc": "The exponents of `a` plus `sign` times those of `b`: a product when `sign` is 1, a quotient when it is -1.",
            "params": [
                {
                    "name": "a",
                    "desc": "",
                    "lua_type": "Dimensions"
                },
                {
                    "name": "b",
                    "desc": "",
                    "lua_type": "Dimensions"
                },
                {
                    "name": "sign",
                    "desc": "1 or -1",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Dimensions"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 42,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        },
        {
            "name": "scale",
            "desc": "The exponents of `a` times `factor`, erroring if any is not a whole number.",
            "params": [
                {
                    "name": "a",
                    "desc": "",
                    "lua_type": "Dimensions"
                },
                {
                    "name": "factor",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Dimensions"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 62,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        },
        {
            "name": "equal",
            "desc": "Whether `a` and `b` have the same exponents.",
            "params": [
                {
                    "name": "a",
                    "desc": "",
                    "lua_type": "Dimensions"
                },
                {
                    "name": "b",
                    "desc": "",
                    "lua_type": "Dimensions"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 90,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        },
        {
            "name": "isDimensions",
            "desc": "Whether `value` is a table of whole-number exponents keyed by name, none of them zero.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 113,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        },
        {
            "name": "describe",
            "desc": "A readable formula for `dimensions`: \"time\", \"length/time\", \"1/time\", \"length^2\" or \"dimensionless\".",
            "params": [
                {
                    "name": "dimensions",
                    "desc": "",
                    "lua_type": "Dimensions"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 136,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "NONE",
            "desc": "No dimensions: a plain number's, and what `combine` returns when every exponent cancels.",
            "lua_type": "Dimensions",
            "source": {
                "line": 32,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        }
    ],
    "types": [
        {
            "name": "Dimensions",
            "desc": "Integer exponents keyed by dimension name, with zero exponents left out.",
            "lua_type": "{ [string]: number }",
            "source": {
                "line": 24,
                "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
            }
        }
    ],
    "name": "MetricUnitDimensionUtils",
    "desc": "Functions over dimensions: frozen tables of integer exponents by name, zero exponents left out, so a speed is\n`{ length = 1, time = -1 }` and a plain number is `{}`. Any name is a dimension; `time`, `length`, `memory`,\n`mass`, `temperature`, `angle`, `current`, `amount` and `luminousIntensity` are the base dimensions [MetricUnit] has units for, and derived ones such as force\nand energy are products of those. The named combinations, such as `\"speed\"`, are in [MetricUnitKinds].\n\n```lua\nMetricUnitDimensionUtils.combine({ length = 1 }, { time = 1 }, -1) -- { length = 1, time = -1 }\nMetricUnitDimensionUtils.describe({ length = 1, time = -1 }) -- \"length/time\"\n```",
    "source": {
        "line": 15,
        "path": "src/metricutils/src/Shared/Definitions/MetricUnitDimensionUtils.lua"
    }
}