• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PathOpsQuadIntersectionTestData.h"
8 #include "SkIntersections.h"
9 #include "SkPathOpsRect.h"
10 #include "SkReduceOrder.h"
11 #include "Test.h"
12 
13 static const QuadPts testSet[] = {
14     {{{1, 1}, {2, 2}, {1, 1.000003}}},
15     {{{1, 0}, {2, 6}, {3, 0}}}
16 };
17 
18 static const size_t testSetCount = SK_ARRAY_COUNT(testSet);
19 
oneOffTest(skiatest::Reporter * reporter)20 static void oneOffTest(skiatest::Reporter* reporter) {
21     for (size_t index = 0; index < testSetCount; ++index) {
22         const QuadPts& q = testSet[index];
23         SkDQuad quad;
24         quad.debugSet(q.fPts);
25         SkReduceOrder reducer;
26         SkDEBUGCODE(int result = ) reducer.reduce(quad);
27         SkASSERT(result == 3);
28     }
29 }
30 
standardTestCases(skiatest::Reporter * reporter)31 static void standardTestCases(skiatest::Reporter* reporter) {
32     size_t index;
33     SkReduceOrder reducer;
34     int order;
35     enum {
36         RunAll,
37         RunQuadraticLines,
38         RunQuadraticModLines,
39         RunNone
40     } run = RunAll;
41     int firstTestIndex = 0;
42 #if 0
43     run = RunQuadraticLines;
44     firstTestIndex = 1;
45 #endif
46     int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex
47             : SK_MaxS32;
48     int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex
49             : SK_MaxS32;
50 
51     for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
52         const QuadPts& q = quadraticLines[index];
53         SkDQuad quad;
54         quad.debugSet(q.fPts);
55         order = reducer.reduce(quad);
56         if (order != 2) {
57             SkDebugf("[%d] line quad order=%d\n", (int) index, order);
58         }
59     }
60     for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
61         const QuadPts& q = quadraticModEpsilonLines[index];
62         SkDQuad quad;
63         quad.debugSet(q.fPts);
64         order = reducer.reduce(quad);
65         if (order != 2 && order != 3) {  // FIXME: data probably is not good
66             SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
67         }
68     }
69 }
70 
DEF_TEST(PathOpsReduceOrderQuad,reporter)71 DEF_TEST(PathOpsReduceOrderQuad, reporter) {
72     oneOffTest(reporter);
73     standardTestCases(reporter);
74 }
75