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

Side by Side Diff: tests/PathOpsCubicLineIntersectionTest.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/PathOpsCubicIntersectionTestData.cpp ('k') | tests/PathOpsCubicReduceOrderTest.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 "SkIntersections.h"
8 #include "SkPathOpsCubic.h"
9 #include "SkPathOpsLine.h"
10 #include "SkReduceOrder.h"
11 #include "Test.h"
12
13 static struct lineCubic {
14 SkDCubic cubic;
15 SkDLine line;
16 } lineCubicTests[] = {
17 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}},
18 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}},
19 };
20
21 static const size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineC ubicTests[0]);
22
23 static void CubicLineIntersectionTest(skiatest::Reporter* reporter) {
24 for (size_t index = 0; index < lineCubicTests_count; ++index) {
25 int iIndex = static_cast<int>(index);
26 const SkDCubic& cubic = lineCubicTests[index].cubic;
27 const SkDLine& line = lineCubicTests[index].line;
28 SkReduceOrder reduce1;
29 SkReduceOrder reduce2;
30 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics,
31 SkReduceOrder::kFill_Style);
32 int order2 = reduce2.reduce(line);
33 if (order1 < 4) {
34 SkDebugf("[%d] cubic order=%d\n", iIndex, order1);
35 REPORTER_ASSERT(reporter, 0);
36 }
37 if (order2 < 2) {
38 SkDebugf("[%d] line order=%d\n", iIndex, order2);
39 REPORTER_ASSERT(reporter, 0);
40 }
41 if (order1 == 4 && order2 == 2) {
42 SkIntersections i;
43 int roots = i.intersect(cubic, line);
44 for (int pt = 0; pt < roots; ++pt) {
45 double tt1 = i[0][pt];
46 SkDPoint xy1 = cubic.xyAtT(tt1);
47 double tt2 = i[1][pt];
48 SkDPoint xy2 = line.xyAtT(tt2);
49 if (!xy1.approximatelyEqual(xy2)) {
50 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
51 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2. fX, xy2.fY);
52 }
53 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
54 }
55 }
56 }
57 }
58
59 #include "TestClassDef.h"
60 DEFINE_TESTCLASS("PathOpsCubicLineIntersection", CubicLineIntersectionTestClass, \
61 CubicLineIntersectionTest)
OLDNEW
« no previous file with comments | « tests/PathOpsCubicIntersectionTestData.cpp ('k') | tests/PathOpsCubicReduceOrderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698