| Romain Guy | 5d4bae7 | 2016-11-08 09:49:25 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2016 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef UI_SCALAR_H | 
|  | 18 | #define UI_SCALAR_H | 
|  | 19 |  | 
|  | 20 | #include <algorithm> | 
|  | 21 | #include <cmath> | 
|  | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 |  | 
|  | 25 | template<typename T> | 
|  | 26 | static constexpr T saturate(T v) noexcept { | 
|  | 27 | return T(std::min(T(1), std::max(T(0), v))); | 
|  | 28 | } | 
|  | 29 |  | 
|  | 30 | template<typename T> | 
|  | 31 | static constexpr T clamp(T v, T min, T max) noexcept { | 
|  | 32 | return T(std::min(max, std::max(min, v))); | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | template<typename T> | 
|  | 36 | static constexpr T mix(T x, T y, T a) noexcept { | 
|  | 37 | return x * (T(1) - a) + y * a; | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | template<typename T> | 
|  | 41 | static constexpr T lerp(T x, T y, T a) noexcept { | 
|  | 42 | return mix(x, y, a); | 
|  | 43 | } | 
|  | 44 |  | 
| Romain Guy | 5d4bae7 | 2016-11-08 09:49:25 -0800 | [diff] [blame] | 45 | } // namespace std | 
|  | 46 |  | 
|  | 47 | #endif // UI_SCALAR_H |