blob: 0245f878c1c5cd8384bae9872e973e4e0b6cf19a [file] [log] [blame]
caryclark@google.com66560ca2013-04-26 19:51:16 +00001/*
2 * Copyright 2013 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 "SkPathOps.h"
8#include "SkPath.h"
9#include "SkPoint.h"
10#include "Test.h"
11
12static const SkPoint nonFinitePts[] = {
13 { SK_ScalarInfinity, 0 },
14 { 0, SK_ScalarInfinity },
15 { SK_ScalarInfinity, SK_ScalarInfinity },
16 { SK_ScalarNegativeInfinity, 0},
17 { 0, SK_ScalarNegativeInfinity },
18 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
19 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
20 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
21 { SK_ScalarNaN, 0 },
22 { 0, SK_ScalarNaN },
23 { SK_ScalarNaN, SK_ScalarNaN },
24};
25
26const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
27
28static const SkPoint finitePts[] = {
29 { 0, 0 },
30 { SK_ScalarMax, 0 },
31 { 0, SK_ScalarMax },
32 { SK_ScalarMax, SK_ScalarMax },
33 { SK_ScalarMin, 0 },
34 { 0, SK_ScalarMin },
35 { SK_ScalarMin, SK_ScalarMin },
36};
37
38const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
39
40static void PathOpsSimplifyFailTest(skiatest::Reporter* reporter) {
41 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
42 SkPath path;
43 int i = (int) (index % nonFinitePtsCount);
44 int f = (int) (index % finitePtsCount);
45 int g = (int) ((f + 1) % finitePtsCount);
46 switch (index % 13) {
47 case 0: path.lineTo(nonFinitePts[i]); break;
48 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
49 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
50 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
51 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
52 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
53 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
54 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
55 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
56 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
57 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
58 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
59 case 12: path.moveTo(nonFinitePts[i]); break;
60 }
61 SkPath result;
62 result.setFillType(SkPath::kWinding_FillType);
63 bool success = Simplify(path, &result);
64 REPORTER_ASSERT(reporter, !success);
65 REPORTER_ASSERT(reporter, result.isEmpty());
66 REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType);
67 reporter->bumpTestCount();
68 }
caryclark@google.come23b4a42013-04-26 20:41:24 +000069 if (sizeof(reporter) == 4) {
70 return;
71 }
caryclark@google.com66560ca2013-04-26 19:51:16 +000072 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
73 SkPath path;
74 int f = (int) (index % finitePtsCount);
75 int g = (int) ((f + 1) % finitePtsCount);
76 switch (index % 11) {
77 case 0: path.lineTo(finitePts[f]); break;
78 case 1: path.quadTo(finitePts[f], finitePts[f]); break;
79 case 2: path.quadTo(finitePts[f], finitePts[g]); break;
80 case 3: path.quadTo(finitePts[g], finitePts[f]); break;
81 case 4: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
82 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
83 case 6: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
84 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
85 case 8: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
86 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
87 case 10: path.moveTo(finitePts[f]); break;
88 }
89 SkPath result;
90 result.setFillType(SkPath::kWinding_FillType);
91 bool success = Simplify(path, &result);
92 REPORTER_ASSERT(reporter, success);
93 REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
94 reporter->bumpTestCount();
95 }
96}
97
98#include "TestClassDef.h"
99DEFINE_TESTCLASS_SHORT(PathOpsSimplifyFailTest)