Skip to content
Shapemetry

@huukhanhnguyen/model / utils/convertExpression

utils/convertExpression

UNIT_TYPE_INCLUDES

const UNIT_TYPE_INCLUDES: Record<string, string[]>

For each unit type, the param/arg valueTypes that need conversion.


convertExpression()

convertExpression(expr, paramType, fromUnit, toUnit, getRefType?): string

Convert unit-carrying literals in a parametric expression string.

Scalar types (length/area/volume/mass): dimensional inference via JSEP AST.

  • Literals in add/subtract with a known-dimension operand → convert.
  • Literals as the dimensional operand in multiply → convert.
  • Dimensionless counts/ratios in multiply/divide → NOT converted.
  • Math.max/min/abs/floor/ceil/round/trunc args → convert.

Composite types (point/axis/plane/arrow): structural schema.

  • Length components (position, displacement) → convert.
  • Direction/normal vectors → NOT converted (dimensionless unit vectors).

Convention: inline literals in expressions are always in the model's canonical unit (usually mm). For cross-param offsets, declare a separate length param rather than hardcoding a display-unit value in an expression.

Parameters

expr

string

paramType

string

fromUnit

string

toUnit

string

getRefType?

(name) => string | null

Returns

string

Last updated: 📖 1 min readEdit on GitHub