mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpiunits] Change units to track their base unit, instead of their base class (#6342)
Unit objects now have a reference to the base unit from which they're derived. Constructing a unit object without specifying a base unit implicitly signifies that it's its own base unit, eg new Angle(null, 1, "Radian", "rad") would be the base angle unit of radians, while new Angle(Radians, 2 * PI, "Rotation", "R") would be a new angle unit based on radians. This fixes much of the hacky code surrounding the derived unit types Velocity, Per, and Mult, but is a breaking change for any user code that defines custom unit classes or uses the anonymous unit type.
This commit is contained in:
@@ -11,36 +11,33 @@ public final class BaseUnits {
|
||||
}
|
||||
|
||||
/** The standard unit of distance, meters. */
|
||||
public static final Distance Distance = new Distance(1, "Meter", "m");
|
||||
public static final Distance Distance = new Distance(null, 1, "Meter", "m");
|
||||
|
||||
/** The standard unit of time, seconds. */
|
||||
public static final Time Time = new Time(1, "Second", "s");
|
||||
|
||||
/** The standard unit of velocity, meters per second. */
|
||||
public static final Velocity<Distance> Velocity =
|
||||
new Velocity<>(Distance, Time, "Meter per Second", "m/s");
|
||||
public static final Time Time = new Time(null, 1, "Second", "s");
|
||||
|
||||
/** The standard unit of mass, kilograms. */
|
||||
public static final Mass Mass = new Mass(1, "Kilogram", "Kg");
|
||||
public static final Mass Mass = new Mass(null, 1, "Kilogram", "Kg");
|
||||
|
||||
/** The standard unit of angles, radians. */
|
||||
public static final Angle Angle = new Angle(1, "Radian", "rad");
|
||||
public static final Angle Angle = new Angle(null, 1, "Radian", "rad");
|
||||
|
||||
/** The standard "unitless" unit. */
|
||||
public static final Dimensionless Value = new Dimensionless(1, "<?>", "<?>");
|
||||
public static final Dimensionless Value = new Dimensionless(null, 1, "<?>", "<?>");
|
||||
|
||||
/** The standard unit of voltage, volts. */
|
||||
public static final Voltage Voltage = new Voltage(1, "Volt", "V");
|
||||
public static final Voltage Voltage = new Voltage(null, 1, "Volt", "V");
|
||||
|
||||
/** The standard unit of electric current, amperes. */
|
||||
public static final Current Current = new Current(1, "Amp", "A");
|
||||
public static final Current Current = new Current(null, 1, "Amp", "A");
|
||||
|
||||
/** The standard unit of energy, joules. */
|
||||
public static final Energy Energy = new Energy(1, "Joule", "J");
|
||||
public static final Energy Energy = new Energy(null, 1, "Joule", "J");
|
||||
|
||||
/** The standard unit of power, watts. */
|
||||
public static final Power Power = new Power(1, "Watt", "W");
|
||||
public static final Power Power = new Power(null, 1, "Watt", "W");
|
||||
|
||||
/** The standard unit of temperature, kelvin. */
|
||||
public static final Temperature Temperature = new Temperature(x -> x, x -> x, "Kelvin", "K");
|
||||
public static final Temperature Temperature =
|
||||
new Temperature(null, x -> x, x -> x, "Kelvin", "K");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user