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

Side by Side Diff: tests/GeometryTest.cpp

Issue 1312243002: Revert of fix zero-length tangent (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 SkScalar t = dt; 98 SkScalar t = dt;
99 for (int j = 1; j < 128; ++j) { 99 for (int j = 1; j < 128; ++j) {
100 test_conic_eval_pos(reporter, conic, t); 100 test_conic_eval_pos(reporter, conic, t);
101 test_conic_eval_tan(reporter, conic, t); 101 test_conic_eval_tan(reporter, conic, t);
102 t += dt; 102 t += dt;
103 } 103 }
104 } 104 }
105 } 105 }
106 } 106 }
107 107
108 static void test_quad_tangents(skiatest::Reporter* reporter) {
109 SkPoint pts[] = {
110 {10, 20}, {10, 20}, {20, 30},
111 {10, 20}, {15, 25}, {20, 30},
112 {10, 20}, {20, 30}, {20, 30},
113 };
114 int count = (int) SK_ARRAY_COUNT(pts) / 3;
115 for (int index = 0; index < count; ++index) {
116 SkConic conic(&pts[index * 3], 0.707f);
117 SkVector start = SkEvalQuadTangentAt(&pts[index * 3], 0);
118 SkVector mid = SkEvalQuadTangentAt(&pts[index * 3], .5f);
119 SkVector end = SkEvalQuadTangentAt(&pts[index * 3], 1);
120 REPORTER_ASSERT(reporter, start.fX && start.fY);
121 REPORTER_ASSERT(reporter, mid.fX && mid.fY);
122 REPORTER_ASSERT(reporter, end.fX && end.fY);
123 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid)));
124 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end)));
125 }
126 }
127
128 static void test_conic_tangents(skiatest::Reporter* reporter) {
129 SkPoint pts[] = {
130 { 10, 20}, {10, 20}, {20, 30},
131 { 10, 20}, {15, 25}, {20, 30},
132 { 10, 20}, {20, 30}, {20, 30}
133 };
134 int count = (int) SK_ARRAY_COUNT(pts) / 3;
135 for (int index = 0; index < count; ++index) {
136 SkConic conic(&pts[index * 3], 0.707f);
137 SkVector start = conic.evalTangentAt(0);
138 SkVector mid = conic.evalTangentAt(.5f);
139 SkVector end = conic.evalTangentAt(1);
140 REPORTER_ASSERT(reporter, start.fX && start.fY);
141 REPORTER_ASSERT(reporter, mid.fX && mid.fY);
142 REPORTER_ASSERT(reporter, end.fX && end.fY);
143 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid)));
144 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end)));
145 }
146 }
147
148 static void test_cubic_tangents(skiatest::Reporter* reporter) {
149 SkPoint pts[] = {
150 { 10, 20}, {10, 20}, {20, 30}, {30, 40},
151 { 10, 20}, {15, 25}, {20, 30}, {30, 40},
152 { 10, 20}, {20, 30}, {30, 40}, {30, 40},
153 };
154 int count = (int) SK_ARRAY_COUNT(pts) / 4;
155 for (int index = 0; index < count; ++index) {
156 SkConic conic(&pts[index * 3], 0.707f);
157 SkVector start, mid, end;
158 SkEvalCubicAt(&pts[index * 4], 0, NULL, &start, NULL);
159 SkEvalCubicAt(&pts[index * 4], .5f, NULL, &mid, NULL);
160 SkEvalCubicAt(&pts[index * 4], 1, NULL, &end, NULL);
161 REPORTER_ASSERT(reporter, start.fX && start.fY);
162 REPORTER_ASSERT(reporter, mid.fX && mid.fY);
163 REPORTER_ASSERT(reporter, end.fX && end.fY);
164 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid)));
165 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end)));
166 }
167 }
168
169 DEF_TEST(Geometry, reporter) { 108 DEF_TEST(Geometry, reporter) {
170 SkPoint pts[3], dst[5]; 109 SkPoint pts[3], dst[5];
171 110
172 pts[0].set(0, 0); 111 pts[0].set(0, 0);
173 pts[1].set(100, 50); 112 pts[1].set(100, 50);
174 pts[2].set(0, 100); 113 pts[2].set(0, 100);
175 114
176 int count = SkChopQuadAtMaxCurvature(pts, dst); 115 int count = SkChopQuadAtMaxCurvature(pts, dst);
177 REPORTER_ASSERT(reporter, count == 1 || count == 2); 116 REPORTER_ASSERT(reporter, count == 1 || count == 2);
178 117
179 pts[0].set(0, 0); 118 pts[0].set(0, 0);
180 pts[1].set(3, 0); 119 pts[1].set(3, 0);
181 pts[2].set(3, 3); 120 pts[2].set(3, 3);
182 SkConvertQuadToCubic(pts, dst); 121 SkConvertQuadToCubic(pts, dst);
183 const SkPoint cubic[] = { 122 const SkPoint cubic[] = {
184 { 0, 0, }, { 2, 0, }, { 3, 1, }, { 3, 3 }, 123 { 0, 0, }, { 2, 0, }, { 3, 1, }, { 3, 3 },
185 }; 124 };
186 for (int i = 0; i < 4; ++i) { 125 for (int i = 0; i < 4; ++i) {
187 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); 126 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
188 } 127 }
189 128
190 testChopCubic(reporter); 129 testChopCubic(reporter);
191 test_evalquadat(reporter); 130 test_evalquadat(reporter);
192 test_conic(reporter); 131 test_conic(reporter);
193 test_cubic_tangents(reporter);
194 test_quad_tangents(reporter);
195 test_conic_tangents(reporter);
196 } 132 }
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