Skip to content

Improve the Java Units Library with additional methods and unit types #6683

Description

@bhall-ctre

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

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>>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions