mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[wpimath] Replace MathUtil.clamp() with Java 21 Math.clamp() (#8186)
This commit is contained in:
@@ -18,21 +18,6 @@ class MathUtilTest extends UtilityClassTest<MathUtil> {
|
||||
super(MathUtil.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClamp() {
|
||||
// int
|
||||
assertEquals(5, MathUtil.clamp(10, 1, 5));
|
||||
|
||||
// double
|
||||
assertEquals(5.5, MathUtil.clamp(10.5, 1.5, 5.5));
|
||||
|
||||
// negative int
|
||||
assertEquals(-5, MathUtil.clamp(-10, -5, -1));
|
||||
|
||||
// negative double
|
||||
assertEquals(-5.5, MathUtil.clamp(-10.5, -5.5, -1.5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testApplyDeadbandUnityScale() {
|
||||
// < 0
|
||||
|
||||
@@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import edu.wpi.first.math.MatBuilder;
|
||||
import edu.wpi.first.math.MathUtil;
|
||||
import edu.wpi.first.math.Matrix;
|
||||
import edu.wpi.first.math.Nat;
|
||||
import edu.wpi.first.math.StateSpaceUtil;
|
||||
@@ -297,7 +296,7 @@ class MerweUKFTest {
|
||||
return MatBuilder.fill(
|
||||
Nat.N1(),
|
||||
Nat.N1(),
|
||||
MathUtil.clamp(
|
||||
Math.clamp(
|
||||
8 * Math.sin(Math.PI * Math.sqrt(2.0) * t)
|
||||
+ 6 * Math.sin(Math.PI * Math.sqrt(3.0) * t)
|
||||
+ 4 * Math.sin(Math.PI * Math.sqrt(5.0) * t),
|
||||
|
||||
@@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import edu.wpi.first.math.MatBuilder;
|
||||
import edu.wpi.first.math.MathUtil;
|
||||
import edu.wpi.first.math.Matrix;
|
||||
import edu.wpi.first.math.Nat;
|
||||
import edu.wpi.first.math.StateSpaceUtil;
|
||||
@@ -297,7 +296,7 @@ class S3UKFTest {
|
||||
return MatBuilder.fill(
|
||||
Nat.N1(),
|
||||
Nat.N1(),
|
||||
MathUtil.clamp(
|
||||
Math.clamp(
|
||||
8 * Math.sin(Math.PI * Math.sqrt(2.0) * t)
|
||||
+ 6 * Math.sin(Math.PI * Math.sqrt(3.0) * t)
|
||||
+ 4 * Math.sin(Math.PI * Math.sqrt(5.0) * t),
|
||||
|
||||
@@ -6,7 +6,6 @@ package edu.wpi.first.math.optimization;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import edu.wpi.first.math.MathUtil;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -20,7 +19,7 @@ class SimulatedAnnealingTest {
|
||||
var simulatedAnnealing =
|
||||
new SimulatedAnnealing<Double>(
|
||||
2.0,
|
||||
x -> MathUtil.clamp(x + (Math.random() - 0.5) * stepSize, -3, 3),
|
||||
x -> Math.clamp(x + (Math.random() - 0.5) * stepSize, -3, 3),
|
||||
function::applyAsDouble);
|
||||
|
||||
double solution = simulatedAnnealing.solve(-1.0, 5000);
|
||||
@@ -37,7 +36,7 @@ class SimulatedAnnealingTest {
|
||||
var simulatedAnnealing =
|
||||
new SimulatedAnnealing<Double>(
|
||||
2.0,
|
||||
x -> MathUtil.clamp(x + (Math.random() - 0.5) * stepSize, 0, 7),
|
||||
x -> Math.clamp(x + (Math.random() - 0.5) * stepSize, 0, 7),
|
||||
function::applyAsDouble);
|
||||
|
||||
double solution = simulatedAnnealing.solve(-1.0, 5000);
|
||||
|
||||
Reference in New Issue
Block a user