Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java units API rewrite #6958

Merged
merged 47 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5112c36
Rename unit classes to end in *Unit
SamCarlberg Jun 14, 2024
869a2c4
Flatten units into discrete types
SamCarlberg Jun 15, 2024
fb61fc7
Rename `IMutable` to `MutableMeasure`
SamCarlberg Jun 20, 2024
cd04e93
Move mutable types to dedicated package
SamCarlberg Jun 25, 2024
485135a
Split into mutable and immutable variants
SamCarlberg Jun 26, 2024
158c576
Small fixups
SamCarlberg Jun 26, 2024
fd0d2d1
Move measure interfaces to their own package
SamCarlberg Jun 26, 2024
29b1e68
Implement toString for immutable measures
SamCarlberg Jun 26, 2024
542b0f6
Misc cleanup
SamCarlberg Jun 27, 2024
a44bf47
Add generic constructor to trapezoid profile constraints
SamCarlberg Jun 27, 2024
38d18ba
Add ratio measure type
SamCarlberg Jun 27, 2024
d23b27f
Add math operator overloads for all known dimensions
SamCarlberg Jun 28, 2024
0e6c8d0
Formatting and linting
SamCarlberg Jun 28, 2024
acfea50
Linting, documentation, and seal nonextensible unit types
SamCarlberg Jun 29, 2024
ab96bf3
Fix import ordering
SamCarlberg Jun 29, 2024
04cb95a
Improve `equals` logic
SamCarlberg Jun 29, 2024
d44ac50
Checkstyle
SamCarlberg Aug 13, 2024
88ecf04
Consistent API in unit subclasses for non-inherited methods
SamCarlberg Aug 13, 2024
0405dff
Refactor usages of old unit APIs
SamCarlberg Aug 13, 2024
2f7cd05
Add wpiunits to pregenerated files CI check
SamCarlberg Aug 13, 2024
90da7a9
Doc fix
SamCarlberg Aug 13, 2024
4c71208
Remove unused import from codegen script
SamCarlberg Aug 13, 2024
0e7a055
Update epilogue logging
SamCarlberg Aug 13, 2024
6fefb1c
Update cmake build
SamCarlberg Aug 13, 2024
1239fb6
Linting
SamCarlberg Aug 13, 2024
a5c821c
Fix some combined base units
SamCarlberg Aug 13, 2024
469d8dc
Add standard zero() and one() factories
SamCarlberg Aug 15, 2024
ef5b23e
Fix Newton definition
SamCarlberg Aug 15, 2024
10081d6
Suppress this-escape warning
SamCarlberg Aug 22, 2024
e20ee8e
Update EpilogueConfiguration
SamCarlberg Aug 22, 2024
3d5134a
Formatting fixes
github-actions[bot] Aug 22, 2024
a08c350
Return sharpened types from `one()` and `zero()` methods
SamCarlberg Aug 28, 2024
65e2c8c
Fix docs typo
SamCarlberg Aug 28, 2024
d7f42e1
Add a `timesConversionFactor()` method
SamCarlberg Aug 28, 2024
055b409
Add Per.timesDivisor() and Per.reciprocal()
SamCarlberg Aug 28, 2024
bbc7784
Basic script documentation
SamCarlberg Aug 28, 2024
ed9204a
Merge remote-tracking branch 'wpi/main' into unit-flattening
SamCarlberg Aug 28, 2024
eedcea4
Remove Force.mult(Distance) -> Energy function for now
SamCarlberg Aug 28, 2024
f1d9dc2
Revert example project constants
SamCarlberg Sep 2, 2024
10bb1af
Use `Measure` input parameters consistently
SamCarlberg Sep 2, 2024
5de0ae9
Add .ofNative factories to PerUnit
SamCarlberg Sep 3, 2024
9d2e419
Linting
SamCarlberg Sep 3, 2024
4d4e61c
Fix derived name/symbol indicating division instead of multiplication
SamCarlberg Sep 3, 2024
7365901
Add simple tests for PerUnit
SamCarlberg Sep 3, 2024
6bb4513
Consistently use dimension-specific measure types wherever possible
SamCarlberg Sep 4, 2024
bcdac63
Add .ofNative to MultUnit
SamCarlberg Sep 4, 2024
2140dec
Linting
SamCarlberg Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public Acceleration<D> ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<AccelerationUnit<D>> zero() {
return (Measure<AccelerationUnit<D>>) super.zero();
@SuppressWarnings({"unchecked", "rawtypes"})
public Acceleration<D> zero() {
return (Acceleration<D>) (Acceleration) super.zero();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A raw cast is required here due to conflicts with the wildcarded return supertype:

wpiunits/src/main/java/edu/wpi/first/units/AccelerationUnit.java:59: error: incompatible types: Measure<CAP#1> cannot be converted to Acceleration<D>
    return (Acceleration<D>) super.zero();
                                       ^
  where D is a type-variable:
    D extends Unit declared in class AccelerationUnit
  where CAP#1 is a fresh type-variable:
    CAP#1 extends PerUnit<VelocityUnit<D>,TimeUnit> from capture of ? extends PerUnit<VelocityUnit<D>,TimeUnit>

}

@Override
@SuppressWarnings("unchecked")
public Measure<AccelerationUnit<D>> one() {
return (Measure<AccelerationUnit<D>>) super.one();
@SuppressWarnings({"unchecked", "rawtypes"})
public Acceleration<D> one() {
return (Acceleration<D>) (Acceleration) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ public AngularAcceleration ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularAccelerationUnit> zero() {
return (Measure<AngularAccelerationUnit>) super.zero();
public AngularAcceleration zero() {
return (AngularAcceleration) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularAccelerationUnit> one() {
return (Measure<AngularAccelerationUnit>) super.one();
public AngularAcceleration one() {
return (AngularAcceleration) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ public AngularMomentum ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularMomentumUnit> zero() {
return (Measure<AngularMomentumUnit>) super.zero();
public AngularMomentum zero() {
return (AngularMomentum) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularMomentumUnit> one() {
return (Measure<AngularMomentumUnit>) super.one();
public AngularMomentum one() {
return (AngularMomentum) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public AngularVelocity ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularVelocityUnit> zero() {
return (Measure<AngularVelocityUnit>) super.zero();
public AngularVelocity zero() {
return (AngularVelocity) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<AngularVelocityUnit> one() {
return (Measure<AngularVelocityUnit>) super.one();
public AngularVelocity one() {
return (AngularVelocity) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/CurrentUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ public Current ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<CurrentUnit> zero() {
return (Measure<CurrentUnit>) super.zero();
public Current zero() {
return (Current) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<CurrentUnit> one() {
return (Measure<CurrentUnit>) super.one();
public Current one() {
return (Current) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ public Dimensionless ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<DimensionlessUnit> zero() {
return (Measure<DimensionlessUnit>) super.zero();
public Dimensionless zero() {
return (Dimensionless) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<DimensionlessUnit> one() {
return (Measure<DimensionlessUnit>) super.one();
public Dimensionless one() {
return (Dimensionless) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/DistanceUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ public Distance ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<DistanceUnit> zero() {
return (Measure<DistanceUnit>) super.zero();
public Distance zero() {
return (Distance) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<DistanceUnit> one() {
return (Measure<DistanceUnit>) super.one();
public Distance one() {
return (Distance) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/EnergyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ public Energy ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<EnergyUnit> zero() {
return (Measure<EnergyUnit>) super.zero();
public Energy zero() {
return (Energy) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<EnergyUnit> one() {
return (Measure<EnergyUnit>) super.one();
public Energy one() {
return (Energy) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/ForceUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ public Force ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<ForceUnit> zero() {
return (Measure<ForceUnit>) super.zero();
public Force zero() {
return (Force) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<ForceUnit> one() {
return (Measure<ForceUnit>) super.one();
public Force one() {
return (Force) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/FrequencyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ public Frequency ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<FrequencyUnit> zero() {
return (Measure<FrequencyUnit>) super.zero();
public Frequency zero() {
return (Frequency) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<FrequencyUnit> one() {
return (Measure<FrequencyUnit>) super.one();
public Frequency one() {
return (Frequency) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ public LinearAcceleration ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearAccelerationUnit> zero() {
return (Measure<LinearAccelerationUnit>) super.zero();
public LinearAcceleration zero() {
return (LinearAcceleration) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearAccelerationUnit> one() {
return (Measure<LinearAccelerationUnit>) super.one();
public LinearAcceleration one() {
return (LinearAcceleration) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public LinearMomentum ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearMomentumUnit> zero() {
return (Measure<LinearMomentumUnit>) super.zero();
public LinearMomentum zero() {
return (LinearMomentum) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearMomentumUnit> one() {
return (Measure<LinearMomentumUnit>) super.one();
public LinearMomentum one() {
return (LinearMomentum) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public LinearVelocity ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearVelocityUnit> zero() {
return (Measure<LinearVelocityUnit>) super.zero();
public LinearVelocity zero() {
return (LinearVelocity) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<LinearVelocityUnit> one() {
return (Measure<LinearVelocityUnit>) super.one();
public LinearVelocity one() {
return (LinearVelocity) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/MassUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ public Mass ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<MassUnit> zero() {
return (Measure<MassUnit>) super.zero();
public Mass zero() {
return (Mass) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<MassUnit> one() {
return (Measure<MassUnit>) super.one();
public Mass one() {
return (Mass) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ public MomentOfInertia ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<MomentOfInertiaUnit> zero() {
return (Measure<MomentOfInertiaUnit>) super.zero();
public MomentOfInertia zero() {
return (MomentOfInertia) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<MomentOfInertiaUnit> one() {
return (Measure<MomentOfInertiaUnit>) super.one();
public MomentOfInertia one() {
return (MomentOfInertia) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/PowerUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ public Power ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<PowerUnit> zero() {
return (Measure<PowerUnit>) super.zero();
public Power zero() {
return (Power) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<PowerUnit> one() {
return (Measure<PowerUnit>) super.one();
public Power one() {
return (Power) super.one();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public Temperature ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<TemperatureUnit> zero() {
return (Measure<TemperatureUnit>) super.zero();
public Temperature zero() {
return (Temperature) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<TemperatureUnit> one() {
return (Measure<TemperatureUnit>) super.one();
public Temperature one() {
return (Temperature) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/TimeUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ public Time ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<TimeUnit> zero() {
return (Measure<TimeUnit>) super.zero();
public Time zero() {
return (Time) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<TimeUnit> one() {
return (Measure<TimeUnit>) super.one();
public Time one() {
return (Time) super.one();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/TorqueUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public Torque ofBaseUnits(double baseUnitMagnitude) {
}

@Override
@SuppressWarnings("unchecked")
public Measure<TorqueUnit> zero() {
return (Measure<TorqueUnit>) super.zero();
public Torque zero() {
return (Torque) super.zero();
}

@Override
@SuppressWarnings("unchecked")
public Measure<TorqueUnit> one() {
return (Measure<TorqueUnit>) super.one();
public Torque one() {
return (Torque) super.one();
}

@Override
Expand Down
Loading