Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a QUDV (Quantity, Unit, Dimension, and Value) library, generalized over the type of values. This is part of #1198, which applies units to numbers, dynamics, and resources, and allows adding units to other types.
In this library, base dimensions are declared at runtime, and derived dimensions are constructed by multiplying and taking powers of base dimensions. A dimension is a product of rational powers of base dimensions, and are represented exactly.
Units are a dimension and a scale. To use them properly, we declare a base unit for each base dimension, which implicitly has a scale of "1", and derive all other units from these through multiplication and powers. Derived units are anonymous by default, but can be given names. Since units are a multiplier and a dimension, we can only represent units with "absolute" scales. (So Kelvin is representable, but degrees Fahrenheit isn't.)
Quantities are represented by the
UnitAware<T>
interface, and represent a value of typeT
and a unit, with the ability to do dimensionality checks and rescale the value to convert to a different unit.Verification
There's a unit test for the Dimension class, but other classes have only been spot-checked. I'm working on converting the Clipper model, and parts of it use UnitAware types, so that should provide some test cases.
Documentation
At the moment, only the inline Javadocs document this code, but we want to make wiki page(s) describing this and other parts of #1198. I'll update this description when that happens.
Future work
See #1198