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

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

Issue 913743002: check for nonfinites in rrects (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: update test for nonfinites Created 5 years, 10 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 | src/core/SkRRect.cpp » ('j') | 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698