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 "SkPathMeasure.h" | 10 #include "SkPathMeasure.h" |
11 | 11 |
12 static void test_small_segment3() { | 12 static void test_small_segment3() { |
13 #ifdef SK_SCALAR_IS_FLOAT | |
14 SkPath path; | 13 SkPath path; |
15 const SkPoint pts[] = { | 14 const SkPoint pts[] = { |
16 { 0, 0 }, | 15 { 0, 0 }, |
17 { 100000000000.0f, 100000000000.0f }, { 0, 0 }, { 10, 10 }, | 16 { 100000000000.0f, 100000000000.0f }, { 0, 0 }, { 10, 10 }, |
18 { 10, 10 }, { 0, 0 }, { 10, 10 } | 17 { 10, 10 }, { 0, 0 }, { 10, 10 } |
19 }; | 18 }; |
20 | 19 |
21 path.moveTo(pts[0]); | 20 path.moveTo(pts[0]); |
22 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 3) { | 21 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 3) { |
23 path.cubicTo(pts[i], pts[i + 1], pts[i + 2]); | 22 path.cubicTo(pts[i], pts[i + 1], pts[i + 2]); |
24 } | 23 } |
25 | 24 |
26 SkPathMeasure meas(path, false); | 25 SkPathMeasure meas(path, false); |
27 meas.getLength(); | 26 meas.getLength(); |
28 #endif | |
29 } | 27 } |
30 | 28 |
31 static void test_small_segment2() { | 29 static void test_small_segment2() { |
32 #ifdef SK_SCALAR_IS_FLOAT | |
33 SkPath path; | 30 SkPath path; |
34 const SkPoint pts[] = { | 31 const SkPoint pts[] = { |
35 { 0, 0 }, | 32 { 0, 0 }, |
36 { 100000000000.0f, 100000000000.0f }, { 0, 0 }, | 33 { 100000000000.0f, 100000000000.0f }, { 0, 0 }, |
37 { 10, 10 }, { 0, 0 }, | 34 { 10, 10 }, { 0, 0 }, |
38 }; | 35 }; |
39 | 36 |
40 path.moveTo(pts[0]); | 37 path.moveTo(pts[0]); |
41 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 2) { | 38 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 2) { |
42 path.quadTo(pts[i], pts[i + 1]); | 39 path.quadTo(pts[i], pts[i + 1]); |
43 } | 40 } |
44 SkPathMeasure meas(path, false); | 41 SkPathMeasure meas(path, false); |
45 meas.getLength(); | 42 meas.getLength(); |
46 #endif | |
47 } | 43 } |
48 | 44 |
49 static void test_small_segment() { | 45 static void test_small_segment() { |
50 #ifdef SK_SCALAR_IS_FLOAT | |
51 SkPath path; | 46 SkPath path; |
52 const SkPoint pts[] = { | 47 const SkPoint pts[] = { |
53 { 100000, 100000}, | 48 { 100000, 100000}, |
54 // big jump between these points, makes a big segment | 49 // big jump between these points, makes a big segment |
55 { 1.0005f, 0.9999f }, | 50 { 1.0005f, 0.9999f }, |
56 // tiny (non-zero) jump between these points | 51 // tiny (non-zero) jump between these points |
57 { SK_Scalar1, SK_Scalar1 }, | 52 { SK_Scalar1, SK_Scalar1 }, |
58 }; | 53 }; |
59 | 54 |
60 path.moveTo(pts[0]); | 55 path.moveTo(pts[0]); |
61 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); ++i) { | 56 for (size_t i = 1; i < SK_ARRAY_COUNT(pts); ++i) { |
62 path.lineTo(pts[i]); | 57 path.lineTo(pts[i]); |
63 } | 58 } |
64 SkPathMeasure meas(path, false); | 59 SkPathMeasure meas(path, false); |
65 | 60 |
66 /* this would assert (before a fix) because we added a segment with | 61 /* this would assert (before a fix) because we added a segment with |
67 the same length as the prev segment, due to the follow (bad) pattern | 62 the same length as the prev segment, due to the follow (bad) pattern |
68 | 63 |
69 d = distance(pts[0], pts[1]); | 64 d = distance(pts[0], pts[1]); |
70 distance += d; | 65 distance += d; |
71 seg->fDistance = distance; | 66 seg->fDistance = distance; |
72 | 67 |
73 SkASSERT(d > 0); // TRUE | 68 SkASSERT(d > 0); // TRUE |
74 SkASSERT(seg->fDistance > prevSeg->fDistance); // FALSE | 69 SkASSERT(seg->fDistance > prevSeg->fDistance); // FALSE |
75 | 70 |
76 This 2nd assert failes because (distance += d) didn't affect distance | 71 This 2nd assert failes because (distance += d) didn't affect distance |
77 because distance >>> d. | 72 because distance >>> d. |
78 */ | 73 */ |
79 meas.getLength(); | 74 meas.getLength(); |
80 #endif | |
81 } | 75 } |
82 | 76 |
83 DEF_TEST(PathMeasure, reporter) { | 77 DEF_TEST(PathMeasure, reporter) { |
84 SkPath path; | 78 SkPath path; |
85 | 79 |
86 path.moveTo(0, 0); | 80 path.moveTo(0, 0); |
87 path.lineTo(SK_Scalar1, 0); | 81 path.lineTo(SK_Scalar1, 0); |
88 path.lineTo(SK_Scalar1, SK_Scalar1); | 82 path.lineTo(SK_Scalar1, SK_Scalar1); |
89 path.lineTo(0, SK_Scalar1); | 83 path.lineTo(0, SK_Scalar1); |
90 | 84 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 SkScalarNearlyEqual(position.fY, | 195 SkScalarNearlyEqual(position.fY, |
202 2.0f, | 196 2.0f, |
203 0.0001f)); | 197 0.0001f)); |
204 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); | 198 REPORTER_ASSERT(reporter, tangent.fX == -SK_Scalar1); |
205 REPORTER_ASSERT(reporter, tangent.fY == 0); | 199 REPORTER_ASSERT(reporter, tangent.fY == 0); |
206 | 200 |
207 test_small_segment(); | 201 test_small_segment(); |
208 test_small_segment2(); | 202 test_small_segment2(); |
209 test_small_segment3(); | 203 test_small_segment3(); |
210 } | 204 } |
OLD | NEW |