[wpiunits] Java units API rewrite (#6958)

Java generics are too limited to do what we need. This refactors generic code previously in Unit and Measure into unit-specific classes that can have unit-safe math operations (notably, times and divide) that can return values in known units instead of a wildcarded Measure<?>.

Unit-specific measure implementations are automatically generated by ./wpiunits/generate_units.py, which generates generic interfaces and mutable and immutable implementations of those interfaces. These make up the bulk of the diff of this PR (approximately 9300 LOC).

This also adds units for angular and linear velocities, accelerations, and momenta; moment of inertia; and torque.
This commit is contained in:
Sam Carlberg
2024-09-07 13:59:29 -04:00
committed by GitHub
parent 496e7c1bba
commit a9b885070e
178 changed files with 14750 additions and 2158 deletions

View File

@@ -11,33 +11,30 @@ public final class BaseUnits {
}
/** The standard unit of distance, meters. */
public static final Distance Distance = new Distance(null, 1, "Meter", "m");
public static final DistanceUnit DistanceUnit = new DistanceUnit(null, 1, "Meter", "m");
/** The standard unit of time, seconds. */
public static final Time Time = new Time(null, 1, "Second", "s");
public static final TimeUnit TimeUnit = new TimeUnit(null, 1, "Second", "s");
/** The standard unit of mass, kilograms. */
public static final Mass Mass = new Mass(null, 1, "Kilogram", "Kg");
public static final MassUnit MassUnit = new MassUnit(null, 1, "Kilogram", "Kg");
/** The standard unit of angles, radians. */
public static final Angle Angle = new Angle(null, 1, "Radian", "rad");
public static final AngleUnit AngleUnit = new AngleUnit(null, 1, "Radian", "rad");
/** The standard "unitless" unit. */
public static final Dimensionless Value = new Dimensionless(null, 1, "<?>", "<?>");
public static final DimensionlessUnit Value = new DimensionlessUnit(null, 1, "<?>", "<?>");
/** The standard unit of voltage, volts. */
public static final Voltage Voltage = new Voltage(null, 1, "Volt", "V");
public static final VoltageUnit VoltageUnit = new VoltageUnit(null, 1, "Volt", "V");
/** The standard unit of electric current, amperes. */
public static final Current Current = new Current(null, 1, "Amp", "A");
public static final CurrentUnit CurrentUnit = new CurrentUnit(null, 1, "Amp", "A");
/** The standard unit of energy, joules. */
public static final Energy Energy = new Energy(null, 1, "Joule", "J");
/** The standard unit of power, watts. */
public static final Power Power = new Power(null, 1, "Watt", "W");
public static final EnergyUnit EnergyUnit = new EnergyUnit(null, 1, "Joule", "J");
/** The standard unit of temperature, kelvin. */
public static final Temperature Temperature =
new Temperature(null, x -> x, x -> x, "Kelvin", "K");
public static final TemperatureUnit TemperatureUnit =
new TemperatureUnit(null, x -> x, x -> x, "Kelvin", "K");
}