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

Side by Side Diff: tests/PathOpsTestCommon.cpp

Issue 19374003: harden and speed up path op unit tests (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rename threaded to single Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/PathOpsTestCommon.h ('k') | tests/Test.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 2012 Google Inc. 2 * Copyright 2012 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 #include "PathOpsTestCommon.h" 7 #include "PathOpsTestCommon.h"
8 #include "SkPathOpsBounds.h"
8 #include "SkPathOpsCubic.h" 9 #include "SkPathOpsCubic.h"
10 #include "SkPathOpsLine.h"
11 #include "SkPathOpsQuad.h"
12 #include "SkPathOpsTriangle.h"
9 13
10 void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, tru e>& quads) { 14 void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, tru e>& quads) {
11 SkTArray<double, true> ts; 15 SkTArray<double, true> ts;
12 cubic.toQuadraticTs(precision, &ts); 16 cubic.toQuadraticTs(precision, &ts);
13 if (ts.count() <= 0) { 17 if (ts.count() <= 0) {
14 SkDQuad quad = cubic.toQuad(); 18 SkDQuad quad = cubic.toQuad();
15 quads.push_back(quad); 19 quads.push_back(quad);
16 return; 20 return;
17 } 21 }
18 double tStart = 0; 22 double tStart = 0;
19 for (int i1 = 0; i1 <= ts.count(); ++i1) { 23 for (int i1 = 0; i1 <= ts.count(); ++i1) {
20 const double tEnd = i1 < ts.count() ? ts[i1] : 1; 24 const double tEnd = i1 < ts.count() ? ts[i1] : 1;
21 SkDCubic part = cubic.subDivide(tStart, tEnd); 25 SkDCubic part = cubic.subDivide(tStart, tEnd);
22 SkDQuad quad = part.toQuad(); 26 SkDQuad quad = part.toQuad();
23 quads.push_back(quad); 27 quads.push_back(quad);
24 tStart = tEnd; 28 tStart = tEnd;
25 } 29 }
26 } 30 }
31
32 static bool SkDoubleIsNaN(double x) {
33 return x != x;
34 }
35
36 bool ValidBounds(const SkPathOpsBounds& bounds) {
37 if (SkScalarIsNaN(bounds.fLeft)) {
38 return false;
39 }
40 if (SkScalarIsNaN(bounds.fTop)) {
41 return false;
42 }
43 if (SkScalarIsNaN(bounds.fRight)) {
44 return false;
45 }
46 return !SkScalarIsNaN(bounds.fBottom);
47 }
48
49 bool ValidCubic(const SkDCubic& cubic) {
50 for (int index = 0; index < 4; ++index) {
51 if (!ValidPoint(cubic[index])) {
52 return false;
53 }
54 }
55 return true;
56 }
57
58 bool ValidLine(const SkDLine& line) {
59 for (int index = 0; index < 2; ++index) {
60 if (!ValidPoint(line[index])) {
61 return false;
62 }
63 }
64 return true;
65 }
66
67 bool ValidPoint(const SkDPoint& pt) {
68 if (SkDoubleIsNaN(pt.fX)) {
69 return false;
70 }
71 return !SkDoubleIsNaN(pt.fY);
72 }
73
74 bool ValidPoints(const SkPoint* pts, int count) {
75 for (int index = 0; index < count; ++index) {
76 if (SkScalarIsNaN(pts[index].fX)) {
77 return false;
78 }
79 if (SkScalarIsNaN(pts[index].fY)) {
80 return false;
81 }
82 }
83 return true;
84 }
85
86 bool ValidQuad(const SkDQuad& quad) {
87 for (int index = 0; index < 3; ++index) {
88 if (!ValidPoint(quad[index])) {
89 return false;
90 }
91 }
92 return true;
93 }
94
95 bool ValidTriangle(const SkDTriangle& triangle) {
96 for (int index = 0; index < 3; ++index) {
97 if (!ValidPoint(triangle.fPts[index])) {
98 return false;
99 }
100 }
101 return true;
102 }
103
104 bool ValidVector(const SkDVector& v) {
105 if (SkDoubleIsNaN(v.fX)) {
106 return false;
107 }
108 return !SkDoubleIsNaN(v.fY);
109 }
OLDNEW
« no previous file with comments | « tests/PathOpsTestCommon.h ('k') | tests/Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698