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 "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
11 #include "SkMath.h" | 11 #include "SkMath.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
14 #include "SkRect.h" | 14 #include "SkRect.h" |
15 | 15 |
16 struct PointSet { | 16 struct PointSet { |
17 const SkPoint* fPts; | 17 const SkPoint* fPts; |
18 size_t fCount; | 18 size_t fCount; |
19 bool fIsFinite; | 19 bool fIsFinite; |
20 }; | 20 }; |
21 | 21 |
22 static void test_isRectFinite(skiatest::Reporter* reporter) { | 22 static void test_isRectFinite(skiatest::Reporter* reporter) { |
23 #ifdef SK_SCALAR_IS_FLOAT | |
24 static const SkPoint gF0[] = { | 23 static const SkPoint gF0[] = { |
25 { 0, 0 }, { 1, 1 } | 24 { 0, 0 }, { 1, 1 } |
26 }; | 25 }; |
27 static const SkPoint gF1[] = { | 26 static const SkPoint gF1[] = { |
28 { 0, 0 }, { 1, 1 }, { 99.234f, -42342 } | 27 { 0, 0 }, { 1, 1 }, { 99.234f, -42342 } |
29 }; | 28 }; |
30 | 29 |
31 static const SkPoint gI0[] = { | 30 static const SkPoint gI0[] = { |
32 { 0, 0 }, { 1, 1 }, { 99.234f, -42342 }, { SK_ScalarNaN, 3 }, { 2, 3 }, | 31 { 0, 0 }, { 1, 1 }, { 99.234f, -42342 }, { SK_ScalarNaN, 3 }, { 2, 3 }, |
33 }; | 32 }; |
(...skipping 20 matching lines...) Expand all Loading... |
54 { gI2, SK_ARRAY_COUNT(gI2), false }, | 53 { gI2, SK_ARRAY_COUNT(gI2), false }, |
55 { gI3, SK_ARRAY_COUNT(gI3), false }, | 54 { gI3, SK_ARRAY_COUNT(gI3), false }, |
56 }; | 55 }; |
57 | 56 |
58 for (size_t i = 0; i < SK_ARRAY_COUNT(gSets); ++i) { | 57 for (size_t i = 0; i < SK_ARRAY_COUNT(gSets); ++i) { |
59 SkRect r; | 58 SkRect r; |
60 r.set(gSets[i].fPts, gSets[i].fCount); | 59 r.set(gSets[i].fPts, gSets[i].fCount); |
61 bool rectIsFinite = !r.isEmpty(); | 60 bool rectIsFinite = !r.isEmpty(); |
62 REPORTER_ASSERT(reporter, gSets[i].fIsFinite == rectIsFinite); | 61 REPORTER_ASSERT(reporter, gSets[i].fIsFinite == rectIsFinite); |
63 } | 62 } |
64 #endif | |
65 } | 63 } |
66 | 64 |
67 static bool isFinite_int(float x) { | 65 static bool isFinite_int(float x) { |
68 uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts | 66 uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts |
69 int exponent = bits << 1 >> 24; | 67 int exponent = bits << 1 >> 24; |
70 return exponent != 0xFF; | 68 return exponent != 0xFF; |
71 } | 69 } |
72 | 70 |
73 static bool isFinite_float(float x) { | 71 static bool isFinite_float(float x) { |
74 return SkToBool(sk_float_isfinite(x)); | 72 return SkToBool(sk_float_isfinite(x)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 test_isRectFinite(reporter); | 182 test_isRectFinite(reporter); |
185 } | 183 } |
186 | 184 |
187 #if defined _WIN32 | 185 #if defined _WIN32 |
188 #pragma warning ( pop ) | 186 #pragma warning ( pop ) |
189 #endif | 187 #endif |
190 | 188 |
191 DEF_TEST(Scalar, reporter) { | 189 DEF_TEST(Scalar, reporter) { |
192 test_isfinite(reporter); | 190 test_isfinite(reporter); |
193 } | 191 } |
OLD | NEW |