1 /* 2 * Copyright 2020 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkTPin_DEFINED 9 #define SkTPin_DEFINED 10 11 #include <algorithm> 12 13 /** @return x pinned (clamped) between lo and hi, inclusively. 14 15 Unlike std::clamp(), SkTPin() always returns a value between lo and hi. 16 If x is NaN, SkTPin() returns lo but std::clamp() returns NaN. 17 */ 18 template <typename T> SkTPin(const T & x,const T & lo,const T & hi)19static constexpr const T& SkTPin(const T& x, const T& lo, const T& hi) { 20 return std::max(lo, std::min(x, hi)); 21 } 22 23 #endif 24