blob: 4c3432755fbcc323ffc266de028cb4b4733982c8 [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 */
7#include "PathOpsQuadIntersectionTestData.h"
8#include "SkIntersections.h"
9#include "SkPathOpsRect.h"
10#include "SkReduceOrder.h"
11#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000012#include "TestClassDef.h"
caryclark@google.com49612012013-04-08 20:37:35 +000013
14static const SkDQuad testSet[] = {
15 {{{1, 1}, {2, 2}, {1, 1.000003}}},
16 {{{1, 0}, {2, 6}, {3, 0}}}
17};
18
caryclark@google.comad65a3e2013-04-15 19:13:59 +000019static const size_t testSetCount = SK_ARRAY_COUNT(testSet);
caryclark@google.com49612012013-04-08 20:37:35 +000020
21static void oneOffTest(skiatest::Reporter* reporter) {
22 for (size_t index = 0; index < testSetCount; ++index) {
23 const SkDQuad& quad = testSet[index];
24 SkReduceOrder reducer;
caryclark@google.com927b7022013-11-25 14:18:21 +000025 SkDEBUGCODE(int result = ) reducer.reduce(quad);
caryclark@google.com49612012013-04-08 20:37:35 +000026 SkASSERT(result == 3);
27 }
28}
29
30static void standardTestCases(skiatest::Reporter* reporter) {
31 size_t index;
32 SkReduceOrder reducer;
33 int order;
34 enum {
35 RunAll,
36 RunQuadraticLines,
37 RunQuadraticModLines,
38 RunNone
39 } run = RunAll;
40 int firstTestIndex = 0;
41#if 0
42 run = RunQuadraticLines;
43 firstTestIndex = 1;
44#endif
45 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex
46 : SK_MaxS32;
47 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex
48 : SK_MaxS32;
49
50 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
51 const SkDQuad& quad = quadraticLines[index];
caryclark@google.com927b7022013-11-25 14:18:21 +000052 order = reducer.reduce(quad);
caryclark@google.com49612012013-04-08 20:37:35 +000053 if (order != 2) {
bungeman@google.comfab44db2013-10-11 18:50:45 +000054 SkDebugf("[%d] line quad order=%d\n", (int) index, order);
caryclark@google.com49612012013-04-08 20:37:35 +000055 }
56 }
57 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
58 const SkDQuad& quad = quadraticModEpsilonLines[index];
caryclark@google.com927b7022013-11-25 14:18:21 +000059 order = reducer.reduce(quad);
caryclark@google.com49612012013-04-08 20:37:35 +000060 if (order != 3) {
bungeman@google.comfab44db2013-10-11 18:50:45 +000061 SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
caryclark@google.com49612012013-04-08 20:37:35 +000062 }
63 }
64}
65
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000066DEF_TEST(PathOpsReduceOrderQuad, reporter) {
caryclark@google.com49612012013-04-08 20:37:35 +000067 oneOffTest(reporter);
68 standardTestCases(reporter);
69}