Skip to content

[core] Add length class

Adds a new class to core named Length which represents a length in meters. This class is similar in design to ns3::Time, except the underlying unit (meters) of Length cannot be changed at run time.

The purpose of the Length class is to replace the usage of basic integer and floating point types as values representing lengths. The problem with using integer and floating point types as lengths is that the unit of the length is implicit and only known by reading the documentation. Some examples of length values with implicit units are the return value of MobilityModel::GetDistanceFrom() and the attribute MaxRange in RangePropagationLossModel.
It is easy for errors to slip in when a programmer forgets the implicit unit a value represents or when the unit is not documented, leading to incorrect output during simulations. Replacing these implicit instances with the Length class allows anyone using the code to know what length unit the value currently represents. Additionally the Length class provides functions for converting to/from various length units making it easy to serialize lengths to ones preferred length unit.

The Length class provides conversions to/from the following units:

  • nanometer
  • micrometer
  • millimeter
  • centimeter
  • meter
  • kilometer
  • nautical mile
  • inch
  • foot
  • yard
  • mile

Merge request reports