aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTypes.h
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-04-16 12:18:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-16 12:18:28 -0700
commitfd0ecf46ce7736a86dd38d8cfc96078e588d10a3 (patch)
treee7fe604419464cc70c70eb940258b29df0b608a2 /include/core/SkTypes.h
parent5b9f42c4d1ddc776334b3de676450f4cdaf607bd (diff)
Add SkTPin.
Currently there exist SkScalarPin and SkPin32, and in a future change another version is desired. This change introduces SkTPin and changes SkScalarPin and SkPin32 to use it. Review URL: https://codereview.chromium.org/1090003002
Diffstat (limited to 'include/core/SkTypes.h')
-rw-r--r--include/core/SkTypes.h15
1 files changed, 6 insertions, 9 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 9014620695..c2c8f0a80b 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -400,16 +400,13 @@ static inline int32_t SkFastMin32(int32_t value, int32_t max) {
return value;
}
-/** Returns signed 32 bit value pinned between min and max, inclusively
-*/
+template <typename T> static inline const T& SkTPin(const T& x, const T& min, const T& max) {
+ return SkTMax(SkTMin(x, max), min);
+}
+
+/** Returns signed 32 bit value pinned between min and max, inclusively. */
static inline int32_t SkPin32(int32_t value, int32_t min, int32_t max) {
- if (value < min) {
- value = min;
- }
- if (value > max) {
- value = max;
- }
- return value;
+ return SkTPin(value, min, max);
}
static inline uint32_t SkSetClearShift(uint32_t bits, bool cond,