caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 10 | namespace 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.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 19 | static bool testSimplifyx(const SkPath& path) { |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 20 | if (false) { |
| 21 | showPath(path); |
| 22 | } |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 23 | SkPath out; |
caryclark@google.com | 65f9f0a | 2012-05-23 18:09:25 +0000 | [diff] [blame] | 24 | simplifyx(path, out); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 25 | if (false) { |
| 26 | return true; |
| 27 | } |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 28 | SkBitmap bitmap; |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 29 | return comparePaths(path, out, bitmap, 0) == 0; |
| 30 | } |
| 31 | |
| 32 | static 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.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 38 | testSimplifyx(path); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static void addInnerCWTriangle(SkPath& path) { |
| 42 | path.moveTo(3,0); |
| 43 | path.lineTo(4,1); |
| 44 | path.lineTo(2,1); |
| 45 | path.close(); |
| 46 | } |
| 47 | |
| 48 | static void addInnerCCWTriangle(SkPath& path) { |
| 49 | path.moveTo(3,0); |
| 50 | path.lineTo(2,1); |
| 51 | path.lineTo(4,1); |
| 52 | path.close(); |
| 53 | } |
| 54 | |
| 55 | static void addOuterCWTriangle(SkPath& path) { |
| 56 | path.moveTo(3,0); |
| 57 | path.lineTo(6,2); |
| 58 | path.lineTo(0,2); |
| 59 | path.close(); |
| 60 | } |
| 61 | |
| 62 | static void addOuterCCWTriangle(SkPath& path) { |
| 63 | path.moveTo(3,0); |
| 64 | path.lineTo(0,2); |
| 65 | path.lineTo(6,2); |
| 66 | path.close(); |
| 67 | } |
| 68 | |
| 69 | static void testLine2() { |
| 70 | SkPath path, simple; |
| 71 | addInnerCWTriangle(path); |
| 72 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 73 | testSimplifyx(path); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 76 | static void testLine3() { |
| 77 | SkPath path, simple; |
| 78 | addInnerCCWTriangle(path); |
| 79 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 80 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void testLine4() { |
| 84 | SkPath path, simple; |
| 85 | addOuterCCWTriangle(path); |
| 86 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 87 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void testLine5() { |
| 91 | SkPath path, simple; |
| 92 | addOuterCWTriangle(path); |
| 93 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 94 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 95 | } |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 96 | |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 97 | static 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 | |
| 110 | static 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 | |
| 123 | static 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 | |
| 136 | static 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.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 150 | static void (*tests[])() = { |
| 151 | testLine1, |
| 152 | testLine2, |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 153 | testLine3, |
| 154 | testLine4, |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 155 | testLine5, |
| 156 | testLine6, |
| 157 | testLine7, |
| 158 | testLine8, |
| 159 | testLine9 |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 163 | |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame^] | 164 | static void (*firstTest)() = 0; |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 165 | static bool skipAll = false; |
| 166 | |
| 167 | void 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.com | a3f05fa | 2012-06-01 17:44:28 +0000 | [diff] [blame] | 179 | SkDebugf("%s [%d]\n", __FUNCTION__, index + 1); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 180 | (*tests[index])(); |
| 181 | firstTestComplete = true; |
| 182 | } |
| 183 | } |