blob: 9098f69fa2fc0a91a4b856a78b8e81483ceff88c [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
19static SkBitmap bitmap;
20
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000021static bool testSimplifyx(const SkPath& path, SkPath& out, SkBitmap& bitmap) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +000022 if (false) {
23 showPath(path);
24 }
caryclark@google.com65f9f0a2012-05-23 18:09:25 +000025 simplifyx(path, out);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000026 if (false) {
27 return true;
28 }
29 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.com65f9f0a2012-05-23 18:09:25 +000038 testSimplifyx(path, simple, bitmap);
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.com65f9f0a2012-05-23 18:09:25 +000073 testSimplifyx(path, simple, bitmap);
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);
80 testSimplifyx(path, simple, bitmap);
81}
82
83static void testLine4() {
84 SkPath path, simple;
85 addOuterCCWTriangle(path);
86 addOuterCWTriangle(path);
87 testSimplifyx(path, simple, bitmap);
88}
89
90static void testLine5() {
91 SkPath path, simple;
92 addOuterCWTriangle(path);
93 addOuterCWTriangle(path);
94 testSimplifyx(path, simple, bitmap);
95}
caryclark@google.comaf46cff2012-05-22 21:12:00 +000096
97static void (*tests[])() = {
98 testLine1,
99 testLine2,
caryclark@google.com495f8e42012-05-31 13:13:11 +0000100 testLine3,
101 testLine4,
102 testLine5
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000103};
104
105static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
106
caryclark@google.coma3f05fa2012-06-01 17:44:28 +0000107static void (*firstTest)() = 0;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000108static bool skipAll = false;
109
110void SimplifyNew_Test() {
111 if (skipAll) {
112 return;
113 }
114 size_t index = 0;
115 if (firstTest) {
116 while (index < testCount && tests[index] != firstTest) {
117 ++index;
118 }
119 }
120 bool firstTestComplete = false;
121 for ( ; index < testCount; ++index) {
caryclark@google.coma3f05fa2012-06-01 17:44:28 +0000122 SkDebugf("%s [%d]\n", __FUNCTION__, index + 1);
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000123 (*tests[index])();
124 firstTestComplete = true;
125 }
126}