caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
| 3 | <div style="height:0"> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 4 | |
| 5 | <div id="testSimplifyQuadratic1"> |
| 6 | SkPath path, out; |
| 7 | path.moveTo(0, 0); |
| 8 | path.quadTo(1, 0, 1, 1); |
| 9 | path.close(); |
| 10 | path.moveTo(1, 0); |
| 11 | path.quadTo(0, 0, 0, 1); |
| 12 | path.close(); |
| 13 | testSimplify(path, true, out, bitmap); |
| 14 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 15 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 16 | |
| 17 | <div id="testSimplifyQuadratic2"> |
| 18 | SkPath path, out; |
| 19 | path.moveTo(0, 0); |
| 20 | path.quadTo(20, 0, 20, 20); |
| 21 | path.close(); |
| 22 | path.moveTo(20, 0); |
| 23 | path.quadTo(0, 0, 0, 20); |
| 24 | path.close(); |
| 25 | testSimplify(path, true, out, bitmap); |
| 26 | } |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 27 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 28 | |
| 29 | <div id="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(); |
| 37 | testSimplify(path, true, out, bitmap); |
| 38 | } |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 39 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 40 | |
| 41 | <div id="testSimplifyQuadratic4"> |
| 42 | SkPath path, out; |
| 43 | path.moveTo(0, 20); |
| 44 | path.quadTo(20, 0, 40, 20); |
| 45 | path.close(); |
| 46 | path.moveTo(40, 10); |
| 47 | path.quadTo(20, 30, 0, 10); |
| 48 | path.close(); |
| 49 | testSimplify(path, true, out, bitmap); |
| 50 | drawAsciiPaths(path, out, true); |
| 51 | } |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 52 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 53 | |
| 54 | <div id="testSimplifyQuadratic5"> |
| 55 | SkPath path, out; |
| 56 | path.moveTo(0, 0); |
| 57 | path.quadTo(0, 0, 0, 0); |
| 58 | path.lineTo(0, 0); |
| 59 | path.close(); |
| 60 | path.moveTo(0, 0); |
| 61 | path.lineTo(0, 0); |
| 62 | path.quadTo(0, 0, 0, 1); |
| 63 | path.close(); |
| 64 | testSimplify(path, true, out, bitmap); |
| 65 | drawAsciiPaths(path, out, true); |
| 66 | } |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 67 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 68 | |
| 69 | <div id="testSimplifyQuadratic6"> |
| 70 | SkPath path, out; |
| 71 | path.moveTo(0, 0); |
| 72 | path.quadTo(0, 0, 0, 0); |
| 73 | path.lineTo(1, 0); |
| 74 | path.close(); |
| 75 | path.moveTo(0, 0); |
| 76 | path.lineTo(0, 0); |
| 77 | path.quadTo(1, 0, 0, 1); |
| 78 | path.close(); |
| 79 | testSimplify(path, true, out, bitmap); |
| 80 | drawAsciiPaths(path, out, true); |
| 81 | } |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 82 | </div> |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 83 | |
| 84 | <div id="testSimplifyQuadratic7"> |
| 85 | SkPath path, out; |
| 86 | path.moveTo(0, 0); |
| 87 | path.quadTo(0, 0, 0, 0); |
| 88 | path.lineTo(0, 1); |
| 89 | path.close(); |
| 90 | path.moveTo(0, 0); |
| 91 | path.lineTo(0, 0); |
| 92 | path.quadTo(1, 0, 0, 2); |
| 93 | path.close(); |
| 94 | testSimplify(path, true, out, bitmap); |
| 95 | drawAsciiPaths(path, out, true); |
| 96 | } |
| 97 | </div> |
| 98 | |
| 99 | <div id="testSimplifyQuadratic8"> |
| 100 | SkPath path, out; |
| 101 | path.moveTo(0, 0); |
| 102 | path.quadTo(0, 0, 0, 0); |
| 103 | path.lineTo(0, 0); |
| 104 | path.close(); |
| 105 | path.moveTo(0, 0); |
| 106 | path.lineTo(0, 0); |
| 107 | path.quadTo(1, 0, 0, 2); |
| 108 | path.close(); |
| 109 | testSimplify(path, true, out, bitmap); |
| 110 | drawAsciiPaths(path, out, true); |
| 111 | } |
| 112 | </div> |
| 113 | |
| 114 | <div id="testSimplifyQuadratic9"> |
| 115 | SkPath path, out; |
| 116 | path.moveTo(0, 0); |
| 117 | path.quadTo(0, 0, 0, 0); |
| 118 | path.lineTo(1, 1); |
| 119 | path.close(); |
| 120 | path.moveTo(0, 0); |
| 121 | path.lineTo(0, 0); |
| 122 | path.quadTo(1, 0, 2, 2); |
| 123 | path.close(); |
| 124 | testSimplify(path, true, out, bitmap); |
| 125 | drawAsciiPaths(path, out, true); |
| 126 | } |
| 127 | </div> |
| 128 | |
| 129 | <div id="testSimplifyQuadratic10"> |
| 130 | SkPath path, out; |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 131 | path.moveTo(0, 0); |
| 132 | path.quadTo(0, 0, 0, 0); |
| 133 | path.lineTo(0, 0); |
| 134 | path.close(); |
| 135 | path.moveTo(0, 0); |
| 136 | path.lineTo(0, 1); |
| 137 | path.quadTo(1, 1, 1, 2); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 138 | path.close(); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 139 | testSimplify(path, true, out, bitmap); |
| 140 | drawAsciiPaths(path, out, true); |
| 141 | } |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 142 | </div> |
| 143 | |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 144 | <div id="testSimplifyQuadratic11"> |
| 145 | SkPath path, out; |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 146 | path.moveTo(0, 0); |
| 147 | path.quadTo(0, 0, 0, 0); |
| 148 | path.lineTo(0, 2); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 149 | path.close(); |
| 150 | path.moveTo(0, 0); |
| 151 | path.lineTo(2, 1); |
| 152 | path.quadTo(2, 2, 3, 3); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 153 | path.close(); |
| 154 | testSimplify(path, true, out, bitmap); |
| 155 | drawAsciiPaths(path, out, true); |
| 156 | } |
| 157 | </div> |
| 158 | |
| 159 | <div id="testSimplifyQuadratic12"> |
| 160 | SkPath path, out; |
| 161 | path.moveTo(0, 0); |
| 162 | path.lineTo(0, 2); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 163 | path.lineTo(0, 0); |
| 164 | path.close(); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 165 | path.moveTo(3, 0); |
| 166 | path.quadTo(1, 1, 0, 2); |
| 167 | path.lineTo(3, 0); |
| 168 | path.close(); |
| 169 | testSimplify(path, true, out, bitmap); |
| 170 | drawAsciiPaths(path, out, true); |
| 171 | } |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 172 | </div> |
| 173 | |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 174 | <div id="testSimplifyQuadratic13"> |
| 175 | SkPath path, out; |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 176 | path.moveTo(0, 0); |
| 177 | path.quadTo(0, 0, 1, 0); |
| 178 | path.lineTo(1, 1); |
| 179 | path.lineTo(0, 0); |
| 180 | path.close(); |
| 181 | path.moveTo(0, 0); |
| 182 | path.quadTo(3, 0, 1, 1); |
| 183 | path.lineTo(0, 0); |
| 184 | path.close(); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 185 | testSimplify(path, true, out, bitmap); |
| 186 | drawAsciiPaths(path, out, true); |
| 187 | } |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 188 | </div> |
| 189 | |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 190 | <div id="testSimplifyQuadratic14"> |
| 191 | SkPath path, out; |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 192 | path.moveTo(0, 0); |
| 193 | path.quadTo(0, 0, 0, 0); |
| 194 | path.lineTo(1, 1); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 195 | path.close(); |
| 196 | path.moveTo(0, 0); |
| 197 | path.lineTo(0, 0); |
| 198 | path.quadTo(0, 1, 2, 1); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 199 | path.close(); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 200 | testSimplify(path, true, out, bitmap); |
| 201 | drawAsciiPaths(path, out, true); |
| 202 | } |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 203 | </div> |
| 204 | |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 205 | <div id="testSimplifyQuadratic15"> |
| 206 | SkPath path, out; |
| 207 | path.moveTo(0, 0); |
| 208 | path.quadTo(0, 0, 1, 3); |
| 209 | path.lineTo(3, 3); |
| 210 | path.close(); |
| 211 | path.moveTo(0, 1); |
| 212 | path.lineTo(1, 1); |
| 213 | path.quadTo(0, 3, 3, 3); |
| 214 | path.close(); |
| 215 | testSimplify(path, true, out, bitmap); |
| 216 | drawAsciiPaths(path, out, true); |
| 217 | } |
| 218 | </div> |
| 219 | |
| 220 | <div id="testSimplifyQuadratic16"> |
| 221 | SkPath path, out; |
| 222 | path.moveTo(0, 0); |
| 223 | path.quadTo(0, 0, 0, 0); |
| 224 | path.lineTo(0, 1); |
| 225 | path.close(); |
| 226 | path.moveTo(0, 0); |
| 227 | path.lineTo(0, 0); |
| 228 | path.quadTo(1, 0, 0, 1); |
| 229 | path.close(); |
| 230 | testSimplify(path, true, out, bitmap); |
| 231 | drawAsciiPaths(path, out, true); |
| 232 | } |
| 233 | </div> |
| 234 | |
| 235 | <div id="testSimplifyQuadratic17"> |
| 236 | SkPath path, out; |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 237 | path.moveTo(8, 8); |
| 238 | path.quadTo(10, 10, 8, -10); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 239 | path.close(); |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 240 | path.moveTo(8, 8); |
| 241 | path.quadTo(12, 12, 14, 4); |
| 242 | path.close(); |
| 243 | path.moveTo(8, 8); |
| 244 | path.quadTo(9, 9, 10, 8); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 245 | path.close(); |
| 246 | testSimplify(path, true, out, bitmap); |
| 247 | drawAsciiPaths(path, out, true); |
| 248 | } |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 249 | </div> |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 250 | |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 251 | <div id="testSimplifyQuadratic18"> |
| 252 | SkPath path, out; |
| 253 | path.moveTo(8.0000000000000071, 8.0000000000000071); |
| 254 | path.quadTo(8.7289570079366854, 8.7289570079366889, 9.3914917259458743, 9.0593802763083691); |
| 255 | path.close(); |
| 256 | path.moveTo(8.0000000000000142, 8.0000000000000142); |
| 257 | path.quadTo(8.1250000000000107, 8.1250000000000071, 8.2500000000000071, 8.2187500000000053); |
| 258 | path.close(); |
| 259 | testSimplify(path, true, out, bitmap); |
| 260 | drawAsciiPaths(path, out, true); |
| 261 | </div> |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 262 | |
| 263 | <div id="testSimplifyQuadratic19"> |
| 264 | SkPath path, simple; |
| 265 | path.moveTo(0,4); |
| 266 | path.lineTo(6,4); |
| 267 | path.lineTo(3,1); |
| 268 | path.close(); |
| 269 | path.moveTo(2,3); |
| 270 | path.lineTo(3,2); |
| 271 | path.lineTo(4,3); |
| 272 | path.close(); |
| 273 | testSimplifyx(path); |
| 274 | </div> |
| 275 | |
| 276 | <div id="testSimplifyQuadratic20"> |
| 277 | SkPath path, simple; |
| 278 | path.moveTo(0,4); |
| 279 | path.lineTo(6,4); |
| 280 | path.lineTo(3,1); |
| 281 | path.close(); |
| 282 | path.moveTo(2,3); |
| 283 | path.lineTo(4,3); |
| 284 | path.lineTo(3,2); |
| 285 | path.close(); |
| 286 | testSimplifyx(path); |
| 287 | </div> |
| 288 | |
| 289 | <div id="testSimplifyQuadratic21"> |
| 290 | SkPath path, simple; |
| 291 | path.moveTo(0,4); |
| 292 | path.lineTo(8,4); |
| 293 | path.lineTo(4,0); |
| 294 | path.close(); |
| 295 | path.moveTo(2,2); |
| 296 | path.lineTo(3,3); |
| 297 | path.lineTo(4,2); |
| 298 | path.close(); |
| 299 | testSimplifyx(path); |
| 300 | </div> |
| 301 | |
| 302 | <div id="testLine6"> |
| 303 | SkPath path, simple; |
| 304 | path.moveTo(0,0); |
| 305 | path.lineTo(4,0); |
| 306 | path.lineTo(2,2); |
| 307 | path.close(); |
| 308 | path.moveTo(2,0); |
| 309 | path.lineTo(6,0); |
| 310 | path.lineTo(4,2); |
| 311 | path.close(); |
| 312 | testSimplifyx(path); |
| 313 | </div> |
| 314 | |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 315 | <div id="testLine7"> |
| 316 | SkPath path, simple; |
| 317 | path.moveTo(0,0); |
| 318 | path.lineTo(4,0); |
| 319 | path.lineTo(2,2); |
| 320 | path.close(); |
| 321 | path.moveTo(6,0); |
| 322 | path.lineTo(2,0); |
| 323 | path.lineTo(4,2); |
| 324 | path.close(); |
| 325 | testSimplifyx(path); |
| 326 | </div> |
| 327 | |
| 328 | <div id="testLine9"> |
| 329 | SkPath path, simple; |
| 330 | path.moveTo(0,4); |
| 331 | path.lineTo(4,4); |
| 332 | path.lineTo(2,2); |
| 333 | path.close(); |
| 334 | path.moveTo(6,4); |
| 335 | path.lineTo(2,4); |
| 336 | path.lineTo(4,2); |
| 337 | path.close(); |
| 338 | testSimplifyx(path); |
| 339 | </div> |
| 340 | |
caryclark@google.com | e21cb18 | 2012-07-23 21:26:31 +0000 | [diff] [blame^] | 341 | <div id="testLine12"> |
| 342 | path.moveTo(0,4); |
| 343 | path.lineTo(6,4); |
| 344 | path.lineTo(3,1); |
| 345 | path.close(); |
| 346 | path.moveTo(2,3); |
| 347 | path.lineTo(3,2); |
| 348 | path.lineTo(4,3); |
| 349 | path.close(); |
| 350 | </div> |
| 351 | |
| 352 | <div id="testLine13"> |
| 353 | path.moveTo(6,4); |
| 354 | path.lineTo(0,4); |
| 355 | path.lineTo(3,1); |
| 356 | path.close(); |
| 357 | path.moveTo(3,2); |
| 358 | path.lineTo(2,3); |
| 359 | path.lineTo(4,3); |
| 360 | path.close(); |
| 361 | </div> |
| 362 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 363 | <div id="testLine17"> |
| 364 | SkPath path, simple; |
| 365 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 366 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 367 | testSimplifyx(path); |
| 368 | </div> |
| 369 | |
caryclark@google.com | 4758069 | 2012-07-23 12:14:49 +0000 | [diff] [blame] | 370 | <div id="testLine19"> |
| 371 | SkPath path, simple; |
| 372 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 373 | path.addRect(12, 16, 21, 21, (SkPath::Direction) 0); |
| 374 | testSimplifyx(path); |
| 375 | </div> |
| 376 | |
| 377 | <div id="testLine24"> |
| 378 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 379 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 380 | </div> |
| 381 | |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 382 | <div id="testLine28"> |
| 383 | SkPath path, simple; |
| 384 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 385 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 386 | testSimplifyx(path); |
| 387 | </div> |
| 388 | |
| 389 | <div id="testLine29"> |
| 390 | SkPath path, simple; |
| 391 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 392 | path.addRect(12, 12, 21, 21, (SkPath::Direction) 0); |
| 393 | testSimplifyx(path); |
| 394 | </div> |
| 395 | |
| 396 | <div id="testLine30"> |
| 397 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 398 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 399 | path.addRect(4, 4, 13, 13, (SkPath::Direction) 0); |
| 400 | </div> |
| 401 | |
| 402 | <div id="testLine31"> |
| 403 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 404 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 405 | path.addRect(0, 4, 9, 9, (SkPath::Direction) 0); |
| 406 | </div> |
| 407 | |
| 408 | <div id="testLine32"> |
| 409 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 410 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 411 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 412 | </div> |
| 413 | |
caryclark@google.com | 9764cc6 | 2012-07-12 19:29:45 +0000 | [diff] [blame] | 414 | <div id="testLine33"> |
| 415 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 416 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 417 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 418 | </div> |
| 419 | |
caryclark@google.com | 210acaf | 2012-07-12 21:05:13 +0000 | [diff] [blame] | 420 | <div id="testLine34"> |
| 421 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 422 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 423 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 424 | </div> |
| 425 | |
| 426 | <div id="testLine35"> |
| 427 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 428 | path.addRect(6, 0, 18, 18, (SkPath::Direction) 0); |
| 429 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 430 | </div> |
| 431 | |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 432 | <div id="testLine36"> |
| 433 | path.addRect(0, 10, 20, 20, (SkPath::Direction) 0); |
| 434 | path.addRect(6, 12, 18, 18, (SkPath::Direction) 0); |
| 435 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 436 | </div> |
| 437 | |
caryclark@google.com | 4758069 | 2012-07-23 12:14:49 +0000 | [diff] [blame] | 438 | <div id="testLine37"> |
| 439 | path.addRect(0, 20, 20, 20, (SkPath::Direction) 0); |
| 440 | path.addRect(18, 24, 30, 30, (SkPath::Direction) 0); |
| 441 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 442 | </div> |
| 443 | |
| 444 | <div id="testLine38"> |
| 445 | path.addRect(10, 0, 30, 30, (SkPath::Direction) 0); |
| 446 | path.addRect(6, 12, 18, 18, (SkPath::Direction) 0); |
| 447 | path.addRect(12, 12, 21, 21, (SkPath::Direction) 0); |
| 448 | </div> |
| 449 | |
| 450 | <div id="testLine39"> |
| 451 | path.addRect(10, 0, 30, 30, (SkPath::Direction) 0); |
| 452 | path.addRect(12, 6, 24, 24, (SkPath::Direction) 0); |
| 453 | path.addRect(12, 4, 21, 21, (SkPath::Direction) 0); |
| 454 | </div> |
| 455 | |
| 456 | <div id="testLine40"> |
| 457 | path.addRect(10, 0, 30, 30, (SkPath::Direction) 0); |
| 458 | path.addRect(12, 18, 24, 24, (SkPath::Direction) 0); |
| 459 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 460 | </div> |
| 461 | |
| 462 | <div id="testLine41"> |
| 463 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 464 | path.addRect(18, 24, 30, 30, (SkPath::Direction) 0); |
| 465 | path.addRect(12, 0, 21, 21, (SkPath::Direction) 0); |
| 466 | </div> |
| 467 | |
| 468 | <div id="testLine42"> |
| 469 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 470 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 471 | path.addRect(8, 16, 17, 17, (SkPath::Direction) 0); |
| 472 | </div> |
| 473 | |
| 474 | <div id="testLine43"> |
| 475 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 476 | path.addRect(6, 24, 18, 18, (SkPath::Direction) 0); |
| 477 | path.addRect(0, 32, 9, 36, (SkPath::Direction) 1); |
| 478 | </div> |
| 479 | |
| 480 | <div id="testLine44"> |
| 481 | path.addRect(10, 40, 30, 30, (SkPath::Direction) 0); |
| 482 | path.addRect(18, 0, 30, 30, (SkPath::Direction) 0); |
| 483 | path.addRect(18, 32, 27, 36, (SkPath::Direction) 1); |
| 484 | </div> |
| 485 | |
| 486 | <div id="testLine45"> |
| 487 | path.addRect(10, 0, 30, 30, (SkPath::Direction) 0); |
| 488 | path.addRect(18, 0, 30, 30, (SkPath::Direction) 0); |
| 489 | path.addRect(24, 32, 33, 36, (SkPath::Direction) 0); |
| 490 | </div> |
| 491 | |
| 492 | <div id="testLine46"> |
| 493 | path.addRect(10, 40, 30, 30, (SkPath::Direction) 0); |
| 494 | path.addRect(24, 0, 36, 36, (SkPath::Direction) 0); |
| 495 | path.addRect(24, 32, 33, 36, (SkPath::Direction) 0); |
| 496 | </div> |
| 497 | |
| 498 | <div id="testLine47"> |
| 499 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 500 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 501 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 1); |
| 502 | </div> |
| 503 | |
| 504 | <div id="testLine48"> |
| 505 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 506 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 507 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 1); |
| 508 | </div> |
| 509 | |
| 510 | <div id="testLine49"> |
| 511 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 512 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 513 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 514 | </div> |
| 515 | |
| 516 | <div id="testLine50"> |
| 517 | path.addRect(10, 30, 30, 30, (SkPath::Direction) 0); |
| 518 | path.addRect(24, 20, 36, 30, (SkPath::Direction) 0); |
| 519 | </div> |
| 520 | |
| 521 | <div id="testLine51"> |
| 522 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 523 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 524 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 1); |
| 525 | </div> |
| 526 | |
caryclark@google.com | e21cb18 | 2012-07-23 21:26:31 +0000 | [diff] [blame^] | 527 | <div id="testLine52"> |
| 528 | path.addRect(0, 30, 20, 20, (SkPath::Direction) 0); |
| 529 | path.addRect(6, 20, 18, 30, (SkPath::Direction) 0); |
| 530 | path.addRect(32, 0, 36, 41, (SkPath::Direction) 0); |
| 531 | </div> |
| 532 | |
| 533 | <div id="testLine53"> |
| 534 | path.addRect(10, 30, 30, 30, (SkPath::Direction) 0); |
| 535 | path.addRect(12, 20, 24, 30, (SkPath::Direction) 0); |
| 536 | path.addRect(12, 32, 21, 36, (SkPath::Direction) 1); |
| 537 | </div> |
| 538 | |
| 539 | <div id="testLine54"> |
| 540 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 541 | path.addRect(6, 0, 18, 18, (SkPath::Direction) 0); |
| 542 | path.addRect(8, 4, 17, 17, (SkPath::Direction) 1); |
| 543 | </div> |
| 544 | |
| 545 | <div id="testLine55"> |
| 546 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 547 | path.addRect(6, 6, 18, 18, (SkPath::Direction) 0); |
| 548 | path.addRect(4, 4, 13, 13, (SkPath::Direction) 1); |
| 549 | </div> |
| 550 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 551 | </div> |
| 552 | |
| 553 | <script type="text/javascript"> |
| 554 | |
| 555 | var testDivs = [ |
caryclark@google.com | e21cb18 | 2012-07-23 21:26:31 +0000 | [diff] [blame^] | 556 | testLine55, |
| 557 | testLine54, |
| 558 | testLine53, |
| 559 | testLine52, |
caryclark@google.com | 4758069 | 2012-07-23 12:14:49 +0000 | [diff] [blame] | 560 | testLine51, |
| 561 | testLine50, |
| 562 | testLine49, |
| 563 | testLine48, |
| 564 | testLine47, |
| 565 | testLine46, |
| 566 | testLine45, |
| 567 | testLine44, |
| 568 | testLine43, |
| 569 | testLine42, |
| 570 | testLine41, |
| 571 | testLine40, |
| 572 | testLine39, |
| 573 | testLine38, |
| 574 | testLine37, |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 575 | testLine36, |
caryclark@google.com | 210acaf | 2012-07-12 21:05:13 +0000 | [diff] [blame] | 576 | testLine35, |
| 577 | testLine34, |
caryclark@google.com | 9764cc6 | 2012-07-12 19:29:45 +0000 | [diff] [blame] | 578 | testLine33, |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 579 | testLine30, |
| 580 | testLine32, |
| 581 | testLine31, |
| 582 | testLine29, |
| 583 | testLine28, |
caryclark@google.com | 4758069 | 2012-07-23 12:14:49 +0000 | [diff] [blame] | 584 | testLine24, |
| 585 | testLine19, |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 586 | testLine17, |
caryclark@google.com | e21cb18 | 2012-07-23 21:26:31 +0000 | [diff] [blame^] | 587 | testLine13, |
| 588 | testLine12, |
caryclark@google.com | 4758069 | 2012-07-23 12:14:49 +0000 | [diff] [blame] | 589 | testLine9, |
| 590 | testLine7, |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 591 | testSimplifyQuadratic21, |
| 592 | testSimplifyQuadratic20, |
| 593 | testSimplifyQuadratic19, |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 594 | testSimplifyQuadratic18, |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 595 | testSimplifyQuadratic17, |
| 596 | testSimplifyQuadratic16, |
| 597 | testSimplifyQuadratic15, |
| 598 | testSimplifyQuadratic14, |
| 599 | testSimplifyQuadratic13, |
| 600 | testSimplifyQuadratic12, |
| 601 | testSimplifyQuadratic11, |
| 602 | testSimplifyQuadratic10, |
| 603 | testSimplifyQuadratic9, |
| 604 | testSimplifyQuadratic8, |
| 605 | testSimplifyQuadratic7, |
| 606 | testSimplifyQuadratic6, |
| 607 | testSimplifyQuadratic5, |
| 608 | testSimplifyQuadratic4, |
| 609 | testSimplifyQuadratic3, |
| 610 | testSimplifyQuadratic2, |
| 611 | testSimplifyQuadratic1, |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 612 | ]; |
| 613 | |
| 614 | var scale, columns, rows, xStart, yStart; |
| 615 | |
| 616 | var ticks = 0.1; |
| 617 | var at_x = 13 + 0.5; |
| 618 | var at_y = 13 + 0.5; |
| 619 | |
| 620 | var tests = []; |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 621 | var testTitles = []; |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 622 | var testIndex = 0; |
| 623 | |
| 624 | var ctx; |
| 625 | |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 626 | function parse(test, title) { |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 627 | var contours = []; |
| 628 | var contourStrs = test.split("path.close();"); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 629 | var pattern = /-?\d+\.*\d*/g; |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 630 | for (var c in contourStrs) { |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 631 | var contour = contourStrs[c]; |
| 632 | var verbStrs = contour.split("path"); |
| 633 | var verbs = []; |
| 634 | for (var v in verbStrs) { |
| 635 | var verbStr = verbStrs[v]; |
| 636 | var points = verbStr.match(pattern); |
| 637 | var pts = []; |
| 638 | for (var wd in points) { |
| 639 | var num = parseFloat(points[wd]); |
| 640 | if (isNaN(num)) continue; |
| 641 | pts.push(num); |
| 642 | } |
| 643 | if (pts.length > 0) |
| 644 | verbs.push(pts); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 645 | } |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 646 | if (verbs.length > 0) { |
| 647 | var lastIndex = verbs.length - 1; |
| 648 | var lastVerb = verbs[lastIndex]; |
| 649 | var lastLen = lastVerb.length; |
| 650 | if (verbs[0][0] != lastVerb[lastLen - 2] && verbs[0][1] != lastVerb[lastLen - 1]) { |
| 651 | var lastPts = []; |
| 652 | lastPts.push(verbs[0][0]); |
| 653 | lastPts.push(verbs[0][1]); |
| 654 | verbs.push(lastPts); |
| 655 | } |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 656 | contours.push(verbs); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 657 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 658 | } |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 659 | if (contours.length > 0) { |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 660 | tests.push(contours); |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 661 | testTitles.push(title); |
| 662 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 663 | } |
| 664 | |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 665 | function parseRect(test, title) { |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 666 | var contours = []; |
| 667 | var rectStrs = test.split("path.addRect"); |
| 668 | var pattern = /-?\d+\.*\d*/g; |
| 669 | for (var r in rectStrs) { |
| 670 | var rect = rectStrs[r]; |
| 671 | var sideStrs = rect.match(pattern); |
| 672 | var sides = []; |
| 673 | for (var wd in sideStrs) { |
| 674 | var num = parseFloat(sideStrs[wd]); |
| 675 | if (isNaN(num)) continue; |
| 676 | sides.push(num); |
| 677 | } |
| 678 | if (sides.length == 0) |
| 679 | continue; |
| 680 | var verbs = []; |
| 681 | var topLeft = []; |
| 682 | topLeft.push(sides[0]); topLeft.push(sides[1]); |
| 683 | var topRight = []; |
| 684 | topRight.push(sides[2]); topRight.push(sides[1]); |
| 685 | var botLeft = []; |
| 686 | botLeft.push(sides[0]); botLeft.push(sides[3]); |
| 687 | var botRight = []; |
| 688 | botRight.push(sides[2]); botRight.push(sides[3]); |
| 689 | verbs.push(topLeft); |
| 690 | if (sides[4] == 0) { |
| 691 | verbs.push(topRight); |
| 692 | verbs.push(botRight); |
| 693 | verbs.push(botLeft); |
| 694 | } else { |
| 695 | verbs.push(botLeft); |
| 696 | verbs.push(botRight); |
| 697 | verbs.push(topRight); |
| 698 | } |
| 699 | verbs.push(topLeft); |
| 700 | contours.push(verbs); |
| 701 | } |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 702 | if (contours.length > 0) { |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 703 | tests.push(contours); |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 704 | testTitles.push(title); |
| 705 | } |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 706 | } |
| 707 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 708 | function init(test) { |
| 709 | var canvas = document.getElementById('canvas'); |
| 710 | if (!canvas.getContext) return; |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 711 | canvas.width = document.width; |
| 712 | canvas.height = document.height; |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 713 | ctx = canvas.getContext('2d'); |
| 714 | var xmin = Infinity; |
| 715 | var xmax = -Infinity; |
| 716 | var ymin = Infinity; |
| 717 | var ymax = -Infinity; |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 718 | for (var contours in test) { |
| 719 | var contour = test[contours]; |
| 720 | for (var verbs in contour) { |
| 721 | var verb = contour[verbs]; |
| 722 | var last = verb.length; |
caryclark@google.com | b45a1b4 | 2012-05-18 20:50:33 +0000 | [diff] [blame] | 723 | for (var idx = 0; idx < last; idx += 2) { |
| 724 | xmin = Math.min(xmin, verb[idx]); |
| 725 | xmax = Math.max(xmax, verb[idx]); |
| 726 | ymin = Math.min(ymin, verb[idx + 1]); |
| 727 | ymax = Math.max(ymax, verb[idx + 1]); |
| 728 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | var subscale = 1; |
| 732 | while ((xmax - xmin) * subscale < 0.1 && (ymax - ymin) * subscale < 0.1) { |
| 733 | subscale *= 10; |
| 734 | } |
| 735 | columns = Math.ceil(xmax) - Math.floor(xmin) + 1; |
| 736 | rows = Math.ceil(ymax) - Math.floor(ymin) + 1; |
| 737 | xStart = Math.floor(xmin); |
| 738 | yStart = Math.floor(ymin); |
| 739 | var hscale = ctx.canvas.width / columns / ticks; |
| 740 | var vscale = ctx.canvas.height / rows / ticks; |
| 741 | scale = Math.floor(Math.min(hscale, vscale)) * subscale; |
| 742 | } |
| 743 | |
| 744 | function drawPoint(px, py, xoffset, yoffset, unit) { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 745 | var label = px.toFixed(3) + ", " + py.toFixed(3); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 746 | var _px = px * unit + xoffset; |
| 747 | var _py = py * unit + yoffset; |
| 748 | ctx.beginPath(); |
| 749 | ctx.arc(_px, _py, 3, 0, Math.PI*2, true); |
| 750 | ctx.closePath(); |
| 751 | ctx.fill(); |
| 752 | ctx.fillText(label, _px + 5, _py); |
| 753 | } |
| 754 | |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 755 | function draw(test, title, _at_x, _at_y, scale) { |
| 756 | ctx.fillStyle = "rgba(0,0,0, 0.1)"; |
| 757 | ctx.font = "normal 50px Arial"; |
| 758 | ctx.fillText(title, 50, 50); |
| 759 | ctx.font = "normal 10px Arial"; |
| 760 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 761 | var unit = scale * ticks; |
| 762 | ctx.lineWidth = 1; |
| 763 | var i; |
| 764 | for (i = 0; i <= rows * ticks; ++i) { |
| 765 | ctx.strokeStyle = (i % ticks) != 0 ? "rgb(160,160,160)" : "black"; |
| 766 | ctx.beginPath(); |
| 767 | ctx.moveTo(_at_x + 0, _at_y + i * scale); |
| 768 | ctx.lineTo(_at_x + unit * columns, _at_y + i * scale); |
| 769 | ctx.stroke(); |
| 770 | } |
| 771 | for (i = 0; i <= columns * ticks; ++i) { |
| 772 | ctx.strokeStyle = (i % ticks) != 0 ? "rgb(160,160,160)" : "black"; |
| 773 | ctx.beginPath(); |
| 774 | ctx.moveTo(_at_x + i * scale, _at_y + 0); |
| 775 | ctx.lineTo(_at_x + i * scale, _at_y + unit * rows); |
| 776 | ctx.stroke(); |
| 777 | } |
| 778 | |
| 779 | var xoffset = xStart * -unit + _at_x; |
| 780 | var yoffset = yStart * -unit + _at_y; |
| 781 | |
| 782 | ctx.fillStyle = "rgb(40,80,60)" |
| 783 | for (i = 0; i <= columns; i += (1 / ticks)) |
| 784 | { |
| 785 | num = (xoffset - _at_x) / -unit + i; |
| 786 | ctx.fillText(num.toFixed(0), i * unit + _at_y - 5, 10); |
| 787 | } |
| 788 | for (i = 0; i <= rows; i += (1 / ticks)) |
| 789 | { |
| 790 | num = (yoffset - _at_x) / -unit + i; |
| 791 | ctx.fillText(num.toFixed(0), 0, i * unit + _at_y + 0); |
| 792 | } |
| 793 | ctx.strokeStyle = "red"; |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 794 | var contours, verbs, pts; |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 795 | ctx.beginPath(); |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 796 | for (contours in test) { |
| 797 | var contour = test[contours]; |
| 798 | if (contours == 2) ctx.strokeStyle = "blue"; |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 799 | var first = true; |
| 800 | for (verbs in contour) { |
| 801 | var verb = contour[verbs]; |
| 802 | switch (verb.length) { |
| 803 | case 2: |
| 804 | if (first) { |
| 805 | ctx.moveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit); |
| 806 | first = false; |
| 807 | } else |
| 808 | ctx.lineTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit); |
| 809 | break; |
| 810 | case 4: |
| 811 | ctx.quadraticCurveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit, |
| 812 | xoffset + verb[2] * unit, yoffset + verb[3] * unit); |
| 813 | break; |
| 814 | case 6: |
| 815 | ctx.bezierCurveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit, |
| 816 | xoffset + verb[2] * unit, yoffset + verb[3] * unit, |
| 817 | xoffset + verb[4] * unit, yoffset + verb[5] * unit); |
| 818 | break; |
| 819 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 820 | } |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 821 | ctx.closePath(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 822 | } |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 823 | ctx.stroke(); |
| 824 | ctx.fillStyle="rgba(192,192,255, 0.3)"; |
| 825 | ctx.fill(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 826 | |
| 827 | ctx.fillStyle="blue"; |
caryclark@google.com | fb17342 | 2012-04-10 18:28:55 +0000 | [diff] [blame] | 828 | for (contours in test) { |
| 829 | var contour = test[contours]; |
| 830 | for (verbs in contour) { |
| 831 | var verb = contour[verbs]; |
| 832 | for (i = 0; i < verb.length; i += 2) { |
| 833 | x = verb[i]; |
| 834 | y = verb[i + 1]; |
| 835 | drawPoint(x, y, xoffset, yoffset, unit); |
| 836 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | var mouseX = Infinity, mouseY; |
| 842 | |
| 843 | function calcXY() { |
| 844 | var e = window.event; |
| 845 | var tgt = e.target || e.srcElement; |
| 846 | var left = tgt.offsetLeft; |
| 847 | var top = tgt.offsetTop; |
| 848 | var unit = scale * ticks; |
| 849 | mouseX = (e.clientX - left - Math.ceil(at_x) + 1) / unit + xStart; |
| 850 | mouseY = (e.clientY - top - Math.ceil(at_y)) / unit + yStart; |
| 851 | } |
| 852 | |
| 853 | function handleMouseOver() { |
| 854 | calcXY(); |
| 855 | var num = mouseX.toFixed(3) + ", " + mouseY.toFixed(3); |
| 856 | ctx.beginPath(); |
| 857 | ctx.rect(300,100,200,10); |
| 858 | ctx.fillStyle="white"; |
| 859 | ctx.fill(); |
| 860 | ctx.fillStyle="black"; |
| 861 | ctx.fillText(num, 300, 108); |
| 862 | } |
| 863 | |
| 864 | function handleMouseClick() { |
| 865 | calcXY(); |
| 866 | // drawInset(); |
| 867 | } |
| 868 | |
| 869 | function drawTop() { |
| 870 | init(tests[testIndex]); |
| 871 | redraw(); |
| 872 | } |
| 873 | |
| 874 | function redraw() { |
| 875 | ctx.beginPath(); |
| 876 | ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 877 | ctx.fillStyle="white"; |
| 878 | ctx.fill(); |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 879 | draw(tests[testIndex], testTitles[testIndex], at_x, at_y, scale); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 880 | // if (insetScale != scale && mouseX != Infinity) |
| 881 | // drawInset(); |
| 882 | } |
| 883 | |
| 884 | function doKeyPress(evt) { |
| 885 | var char = String.fromCharCode(evt.charCode); |
| 886 | switch (char) { |
| 887 | case 'N': |
| 888 | case 'n': |
| 889 | if (++testIndex >= tests.length) |
| 890 | testIndex = 0; |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 891 | mouseX = Infinity; |
| 892 | drawTop(); |
| 893 | break; |
| 894 | case 'P': |
| 895 | case 'p': |
| 896 | if (--testIndex < 0) |
| 897 | testIndex = tests.length - 1; |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 898 | mouseX = Infinity; |
| 899 | drawTop(); |
| 900 | break; |
| 901 | case 'T': |
| 902 | case 't': |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 903 | break; |
| 904 | case '-': |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 905 | redraw(); |
| 906 | break; |
| 907 | case '=': |
| 908 | case '+': |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 909 | redraw(); |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | function start() { |
| 915 | for (i = 0; i < testDivs.length; ++i) { |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 916 | var title = testDivs[i].id.toString(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 917 | var str = testDivs[i].firstChild.data; |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 918 | if (str.split("addRect").length > 1) { |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 919 | parseRect(str, title); |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 920 | } else { |
caryclark@google.com | 0e08a19 | 2012-07-13 21:07:52 +0000 | [diff] [blame] | 921 | parse(str, title); |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 922 | } |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 923 | } |
| 924 | drawTop(); |
| 925 | window.addEventListener('keypress', doKeyPress, true); |
| 926 | } |
| 927 | |
| 928 | </script> |
| 929 | </head> |
| 930 | |
| 931 | <body onLoad="start();"> |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 932 | <canvas id="canvas" width="750" height="500" |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 933 | onmousemove="handleMouseOver()" |
| 934 | onclick="handleMouseClick()" |
| 935 | ></canvas > |
| 936 | </body> |
| 937 | </html> |