OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |