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

Side by Side Diff: tests/PathOpsLineParametetersTest.cpp

Issue 12880016: Add intersections for path ops (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/PathOpsLineIntersectionTest.cpp ('k') | tests/PathOpsQuadIntersectionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkLineParameters.h"
8 #include "Test.h"
9
10 // tests to verify that distance calculations are coded correctly
11 static const SkDCubic tests[] = {
12 {{{0, 0}, {1, 1}, {2, 2}, {0, 3}}},
13 {{{0, 0}, {1, 1}, {2, 2}, {3, 0}}},
14 {{{0, 0}, {5, 0}, {-2, 4}, {3, 4}}},
15 {{{0, 2}, {1, 0}, {2, 0}, {3, 0}}},
16 {{{0, .2}, {1, 0}, {2, 0}, {3, 0}}},
17 {{{0, .02}, {1, 0}, {2, 0}, {3, 0}}},
18 {{{0, .002}, {1, 0}, {2, 0}, {3, 0}}},
19 {{{0, .0002}, {1, 0}, {2, 0}, {3, 0}}},
20 {{{0, .00002}, {1, 0}, {2, 0}, {3, 0}}},
21 {{{0, FLT_EPSILON * 2}, {1, 0}, {2, 0}, {3, 0}}},
22 };
23
24 static const double answers[][2] = {
25 {1, 2},
26 {1, 2},
27 {4, 4},
28 {1.1094003924, 0.5547001962},
29 {0.133038021, 0.06651901052},
30 {0.0133330370, 0.006666518523},
31 {0.001333333037, 0.0006666665185},
32 {0.000133333333, 6.666666652e-05},
33 {1.333333333e-05, 6.666666667e-06},
34 {1.5894571940104115e-07, 7.9472859700520577e-08},
35 };
36
37 static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
38
39 static void LineParameterTest(skiatest::Reporter* reporter) {
40 for (size_t index = 0; index < tests_count; ++index) {
41 SkLineParameters lineParameters;
42 const SkDCubic& cubic = tests[index];
43 lineParameters.cubicEndPoints(cubic);
44 double denormalizedDistance[2];
45 denormalizedDistance[0] = lineParameters.controlPtDistance(cubic, 1);
46 denormalizedDistance[1] = lineParameters.controlPtDistance(cubic, 2);
47 double normalSquared = lineParameters.normalSquared();
48 size_t inner;
49 for (inner = 0; inner < 2; ++inner) {
50 double distSq = denormalizedDistance[inner];
51 distSq *= distSq;
52 double answersSq = answers[index][inner];
53 answersSq *= answersSq;
54 if (AlmostEqualUlps(distSq, normalSquared * answersSq)) {
55 continue;
56 }
57 SkDebugf("%s [%d,%d] denormalizedDistance:%g != answer:%g"
58 " distSq:%g answerSq:%g normalSquared:%g\n",
59 __FUNCTION__, static_cast<int>(index), (int)inner,
60 denormalizedDistance[inner], answers[index][inner],
61 distSq, answersSq, normalSquared);
62 }
63 lineParameters.normalize();
64 double normalizedDistance[2];
65 normalizedDistance[0] = lineParameters.controlPtDistance(cubic, 1);
66 normalizedDistance[1] = lineParameters.controlPtDistance(cubic, 2);
67 for (inner = 0; inner < 2; ++inner) {
68 if (AlmostEqualUlps(fabs(normalizedDistance[inner]), answers[index][ inner])) {
69 continue;
70 }
71 SkDebugf("%s [%d,%d] normalizedDistance:%1.10g != answer:%g\n",
72 __FUNCTION__, static_cast<int>(index), (int)inner,
73 normalizedDistance[inner], answers[index][inner]);
74 REPORTER_ASSERT(reporter, 0);
75 }
76 }
77 }
78
79 #include "TestClassDef.h"
80 DEFINE_TESTCLASS("PathOpsLineParameters", PathOpsLineParametersClass, LineParame terTest)
OLDNEW
« no previous file with comments | « tests/PathOpsLineIntersectionTest.cpp ('k') | tests/PathOpsQuadIntersectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698