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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 76 |
77 #define SkScalarFloorToScalar(x) sk_float_floor(x) | 77 #define SkScalarFloorToScalar(x) sk_float_floor(x) |
78 #define SkScalarCeilToScalar(x) sk_float_ceil(x) | 78 #define SkScalarCeilToScalar(x) sk_float_ceil(x) |
79 #define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f) | 79 #define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f) |
80 | 80 |
81 #define SkScalarFloorToInt(x) sk_float_floor2int(x) | 81 #define SkScalarFloorToInt(x) sk_float_floor2int(x) |
82 #define SkScalarCeilToInt(x) sk_float_ceil2int(x) | 82 #define SkScalarCeilToInt(x) sk_float_ceil2int(x) |
83 #define SkScalarRoundToInt(x) sk_float_round2int(x) | 83 #define SkScalarRoundToInt(x) sk_float_round2int(x) |
84 #define SkScalarTruncToInt(x) static_cast<int>(x) | 84 #define SkScalarTruncToInt(x) static_cast<int>(x) |
85 | 85 |
86 /** | |
87 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5) explicitly using | |
88 * double, to avoid possibly losing the low bit(s) of the answer before calling floor(). | |
89 * | |
90 * This routine will likely be slower than SkScalarRoundToInt(), and should onl y be used when the | |
91 * extra precision is known to be valuable. | |
92 * | |
93 * In particular, this catches the following case: | |
94 * SkScalar x = 0.49999997; | |
95 * int ix = SkScalarRoundToInt(x); | |
96 * SkASSERT(0 == ix); // <--- fails | |
97 * ix = SkDScalarRoundToInt(x); | |
98 * SkASSERT(0 == ix); // <--- succeeds | |
99 */ | |
100 static inline int SkDScalarRoundToInt(SkScalar x) { | |
101 double xx = x; | |
102 xx += 0.5; | |
103 return (int)floor(xx); | |
bungeman-skia
2014/05/05 15:39:31
So this is round to nearest, round half up. C++11
reed1
2014/05/05 15:56:37
Agreed, that's why unfortunately we have to write
| |
104 } | |
105 | |
86 /** Returns the absolute value of the specified SkScalar | 106 /** Returns the absolute value of the specified SkScalar |
87 */ | 107 */ |
88 #define SkScalarAbs(x) sk_float_abs(x) | 108 #define SkScalarAbs(x) sk_float_abs(x) |
89 /** Return x with the sign of y | 109 /** Return x with the sign of y |
90 */ | 110 */ |
91 #define SkScalarCopySign(x, y) sk_float_copysign(x, y) | 111 #define SkScalarCopySign(x, y) sk_float_copysign(x, y) |
92 /** Returns the value pinned between 0 and max inclusive | 112 /** Returns the value pinned between 0 and max inclusive |
93 */ | 113 */ |
94 inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) { | 114 inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) { |
95 return x < 0 ? 0 : x > max ? max : x; | 115 return x < 0 ? 0 : x > max ? max : x; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 SkASSERT(n >= 0); | 245 SkASSERT(n >= 0); |
226 for (int i = 0; i < n; ++i) { | 246 for (int i = 0; i < n; ++i) { |
227 if (a[i] != b[i]) { | 247 if (a[i] != b[i]) { |
228 return false; | 248 return false; |
229 } | 249 } |
230 } | 250 } |
231 return true; | 251 return true; |
232 } | 252 } |
233 | 253 |
234 #endif | 254 #endif |
OLD | NEW |