diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-15 14:17:36 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-15 14:17:36 +0000 |
commit | 30d90ebe7c05b7067f5c67bd8278371c2a355b02 (patch) | |
tree | 6631831b2e72edcff69fd8a7274b06a61e85c0cd /src | |
parent | 63c57613b8b53d142be6d44aed4ef9e3b9d7cf11 (diff) |
Use x*0 instead of x!=x to detect non-finite values, since x*0 also detects infinities
and it is faster (at least faster in SkRect::set).
Add unittest for SkRect::set to see that it correctly detects NaN and infinities.
git-svn-id: http://skia.googlecode.com/svn/trunk@3936 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkRect.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/core/SkRect.cpp b/src/core/SkRect.cpp index 5e3d93c339..687febe3fc 100644 --- a/src/core/SkRect.cpp +++ b/src/core/SkRect.cpp @@ -90,19 +90,24 @@ void SkRect::set(const SkPoint pts[], int count) { l = r = pts[0].fX; t = b = pts[0].fY; - SkFLOATCODE(isNaN = (l != l) | (t != t);) + + // If all of the points are finite, accum should stay 0. If we encounter + // a NaN or infinity, then accum should become NaN. + SkFLOATCODE(float accum = 0;) for (int i = 1; i < count; i++) { SkScalar x = pts[i].fX; SkScalar y = pts[i].fY; - SkFLOATCODE(isNaN |= (x != x) | (y != y);) + + SkFLOATCODE(accum *= x; accum *= y;) if (x < l) l = x; else if (x > r) r = x; if (y < t) t = y; else if (y > b) b = y; } #ifdef SK_SCALAR_IS_FLOAT - if (isNaN) { + SkASSERT(!accum || !SkScalarIsFinite(accum)); + if (accum) { l = t = r = b = 0; } #endif |