mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[docs] Add wpiunits to JavaDocs (#5793)
Co-authored-by: Sam Carlberg <sam.carlberg@gmail.com>
This commit is contained in:
@@ -8,6 +8,12 @@ import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface UnaryFunction {
|
||||
/**
|
||||
* Applies this function to the input value and returns the result.
|
||||
*
|
||||
* @param input the input value to the function
|
||||
* @return the result
|
||||
*/
|
||||
double apply(double input);
|
||||
|
||||
/**
|
||||
@@ -15,13 +21,14 @@ public interface UnaryFunction {
|
||||
* input.
|
||||
*
|
||||
* <pre>
|
||||
* f = x -> x + 1 // f(x) = x + 1
|
||||
* g = x -> 2 * x // g(x) = 2x
|
||||
* f = x -> x + 1 // f(x) = x + 1
|
||||
* g = x -> 2 * x // g(x) = 2x
|
||||
*
|
||||
* h = f.pipeTo(g) // h(x) = g(f(x))
|
||||
* </pre>
|
||||
*
|
||||
* @param next the next operation to pipe to
|
||||
* @return the composite function g(f(x))
|
||||
*/
|
||||
default UnaryFunction pipeTo(UnaryFunction next) {
|
||||
Objects.requireNonNull(next, "The next operation in the chain must be provided");
|
||||
@@ -29,19 +36,34 @@ public interface UnaryFunction {
|
||||
return x -> next.apply(this.apply(x));
|
||||
}
|
||||
|
||||
/** h(x) = f(x) * g(x). */
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = f(x) * g(x).
|
||||
*
|
||||
* @param multiplier the function to multiply this one by
|
||||
* @return the composite function f(x) * g(x)
|
||||
*/
|
||||
default UnaryFunction mult(UnaryFunction multiplier) {
|
||||
Objects.requireNonNull(multiplier, "A multiplier function must be provided");
|
||||
|
||||
return x -> this.apply(x) * multiplier.apply(x);
|
||||
}
|
||||
|
||||
/** g(x) = f(x) * k. */
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = k * f(x).
|
||||
*
|
||||
* @param multiplier the constant value to multiply this function's results by
|
||||
* @return the composite function k * f(x)
|
||||
*/
|
||||
default UnaryFunction mult(double multiplier) {
|
||||
return x -> this.apply(x) * multiplier;
|
||||
}
|
||||
|
||||
/** h(x) = f(x) / g(x). */
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = f(x) / g(x).
|
||||
*
|
||||
* @param divisor the function to divide this one by
|
||||
* @return the composite function f(x) / g(x)
|
||||
*/
|
||||
default UnaryFunction div(UnaryFunction divisor) {
|
||||
Objects.requireNonNull(divisor, "A divisor function must be provided");
|
||||
|
||||
@@ -59,18 +81,34 @@ public interface UnaryFunction {
|
||||
};
|
||||
}
|
||||
|
||||
/** g(x) * f(x) / k. */
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = 1/k * f(x).
|
||||
*
|
||||
* @param divisor the constant value to divide this function's results by
|
||||
* @return the composite function 1/k * f(x)
|
||||
*/
|
||||
default UnaryFunction div(double divisor) {
|
||||
return x -> this.apply(x) / divisor;
|
||||
}
|
||||
|
||||
/** h(x) = f(x) ^ g(x). */
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = f(x) ^ g(x).
|
||||
*
|
||||
* @param exponent the function to exponentiate this function's results by
|
||||
* @return the composite function f(x) ^ g(x)
|
||||
*/
|
||||
default UnaryFunction exp(UnaryFunction exponent) {
|
||||
Objects.requireNonNull(exponent, "An exponent function must be provided");
|
||||
|
||||
return x -> Math.pow(this.apply(x), exponent.apply(x));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a composite function h(x) such that h(x) = f(x) ^ k.
|
||||
*
|
||||
* @param exponent the constant value to exponentiate this function's results by
|
||||
* @return the composite function f(x) ^ k
|
||||
*/
|
||||
default UnaryFunction exp(double exponent) {
|
||||
return x -> Math.pow(this.apply(x), exponent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user