Skip to content

Commit dfbc91b

Browse files
committed
Consistent defined termininology for dimension, unit, and measure
1 parent 4127683 commit dfbc91b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

source/docs/software/basic-programming/java-units.rst

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ The units library has a number of features:
1212
- Support for performing arithmetic and comparisons on quantities with units.
1313
- Support for displaying quantities with units in a human-readable format.
1414

15+
Terminology
16+
-----------
17+
Dimension
18+
Dimensions represent the nature of a physical quantity, such as length, time, or mass. They are independent of any specific unit system. For example, the dimension of meters is length, regardless of whether the length is expressed in meters, millimeters, or inches.
19+
20+
Unit
21+
Units are specific realizations of dimensions. They are the way of expressing physical quantities. Each dimension has a base unit, such as the meter for length, the second for time, the kilogram for mass. Derived units are formed by combining base units, such as meters per second for velocity.
22+
23+
Measure
24+
Measures are the specific magnitude of physical quantities, expressed in a particular unit. For example, 5 meters is a measure of distance.
25+
26+
These concepts are used within the Units Library. For example, the **measure** *10 seconds* has a magnitude of 10, the **dimension** is time, and the **unit** is seconds.
27+
1528
Using the Units Library
1629
-----------------------
1730

@@ -59,11 +72,11 @@ The library comes with many predefined units:
5972

6073
Java Generics
6174
^^^^^^^^^^^^^
62-
Units of measurement can be complex expressions involving various quantities, such as distance, time, and velocity. Nested `generic type parameters <https://docs.oracle.com/javase/tutorial/java/generics/index.html>`__ allow for the definition of units that can represent such complex expressions. Generics are used to keep the library concise, reusable, and extensible, but it tends to be verbose due to the syntax for Java generics.
75+
Units of measurement can be complex expressions involving various dimension, such as distance, time, and velocity. Nested `generic type parameters <https://docs.oracle.com/javase/tutorial/java/generics/index.html>`__ allow for the definition of units that can represent such complex expressions. Generics are used to keep the library concise, reusable, and extensible, but it tends to be verbose due to the syntax for Java generics.
6376

64-
For instance, consider the type ``Measure<Velocity<Distance>>``. This type represents a unit of measurement for velocity, where the velocity itself is expressed as a unit of distance per unit of time. This nested structure allows for the representation of units like meters per second or feet per minute. Similarly, the type ``Measure<Per<Voltage, Velocity<Distance>>>`` represents a unit of measurement for a ratio of voltage to velocity. This type is useful for representing quantities like volts per meter per second.
77+
For instance, consider the type ``Measure<Velocity<Distance>>``. This type represents a measurement for velocity, where the velocity itself is expressed as a unit of distance per unit of time. This nested structure allows for the representation of units like meters per second or feet per minute. Similarly, the type ``Measure<Per<Voltage, Velocity<Distance>>>`` represents a measurement for a ratio of voltage to velocity. This type is useful for representing quantities like volts per meter per second.
6578

66-
It's important to note that not all units of measurement require such complex nested types. For example, the type ``Measure<Distance>`` is sufficient for representing simple units like meters or feet. However, for more complex units, the use of nested generic type parameters is essential.
79+
It's important to note that not all measurements require such complex nested types. For example, the type ``Measure<Distance>`` is sufficient for representing simple units like meters or feet. However, for more complex units, the use of nested generic type parameters is essential.
6780

6881
For local variables, you may choose to use Java's `var` keyword instead of including the full type name. For example, these are equivalent:
6982

@@ -75,7 +88,7 @@ For local variables, you may choose to use Java's `var` keyword instead of inclu
7588
Creating Measures
7689
^^^^^^^^^^^^^^^^^
7790

78-
The ``Measure`` class is a generic type that represents a physical quantity with its corresponding unit of measurement. It provides a consistent and type-safe way to handle different types of measurements, such as distance, angle, and velocity, but abstracts away the particular unit of measure (e.g. meter vs. inch). To create a ``Measure`` object, you call the ``Unit.of`` method on the appropriate unit object. For example, to create a ``Measure<Distance>`` object representing a distance of 6 inches, you would write:
91+
The ``Measure`` class is a generic type that represents a magnitude (physical quantity) with its corresponding unit. It provides a consistent and type-safe way to handle different dimensions of measurements, such as distance, angle, and velocity, but abstracts away the particular unit (e.g. meter vs. inch). To create a ``Measure`` object, you call the ``Unit.of`` method on the appropriate unit object. For example, to create a ``Measure<Distance>`` object representing a distance of 6 inches, you would write:
7992

