Skip to content

Commit

Permalink
Formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SamCarlberg committed Jul 23, 2023
1 parent 679fb6f commit b680692
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
23 changes: 15 additions & 8 deletions wpiunits/src/main/java/edu/wpi/first/units/Measure.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,21 @@ default Measure<U> divide(double divisor) {

/**
* Divides this measurement by some constant divisor and returns the result. This is equivalent to
* {@code divide(scalar.baseUnitMagnitude())}
* {@code divide(divisor.baseUnitMagnitude())}
*
* @param divisor the dimensionless measure to divide by
* @see #divide(double)
* @see #times(double)
*/
default Measure<U> divide(Measure<Dimensionless> scalar) {
return divide(scalar.baseUnitMagnitude());
default Measure<U> divide(Measure<Dimensionless> divisor) {
return divide(divisor.baseUnitMagnitude());
}

/**
* Creates a velocity measure by dividing this one by a time period measure.
*
* <pre>
* Meters.of(1).per(Second) // => Measure&lt;Velocity&lt;Distance&gt;&gt;
* Millimeters.of(1).per(Millisecond) // => Measure&lt;Velocity&lt;Distance&gt;&gt; equivalent to the first measure
* </pre>
*
* @param period the time period to divide by.
Expand All @@ -153,20 +152,29 @@ default Measure<Velocity<U>> per(Measure<Time> period) {
*
* @param <U2> the type of the denominator unit
* @param denominator the denominator unit being divided by
*
* @return the relational measure
*/
default <U2 extends Unit<U2>> Measure<Per<U, U2>> per(U2 denominator) {
var newUnit = unit().per(denominator);
return newUnit.of(magnitude());
}

/** Adds another measure to this one. The resulting measure has the same unit as this one. */
/**
* Adds another measure to this one. The resulting measure has the same unit as this one.
*
* @param other the measure to add to this one
* @return a new measure containing the result
*/
default Measure<U> plus(Measure<U> other) {
return unit().ofBaseUnits(baseUnitMagnitude() + other.baseUnitMagnitude());
}

/** Subtracts another measure from this one. The resulting measure has the same unit as this one. */
/**
* Subtracts another measure from this one. The resulting measure has the same unit as this one.
*
* @param other the measure to subtract from this one
* @return a new measure containing the result
*/
default Measure<U> minus(Measure<U> other) {
return unit().ofBaseUnits(baseUnitMagnitude() - other.baseUnitMagnitude());
}
Expand Down Expand Up @@ -204,7 +212,6 @@ default MutableMeasure<U> mutableCopy() {
* @param varianceThreshold the acceptable variance threshold, in terms of an acceptable +/- error
* range multiplier. Checking if a value is within 10% means a value of 0.1 should be passed;
* checking if a value is within 1% means a value of 0.01 should be passed, and so on.
*
* @return true if this unit is near the other measure, otherwise false
*/
default boolean isNear(Measure<?> other, double varianceThreshold) {
Expand Down
22 changes: 10 additions & 12 deletions wpiunits/src/main/java/edu/wpi/first/units/MutableMeasure.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public MutableMeasure<U> mut_acc(Measure<U> other) {
// Math

/**
* Adds another measurement to this one. This will mutate the object instead of
* generating a new measurement object.
* Adds another measurement to this one. This will mutate the object instead of generating a new
* measurement object.
*
* @param other the measurement to add
* @return this measure
Expand All @@ -191,10 +191,9 @@ public MutableMeasure<U> mut_plus(Measure<U> other) {
}

/**
* Adds another measurement to this one. This will mutate the object instead of
* generating a new measurement object. This is a denormalized version of
* {@link #mut_plus(Measure)} to avoid having to wrap raw numbers in a {@code Measure} object
* and pay for an object allocation.
* Adds another measurement to this one. This will mutate the object instead of generating a new
* measurement object. This is a denormalized version of {@link #mut_plus(Measure)} to avoid
* having to wrap raw numbers in a {@code Measure} object and pay for an object allocation.
*
* @param magnitude the magnitude of the other measurement.
* @param unit the unit of the other measurement
Expand All @@ -206,8 +205,8 @@ public MutableMeasure<U> mut_plus(double magnitude, U unit) {
}

/**
* Subtracts another measurement to this one. This will mutate the object instead of
* generating a new measurement object.
* Subtracts another measurement to this one. This will mutate the object instead of generating a
* new measurement object.
*
* @param other the measurement to add
* @return this measure
Expand All @@ -217,10 +216,9 @@ public MutableMeasure<U> mut_minus(Measure<U> other) {
}

/**
* Subtracts another measurement to this one. This will mutate the object instead of
* generating a new measurement object. This is a denormalized version of
* {@link #mut_minus(Measure)} to avoid having to wrap raw numbers in a {@code Measure} object
* and pay for an object allocation.
* Subtracts another measurement to this one. This will mutate the object instead of generating a
* new measurement object. This is a denormalized version of {@link #mut_minus(Measure)} to avoid
* having to wrap raw numbers in a {@code Measure} object and pay for an object allocation.
*
* @param magnitude the magnitude of the other measurement.
* @return this measure
Expand Down
4 changes: 4 additions & 0 deletions wpiunits/src/main/java/edu/wpi/first/units/UnitBuilder.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.units;

import java.lang.reflect.Constructor;
Expand Down
17 changes: 11 additions & 6 deletions wpiunits/src/main/java/edu/wpi/first/units/Units.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ private Units() {
.symbol("°F")
.make();

// Standard feedforward units for kV and kA (kS and kG are just volts, which is already defined earlier)
public static final Per<Voltage, Velocity<Distance>> VoltsPerMeterPerSecond = Volts.per(MetersPerSecond);
public static final Per<Voltage, Velocity<Velocity<Distance>>> VoltsPerMeterPerSecondSquared = Volts.per(MetersPerSecondPerSecond);

public static final Per<Voltage, Velocity<Angle>> VoltsPerRadianPerSecond = Volts.per(RadiansPerSecond);
public static final Per<Voltage, Velocity<Velocity<Angle>>> VoltsPerRadianPerSecondSquared = Volts.per(RadiansPerSecond.per(Second));
// Standard feedforward units for kV and kA.
// kS and kG are just volts, which is already defined earlier
public static final Per<Voltage, Velocity<Distance>> VoltsPerMeterPerSecond =
Volts.per(MetersPerSecond);
public static final Per<Voltage, Velocity<Velocity<Distance>>> VoltsPerMeterPerSecondSquared =
Volts.per(MetersPerSecondPerSecond);

public static final Per<Voltage, Velocity<Angle>> VoltsPerRadianPerSecond =
Volts.per(RadiansPerSecond);
public static final Per<Voltage, Velocity<Velocity<Angle>>> VoltsPerRadianPerSecondSquared =
Volts.per(RadiansPerSecond.per(Second));

/**
* Creates a unit equal to a thousandth of the base unit, eg Milliseconds = Milli(Units.Seconds).
Expand Down
4 changes: 4 additions & 0 deletions wpiunits/src/test/java/edu/wpi/first/units/MultTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.units;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down

0 comments on commit b680692

Please sign in to comment.