pipeline.domain.measures.Distance

class Distance(value: int | float | Decimal = 0, units: dict = {'metres': Decimal('1000'), 'name': 'KILOMETRE', 'symbol': 'km'})[source]

Bases: ComparableUnit

Methods

convert_to

Converts this measure of distance to the new units.

to_units

Returns the magnitude of this distance in otherUnits.

Attributes

value

units

__init__(value: int | float | Decimal = 0, units: dict = {'metres': Decimal('1000'), 'name': 'KILOMETRE', 'symbol': 'km'}) None[source]

Creates a new distance with the given magnitude and units.

If no arguments are given, a new distance of 0 km is created. If no units are given, kilometres are assumed.

convert_to(newUnits: dict = {'metres': Decimal('1'), 'name': 'METRE', 'symbol': 'm'}) Distance[source]

Converts this measure of distance to the new units.

After this method is complete this distance will have units of newUnits and its value will have been converted accordingly.

Parameters:

newUnits -- The new units for this distance (default: m).

Returns:

This distance. The reason for this return type is to allow code of this nature:

kilometers = myDistance.convert_to(DistanceUnits.KILOMETRES).value

to_units(otherUnits: dict = {'metres': Decimal('1'), 'name': 'METRE', 'symbol': 'm'}) Decimal[source]

Returns the magnitude of this distance in otherUnits.

Note that this method does not alter the state of this distance. Contrast this with convert_to(DistanceUnits).

Parameters:

otherUnits -- The units in which to express this distance's magnitude.

Returns:

This distance's value converted to otherUnits.