8093
.. code-block:: java
8194
@@ -94,7 +107,7 @@ Other measures can also be created using their ``Unit.of`` method:
94107
Performing Calculations
95108
^^^^^^^^^^^^^^^^^^^^^^^
96109

97-
The ``Measure`` class also supports arithmetic operations, such as addition, subtraction, multiplication, and division. These are done by calling methods on the objects. These operations always ensure that the units of measurement are compatible before performing the calculation, and they return a new ``Measure`` object. For example, you can add two ``Measure<Distance>`` objects together, even if they have different units:
110+
The ``Measure`` class also supports arithmetic operations, such as addition, subtraction, multiplication, and division. These are done by calling methods on the objects. These operations always ensure that the units are compatible before performing the calculation, and they return a new ``Measure`` object. For example, you can add two ``Measure<Distance>`` objects together, even if they have different units:
98111

99112
.. code-block:: java
100113
@@ -103,7 +116,7 @@ The ``Measure`` class also supports arithmetic operations, such as addition, sub
103116
104117
Measure<Distance> totalDistance = distance1.plus(distance2);
105118
106-
In this code, the units library will automatically convert the units of measurement to the same unit before adding the two distances. The resulting ``totalDistance`` object will be a new ``Measure<Distance>`` object that has a value of 0.508 meters, or 20 inches.
119+
In this code, the units library will automatically convert the measures to the same unit before adding the two distances. The resulting ``totalDistance`` object will be a new ``Measure<Distance>`` object that has a value of 0.508 meters, or 20 inches.
107120

108121
This example combines the wheel diameter and gear ratio to calcualate the distance per rotation of the wheel:
109122

@@ -146,10 +159,10 @@ Pulling all of the concepts together, we can create an example that calculates t
146159
Human-readable Formatting
147160
^^^^^^^^^^^^^^^^^^^^^^^^^
148161

149-
The ``Measure`` class has both ``toLongString()`` and ``toShortString()`` methods that can be used to get a human-readable representation of the measure. This feature is useful to display a measurement on a dashboard or in logs.
162+
The ``Measure`` class has both ``toLongString()`` and ``toShortString()`` methods that can be used to get a human-readable representation of the measure. This feature is useful to display a measure on a dashboard or in logs.
150163

151-
- ``toLongString()`` returns a string representation of this measurement in a longhand form. The name of the backing unit is used, rather than its symbol, and the magnitude is represented in a full string, not scientific notation. For example, 1234 Volt per Meter
152-
- ``toShortString()`` returns a string representation of this measurement in a shorthand form. The symbol of the backing unit is used, rather than the full name, and the magnitude is represented in scientific notation. For example, 1.234e+04 V/m
164+
- ``toLongString()`` returns a string representation of the measure in a longhand form. The name of the backing unit is used, rather than its symbol, and the magnitude is represented in a full string, not scientific notation. For example, 1234 Volt per Meter
165+
- ``toShortString()`` returns a string representation of the measure in a shorthand form. The symbol of the backing unit is used, rather than the full name, and the magnitude is represented in scientific notation. For example, 1.234e+04 V/m
153166

154167
Mutability and Object Creation
155168
------------------------------
@@ -315,7 +328,7 @@ There are four ways to define a new unit that isn't already present in the libra
315328
- Using the ``Unit.per`` or ``Unit.mult`` methods to create a composite of two other units;
316329
- Using the ``Milli``, ``Micro``, and ``Kilo`` helper methods;
317330
- Using the ``derive`` method and customizing how the new unit relates to the base unit;
318-
- Subclassing ``Unit`` to define a new type of unit
331+
- Subclassing ``Unit`` to define a new diimension
319332

320333
New units can be defined as combinations of existing units using the ``Unit.mult`` and ``Unit.per`` methods.
321334

@@ -338,7 +351,7 @@ Using ``mult`` and ``per`` will store the resulting unit. Every call will return
338351
339352
.. note:: Calling ``Unit.per(Time)`` will return a ``Velocity`` unit, which is different from and incompatible with a ``Per`` unit!
340353

341-
New unit types can also be created by subclassing ``Unit`` and implementing the two constructors. Note that ``Unit`` is also a parameterized generic type, where the generic type argument is self-referential; ``Distance`` is a ``Unit<Distance>``. This is what allows us to have stronger guarantees in the type system to prevent conversions between unrelated unit types.
354+
New dimensions can also be created by subclassing ``Unit`` and implementing the two constructors. Note that ``Unit`` is also a parameterized generic type, where the generic type argument is self-referential; ``Distance`` is a ``Unit<Distance>``. This is what allows us to have stronger guarantees in the type system to prevent conversions between unrelated dimensions.
342355

343356
.. code-block:: java
344357

0 commit comments

Comments
 (0)