[wpimath] Add InterpolatingDoubleTreeMap.ofEntries() (#6635)

Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
This commit is contained in:
Wispy
2024-05-20 14:18:28 -05:00
committed by GitHub
parent 8c420fa4c1
commit 820f68dc08

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.math.interpolation;
import java.util.Map;
/**
* Interpolating Tree Maps are used to get values at points that are not defined by making a guess
* from points that are defined. This uses linear interpolation.
@@ -13,4 +15,19 @@ public class InterpolatingDoubleTreeMap extends InterpolatingTreeMap<Double, Dou
public InterpolatingDoubleTreeMap() {
super(InverseInterpolator.forDouble(), Interpolator.forDouble());
}
/**
* Creates an {@link InterpolatingDoubleTreeMap} from the given entries.
*
* @param entries The entries to add to the map.
* @return The map filled with the {@code entries}.
*/
@SafeVarargs
public static InterpolatingDoubleTreeMap ofEntries(Map.Entry<Double, Double>... entries) {
InterpolatingDoubleTreeMap map = new InterpolatingDoubleTreeMap();
for (var entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
}