| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" | 
 | 2 | #include "Intersection_Tests.h" | 
| caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 3 | #include "SkBitmap.h" | 
 | 4 |  | 
 | 5 | static SkBitmap bitmap; | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 6 |  | 
 | 7 | static void testSimplifyQuadratic1() { | 
 | 8 |     SkPath path, out; | 
 | 9 |     path.moveTo(0, 0); | 
 | 10 |     path.quadTo(1, 0, 1, 1); | 
 | 11 |     path.close(); | 
 | 12 |     path.moveTo(1, 0); | 
 | 13 |     path.quadTo(0, 0, 0, 1); | 
 | 14 |     path.close(); | 
| caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 15 |     testSimplify(path, true, out, bitmap); | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 16 | } | 
 | 17 |  | 
 | 18 | static void testSimplifyQuadratic2() { | 
 | 19 |     SkPath path, out; | 
 | 20 |     path.moveTo(0, 0); | 
 | 21 |     path.quadTo(20, 0, 20, 20); | 
 | 22 |     path.close(); | 
 | 23 |     path.moveTo(20, 0); | 
 | 24 |     path.quadTo(0, 0, 0, 20); | 
 | 25 |     path.close(); | 
| caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 26 |     testSimplify(path, true, out, bitmap); | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 27 | } | 
 | 28 |  | 
 | 29 | static void testSimplifyQuadratic3() { | 
 | 30 |     SkPath path, out; | 
 | 31 |     path.moveTo(0, 0); | 
 | 32 |     path.quadTo(20, 0, 20, 20); | 
 | 33 |     path.close(); | 
 | 34 |     path.moveTo(0, 20); | 
 | 35 |     path.quadTo(0, 0, 20, 0); | 
 | 36 |     path.close(); | 
| caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 37 |     testSimplify(path, true, out, bitmap); | 
 | 38 | } | 
 | 39 |  | 
 | 40 | static void testSimplifyQuadratic4() { | 
 | 41 |     SkPath path, out; | 
 | 42 |     path.moveTo(0, 20); | 
 | 43 |     path.quadTo(20, 0, 40, 20); | 
 | 44 |     path.close(); | 
 | 45 |     path.moveTo(40, 10); | 
 | 46 |     path.quadTo(20, 30, 0, 10); | 
 | 47 |     path.close(); | 
 | 48 |     testSimplify(path, true, out, bitmap); | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 49 |     drawAsciiPaths(path, out, true); | 
 | 50 | } | 
 | 51 |  | 
| caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 52 | static void testSimplifyQuadratic5() { | 
 | 53 |     SkPath path, out; | 
 | 54 |     path.moveTo(0, 0); | 
 | 55 |     path.quadTo(0, 0, 0, 0); | 
 | 56 |     path.lineTo(0, 0); | 
 | 57 |     path.close(); | 
 | 58 |     path.moveTo(0, 0); | 
 | 59 |     path.lineTo(0, 0); | 
 | 60 |     path.quadTo(0, 0, 0, 1); | 
 | 61 |     path.close(); | 
 | 62 |     testSimplify(path, true, out, bitmap); | 
 | 63 |     drawAsciiPaths(path, out, true); | 
 | 64 | } | 
 | 65 |  | 
 | 66 | static void testSimplifyQuadratic6() { | 
 | 67 |     SkPath path, out; | 
 | 68 |     path.moveTo(0, 0); | 
 | 69 |     path.quadTo(0, 0, 0, 0); | 
 | 70 |     path.lineTo(1, 0); | 
 | 71 |     path.close(); | 
 | 72 |     path.moveTo(0, 0); | 
 | 73 |     path.lineTo(0, 0); | 
 | 74 |     path.quadTo(1, 0, 0, 1); | 
 | 75 |     path.close(); | 
 | 76 |     testSimplify(path, true, out, bitmap); | 
 | 77 |     drawAsciiPaths(path, out, true); | 
 | 78 | } | 
 | 79 |  | 
 | 80 | static void testSimplifyQuadratic7() { | 
 | 81 |     SkPath path, out; | 
 | 82 |     path.moveTo(0, 0); | 
 | 83 |     path.quadTo(0, 0, 0, 0); | 
 | 84 |     path.lineTo(0, 1); | 
 | 85 |     path.close(); | 
 | 86 |     path.moveTo(0, 0); | 
 | 87 |     path.lineTo(0, 0); | 
 | 88 |     path.quadTo(1, 0, 0, 2); | 
 | 89 |     path.close(); | 
 | 90 |     testSimplify(path, true, out, bitmap); | 
 | 91 |     drawAsciiPaths(path, out, true); | 
 | 92 | } | 
 | 93 |  | 
 | 94 | static void testSimplifyQuadratic8() { | 
 | 95 |     SkPath path, out; | 
 | 96 |     path.moveTo(0, 0); | 
 | 97 |     path.quadTo(0, 0, 0, 0); | 
 | 98 |     path.lineTo(0, 0); | 
 | 99 |     path.close(); | 
 | 100 |     path.moveTo(0, 0); | 
 | 101 |     path.lineTo(0, 0); | 
 | 102 |     path.quadTo(1, 0, 0, 2); | 
 | 103 |     path.close(); | 
 | 104 |     testSimplify(path, true, out, bitmap); | 
 | 105 |     drawAsciiPaths(path, out, true); | 
 | 106 | } | 
 | 107 |  | 
 | 108 | static void testSimplifyQuadratic9() { | 
 | 109 |     SkPath path, out; | 
 | 110 |     path.moveTo(0, 0); | 
 | 111 |     path.quadTo(0, 0, 0, 0); | 
 | 112 |     path.lineTo(1, 1); | 
 | 113 |     path.close(); | 
 | 114 |     path.moveTo(0, 0); | 
 | 115 |     path.lineTo(0, 0); | 
 | 116 |     path.quadTo(1, 0, 2, 2); | 
 | 117 |     path.close(); | 
 | 118 |     testSimplify(path, true, out, bitmap); | 
 | 119 |     drawAsciiPaths(path, out, true); | 
 | 120 | } | 
 | 121 |  | 
 | 122 | static void testSimplifyQuadratic10() { | 
 | 123 |     SkPath path, out; | 
 | 124 |     path.moveTo(0, 0); | 
 | 125 |     path.quadTo(0, 0, 0, 0); | 
 | 126 |     path.lineTo(0, 0); | 
 | 127 |     path.close(); | 
 | 128 |     path.moveTo(0, 0); | 
 | 129 |     path.lineTo(0, 1); | 
 | 130 |     path.quadTo(1, 1, 1, 2); | 
 | 131 |     path.close(); | 
 | 132 |     testSimplify(path, true, out, bitmap); | 
 | 133 |     drawAsciiPaths(path, out, true); | 
 | 134 | } | 
 | 135 |  | 
 | 136 | static void testSimplifyQuadratic11() { | 
 | 137 |     SkPath path, out; | 
 | 138 |     path.moveTo(0, 0); | 
 | 139 |     path.quadTo(0, 0, 0, 0); | 
 | 140 |     path.lineTo(0, 2); | 
 | 141 |     path.close(); | 
 | 142 |     path.moveTo(0, 0); | 
 | 143 |     path.lineTo(2, 1); | 
 | 144 |     path.quadTo(2, 2, 3, 3); | 
 | 145 |     path.close(); | 
 | 146 |     testSimplify(path, true, out, bitmap); | 
 | 147 |     drawAsciiPaths(path, out, true); | 
 | 148 | } | 
 | 149 |  | 
 | 150 | static void testSimplifyQuadratic12() { | 
 | 151 |     SkPath path, out; | 
 | 152 |     path.moveTo(0, 0); | 
 | 153 |     path.lineTo(0, 2); | 
 | 154 |     path.lineTo(0, 0); | 
 | 155 |     path.close(); | 
 | 156 |     path.moveTo(3, 0); | 
 | 157 |     path.quadTo(1, 1, 0, 2); | 
 | 158 |     path.lineTo(3, 0); | 
 | 159 |     path.close(); | 
 | 160 |     testSimplify(path, true, out, bitmap); | 
 | 161 |     drawAsciiPaths(path, out, true); | 
 | 162 | } | 
 | 163 |  | 
 | 164 | static void testSimplifyQuadratic13() { | 
 | 165 |     SkPath path, out; | 
 | 166 | path.moveTo(0, 0); | 
 | 167 | path.quadTo(0, 0, 1, 0); | 
 | 168 | path.lineTo(1, 1); | 
 | 169 | path.lineTo(0, 0); | 
 | 170 | path.close(); | 
 | 171 | path.moveTo(0, 0); | 
 | 172 | path.quadTo(3, 0, 1, 1); | 
 | 173 | path.lineTo(0, 0); | 
 | 174 | path.close(); | 
 | 175 |     testSimplify(path, true, out, bitmap); | 
 | 176 |     drawAsciiPaths(path, out, true); | 
 | 177 | } | 
 | 178 |  | 
 | 179 | static void testSimplifyQuadratic14() { | 
 | 180 |     SkPath path, out; | 
 | 181 |     path.moveTo(0, 0); | 
 | 182 |     path.quadTo(0, 0, 0, 0); | 
 | 183 |     path.lineTo(1, 1); | 
 | 184 |     path.close(); | 
 | 185 |     path.moveTo(0, 0); | 
 | 186 |     path.lineTo(0, 0); | 
 | 187 |     path.quadTo(0, 1, 2, 1); | 
 | 188 |     path.close(); | 
 | 189 |     testSimplify(path, true, out, bitmap); | 
 | 190 |     drawAsciiPaths(path, out, true); | 
 | 191 | } | 
 | 192 |  | 
 | 193 | static void testSimplifyQuadratic15() { | 
 | 194 |     SkPath path, out; | 
 | 195 |     path.moveTo(0, 0); | 
 | 196 |     path.quadTo(0, 0, 1, 3); | 
 | 197 |     path.lineTo(3, 3); | 
 | 198 |     path.close(); | 
 | 199 |     path.moveTo(0, 1); | 
 | 200 |     path.lineTo(1, 1); | 
 | 201 |     path.quadTo(0, 3, 3, 3); | 
 | 202 |     path.close(); | 
 | 203 |     testSimplify(path, true, out, bitmap); | 
 | 204 |     drawAsciiPaths(path, out, true); | 
 | 205 | } | 
 | 206 |  | 
 | 207 | static void testSimplifyQuadratic16() { | 
 | 208 |     SkPath path, out; | 
 | 209 |     path.moveTo(0, 0); | 
 | 210 |     path.quadTo(0, 0, 0, 0); | 
 | 211 |     path.lineTo(0, 1); | 
 | 212 |     path.close(); | 
 | 213 |     path.moveTo(0, 0); | 
 | 214 |     path.lineTo(0, 0); | 
 | 215 |     path.quadTo(1, 0, 0, 1); | 
 | 216 |     path.close(); | 
 | 217 |     testSimplify(path, true, out, bitmap); | 
 | 218 |     drawAsciiPaths(path, out, true); | 
 | 219 | } | 
 | 220 |  | 
| caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 221 | static void testSimplifyQuadratic17() { | 
 | 222 |     SkPath path, out; | 
 | 223 |     path.moveTo(0, 0); | 
 | 224 |     path.quadTo(0, 0, 0, 0); | 
 | 225 |     path.lineTo(2, 2); | 
 | 226 |     path.close(); | 
 | 227 |     path.moveTo(0, 1); | 
 | 228 |     path.lineTo(0, 1); | 
 | 229 |     path.quadTo(2, 1, 3, 3); | 
 | 230 |     path.close(); | 
 | 231 |     testSimplify(path, true, out, bitmap); | 
 | 232 |     drawAsciiPaths(path, out, true); | 
 | 233 | } | 
 | 234 |  | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 235 | static void (*simplifyTests[])() = { | 
| caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 236 |     testSimplifyQuadratic17, | 
| caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 237 |     testSimplifyQuadratic16, | 
 | 238 |     testSimplifyQuadratic15, | 
 | 239 |     testSimplifyQuadratic14, | 
 | 240 |     testSimplifyQuadratic13, | 
 | 241 |     testSimplifyQuadratic12, | 
 | 242 |     testSimplifyQuadratic11, | 
 | 243 |     testSimplifyQuadratic10, | 
 | 244 |     testSimplifyQuadratic9, | 
 | 245 |     testSimplifyQuadratic8, | 
 | 246 |     testSimplifyQuadratic7, | 
 | 247 |     testSimplifyQuadratic6, | 
 | 248 |     testSimplifyQuadratic5, | 
| caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 249 |     testSimplifyQuadratic4, | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 250 |     testSimplifyQuadratic3, | 
 | 251 |     testSimplifyQuadratic2, | 
 | 252 |     testSimplifyQuadratic1, | 
 | 253 | }; | 
 | 254 |  | 
 | 255 | static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]); | 
 | 256 |  | 
| caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 257 | static void (*firstTest)() = testSimplifyQuadratic14; | 
| caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 258 | static bool skipAll = false; | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 259 |  | 
 | 260 | void SimplifyQuadraticPaths_Test() { | 
| caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 261 |     if (skipAll) { | 
 | 262 |         return; | 
 | 263 |     } | 
| caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 264 |     size_t index = 0; | 
 | 265 |     if (firstTest) { | 
 | 266 |         while (index < simplifyTestsCount && simplifyTests[index] != firstTest) { | 
 | 267 |             ++index; | 
 | 268 |         } | 
 | 269 |     } | 
 | 270 |     bool firstTestComplete = false; | 
 | 271 |     for ( ; index < simplifyTestsCount; ++index) { | 
 | 272 |         (*simplifyTests[index])(); | 
 | 273 |         if (simplifyTests[index] == testSimplifyQuadratic1) { | 
 | 274 |             SkDebugf("%s last fast quad test\n", __FUNCTION__); | 
 | 275 |         } | 
 | 276 |         firstTestComplete = true; | 
 | 277 |     } | 
 | 278 | } |