-
Notifications
You must be signed in to change notification settings - Fork 694
Add an InterpolatingMeasureTreeMap #8670
Description
Is your feature request related to a problem? Please describe.
Whenever trying to use the InterpolatingDoubleTreeMap to store measurements, you can't really take advantage of the unit-safety of the Units library, and if you need to convert between units, you can often end up with stuff like this.
map.put(Feet.of(5.0).in(Meters), RPM.of(10.0).in(RadiansPerSecond));
map.put(Feet.of(10.0).in(Meters), RPM.of(20.0).in(RadiansPerSecond));
map.put(Feet.of(20.0).in(Meters), RPM.of(50.0).in(RadiansPerSecond));And it isn't great to get values from either, especially if you want it back in Units.
RadiansPerSecond.of(map.get(10.0)).in(RotationsPerSecond);Describe the solution you'd like
Some sort of map that instead takes in Measures would be much better in this sort of a situation. You could define it something like this.
map.put(Feet.of(5.0), RPM.of(10.0));
map.put(Feet.of(10.0), RPM.of(20.0));
map.put(Feet.of(20.0), RPM.of(50.0));And then when you need a value, you don't need to think about what units it's in.
map.get(Meters.of(3.0)).in(RotationsPerSecond);Describe alternatives you've considered
Mainly just the stuff above with just converting when you add/fetch the keys.
Additional context
I'd be willing to implement this myself (in fact, I already have something working, which you can find here, with a sample of it being used here - this is pretty heavily based off of some of @Team254's code). The main thing I would like to ask for some help with though is figuring out some sort of way to remove the requirement to pass in both the Measure type and the Unit type, because that makes it a little annoying/unintuitive to create these. Not sure if that's really possible though.