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