Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: include/core/SkScalar.h

Issue 993593002: Use SkTMin and SkTMax for clamp/pin. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: State type and auto convert constant. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkScalar_DEFINED 8 #ifndef SkScalar_DEFINED
9 #define SkScalar_DEFINED 9 #define SkScalar_DEFINED
10 10
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 * ix = SkDScalarRoundToInt(x); 162 * ix = SkDScalarRoundToInt(x);
163 * SkASSERT(0 == ix); // <--- succeeds 163 * SkASSERT(0 == ix); // <--- succeeds
164 */ 164 */
165 static inline int SkDScalarRoundToInt(SkScalar x) { 165 static inline int SkDScalarRoundToInt(SkScalar x) {
166 double xx = x; 166 double xx = x;
167 xx += 0.5; 167 xx += 0.5;
168 return (int)floor(xx); 168 return (int)floor(xx);
169 } 169 }
170 170
171 static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) { 171 static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) {
172 return x < 0 ? 0 : x > max ? max : x; 172 x = SkTMin(x, max);
173 x = SkTMax<SkScalar>(x, 0);
174 return x;
173 } 175 }
174 176
175 static inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) { 177 static inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) {
176 return x < min ? min : x > max ? max : x; 178 x = SkTMin(x, max);
179 x = SkTMax(x, min);
180 return x;
177 } 181 }
178 182
179 SkScalar SkScalarSinCos(SkScalar radians, SkScalar* cosValue); 183 SkScalar SkScalarSinCos(SkScalar radians, SkScalar* cosValue);
180 184
181 static inline SkScalar SkScalarSquare(SkScalar x) { return x * x; } 185 static inline SkScalar SkScalarSquare(SkScalar x) { return x * x; }
182 186
183 #define SkScalarMul(a, b) ((SkScalar)(a) * (b)) 187 #define SkScalarMul(a, b) ((SkScalar)(a) * (b))
184 #define SkScalarMulAdd(a, b, c) ((SkScalar)(a) * (b) + (c)) 188 #define SkScalarMulAdd(a, b, c) ((SkScalar)(a) * (b) + (c))
185 #define SkScalarDiv(a, b) ((SkScalar)(a) / (b)) 189 #define SkScalarDiv(a, b) ((SkScalar)(a) / (b))
186 #define SkScalarMulDiv(a, b, c) ((SkScalar)(a) * (b) / (c)) 190 #define SkScalarMulDiv(a, b, c) ((SkScalar)(a) * (b) / (c))
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 SkASSERT(n >= 0); 263 SkASSERT(n >= 0);
260 for (int i = 0; i < n; ++i) { 264 for (int i = 0; i < n; ++i) {
261 if (a[i] != b[i]) { 265 if (a[i] != b[i]) {
262 return false; 266 return false;
263 } 267 }
264 } 268 }
265 return true; 269 return true;
266 } 270 }
267 271
268 #endif 272 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698