blob: 0f0e334222ba3328f50e47575bc1bd33b368e9e9 [file] [log] [blame]
caryclark@google.com49612012013-04-08 20:37:35 +00001/*
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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "src/pathops/SkIntersections.h"
8#include "src/pathops/SkPathOpsRect.h"
9#include "src/pathops/SkReduceOrder.h"
10#include "tests/PathOpsQuadIntersectionTestData.h"
11#include "tests/Test.h"
caryclark@google.com49612012013-04-08 20:37:35 +000012
caryclarka35ab3e2016-10-20 08:32:18 -070013static const QuadPts testSet[] = {
caryclark@google.com49612012013-04-08 20:37:35 +000014 {{{1, 1}, {2, 2}, {1, 1.000003}}},
15 {{{1, 0}, {2, 6}, {3, 0}}}
16};
17
caryclark@google.comad65a3e2013-04-15 19:13:59 +000018static const size_t testSetCount = SK_ARRAY_COUNT(testSet);
caryclark@google.com49612012013-04-08 20:37:35 +000019
20static void oneOffTest(skiatest::Reporter* reporter) {
21 for (size_t index = 0; index < testSetCount; ++index) {
caryclarka35ab3e2016-10-20 08:32:18 -070022 const QuadPts& q = testSet[index];
23 SkDQuad quad;
24 quad.debugSet(q.fPts);
caryclark@google.com49612012013-04-08 20:37:35 +000025 SkReduceOrder reducer;
caryclark@google.com927b7022013-11-25 14:18:21 +000026 SkDEBUGCODE(int result = ) reducer.reduce(quad);
caryclark@google.com49612012013-04-08 20:37:35 +000027 SkASSERT(result == 3);
28 }
29}
30
31static 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) {
caryclarka35ab3e2016-10-20 08:32:18 -070052 const QuadPts& q = quadraticLines[index];
53 SkDQuad quad;
54 quad.debugSet(q.fPts);
caryclark@google.com927b7022013-11-25 14:18:21 +000055 order = reducer.reduce(quad);
caryclark@google.com49612012013-04-08 20:37:35 +000056 if (order != 2) {
bungeman@google.comfab44db2013-10-11 18:50:45 +000057 SkDebugf("[%d] line quad order=%d\n", (int) index, order);
caryclark@google.com49612012013-04-08 20:37:35 +000058 }
59 }
60 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
caryclarka35ab3e2016-10-20 08:32:18 -070061 const QuadPts& q = quadraticModEpsilonLines[index];
62 SkDQuad quad;
63 quad.debugSet(q.fPts);
caryclark@google.com927b7022013-11-25 14:18:21 +000064 order = reducer.reduce(quad);
caryclark65f55312014-11-13 06:58:52 -080065 if (order != 2 && order != 3) { // FIXME: data probably is not good
bungeman@google.comfab44db2013-10-11 18:50:45 +000066 SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
caryclark@google.com49612012013-04-08 20:37:35 +000067 }
68 }
69}
70
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000071DEF_TEST(PathOpsReduceOrderQuad, reporter) {
caryclark@google.com49612012013-04-08 20:37:35 +000072 oneOffTest(reporter);
73 standardTestCases(reporter);
74}