| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 /** Returns true if x is not NaN and not infinite | 120 /** Returns true if x is not NaN and not infinite |
| 121 */ | 121 */ |
| 122 static inline bool SkScalarIsFinite(SkScalar x) { | 122 static inline bool SkScalarIsFinite(SkScalar x) { |
| 123 // We rely on the following behavior of infinities and nans | 123 // We rely on the following behavior of infinities and nans |
| 124 // 0 * finite --> 0 | 124 // 0 * finite --> 0 |
| 125 // 0 * infinity --> NaN | 125 // 0 * infinity --> NaN |
| 126 // 0 * NaN --> NaN | 126 // 0 * NaN --> NaN |
| 127 SkScalar prod = x * 0; | 127 SkScalar prod = x * 0; |
| 128 // At this point, prod will either be NaN or 0 | 128 // At this point, prod will either be NaN or 0 |
| 129 // Therefore we can return (prod == prod) or (0 == prod). | 129 // Therefore we can return (prod == prod) or (0 == prod). |
| 130 return prod == prod; | 130 return !SkScalarIsNaN(prod); |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5)
explicitly using | 134 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5)
explicitly using |
| 135 * double, to avoid possibly losing the low bit(s) of the answer before calling
floor(). | 135 * double, to avoid possibly losing the low bit(s) of the answer before calling
floor(). |
| 136 * | 136 * |
| 137 * This routine will likely be slower than SkScalarRoundToInt(), and should onl
y be used when the | 137 * This routine will likely be slower than SkScalarRoundToInt(), and should onl
y be used when the |
| 138 * extra precision is known to be valuable. | 138 * extra precision is known to be valuable. |
| 139 * | 139 * |
| 140 * In particular, this catches the following case: | 140 * In particular, this catches the following case: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 SkASSERT(n >= 0); | 241 SkASSERT(n >= 0); |
| 242 for (int i = 0; i < n; ++i) { | 242 for (int i = 0; i < n; ++i) { |
| 243 if (a[i] != b[i]) { | 243 if (a[i] != b[i]) { |
| 244 return false; | 244 return false; |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 #endif | 250 #endif |
| OLD | NEW |