Add a simple helper to remap values (#2850)

This commit is contained in:
Jesse Hills 2021-12-02 21:23:11 +13:00 committed by GitHub
parent 6a0b343289
commit f0bcf81a98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -415,4 +415,14 @@ optional<T> parse_number(const std::string &str) {
///@}
/// @name Number manipulation
///@{
/// Remap a number from one range to another.
template<typename T, typename U> T remap(U value, U min, U max, T min_out, T max_out) {
return (value - min) * (max_out - min_out) / (max - min) + min_out;
}
///@}
} // namespace esphome