| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 /** Returns true if x is not NaN and not infinite | 122 /** Returns true if x is not NaN and not infinite |
| 123 */ | 123 */ |
| 124 static inline bool SkScalarIsFinite(SkScalar x) { | 124 static inline bool SkScalarIsFinite(SkScalar x) { |
| 125 // We rely on the following behavior of infinities and nans | 125 // We rely on the following behavior of infinities and nans |
| 126 // 0 * finite --> 0 | 126 // 0 * finite --> 0 |
| 127 // 0 * infinity --> NaN | 127 // 0 * infinity --> NaN |
| 128 // 0 * NaN --> NaN | 128 // 0 * NaN --> NaN |
| 129 SkScalar prod = x * 0; | 129 SkScalar prod = x * 0; |
| 130 // At this point, prod will either be NaN or 0 | 130 // At this point, prod will either be NaN or 0 |
| 131 // Therefore we can return (prod == prod) or (0 == prod). | |
| 132 return !SkScalarIsNaN(prod); | 131 return !SkScalarIsNaN(prod); |
| 133 } | 132 } |
| 134 | 133 |
| 134 static inline bool SkScalarsAreFinite(SkScalar a, SkScalar b) { |
| 135 SkScalar prod = 0; |
| 136 prod *= a; |
| 137 prod *= b; |
| 138 // At this point, prod will either be NaN or 0 |
| 139 return !SkScalarIsNaN(prod); |
| 140 } |
| 141 |
| 142 static inline bool SkScalarsAreFinite(const SkScalar array[], int count) { |
| 143 SkScalar prod = 0; |
| 144 for (int i = 0; i < count; ++i) { |
| 145 prod *= array[i]; |
| 146 } |
| 147 // At this point, prod will either be NaN or 0 |
| 148 return !SkScalarIsNaN(prod); |
| 149 } |
| 150 |
| 135 /** | 151 /** |
| 136 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5)
explicitly using | 152 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5)
explicitly using |
| 137 * double, to avoid possibly losing the low bit(s) of the answer before calling
floor(). | 153 * double, to avoid possibly losing the low bit(s) of the answer before calling
floor(). |
| 138 * | 154 * |
| 139 * This routine will likely be slower than SkScalarRoundToInt(), and should onl
y be used when the | 155 * This routine will likely be slower than SkScalarRoundToInt(), and should onl
y be used when the |
| 140 * extra precision is known to be valuable. | 156 * extra precision is known to be valuable. |
| 141 * | 157 * |
| 142 * In particular, this catches the following case: | 158 * In particular, this catches the following case: |
| 143 * SkScalar x = 0.49999997; | 159 * SkScalar x = 0.49999997; |
| 144 * int ix = SkScalarRoundToInt(x); | 160 * int ix = SkScalarRoundToInt(x); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 SkASSERT(n >= 0); | 259 SkASSERT(n >= 0); |
| 244 for (int i = 0; i < n; ++i) { | 260 for (int i = 0; i < n; ++i) { |
| 245 if (a[i] != b[i]) { | 261 if (a[i] != b[i]) { |
| 246 return false; | 262 return false; |
| 247 } | 263 } |
| 248 } | 264 } |
| 249 return true; | 265 return true; |
| 250 } | 266 } |
| 251 | 267 |
| 252 #endif | 268 #endif |
| OLD | NEW |