mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpimath] Rename 1D copySignPow to match 2D copyDirectionPow (#8286)
This commit is contained in:
@@ -157,7 +157,7 @@ public final class MathUtil {
|
||||
* @param maxMagnitude The maximum expected absolute value of input. Must be positive.
|
||||
* @return The transformed value with the same sign and scaled to the input range.
|
||||
*/
|
||||
public static double copySignPow(double value, double exponent, double maxMagnitude) {
|
||||
public static double copyDirectionPow(double value, double exponent, double maxMagnitude) {
|
||||
return Math.copySign(Math.pow(Math.abs(value) / maxMagnitude, exponent), value) * maxMagnitude;
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ public final class MathUtil {
|
||||
* positive.
|
||||
* @return The transformed value with the same sign.
|
||||
*/
|
||||
public static double copySignPow(double value, double exponent) {
|
||||
return copySignPow(value, exponent, 1);
|
||||
public static double copyDirectionPow(double value, double exponent) {
|
||||
return copyDirectionPow(value, exponent, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +196,7 @@ public final class MathUtil {
|
||||
if (value.norm() < 1e-9) {
|
||||
return value.times(0);
|
||||
}
|
||||
return value.unit().times(copySignPow(value.norm(), exponent, maxMagnitude));
|
||||
return value.unit().times(copyDirectionPow(value.norm(), exponent, maxMagnitude));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -143,7 +143,8 @@ Eigen::Vector<T, N> ApplyDeadband(const Eigen::Vector<T, N>& value, T deadband,
|
||||
*/
|
||||
template <typename T>
|
||||
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
|
||||
constexpr T CopySignPow(T value, double exponent, T maxMagnitude = T{1.0}) {
|
||||
constexpr T CopyDirectionPow(T value, double exponent,
|
||||
T maxMagnitude = T{1.0}) {
|
||||
if constexpr (std::is_arithmetic_v<T>) {
|
||||
return gcem::copysign(
|
||||
gcem::pow(gcem::abs(value) / maxMagnitude, exponent) * maxMagnitude,
|
||||
@@ -183,7 +184,7 @@ Eigen::Vector<T, N> CopyDirectionPow(const Eigen::Vector<T, N>& value,
|
||||
return Eigen::Vector<T, N>::Zero();
|
||||
}
|
||||
return value.normalized() *
|
||||
CopySignPow(value.norm(), exponent, maxMagnitude);
|
||||
CopyDirectionPow(value.norm(), exponent, maxMagnitude);
|
||||
} else {
|
||||
const Eigen::Vector<double, N> asDouble = value.template cast<double>();
|
||||
const Eigen::Vector<double, N> processed =
|
||||
|
||||
Reference in New Issue
Block a user