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

Side by Side Diff: tests/GeometryTest.cpp

Issue 1025033002: use Sk2s for conics (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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 for (int k = 0; k < 5; ++k) { 70 for (int k = 0; k < 5; ++k) {
71 check_pairs(reporter, i, t, "chop-quad", 71 check_pairs(reporter, i, t, "chop-quad",
72 dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY); 72 dst0[k].fX, dst0[k].fY, dst1[k].fX, dst1[k].fY);
73 } 73 }
74 74
75 t += dt; 75 t += dt;
76 } 76 }
77 } 77 }
78 } 78 }
79 79
80 static void test_conic_eval_pos(skiatest::Reporter* reporter, const SkConic& con ic, SkScalar t) {
81 SkPoint p0, p1;
82 conic.evalAt(t, &p0, NULL);
83 p1 = conic.evalAt(t);
84 check_pairs(reporter, 0, t, "conic-pos", p0.fX, p0.fY, p1.fX, p1.fY);
85 }
86
87 static void test_conic_eval_tan(skiatest::Reporter* reporter, const SkConic& con ic, SkScalar t) {
88 SkVector v0, v1;
89 conic.evalAt(t, NULL, &v0);
90 v1 = conic.evalTangentAt(t);
91 check_pairs(reporter, 0, t, "conic-tan", v0.fX, v0.fY, v1.fX, v1.fY);
92 }
93
94 static void test_conic_chop_half(skiatest::Reporter* reporter, const SkConic& co nic) {
95 SkConic dst0[2], dst1[2];
96 conic.chop(dst0);
97 conic.chop2(dst1);
98
99 for (int i = 0; i < 2; ++i) {
100 REPORTER_ASSERT(reporter, dst0[i].fW == dst1[i].fW);
101 for (int j = 0; j < 3; ++j) {
102 check_pairs(reporter, j, 0.5f, "conic-chop",
103 dst0[i].fPts[j].fX, dst0[i].fPts[j].fY,
104 dst0[i].fPts[j].fX, dst1[i].fPts[j].fY);
105 }
106 }
107 }
108
109 static void test_conic(skiatest::Reporter* reporter) {
110 SkRandom rand;
111 for (int i = 0; i < 1000; ++i) {
112 SkPoint pts[3];
113 for (int j = 0; j < 3; ++j) {
114 pts[j].set(rand.nextSScalar1() * 100, rand.nextSScalar1() * 100);
115 }
116 for (int k = 0; k < 10; ++k) {
117 SkScalar w = rand.nextUScalar1() * 2;
118 SkConic conic(pts, w);
119 test_conic_chop_half(reporter, conic);
120
121 const SkScalar dt = SK_Scalar1 / 128;
122 SkScalar t = dt;
123 for (int j = 1; j < 128; ++j) {
124 test_conic_eval_pos(reporter, conic, t);
125 test_conic_eval_tan(reporter, conic, t);
126 t += dt;
127 }
128 }
129 }
130 }
131
80 DEF_TEST(Geometry, reporter) { 132 DEF_TEST(Geometry, reporter) {
81 SkPoint pts[3], dst[5]; 133 SkPoint pts[3], dst[5];
82 134
83 pts[0].set(0, 0); 135 pts[0].set(0, 0);
84 pts[1].set(100, 50); 136 pts[1].set(100, 50);
85 pts[2].set(0, 100); 137 pts[2].set(0, 100);
86 138
87 int count = SkChopQuadAtMaxCurvature(pts, dst); 139 int count = SkChopQuadAtMaxCurvature(pts, dst);
88 REPORTER_ASSERT(reporter, count == 1 || count == 2); 140 REPORTER_ASSERT(reporter, count == 1 || count == 2);
89 141
90 pts[0].set(0, 0); 142 pts[0].set(0, 0);
91 pts[1].set(SkIntToScalar(3), 0); 143 pts[1].set(SkIntToScalar(3), 0);
92 pts[2].set(SkIntToScalar(3), SkIntToScalar(3)); 144 pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
93 SkConvertQuadToCubic(pts, dst); 145 SkConvertQuadToCubic(pts, dst);
94 const SkPoint cubic[] = { 146 const SkPoint cubic[] = {
95 { 0, 0, }, 147 { 0, 0, },
96 { SkIntToScalar(2), 0, }, 148 { SkIntToScalar(2), 0, },
97 { SkIntToScalar(3), SkIntToScalar(1), }, 149 { SkIntToScalar(3), SkIntToScalar(1), },
98 { SkIntToScalar(3), SkIntToScalar(3) }, 150 { SkIntToScalar(3), SkIntToScalar(3) },
99 }; 151 };
100 for (int i = 0; i < 4; ++i) { 152 for (int i = 0; i < 4; ++i) {
101 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); 153 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
102 } 154 }
103 155
104 testChopCubic(reporter); 156 testChopCubic(reporter);
105 test_evalquadat(reporter); 157 test_evalquadat(reporter);
158 test_conic(reporter);
106 } 159 }
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