UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

29 lines 1.84 kB
/** * Convert a {@link UnitMatrix} into a human-readable string such as `m/s`, `kg·m/s^2` or `Hz`. * * Output rules: * - dimensions with positive exponent appear in the numerator, joined by `·` * - dimensions with negative exponent appear in the denominator, joined by `·` * - exponents of magnitude 1 are written without a suffix; otherwise `^n` is appended * - dimensionless matrices return an empty string * - if every term lives in the denominator, the numerator is rendered as `1` * * Optional named-unit registry (`named_units` argument): * - if the matrix is a non-zero scalar multiple of any registry entry, that entry is used * directly: `Hz` for `1/s`, `V` for the volt matrix, `V^2` for its square, `1/V` for its * inverse. * - otherwise the matrix is greedily decomposed against compound registry entries (named * units with at least two non-zero exponents). The algorithm tries to use the fewest terms * possible — `V/m^2` is rendered as `V/m^2` (two terms) rather than `kg/(s^3·A)` (four * terms). Single-dimension entries (`METER`, `SECOND`, ...) are skipped here so the * leftover base residual renders in canonical `Mass·Length·Time·...` order. * - registry order acts as a tiebreaker — the first match wins among options with the same * term-count reduction. * * @param {UnitMatrix} unit_matrix * @param {NamedUnit[]} [named_units] Optional registry of compound-unit symbols. * @param {NamedUnit[]} [dimension_units=UNIT_DIMENSION_MAPPING] One {@link NamedUnit} per base dimension, indexed by {@link UnitDimension}. Only the `.symbol` field is read. * @returns {string} */ export function unit_matrix_to_string(unit_matrix: UnitMatrix, named_units?: NamedUnit[], dimension_units?: NamedUnit[]): string; //# sourceMappingURL=unit_matrix_to_string.d.ts.map