rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.89k stars 12.67k forks source link

Implement interpolation methods in std #71015

Open vertexclique opened 4 years ago

vertexclique commented 4 years ago

Currently, linear interpolation (aka lerp) and midpoint don't exist in std. But exists in C++20 forwards. It would be nice to have them.

vertexclique commented 4 years ago

I am working on lerp, soon I will open a PR for it.

vertexclique commented 4 years ago

@rustbot claim

clarfonthey commented 3 years ago

(I claimed it since there was no new PR after a year, also repurposing this as a tracking issue)

bugadani commented 3 years ago

Just want to throw in some food for thought as I think it's loosely related:

In p5js, there is the map function that can interpolate a value from an input range to an output range. This is more general than @clarfonthey's proposed lerp as it doesn't assume a constant input range, but the downside is a lot more parameters.

I think if we were to introduce lerp, a conceptual sibling normalize would also be useful. normalize would take a number and a range, and produce a value such that A.normalize(A, B) = 0 and B.normalize(A, B) = 1. This would enable a map-like operation by chaining normalize and lerp: A.normalize(IN_MIN, IN_MAX).lerp(OUT_MIN, OUT_MAX).

dtolnay commented 2 years ago

@rustbot release-assignment