Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Group

A group combines units of one quantity. Units of one group are convertible into each other. A group is always part of one single Collection. Groups can be edited through the Group.Editor. Like collections they can be modified in their entirety at runtime. Each group has a unique name (Group.name) that serves as an id.

As said all units of one group are convertible into each other. This works through the concept of "base units":

Every group has one single base unit. All other units of the group are defined in relation to this special unit. In this way, the library can figure out any conversion between any units of one group.

Example:

You create the group "length".

const length = new Group("length");

You want to implement the units "meter", "inch" and "yard". Now you have to decide on a unit that you want to be the base. You take "meter".

After that you have to define the other units in relation to your base unit. You know: 1 inch = 0.0254 meter. So you set the ratio to 0.0254 and the shift to 0.

const inch = new Unit({...}, 0.0254, 0, ...);

You know aswell: 1 yard = 0.9144 meter. So you set the ratio to 0.9144 and the shift to 0.

const yard = new Unit({...}, 0.9144, 0, ...);

The base unit's ratio is always 1, its shift is always 0 (because 1 meter = 1 meter).

const meter = new Unit({...}, 1, 0, ...);

Now you finally have to add the units to your group. You can do that using the Group.Editor.

length.add(inch, yard, meter);

And you're done.

Hierarchy

  • Group

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Group(name: string): Group
  • Creates a new group.

    Parameters

    • name: string

      the group's unique name

    Returns Group

Properties

Readonly Editor

Editor: GroupEditor = ...

The group's editor. Provides methods to add, remove and overwrite units.

see

GroupEditor

Readonly name

name: string

The group's name. Has to be unique.

Private Readonly units

units: Map<string, Unit> = ...

All units of the group arranged in a map.

Accessors

collection

Methods

possibilities

  • possibilities(): string[]
  • Returns a string array containing the short names of all units of this group.

    Returns string[]

    a string array containing the short names of all units of this group.

toString

  • toString(): string
  • Returns the group as human-readable string.

    Returns string

    the group as string

Generated using TypeDoc