Skip to content

UnitConversionProperty

Overview

A MappedProperty specialized for unit conversion. Just provide multiplicative factor to convert between the units, or optionally a map/inverseMap. Additionally if there is a rangeProperty on the source, this Property will have a mapped range.

For example: const metersProperty = new NumberProperty( 0.5, { range: new Range( 0, 1 ) } ); const centimetersProperty = new UnitConversionProperty( metersProperty, { factor: 100 } ); centimetersProperty.value; // 50 centimetersProperty.range; // Range( 0, 100 )

// One way metersProperty.value = 0.25 centimetersProperty.value; // 25

// Bidirectional centimetersProperty.value = 100; metersProperty.value; // 1

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class UnitConversionProperty

import { UnitConversionProperty } from 'scenerystack/axon';

Constructor

new UnitConversionProperty( property : ( TReadOnlyProperty<number> | TRangedProperty ), providedOptions : UnitConversionPropertyOptions )

Instance Methods

dispose()

Instance Properties

rangeProperty : TProperty<Range>

(readonly)

Type UnitConversionPropertyOptions

import type { UnitConversionPropertyOptions } from 'scenerystack/axon';
  • factor: number
    The multiplicative factor to convert from INPUT => OUTPUT, e.g. this.value === factor * property.value This will be used to provide defaults for map/inverseMap if provided
  • & MappedPropertyOptions<number, number>

Source Code

See the source for UnitConversionProperty.ts in the axon repository.