blob: daf5af77f30c5fe125976302343cb80890c10d64 [file] [log] [blame]
caryclark@google.com4917f172012-03-05 22:01:21 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00003#include "SkBitmap.h"
4
5static SkBitmap bitmap;
caryclark@google.com4917f172012-03-05 22:01:21 +00006
7static void testSimplifyQuad1() {
8 SkPath path, out;
9 path.moveTo(0, 0);
10 path.lineTo(1, 0);
11 path.lineTo(3, 2);
12 path.lineTo(3, 3);
13 path.close();
14 path.moveTo(1, 0);
15 path.lineTo(1, 3);
16 path.lineTo(1, 3);
17 path.lineTo(1, 3);
18 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000019 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000020}
21
22static void testSimplifyQuad2() {
23 SkPath path, out;
24 path.moveTo(0, 0);
25 path.lineTo(0, 0);
26 path.lineTo(0, 0);
27 path.lineTo(0, 2);
28 path.close();
29 path.moveTo(0, 1);
30 path.lineTo(0, 1);
31 path.lineTo(1, 1);
32 path.lineTo(0, 2);
33 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000034 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000035}
36
37static void testSimplifyQuad3() {
38 SkPath path, out;
39 path.moveTo(0, 0);
40 path.lineTo(0, 0);
41 path.lineTo(1, 0);
42 path.lineTo(1, 2);
43 path.close();
44 path.moveTo(0, 1);
45 path.lineTo(1, 1);
46 path.lineTo(2, 1);
47 path.lineTo(0, 2);
48 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000049 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000050}
51
52static void testSimplifyQuad4() {
53 SkPath path, out;
54 path.moveTo(0, 0);
55 path.lineTo(0, 0);
56 path.lineTo(1, 0);
57 path.lineTo(2, 2);
58 path.close();
59 path.moveTo(0, 0);
60 path.lineTo(2, 1);
61 path.lineTo(3, 1);
62 path.lineTo(3, 3);
63 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000064 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000065}
66
67static void testSimplifyQuad5() {
68 SkPath path, out;
69 path.moveTo(0, 0);
70 path.lineTo(0, 0);
71 path.lineTo(1, 0);
72 path.lineTo(3, 2);
73 path.close();
74 path.moveTo(0, 1);
75 path.lineTo(1, 1);
76 path.lineTo(2, 1);
77 path.lineTo(0, 2);
78 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000079 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000080}
81
82static void testSimplifyQuad6() {
83 SkPath path, out;
84 path.moveTo(0, 0);
85 path.lineTo(1, 0);
86 path.lineTo(1, 1);
87 path.lineTo(3, 3);
88 path.close();
89 path.moveTo(1, 1);
90 path.lineTo(1, 1);
91 path.lineTo(1, 1);
92 path.lineTo(2, 2);
93 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000094 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +000095}
96
caryclark@google.com4917f172012-03-05 22:01:21 +000097static void (*simplifyTests[])() = {
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000098 testSimplifyQuad6,
99 testSimplifyQuad5,
100 testSimplifyQuad4,
101 testSimplifyQuad3,
102 testSimplifyQuad2,
caryclark@google.com4917f172012-03-05 22:01:21 +0000103 testSimplifyQuad1,
caryclark@google.com4917f172012-03-05 22:01:21 +0000104};
105
106static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
107
108static void (*firstTest)() = 0;
109
110void SimplifyQuadralateralPaths_Test() {
111 size_t index = 0;
112 if (firstTest) {
113 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
114 ++index;
115 }
116 }
117 for ( ; index < simplifyTestsCount; ++index) {
118 (*simplifyTests[index])();
119 }
120}