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 "SkGeometry.h" | 8 #include "SkGeometry.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 const SkScalar dt = SK_Scalar1 / 128; | 54 const SkScalar dt = SK_Scalar1 / 128; |
55 SkScalar t = dt; | 55 SkScalar t = dt; |
56 for (int j = 1; j < 128; ++j) { | 56 for (int j = 1; j < 128; ++j) { |
57 SkPoint r0; | 57 SkPoint r0; |
58 SkEvalQuadAt(pts, t, &r0); | 58 SkEvalQuadAt(pts, t, &r0); |
59 SkPoint r1 = SkEvalQuadAt(pts, t); | 59 SkPoint r1 = SkEvalQuadAt(pts, t); |
60 check_pairs(reporter, i, t, "quad-pos", r0.fX, r0.fY, r1.fX, r1.fY); | 60 check_pairs(reporter, i, t, "quad-pos", r0.fX, r0.fY, r1.fX, r1.fY); |
61 | 61 |
62 SkVector v0; | 62 SkVector v0; |
63 SkEvalQuadAt(pts, t, NULL, &v0); | 63 SkEvalQuadAt(pts, t, nullptr, &v0); |
64 SkVector v1 = SkEvalQuadTangentAt(pts, t); | 64 SkVector v1 = SkEvalQuadTangentAt(pts, t); |
65 check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY); | 65 check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY); |
66 | 66 |
67 t += dt; | 67 t += dt; |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 static void test_conic_eval_pos(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { | 72 static void test_conic_eval_pos(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { |
73 SkPoint p0, p1; | 73 SkPoint p0, p1; |
74 conic.evalAt(t, &p0, NULL); | 74 conic.evalAt(t, &p0, nullptr); |
75 p1 = conic.evalAt(t); | 75 p1 = conic.evalAt(t); |
76 check_pairs(reporter, 0, t, "conic-pos", p0.fX, p0.fY, p1.fX, p1.fY); | 76 check_pairs(reporter, 0, t, "conic-pos", p0.fX, p0.fY, p1.fX, p1.fY); |
77 } | 77 } |
78 | 78 |
79 static void test_conic_eval_tan(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { | 79 static void test_conic_eval_tan(skiatest::Reporter* reporter, const SkConic& con
ic, SkScalar t) { |
80 SkVector v0, v1; | 80 SkVector v0, v1; |
81 conic.evalAt(t, NULL, &v0); | 81 conic.evalAt(t, nullptr, &v0); |
82 v1 = conic.evalTangentAt(t); | 82 v1 = conic.evalTangentAt(t); |
83 check_pairs(reporter, 0, t, "conic-tan", v0.fX, v0.fY, v1.fX, v1.fY); | 83 check_pairs(reporter, 0, t, "conic-tan", v0.fX, v0.fY, v1.fX, v1.fY); |
84 } | 84 } |
85 | 85 |
86 static void test_conic(skiatest::Reporter* reporter) { | 86 static void test_conic(skiatest::Reporter* reporter) { |
87 SkRandom rand; | 87 SkRandom rand; |
88 for (int i = 0; i < 1000; ++i) { | 88 for (int i = 0; i < 1000; ++i) { |
89 SkPoint pts[3]; | 89 SkPoint pts[3]; |
90 for (int j = 0; j < 3; ++j) { | 90 for (int j = 0; j < 3; ++j) { |
91 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100); | 91 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 static void test_cubic_tangents(skiatest::Reporter* reporter) { | 148 static void test_cubic_tangents(skiatest::Reporter* reporter) { |
149 SkPoint pts[] = { | 149 SkPoint pts[] = { |
150 { 10, 20}, {10, 20}, {20, 30}, {30, 40}, | 150 { 10, 20}, {10, 20}, {20, 30}, {30, 40}, |
151 { 10, 20}, {15, 25}, {20, 30}, {30, 40}, | 151 { 10, 20}, {15, 25}, {20, 30}, {30, 40}, |
152 { 10, 20}, {20, 30}, {30, 40}, {30, 40}, | 152 { 10, 20}, {20, 30}, {30, 40}, {30, 40}, |
153 }; | 153 }; |
154 int count = (int) SK_ARRAY_COUNT(pts) / 4; | 154 int count = (int) SK_ARRAY_COUNT(pts) / 4; |
155 for (int index = 0; index < count; ++index) { | 155 for (int index = 0; index < count; ++index) { |
156 SkConic conic(&pts[index * 3], 0.707f); | 156 SkConic conic(&pts[index * 3], 0.707f); |
157 SkVector start, mid, end; | 157 SkVector start, mid, end; |
158 SkEvalCubicAt(&pts[index * 4], 0, NULL, &start, NULL); | 158 SkEvalCubicAt(&pts[index * 4], 0, nullptr, &start, nullptr); |
159 SkEvalCubicAt(&pts[index * 4], .5f, NULL, &mid, NULL); | 159 SkEvalCubicAt(&pts[index * 4], .5f, nullptr, &mid, nullptr); |
160 SkEvalCubicAt(&pts[index * 4], 1, NULL, &end, NULL); | 160 SkEvalCubicAt(&pts[index * 4], 1, nullptr, &end, nullptr); |
161 REPORTER_ASSERT(reporter, start.fX && start.fY); | 161 REPORTER_ASSERT(reporter, start.fX && start.fY); |
162 REPORTER_ASSERT(reporter, mid.fX && mid.fY); | 162 REPORTER_ASSERT(reporter, mid.fX && mid.fY); |
163 REPORTER_ASSERT(reporter, end.fX && end.fY); | 163 REPORTER_ASSERT(reporter, end.fX && end.fY); |
164 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid))); | 164 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid))); |
165 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end))); | 165 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end))); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 DEF_TEST(Geometry, reporter) { | 169 DEF_TEST(Geometry, reporter) { |
170 SkPoint pts[3], dst[5]; | 170 SkPoint pts[3], dst[5]; |
(...skipping 16 matching lines...) Expand all Loading... |
187 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); | 187 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); |
188 } | 188 } |
189 | 189 |
190 testChopCubic(reporter); | 190 testChopCubic(reporter); |
191 test_evalquadat(reporter); | 191 test_evalquadat(reporter); |
192 test_conic(reporter); | 192 test_conic(reporter); |
193 test_cubic_tangents(reporter); | 193 test_cubic_tangents(reporter); |
194 test_quad_tangents(reporter); | 194 test_quad_tangents(reporter); |
195 test_conic_tangents(reporter); | 195 test_conic_tangents(reporter); |
196 } | 196 } |
OLD | NEW |