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

Side by Side Diff: tests/ClipCubicTest.cpp

Issue 85463005: remove SkFloatToScalar macro (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add flag to expose SkFloatToScalar to chromium Created 7 years 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/BlurTest.cpp ('k') | tests/ClipperTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 26 matching lines...) Expand all
37 (float)crv[2].fX, (float)crv[2].fY, 37 (float)crv[2].fX, (float)crv[2].fY,
38 (float)crv[3].fX, (float)crv[3].fY); 38 (float)crv[3].fX, (float)crv[3].fY);
39 39
40 } 40 }
41 41
42 42
43 static bool CurvesAreEqual(const SkPoint c0[4], 43 static bool CurvesAreEqual(const SkPoint c0[4],
44 const SkPoint c1[4], 44 const SkPoint c1[4],
45 float tol) { 45 float tol) {
46 for (int i = 0; i < 4; i++) { 46 for (int i = 0; i < 4; i++) {
47 if (SkScalarAbs(c0[i].fX - c1[i].fX) > SkFloatToScalar(tol) || 47 if (SkScalarAbs(c0[i].fX - c1[i].fX) > tol ||
48 SkScalarAbs(c0[i].fY - c1[i].fY) > SkFloatToScalar(tol) 48 SkScalarAbs(c0[i].fY - c1[i].fY) > tol
49 ) { 49 ) {
50 PrintCurve("c0", c0); 50 PrintCurve("c0", c0);
51 PrintCurve("c1", c1); 51 PrintCurve("c1", c1);
52 return false; 52 return false;
53 } 53 }
54 } 54 }
55 return true; 55 return true;
56 } 56 }
57 57
58 58
59 static SkPoint* SetCurve(float x0, float y0, 59 static SkPoint* SetCurve(float x0, float y0,
60 float x1, float y1, 60 float x1, float y1,
61 float x2, float y2, 61 float x2, float y2,
62 float x3, float y3, 62 float x3, float y3,
63 SkPoint crv[4]) { 63 SkPoint crv[4]) {
64 crv[0].fX = SkFloatToScalar(x0); crv[0].fY = SkFloatToScalar(y0); 64 crv[0].fX = x0; crv[0].fY = y0;
65 crv[1].fX = SkFloatToScalar(x1); crv[1].fY = SkFloatToScalar(y1); 65 crv[1].fX = x1; crv[1].fY = y1;
66 crv[2].fX = SkFloatToScalar(x2); crv[2].fY = SkFloatToScalar(y2); 66 crv[2].fX = x2; crv[2].fY = y2;
67 crv[3].fX = SkFloatToScalar(x3); crv[3].fY = SkFloatToScalar(y3); 67 crv[3].fX = x3; crv[3].fY = y3;
68 return crv; 68 return crv;
69 } 69 }
70 70
71 71
72 static void TestCubicClipping(skiatest::Reporter* reporter) { 72 static void TestCubicClipping(skiatest::Reporter* reporter) {
73 static SkPoint crv[4] = { 73 static SkPoint crv[4] = {
74 { SkIntToScalar(0), SkIntToScalar(0) }, 74 { SkIntToScalar(0), SkIntToScalar(0) },
75 { SkIntToScalar(2), SkIntToScalar(3) }, 75 { SkIntToScalar(2), SkIntToScalar(3) },
76 { SkIntToScalar(1), SkIntToScalar(10) }, 76 { SkIntToScalar(1), SkIntToScalar(10) },
77 { SkIntToScalar(4), SkIntToScalar(12) } 77 { SkIntToScalar(4), SkIntToScalar(12) }
78 }; 78 };
79 79
80 SkCubicClipper clipper; 80 SkCubicClipper clipper;
81 SkPoint clipped[4], shouldbe[4]; 81 SkPoint clipped[4], shouldbe[4];
82 SkIRect clipRect; 82 SkIRect clipRect;
83 bool success; 83 bool success;
84 const float tol = SkFloatToScalar(1e-4f); 84 const float tol = 1e-4f;
85 85
86 // Test no clip, with plenty of room. 86 // Test no clip, with plenty of room.
87 clipRect.set(-2, -2, 6, 14); 87 clipRect.set(-2, -2, 6, 14);
88 clipper.setClip(clipRect); 88 clipper.setClip(clipRect);
89 success = clipper.clipCubic(crv, clipped); 89 success = clipper.clipCubic(crv, clipped);
90 REPORTER_ASSERT(reporter, success == true); 90 REPORTER_ASSERT(reporter, success == true);
91 REPORTER_ASSERT(reporter, CurvesAreEqual(clipped, SetCurve( 91 REPORTER_ASSERT(reporter, CurvesAreEqual(clipped, SetCurve(
92 0, 0, 2, 3, 1, 10, 4, 12, shouldbe), tol)); 92 0, 0, 2, 3, 1, 10, 4, 12, shouldbe), tol));
93 93
94 // Test no clip, touching first point. 94 // Test no clip, touching first point.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 shouldbe), tol)); 162 shouldbe), tol));
163 163
164 test_giantClip(); 164 test_giantClip();
165 } 165 }
166 166
167 167
168 168
169 169
170 #include "TestClassDef.h" 170 #include "TestClassDef.h"
171 DEFINE_TESTCLASS("CubicClipper", CubicClippingTestClass, TestCubicClipping) 171 DEFINE_TESTCLASS("CubicClipper", CubicClippingTestClass, TestCubicClipping)
OLDNEW
« no previous file with comments | « tests/BlurTest.cpp ('k') | tests/ClipperTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698