blob: 92e474b84a9679710625bd1615b51ad46e8fb0b4 [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +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 */
caryclark@google.com4917f172012-03-05 22:01:21 +00007#include "EdgeWalker_Test.h"
8#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00009#include "SkBitmap.h"
10
11static SkBitmap bitmap;
caryclark@google.com4917f172012-03-05 22:01:21 +000012
13static void testSimplifyQuad1() {
14 SkPath path, out;
15 path.moveTo(0, 0);
16 path.lineTo(1, 0);
17 path.lineTo(3, 2);
18 path.lineTo(3, 3);
19 path.close();
20 path.moveTo(1, 0);
21 path.lineTo(1, 3);
22 path.lineTo(1, 3);
23 path.lineTo(1, 3);
24 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000025 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000026}
27
28static void testSimplifyQuad2() {
29 SkPath path, out;
30 path.moveTo(0, 0);
31 path.lineTo(0, 0);
32 path.lineTo(0, 0);
33 path.lineTo(0, 2);
34 path.close();
35 path.moveTo(0, 1);
36 path.lineTo(0, 1);
37 path.lineTo(1, 1);
38 path.lineTo(0, 2);
39 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000040 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000041}
42
43static void testSimplifyQuad3() {
44 SkPath path, out;
45 path.moveTo(0, 0);
46 path.lineTo(0, 0);
47 path.lineTo(1, 0);
48 path.lineTo(1, 2);
49 path.close();
50 path.moveTo(0, 1);
51 path.lineTo(1, 1);
52 path.lineTo(2, 1);
53 path.lineTo(0, 2);
54 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000055 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000056}
57
58static void testSimplifyQuad4() {
59 SkPath path, out;
60 path.moveTo(0, 0);
61 path.lineTo(0, 0);
62 path.lineTo(1, 0);
63 path.lineTo(2, 2);
64 path.close();
65 path.moveTo(0, 0);
66 path.lineTo(2, 1);
67 path.lineTo(3, 1);
68 path.lineTo(3, 3);
69 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000070 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000071}
72
73static void testSimplifyQuad5() {
74 SkPath path, out;
75 path.moveTo(0, 0);
76 path.lineTo(0, 0);
77 path.lineTo(1, 0);
78 path.lineTo(3, 2);
79 path.close();
80 path.moveTo(0, 1);
81 path.lineTo(1, 1);
82 path.lineTo(2, 1);
83 path.lineTo(0, 2);
84 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000085 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000086}
87
88static void testSimplifyQuad6() {
89 SkPath path, out;
90 path.moveTo(0, 0);
91 path.lineTo(1, 0);
92 path.lineTo(1, 1);
93 path.lineTo(3, 3);
94 path.close();
95 path.moveTo(1, 1);
96 path.lineTo(1, 1);
97 path.lineTo(1, 1);
98 path.lineTo(2, 2);
99 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000100 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000101}
102
caryclark@google.com4917f172012-03-05 22:01:21 +0000103static void (*simplifyTests[])() = {
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000104 testSimplifyQuad6,
105 testSimplifyQuad5,
106 testSimplifyQuad4,
107 testSimplifyQuad3,
108 testSimplifyQuad2,
caryclark@google.com4917f172012-03-05 22:01:21 +0000109 testSimplifyQuad1,
caryclark@google.com4917f172012-03-05 22:01:21 +0000110};
111
112static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
113
114static void (*firstTest)() = 0;
115
116void SimplifyQuadralateralPaths_Test() {
117 size_t index = 0;
118 if (firstTest) {
119 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
120 ++index;
121 }
122 }
123 for ( ; index < simplifyTestsCount; ++index) {
124 (*simplifyTests[index])();
125 }
126}