Coming from the C++ units library, the Java units library has a few rough edges that can occasionally make working with the library difficult. Below are some suggestions for unit and feature additions to improve the usability of the library, based on both my experience with the library so far and our requirements for the library at CTRE.
Unit Additions
- Frequency
- Hertz (should this be a
Velocity<Dimensionless>?)
- Magnetic Field Strength
- Tesla, Millitesla, Microtesla
- Force and Torque
Functionality Improvements
Unfortunately, there may be some limitations of Java that prevent all these suggestions from being implemented, but I believe we should add whatever we can.
- Add support for dividing a
Measure<U1> by a Measure<U2>
- Add
inverse() to Measure and Unit
- For example, I should be able to take a time in Seconds and invert it to become a frequency in Hertz.
- There may be technical challenges with this and dividing two measures, as doing
Value.of(1).divide(meas) would also be a method of creating an inverse. Likewise, Meters.mult(Seconds.inverse()) may not give the desired type of Velocity<Distance>, although that can probably be handled in documentation.
- Add
squared() and cubed() to Unit
- This would just be an easy way to get square and cubic units. For example,
Meters.squared() is equivalent to Meters.mult(Meters).
- However, this could also be a footgun, as
Rotations.per(Second.squared()) may not result in a type of Velocity<Velocity<Angle>>.
Coming from the C++ units library, the Java units library has a few rough edges that can occasionally make working with the library difficult. Below are some suggestions for unit and feature additions to improve the usability of the library, based on both my experience with the library so far and our requirements for the library at CTRE.
Unit Additions
Velocity<Dimensionless>?)Functionality Improvements
Unfortunately, there may be some limitations of Java that prevent all these suggestions from being implemented, but I believe we should add whatever we can.
Measure<U1>by aMeasure<U2>inverse()to Measure and UnitValue.of(1).divide(meas)would also be a method of creating an inverse. Likewise,Meters.mult(Seconds.inverse())may not give the desired type ofVelocity<Distance>, although that can probably be handled in documentation.squared()andcubed()to UnitMeters.squared()is equivalent toMeters.mult(Meters).Rotations.per(Second.squared())may not result in a type ofVelocity<Velocity<Angle>>.