blob: c99b8e93200a6eb26a2a311f18a223f9a5cbc0c2 [file] [log] [blame]
caryclark@google.comaf46cff2012-05-22 21:12:00 +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
8#include "Simplify.h"
9
10namespace SimplifyNewTest {
11
12#include "Simplify.cpp"
13
14} // end of SimplifyNewTest namespace
15
16#include "EdgeWalker_Test.h"
17#include "Intersection_Tests.h"
18
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000019static bool testSimplifyx(const SkPath& path) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +000020 if (false) {
21 showPath(path);
22 }
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000023 SkPath out;
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000024 simplifyx(path, out);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000025 if (false) {
26 return true;
27 }
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000028 SkBitmap bitmap;
caryclark@google.comaf46cff2012-05-22 21:12:00 +000029 return comparePaths(path, out, bitmap, 0) == 0;
30}
31
32static void testLine1() {
33 SkPath path, simple;
34 path.moveTo(2,0);
35 path.lineTo(1,1);
36 path.lineTo(0,0);
37 path.close();
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000038 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000039}
40
41static void addInnerCWTriangle(SkPath& path) {
42 path.moveTo(3,0);
43 path.lineTo(4,1);
44 path.lineTo(2,1);
45 path.close();
46}
47
48static void addInnerCCWTriangle(SkPath& path) {
49 path.moveTo(3,0);
50 path.lineTo(2,1);
51 path.lineTo(4,1);
52 path.close();
53}
54
55static void addOuterCWTriangle(SkPath& path) {
56 path.moveTo(3,0);
57 path.lineTo(6,2);
58 path.lineTo(0,2);
59 path.close();
60}
61
62static void addOuterCCWTriangle(SkPath& path) {
63 path.moveTo(3,0);
64 path.lineTo(0,2);
65 path.lineTo(6,2);
66 path.close();
67}
68
69static void testLine2() {
70 SkPath path, simple;
71 addInnerCWTriangle(path);
72 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000073 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000074}
75
caryclark@google.com495f8e42012-05-31 13:13:11 +000076static void testLine3() {
77 SkPath path, simple;
78 addInnerCCWTriangle(path);
79 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000080 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000081}
82
83static void testLine4() {
84 SkPath path, simple;
85 addOuterCCWTriangle(path);
86 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000087 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000088}
89
90static void testLine5() {
91 SkPath path, simple;
92 addOuterCWTriangle(path);
93 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000094 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000095}
caryclark@google.comaf46cff2012-05-22 21:12:00 +000096
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000097static void testLine6() {
98 SkPath path, simple;
99 path.moveTo(0,0);
100 path.lineTo(4,0);
101 path.lineTo(2,2);
102 path.close();
103 path.moveTo(2,0);
104 path.lineTo(6,0);
105 path.lineTo(4,2);
106 path.close();
107 testSimplifyx(path);
108}
109
110static void testLine7() {
111 SkPath path, simple;
112 path.moveTo(0,0);
113 path.lineTo(4,0);
114 path.lineTo(2,2);
115 path.close();
116 path.moveTo(6,0);
117 path.lineTo(2,0);
118 path.lineTo(4,2);
119 path.close();
120 testSimplifyx(path);
121}
122
123static void testLine8() {
124 SkPath path, simple;
125 path.moveTo(0,4);
126 path.lineTo(4,4);
127 path.lineTo(2,2);
128 path.close();
129 path.moveTo(2,4);
130 path.lineTo(6,4);
131 path.lineTo(4,2);
132 path.close();
133 testSimplifyx(path);
134}
135
136static void testLine9() {
137 SkPath path, simple;
138 path.moveTo(0,4);
139 path.lineTo(4,4);
140 path.lineTo(2,2);
141 path.close();
142 path.moveTo(6,4);
143 path.lineTo(2,4);
144 path.lineTo(4,2);
145 path.close();
146 testSimplifyx(path);
147}
148
149
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000150static void (*tests[])() = {
151 testLine1,
152 testLine2,
caryclark@google.com495f8e42012-05-31 13:13:11 +0000153 testLine3,
154 testLine4,
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000155 testLine5,
156 testLine6,
157 testLine7,
158 testLine8,
159 testLine9
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000160};
161
162static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
163
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000164static void (*firstTest)() = 0;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000165static bool skipAll = false;
166
167void SimplifyNew_Test() {
168 if (skipAll) {
169 return;
170 }
171 size_t index = 0;
172 if (firstTest) {
173 while (index < testCount && tests[index] != firstTest) {
174 ++index;
175 }
176 }
177 bool firstTestComplete = false;
178 for ( ; index < testCount; ++index) {
caryclark@google.coma3f05fa2012-06-01 17:44:28 +0000179 SkDebugf("%s [%d]\n", __FUNCTION__, index + 1);
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000180 (*tests[index])();
181 firstTestComplete = true;
182 }
183}