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

Side by Side Diff: tests/GeometryTest.cpp

Issue 2142393003: handle large conic weights (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another double warning Created 4 years, 5 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') | tests/PathTest.cpp » ('j') | 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 SkVector mid = conic.evalTangentAt(.5f); 138 SkVector mid = conic.evalTangentAt(.5f);
139 SkVector end = conic.evalTangentAt(1); 139 SkVector end = conic.evalTangentAt(1);
140 REPORTER_ASSERT(reporter, start.fX && start.fY); 140 REPORTER_ASSERT(reporter, start.fX && start.fY);
141 REPORTER_ASSERT(reporter, mid.fX && mid.fY); 141 REPORTER_ASSERT(reporter, mid.fX && mid.fY);
142 REPORTER_ASSERT(reporter, end.fX && end.fY); 142 REPORTER_ASSERT(reporter, end.fX && end.fY);
143 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid))); 143 REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid)));
144 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end))); 144 REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end)));
145 } 145 }
146 } 146 }
147 147
148 static void test_this_conic_to_quad(skiatest::Reporter* r, const SkPoint pts[3], SkScalar w) {
149 SkAutoConicToQuads quadder;
150 const SkPoint* qpts = quadder.computeQuads(pts, w, 0.25);
151 const int qcount = quadder.countQuads();
152 const int pcount = qcount * 2 + 1;
153
154 REPORTER_ASSERT(r, SkPointsAreFinite(qpts, pcount));
155 }
156
157 /**
158 * We need to ensure that when a conic is approximated by quads, that we always return finite
159 * values in the quads.
160 *
161 * Inspired by crbug_627414
162 */
163 static void test_conic_to_quads(skiatest::Reporter* reporter) {
164 const SkPoint triples[] = {
165 { 0, 0 }, { 1, 0 }, { 1, 1 },
166 { 3.58732e-43f, 2.72084f }, { 3.00392f, 3.00392f },
167 { 0, 0 }, { 100000, 0 }, { 100000, 100000 },
168 { 0, 0 }, { 1e30f, 0 }, { 1e30f, 1e30f },
169 };
170 const int N = sizeof(triples) / sizeof(SkPoint);
171
172 for (int i = 0; i < N; i += 3) {
173 const SkPoint* pts = &triples[i];
174
175 SkRect bounds;
176 bounds.set(pts, 3);
177
178 SkScalar w = 1e30f;
179 do {
180 w *= 2;
181 test_this_conic_to_quad(reporter, pts, w);
182 } while (SkScalarIsFinite(w));
183 test_this_conic_to_quad(reporter, pts, SK_ScalarNaN);
184 }
185 }
186
148 static void test_cubic_tangents(skiatest::Reporter* reporter) { 187 static void test_cubic_tangents(skiatest::Reporter* reporter) {
149 SkPoint pts[] = { 188 SkPoint pts[] = {
150 { 10, 20}, {10, 20}, {20, 30}, {30, 40}, 189 { 10, 20}, {10, 20}, {20, 30}, {30, 40},
151 { 10, 20}, {15, 25}, {20, 30}, {30, 40}, 190 { 10, 20}, {15, 25}, {20, 30}, {30, 40},
152 { 10, 20}, {20, 30}, {30, 40}, {30, 40}, 191 { 10, 20}, {20, 30}, {30, 40}, {30, 40},
153 }; 192 };
154 int count = (int) SK_ARRAY_COUNT(pts) / 4; 193 int count = (int) SK_ARRAY_COUNT(pts) / 4;
155 for (int index = 0; index < count; ++index) { 194 for (int index = 0; index < count; ++index) {
156 SkConic conic(&pts[index * 3], 0.707f); 195 SkConic conic(&pts[index * 3], 0.707f);
157 SkVector start, mid, end; 196 SkVector start, mid, end;
(...skipping 28 matching lines...) Expand all
186 for (int i = 0; i < 4; ++i) { 225 for (int i = 0; i < 4; ++i) {
187 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); 226 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
188 } 227 }
189 228
190 testChopCubic(reporter); 229 testChopCubic(reporter);
191 test_evalquadat(reporter); 230 test_evalquadat(reporter);
192 test_conic(reporter); 231 test_conic(reporter);
193 test_cubic_tangents(reporter); 232 test_cubic_tangents(reporter);
194 test_quad_tangents(reporter); 233 test_quad_tangents(reporter);
195 test_conic_tangents(reporter); 234 test_conic_tangents(reporter);
235 test_conic_to_quads(reporter);
196 } 236 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698