1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkPath.h"
#include "SkPathOps.h"
#include "SkPoint.h"
#include "Test.h"
static const SkPoint nonFinitePts[] = {
{ SK_ScalarInfinity, 0 },
{ 0, SK_ScalarInfinity },
{ SK_ScalarInfinity, SK_ScalarInfinity },
{ SK_ScalarNegativeInfinity, 0},
{ 0, SK_ScalarNegativeInfinity },
{ SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
{ SK_ScalarNegativeInfinity, SK_ScalarInfinity },
{ SK_ScalarInfinity, SK_ScalarNegativeInfinity },
{ SK_ScalarNaN, 0 },
{ 0, SK_ScalarNaN },
{ SK_ScalarNaN, SK_ScalarNaN },
};
const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
static const SkPoint finitePts[] = {
{ 0, 0 },
{ SK_ScalarMax, 0 },
{ 0, SK_ScalarMax },
{ SK_ScalarMax, SK_ScalarMax },
{ SK_ScalarMin, 0 },
{ 0, SK_ScalarMin },
{ SK_ScalarMin, SK_ScalarMin },
};
const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
static void failOne(skiatest::Reporter* reporter, int index) {
SkPath path;
int i = (int) (index % nonFinitePtsCount);
int f = (int) (index % finitePtsCount);
int g = (int) ((f + 1) % finitePtsCount);
switch (index % 13) {
case 0: path.lineTo(nonFinitePts[i]); break;
case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
case 12: path.moveTo(nonFinitePts[i]); break;
}
SkPath result;
result.setFillType(SkPath::kWinding_FillType);
bool success = Simplify(path, &result);
REPORTER_ASSERT(reporter, !success);
REPORTER_ASSERT(reporter, result.isEmpty());
REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType);
reporter->bumpTestCount();
}
static void dontFailOne(skiatest::Reporter* reporter, int index) {
SkPath path;
int f = (int) (index % finitePtsCount);
int g = (int) ((f + 1) % finitePtsCount);
switch (index % 11) {
case 0: path.lineTo(finitePts[f]); break;
case 1: path.quadTo(finitePts[f], finitePts[f]); break;
case 2: path.quadTo(finitePts[f], finitePts[g]); break;
case 3: path.quadTo(finitePts[g], finitePts[f]); break;
case 4: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
case 6: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
case 8: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
case 10: path.moveTo(finitePts[f]); break;
}
SkPath result;
result.setFillType(SkPath::kWinding_FillType);
bool success = Simplify(path, &result);
// linux 32 debug fails test 13 because the quad is not treated as linear
// there's no error in the math that I can find -- it looks like a processor
// or compiler bug -- so for now, allow either to work
REPORTER_ASSERT(reporter, success || index == 13);
REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
reporter->bumpTestCount();
}
DEF_TEST(PathOpsSimplifyFail, reporter) {
for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
failOne(reporter, index);
}
for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
dontFailOne(reporter, index);
}
}
DEF_TEST(PathOpsSimplifyFailOne, reporter) {
int index = 0;
failOne(reporter, index);
}
DEF_TEST(PathOpsSimplifyDontFailOne, reporter) {
int index = 13;
dontFailOne(reporter, index);
}
|