| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 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 #include "SkFloatingPoint.h" | 8 #include "SkFloatingPoint.h" |
| 9 #include "SkMath.h" | 9 #include "SkMath.h" |
| 10 #include "SkPoint.h" | 10 #include "SkPoint.h" |
| 11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 #include "Test.h" | 13 #include "Test.h" |
| 14 | 14 |
| 15 static void test_roundtoint(skiatest::Reporter* reporter) { |
| 16 SkScalar x = 0.49999997; |
| 17 int ix = SkScalarRoundToInt(x); |
| 18 // We "should" get 0, since x < 0.5, but we don't due to float addition roun
ding up the low |
| 19 // bit after adding 0.5. |
| 20 REPORTER_ASSERT(reporter, 1 == ix); |
| 21 |
| 22 // This version explicitly performs the +0.5 step using double, which should
avoid losing the |
| 23 // low bits. |
| 24 ix = SkDScalarRoundToInt(x); |
| 25 REPORTER_ASSERT(reporter, 0 == ix); |
| 26 } |
| 27 |
| 15 struct PointSet { | 28 struct PointSet { |
| 16 const SkPoint* fPts; | 29 const SkPoint* fPts; |
| 17 size_t fCount; | 30 size_t fCount; |
| 18 bool fIsFinite; | 31 bool fIsFinite; |
| 19 }; | 32 }; |
| 20 | 33 |
| 21 static void test_isRectFinite(skiatest::Reporter* reporter) { | 34 static void test_isRectFinite(skiatest::Reporter* reporter) { |
| 22 static const SkPoint gF0[] = { | 35 static const SkPoint gF0[] = { |
| 23 { 0, 0 }, { 1, 1 } | 36 { 0, 0 }, { 1, 1 } |
| 24 }; | 37 }; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 193 |
| 181 test_isRectFinite(reporter); | 194 test_isRectFinite(reporter); |
| 182 } | 195 } |
| 183 | 196 |
| 184 #if defined _WIN32 | 197 #if defined _WIN32 |
| 185 #pragma warning ( pop ) | 198 #pragma warning ( pop ) |
| 186 #endif | 199 #endif |
| 187 | 200 |
| 188 DEF_TEST(Scalar, reporter) { | 201 DEF_TEST(Scalar, reporter) { |
| 189 test_isfinite(reporter); | 202 test_isfinite(reporter); |
| 203 test_roundtoint(reporter); |
| 190 } | 204 } |
| OLD | NEW |