Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Side by Side Diff: tests/GeometryTest.cpp

Issue 1024873003: use Sk2s for EvalQuadTangent and ChopQuadAt (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 }; 27 };
28 SkPoint dst[13]; 28 SkPoint dst[13];
29 SkScalar tValues[3]; 29 SkScalar tValues[3];
30 // make sure we don't assert internally 30 // make sure we don't assert internally
31 int count = SkChopCubicAtMaxCurvature(src, dst, tValues); 31 int count = SkChopCubicAtMaxCurvature(src, dst, tValues);
32 if (false) { // avoid bit rot, suppress warning 32 if (false) { // avoid bit rot, suppress warning
33 REPORTER_ASSERT(reporter, count); 33 REPORTER_ASSERT(reporter, count);
34 } 34 }
35 } 35 }
36 36
37 static void check_pairs(skiatest::Reporter* reporter, int index, SkScalar t, con st char name[],
38 SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1) {
39 bool eq = SkScalarNearlyEqual(x0, x1) && SkScalarNearlyEqual(y0, y1);
40 if (!eq) {
41 SkDebugf("%s [%d %g] p0 [%10.8f %10.8f] p1 [%10.8f %10.8f]\n",
42 name, index, t, x0, y0, x1, y1);
43 REPORTER_ASSERT(reporter, eq);
44 }
45 }
46
37 static void test_evalquadat(skiatest::Reporter* reporter) { 47 static void test_evalquadat(skiatest::Reporter* reporter) {
38 SkRandom rand; 48 SkRandom rand;
39 for (int i = 0; i < 1000; ++i) { 49 for (int i = 0; i < 1000; ++i) {
40 SkPoint pts[3]; 50 SkPoint pts[3];
41 for (int j = 0; j < 3; ++j) { 51 for (int j = 0; j < 3; ++j) {
42 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100); 52 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100);
43 } 53 }
44 SkScalar t = 0;
45 const SkScalar dt = SK_Scalar1 / 128; 54 const SkScalar dt = SK_Scalar1 / 128;
46 for (int j = 0; j < 128; ++j) { 55 SkScalar t = dt;
56 for (int j = 1; j < 128; ++j) {
47 SkPoint r0; 57 SkPoint r0;
48 SkEvalQuadAt(pts, t, &r0); 58 SkEvalQuadAt(pts, t, &r0);
49 SkPoint r1 = SkEvalQuadAt(pts, t); 59 SkPoint r1 = SkEvalQuadAt(pts, t);
50 bool eq = SkScalarNearlyEqual(r0.fX, r1.fX) && SkScalarNearlyEqual(r 0.fY, r1.fY); 60 check_pairs(reporter, i, t, "quad-pos", r0.fX, r0.fY, r1.fX, r1.fY);
51 if (!eq) { 61
52 SkDebugf("[%d %g] p0 [%10.8f %10.8f] p1 [%10.8f %10.8f]\n", i, t , r0.fX, r0.fY, r1.fX, r1.fY); 62 SkVector v0;
53 REPORTER_ASSERT(reporter, eq); 63 SkEvalQuadAt(pts, t, NULL, &v0);
64 SkVector v1 = SkEvalQuadTangentAt(pts, t);
65 check_pairs(reporter, i, t, "quad-tan", v0.fX, v0.fY, v1.fX, v1.fY);
66
67 SkPoint dst0[5], dst1[5];
68 SkChopQuadAt(pts, dst0, t);
69 SkChopQuadAt2(pts, dst1, t);
70 for (int k = 0; k < 5; ++k) {
71 check_pairs(reporter, i, t, "chop-quad",
72 dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY);
54 } 73 }
74
55 t += dt; 75 t += dt;
56 } 76 }
57 } 77 }
58 } 78 }
59 79
60 DEF_TEST(Geometry, reporter) { 80 DEF_TEST(Geometry, reporter) {
61 SkPoint pts[3], dst[5]; 81 SkPoint pts[3], dst[5];
62 82
63 pts[0].set(0, 0); 83 pts[0].set(0, 0);
64 pts[1].set(100, 50); 84 pts[1].set(100, 50);
(...skipping 12 matching lines...) Expand all
77 { SkIntToScalar(3), SkIntToScalar(1), }, 97 { SkIntToScalar(3), SkIntToScalar(1), },
78 { SkIntToScalar(3), SkIntToScalar(3) }, 98 { SkIntToScalar(3), SkIntToScalar(3) },
79 }; 99 };
80 for (int i = 0; i < 4; ++i) { 100 for (int i = 0; i < 4; ++i) {
81 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); 101 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
82 } 102 }
83 103
84 testChopCubic(reporter); 104 testChopCubic(reporter);
85 test_evalquadat(reporter); 105 test_evalquadat(reporter);
86 } 106 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698