aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pathops_visualizer.htm
blob: 194c89980d948844bd709d0890a6c7f92da98551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
<html>
<head>
<div height="0" hidden="true">

<div id="battleOp183">
seg=1 {{{6.31801322e-006f, -60}, {0, -83}}}
seg=2 {{{0, -83}, {32.0712242f, -83}, {61.2726326f, -64.5230865f}, {75.0056381f, -35.5408783f}}}
seg=3 {{{75.0056381f, -35.5408783f}, {88.7386475f, -6.55867052f}, {84.545517f, 27.7420006f}, {64.2353287f, 52.562561f}}}
seg=4 {{{64.2353287f, 52.562561f}, {60.2773972f, 57.3994484f}, {55.7858162f, 61.773819f}, {50.8459854f, 65.6024933f}}}
seg=5 {{{50.8459854f, 65.6024933f}, {36.756134f, 47.423481f}}}
seg=6 {{{36.756134f, 47.423481f}, {40.3270988f, 44.6557693f}, {43.5740242f, 41.493576f}, {46.4351768f, 37.9970322f}}}
seg=7 {{{46.4351768f, 37.9970322f}, {61.1172447f, 20.0544662f}, {64.1484222f, -4.74120331f}, {54.2209473f, -25.6921959f}}}
seg=8 {{{54.2209473f, -25.6921959f}, {44.2934723f, -46.6431847f}, {23.1840267f, -60}, {6.31801322e-006f, -60}}}
op union
seg=9 {{{50.8459854f, 65.6024857f}, {23.334074f, 86.9259186f}, {-14.5602179f, 88.8177719f}, {-44.0591507f, 70.3405457f}}}
seg=10 {{{-44.0591507f, 70.3405457f}, {-73.5580902f, 51.8633156f}, {-88.3942261f, 16.9427452f}, {-81.2158127f, -17.116993f}}}
seg=11 {{{-81.2158127f, -17.116993f}, {-74.0374069f, -51.1767159f}, {-46.3696136f, -77.1391754f}, {-11.9226456f, -82.1392059f}}}
seg=12 {{{-11.9226456f, -82.1392059f}, {-8.61876869f, -59.3777466f}}}
seg=13 {{{-8.61876869f, -59.3777466f}, {-33.5202026f, -55.7632599f}, {-53.5210152f, -36.9952087f}, {-58.7102203f, -12.3737135f}}}
seg=14 {{{-58.7102203f, -12.3737135f}, {-63.8994179f, 12.2477798f}, {-53.1744957f, 37.4915581f}, {-31.849966f, 50.8485832f}}}
seg=15 {{{-31.849966f, 50.8485832f}, {-10.5254354f, 64.2056046f}, {16.8680305f, 62.8380051f}, {36.7561607f, 47.4234695f}}}
seg=16 {{{36.7561607f, 47.4234695f}, {50.8459854f, 65.6024857f}}}
debugShowCubicLineIntersection wtTs[0]=0 {{{0,-83}, {32.0712242,-83}, {61.2726326,-64.5230865}, {75.0056381,-35.5408783}}} {{0,-83}} wnTs[0]=1 {{{6.31801322e-006,-60}, {0,-83}}}
debugShowCubicLineIntersection wtTs[0]=1 {{{54.2209473,-25.6921959}, {44.2934723,-46.6431847}, {23.1840267,-60}, {6.31801322e-006,-60}}} {{6.31801322e-006,-60}} wnTs[0]=0 {{{6.31801322e-006,-60}, {0,-83}}}
debugShowCubicIntersection wtTs[0]=1 {{{0,-83}, {32.0712242,-83}, {61.2726326,-64.5230865}, {75.0056381,-35.5408783}}} {{75.0056381,-35.5408783}} wnTs[0]=0 {{{75.0056381,-35.5408783}, {88.7386475,-6.55867052}, {84.545517,27.7420006}, {64.2353287,52.562561}}}
debugShowCubicIntersection no intersect {{{0,-83}, {32.0712242,-83}, {61.2726326,-64.5230865}, {75.0056381,-35.5408783}}} {{{54.2209473,-25.6921959}, {44.2934723,-46.6431847}, {23.1840267,-60}, {6.31801322e-006,-60}}}
debugShowCubicIntersection wtTs[0]=1 {{{75.0056381,-35.5408783}, {88.7386475,-6.55867052}, {84.545517,27.7420006}, {64.2353287,52.562561}}} {{64.2353287,52.562561}} wnTs[0]=0 {{{64.2353287,52.562561}, {60.2773972,57.3994484}, {55.7858162,61.773819}, {50.8459854,65.6024933}}}
debugShowCubicLineIntersection wtTs[0]=1 {{{64.2353287,52.562561}, {60.2773972,57.3994484}, {55.7858162,61.773819}, {50.8459854,65.6024933}}} {{50.8459854,65.6024933}} wnTs[0]=0 {{{50.8459854,65.6024933}, {36.756134,47.423481}}}
debugShowCubicLineIntersection wtTs[0]=0 {{{36.756134,47.423481}, {40.3270988,44.6557693}, {43.5740242,41.493576}, {46.4351768,37.9970322}}} {{36.756134,47.423481}} wnTs[0]=1 {{{50.8459854,65.6024933}, {36.756134,47.423481}}}
debugShowCubicIntersection wtTs[0]=1 {{{36.756134,47.423481}, {40.3270988,44.6557693}, {43.5740242,41.493576}, {46.4351768,37.9970322}}} {{46.4351768,37.9970322}} wnTs[0]=0 {{{46.4351768,37.9970322}, {61.1172447,20.0544662}, {64.1484222,-4.74120331}, {54.2209473,-25.6921959}}}
debugShowCubicIntersection wtTs[0]=1 {{{46.4351768,37.9970322}, {61.1172447,20.0544662}, {64.1484222,-4.74120331}, {54.2209473,-25.6921959}}} {{54.2209473,-25.6921959}} wnTs[0]=0 {{{54.2209473,-25.6921959}, {44.2934723,-46.6431847}, {23.1840267,-60}, {6.31801322e-006,-60}}}
debugShowCubicIntersection no intersect {{{64.2353287,52.562561}, {60.2773972,57.3994484}, {55.7858162,61.773819}, {50.8459854,65.6024933}}} {{{50.8459854,65.6024857}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}}
debugShowCubicLineIntersection no intersect {{{64.2353287,52.562561}, {60.2773972,57.3994484}, {55.7858162,61.773819}, {50.8459854,65.6024933}}} {{{36.7561607,47.4234695}, {50.8459854,65.6024857}}}
debugShowCubicLineIntersection wtTs[0]=0 {{{50.8459854,65.6024857}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} {{50.8459854,65.6024857}} wnTs[0]=2.62183e-007 {{{50.8459854,65.6024933}, {36.756134,47.423481}}}
SkOpSegment::addT alias t=2.62182896e-007 segID=5 spanID=9
debugShowCubicLineIntersection wtTs[0]=0.999999628 {{{-31.849966,50.8485832}, {-10.5254354,64.2056046}, {16.8680305,62.8380051}, {36.7561607,47.4234695}}} {{36.7561378,47.4234886}} wnTs[0]=1 {{{50.8459854,65.6024933}, {36.756134,47.423481}}}
SkOpSegment::addT alias t=0.999999682 segID=5 spanID=10
SkOpSegment::addT insert t=0.999999628 segID=15 spanID=33
debugShowLineIntersection wtTs[0]=2.62182896e-007 {{{50.8459854,65.6024933}, {36.756134,47.423481}}} {{50.8459854,65.6024857}} wnTs[0]=1 {{{36.7561607,47.4234695}, {50.8459854,65.6024857}}}
debugShowCubicIntersection no intersect {{{36.756134,47.423481}, {40.3270988,44.6557693}, {43.5740242,41.493576}, {46.4351768,37.9970322}}} {{{-31.849966,50.8485832}, {-10.5254354,64.2056046}, {16.8680305,62.8380051}, {36.7561607,47.4234695}}}
debugShowCubicLineIntersection no intersect {{{36.756134,47.423481}, {40.3270988,44.6557693}, {43.5740242,41.493576}, {46.4351768,37.9970322}}} {{{36.7561607,47.4234695}, {50.8459854,65.6024857}}}
debugShowCubicIntersection wtTs[0]=1 {{{50.8459854,65.6024857}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} {{-44.0591507,70.3405457}} wnTs[0]=0 {{{-44.0591507,70.3405457}, {-73.5580902,51.8633156}, {-88.3942261,16.9427452}, {-81.2158127,-17.116993}}}
debugShowCubicLineIntersection wtTs[0]=0 {{{50.8459854,65.6024857}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} {{50.8459854,65.6024857}} wnTs[0]=1 {{{36.7561607,47.4234695}, {50.8459854,65.6024857}}}
debugShowCubicIntersection wtTs[0]=1 {{{-44.0591507,70.3405457}, {-73.5580902,51.8633156}, {-88.3942261,16.9427452}, {-81.2158127,-17.116993}}} {{-81.2158127,-17.116993}} wnTs[0]=0 {{{-81.2158127,-17.116993}, {-74.0374069,-51.1767159}, {-46.3696136,-77.1391754}, {-11.9226456,-82.1392059}}}
debugShowCubicIntersection no intersect {{{-44.0591507,70.3405457}, {-73.5580902,51.8633156}, {-88.3942261,16.9427452}, {-81.2158127,-17.116993}}} {{{-8.61876869,-59.3777466}, {-33.5202026,-55.7632599}, {-53.5210152,-36.9952087}, {-58.7102203,-12.3737135}}}
debugShowCubicIntersection no intersect {{{-44.0591507,70.3405457}, {-73.5580902,51.8633156}, {-88.3942261,16.9427452}, {-81.2158127,-17.116993}}} {{{-58.7102203,-12.3737135}, {-63.8994179,12.2477798}, {-53.1744957,37.4915581}, {-31.849966,50.8485832}}}
debugShowCubicLineIntersection wtTs[0]=1 {{{-81.2158127,-17.116993}, {-74.0374069,-51.1767159}, {-46.3696136,-77.1391754}, {-11.9226456,-82.1392059}}} {{-11.9226456,-82.1392059}} wnTs[0]=0 {{{-11.9226456,-82.1392059}, {-8.61876869,-59.3777466}}}
debugShowCubicIntersection no intersect {{{-81.2158127,-17.116993}, {-74.0374069,-51.1767159}, {-46.3696136,-77.1391754}, {-11.9226456,-82.1392059}}} {{{-8.61876869,-59.3777466}, {-33.5202026,-55.7632599}, {-53.5210152,-36.9952087}, {-58.7102203,-12.3737135}}}
debugShowCubicLineIntersection wtTs[0]=0 {{{-8.61876869,-59.3777466}, {-33.5202026,-55.7632599}, {-53.5210152,-36.9952087}, {-58.7102203,-12.3737135}}} {{-8.61876869,-59.3777466}} wnTs[0]=1 {{{-11.9226456,-82.1392059}, {-8.61876869,-59.3777466}}}
debugShowCubicIntersection wtTs[0]=1 {{{-8.61876869,-59.3777466}, {-33.5202026,-55.7632599}, {-53.5210152,-36.9952087}, {-58.7102203,-12.3737135}}} {{-58.7102203,-12.3737135}} wnTs[0]=0 {{{-58.7102203,-12.3737135}, {-63.8994179,12.2477798}, {-53.1744957,37.4915581}, {-31.849966,50.8485832}}}
debugShowCubicIntersection wtTs[0]=1 {{{-58.7102203,-12.3737135}, {-63.8994179,12.2477798}, {-53.1744957,37.4915581}, {-31.849966,50.8485832}}} {{-31.849966,50.8485832}} wnTs[0]=0 {{{-31.849966,50.8485832}, {-10.5254354,64.2056046}, {16.8680305,62.8380051}, {36.7561607,47.4234695}}}
debugShowCubicLineIntersection wtTs[0]=1 {{{-31.849966,50.8485832}, {-10.5254354,64.2056046}, {16.8680305,62.8380051}, {36.7561607,47.4234695}}} {{36.7561607,47.4234695}} wnTs[0]=0 {{{36.7561607,47.4234695}, {50.8459854,65.6024857}}}
SkOpSegment::sortAngles [4] tStart=1 [8]
SkOpAngle::after [4/1] 1/1 tStart=1 tEnd=0 < [16/8] 9/9 tStart=1 tEnd=0 < [5/2] 9/9 tStart=0 tEnd=1  T 7
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {55.7858162,61.773819}, {60.2773972,57.3994484}, {64.2353287,52.562561}}} id=4
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.7561607,47.4234695}}} id=16
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.756134,47.423481}}} id=5
SkOpAngle::after [4/1] 1/1 tStart=1 tEnd=0 < [9/5] 17/17 tStart=0 tEnd=1 < [16/8] 9/9 tStart=1 tEnd=0  F 4
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {55.7858162,61.773819}, {60.2773972,57.3994484}, {64.2353287,52.562561}}} id=4
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} id=9
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.7561607,47.4234695}}} id=16
SkOpAngle::after [16/8] 9/9 tStart=1 tEnd=0 < [9/5] 17/17 tStart=0 tEnd=1 < [5/2] 9/9 tStart=0 tEnd=1  F 5
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.7561607,47.4234695}}} id=16
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} id=9
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.756134,47.423481}}} id=5
SkOpAngle::after [5/2] 9/9 tStart=0 tEnd=1 < [9/5] 17/17 tStart=0 tEnd=1 < [4/1] 1/1 tStart=1 tEnd=0  T 4
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {36.756134,47.423481}}} id=5
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {23.334074,86.9259186}, {-14.5602179,88.8177719}, {-44.0591507,70.3405457}}} id=9
SkOpAngle::afterPart {{{50.8459854,65.6024933}, {55.7858162,61.773819}, {60.2773972,57.3994484}, {64.2353287,52.562561}}} id=4
SkOpSegment::sortAngles [5] tStart=0 [9]
SkOpSegment::sortAngles [5] tStart=1 [10]
SkOpAngle::after [5/3] 25/25 tStart=1 tEnd=0 < [15/7] 1/1 tStart=0.999999628 tEnd=1 < [15/6] 17/17 tStart=0.999999628 tEnd=0  T 4
SkOpAngle::afterPart {{{36.756134,47.423481}, {50.8459854,65.6024933}}} id=5
SkOpAngle::afterPart {{{36.756134,47.423481}, {36.7561414,47.4234752}, {36.7561533,47.4234753}, {36.7561607,47.4234695}}} id=15
SkOpAngle::afterPart {{{36.756134,47.423481}, {16.8680057,62.8380003}, {-10.5254434,64.2055996}, {-31.849966,50.8485832}}} id=15
SkOpAngle::after [5/3] 25/25 tStart=1 tEnd=0 < [6/4] 1/1 tStart=0 tEnd=1 < [15/7] 1/1 tStart=0.999999628 tEnd=1  T 7
SkOpAngle::afterPart {{{36.756134,47.423481}, {50.8459854,65.6024933}}} id=5
SkOpAngle::afterPart {{{36.756134,47.423481}, {40.3270988,44.6557693}, {43.5740242,41.493576}, {46.4351768,37.9970322}}} id=6
SkOpAngle::afterPart {{{36.756134,47.423481}, {36.7561414,47.4234752}, {36.7561533,47.4234753}, {36.7561607,47.4234695}}} id=15
SkOpSegment::sortAngles [6] tStart=0 [11]
SkOpSegment::sortAngles [9] tStart=0 [17]
SkOpSegment::sortAngles [15] tStart=0.999999628 [33]
SkOpSegment::sortAngles [16] tStart=1 [32]
SkOpSegment::debugShowActiveSpans id=1 (6.31801322e-006,-60 0,-83) t=0 (6.31801322e-006,-60) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=2 (0,-83 32.0712242,-83 61.2726326,-64.5230865 75.0056381,-35.5408783) t=0 (0,-83) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=3 (75.0056381,-35.5408783 88.7386475,-6.55867052 84.545517,27.7420006 64.2353287,52.562561) t=0 (75.0056381,-35.5408783) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=4 (64.2353287,52.562561 60.2773972,57.3994484 55.7858162,61.773819 50.8459854,65.6024933) t=0 (64.2353287,52.562561) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=5 (50.8459854,65.6024933 36.756134,47.423481) t=0 (50.8459854,65.6024933) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=6 (36.756134,47.423481 40.3270988,44.6557693 43.5740242,41.493576 46.4351768,37.9970322) t=0 (36.756134,47.423481) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=7 (46.4351768,37.9970322 61.1172447,20.0544662 64.1484222,-4.74120331 54.2209473,-25.6921959) t=0 (46.4351768,37.9970322) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=8 (54.2209473,-25.6921959 44.2934723,-46.6431847 23.1840267,-60 6.31801322e-006,-60) t=0 (54.2209473,-25.6921959) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=9 (50.8459854,65.6024933 23.334074,86.9259186 -14.5602179,88.8177719 -44.0591507,70.3405457) t=0 (50.8459854,65.6024933) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=10 (-44.0591507,70.3405457 -73.5580902,51.8633156 -88.3942261,16.9427452 -81.2158127,-17.116993) t=0 (-44.0591507,70.3405457) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=11 (-81.2158127,-17.116993 -74.0374069,-51.1767159 -46.3696136,-77.1391754 -11.9226456,-82.1392059) t=0 (-81.2158127,-17.116993) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=12 (-11.9226456,-82.1392059 -8.61876869,-59.3777466) t=0 (-11.9226456,-82.1392059) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=13 (-8.61876869,-59.3777466 -33.5202026,-55.7632599 -53.5210152,-36.9952087 -58.7102203,-12.3737135) t=0 (-8.61876869,-59.3777466) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=14 (-58.7102203,-12.3737135 -63.8994179,12.2477798 -53.1744957,37.4915581 -31.849966,50.8485832) t=0 (-58.7102203,-12.3737135) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0 (-31.849966,50.8485832) tEnd=0.999999628 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0.999999628 (36.756134,47.423481) tEnd=1 windSum=? windValue=1
SkOpSegment::debugShowActiveSpans id=16 (36.7561607,47.4234695 50.8459854,65.6024933) t=0 (36.7561607,47.4234695) tEnd=1 windSum=? windValue=1
SkOpSpan::sortableTop dir=kLeft seg=1 t=0.5 pt=(3.15900661e-006,-71.5)
SkOpSpan::sortableTop [0] valid=1 operand=1 span=21 ccw=1 seg=11 {{{-81.2158127f, -17.116993f}, {-74.0374069f, -51.1767159f}, {-46.3696136f, -77.1391754f}, {-11.9226456f, -82.1392059f}}} t=0.683500004 pt=(-42.1581116,-71.5) slope=(86.347103,-50.9415461)
SkOpSpan::sortableTop [1] valid=1 operand=1 span=23 ccw=0 seg=12 {{{-11.9226456f, -82.1392059f}, {-8.61876869f, -59.3777466f}}} t=0.46742196 pt=(-10.3783407,-71.5) slope=(3.30387688,22.7614594)
SkOpSpan::sortableTop [2] valid=1 operand=0 span=1 ccw=1 seg=1 {{{6.31801322e-006f, -60}, {0, -83}}} t=0.5 pt=(3.15900661e-006,-71.5) slope=(-6.31801322e-006,-23)
SkOpSegment::markWinding id=11 (-81.2158127,-17.116993 -74.0374069,-51.1767159 -46.3696136,-77.1391754 -11.9226456,-82.1392059) t=0 [21] (-81.2158127,-17.116993) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markWinding id=12 (-11.9226456,-82.1392059 -8.61876869,-59.3777466) t=0 [23] (-11.9226456,-82.1392059) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=13 (-8.61876869,-59.3777466 -33.5202026,-55.7632599 -53.5210152,-36.9952087 -58.7102203,-12.3737135) t=0 [25] (-8.61876869,-59.3777466) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=14 (-58.7102203,-12.3737135 -63.8994179,12.2477798 -53.1744957,37.4915581 -31.849966,50.8485832) t=0 [27] (-58.7102203,-12.3737135) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0 [29] (-31.849966,50.8485832) tEnd=0.999999628 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=11 (-81.2158127,-17.116993 -74.0374069,-51.1767159 -46.3696136,-77.1391754 -11.9226456,-82.1392059) t=0 [21] (-81.2158127,-17.116993) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markWinding id=10 (-44.0591507,70.3405457 -73.5580902,51.8633156 -88.3942261,16.9427452 -81.2158127,-17.116993) t=0 [19] (-44.0591507,70.3405457) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=9 (50.8459854,65.6024933 23.334074,86.9259186 -14.5602179,88.8177719 -44.0591507,70.3405457) t=0 [17] (50.8459854,65.6024933) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=1 (6.31801322e-006,-60 0,-83) t=0 [1] (6.31801322e-006,-60) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markWinding id=2 (0,-83 32.0712242,-83 61.2726326,-64.5230865 75.0056381,-35.5408783) t=0 [3] (0,-83) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=3 (75.0056381,-35.5408783 88.7386475,-6.55867052 84.545517,27.7420006 64.2353287,52.562561) t=0 [5] (75.0056381,-35.5408783) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=4 (64.2353287,52.562561 60.2773972,57.3994484 55.7858162,61.773819 50.8459854,65.6024933) t=0 [7] (64.2353287,52.562561) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=1 (6.31801322e-006,-60 0,-83) t=0 [1] (6.31801322e-006,-60) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markWinding id=8 (54.2209473,-25.6921959 44.2934723,-46.6431847 23.1840267,-60 6.31801322e-006,-60) t=0 [15] (54.2209473,-25.6921959) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=7 (46.4351768,37.9970322 61.1172447,20.0544662 64.1484222,-4.74120331 54.2209473,-25.6921959) t=0 [13] (46.4351768,37.9970322) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=6 (36.756134,47.423481 40.3270988,44.6557693 43.5740242,41.493576 46.4351768,37.9970322) t=0 [11] (36.756134,47.423481) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::activeOp id=1 t=1 tEnd=0 op=union miFrom=0 miTo=1 suFrom=0 suTo=0 result=1
SkOpSegment::findNextOp simple
SkOpSegment::markDone id=1 (6.31801322e-006,-60 0,-83) t=0 [1] (6.31801322e-006,-60) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
bridgeOp current id=1 from=(0,-83) to=(6.31801322e-006,-60)
SkOpSegment::findNextOp simple
SkOpSegment::markDone id=8 (54.2209473,-25.6921959 44.2934723,-46.6431847 23.1840267,-60 6.31801322e-006,-60) t=0 [15] (54.2209473,-25.6921959) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
bridgeOp current id=8 from=(6.31801322e-006,-60) to=(54.2209473,-25.6921959)
path.moveTo(0,-83);
path.lineTo(6.31801322e-006,-60);
path.cubicTo(23.1840267,-60, 44.2934723,-46.6431847, 54.2209473,-25.6921959);
SkOpSegment::findNextOp simple
SkOpSegment::markDone id=7 (46.4351768,37.9970322 61.1172447,20.0544662 64.1484222,-4.74120331 54.2209473,-25.6921959) t=0 [13] (46.4351768,37.9970322) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
bridgeOp current id=7 from=(54.2209473,-25.6921959) to=(46.4351768,37.9970322)
path.cubicTo(64.1484222,-4.74120331, 61.1172447,20.0544662, 46.4351768,37.9970322);
SkOpSegment::markWinding id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0.999999628 [33] (36.756134,47.423481) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markWinding id=16 (36.7561607,47.4234695 50.8459854,65.6024933) t=0 [31] (36.7561607,47.4234695) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markAngle last segment=16 span=32 
SkOpSegment::markWinding id=5 (50.8459854,65.6024933 36.756134,47.423481) t=0 [9] (50.8459854,65.6024933) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
SkOpSegment::markAngle last segment=5 span=9 windSum=-1 
SkOpSegment::findNextOp
SkOpAngle::dumpOne [6/4] next=15/7 sect=1/1  s=0 [11] e=1 [12] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=0
SkOpAngle::dumpOne [15/7] next=15/6 sect=1/1  s=0.999999628 [33] e=1 [30] sgn=-1 windVal=1 windSum=1 oppVal=0 oppSum=0 operand
SkOpAngle::dumpOne [15/6] next=5/3 sect=17/17  s=0.999999628 [33] e=0 [29] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=0 operand
SkOpAngle::dumpOne [5/3] next=6/4 sect=25/25  s=1 [10] e=0 [9] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=-1
SkOpSegment::activeOp id=15 t=0.999999628 tEnd=1 op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1
SkOpSegment::findNextOp chase.append segment=16 span=32
SkOpSegment::activeOp id=15 t=0.999999628 tEnd=0 op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
SkOpSegment::activeOp id=5 t=1 tEnd=0 op=union miFrom=0 miTo=1 suFrom=0 suTo=0 result=1
SkOpSegment::findNextOp chase.append segment=5 span=9 windSum=-1
SkOpSegment::markDone id=6 (36.756134,47.423481 40.3270988,44.6557693 43.5740242,41.493576 46.4351768,37.9970322) t=0 [11] (36.756134,47.423481) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::findNextOp from:[6] to:[15] start=13585868 end=13585412
bridgeOp current id=6 from=(46.4351768,37.9970322) to=(36.756134,47.423481)
path.cubicTo(43.5740242,41.493576, 40.3270988,44.6557693, 36.756134,47.423481);
SkOpSegment::findNextOp simple
SkOpSegment::markDone id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0.999999628 [33] (36.756134,47.423481) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
bridgeOp current id=15 from=(36.756134,47.423481) to=(36.7561607,47.4234695)
path.cubicTo(36.7561417,47.4234734, 36.7561531,47.4234772, 36.7561607,47.4234695);
SkOpSegment::findNextOp
SkOpAngle::dumpOne [16/8] next=5/2 sect=9/9  s=1 [32] e=0 [31] sgn=1 windVal=1 windSum=1 oppVal=0 oppSum=0 operand
SkOpAngle::dumpOne [5/2] next=9/5 sect=9/9  s=0 [9] e=1 [10] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=-1
SkOpAngle::dumpOne [9/5] next=4/1 sect=17/17  s=0 [17] e=1 [18] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=0 operand
SkOpAngle::dumpOne [4/1] next=16/8 sect=1/1  s=1 [8] e=0 [7] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=0
SkOpSegment::activeOp id=5 t=0 tEnd=1 op=union miFrom=0 miTo=1 suFrom=0 suTo=0 result=1
SkOpSegment::activeOp id=9 t=0 tEnd=1 op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
SkOpSegment::markDone id=9 (50.8459854,65.6024933 23.334074,86.9259186 -14.5602179,88.8177719 -44.0591507,70.3405457) t=0 [17] (50.8459854,65.6024933) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=10 (-44.0591507,70.3405457 -73.5580902,51.8633156 -88.3942261,16.9427452 -81.2158127,-17.116993) t=0 [19] (-44.0591507,70.3405457) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=11 (-81.2158127,-17.116993 -74.0374069,-51.1767159 -46.3696136,-77.1391754 -11.9226456,-82.1392059) t=0 [21] (-81.2158127,-17.116993) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=12 (-11.9226456,-82.1392059 -8.61876869,-59.3777466) t=0 [23] (-11.9226456,-82.1392059) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=13 (-8.61876869,-59.3777466 -33.5202026,-55.7632599 -53.5210152,-36.9952087 -58.7102203,-12.3737135) t=0 [25] (-8.61876869,-59.3777466) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=14 (-58.7102203,-12.3737135 -63.8994179,12.2477798 -53.1744957,37.4915581 -31.849966,50.8485832) t=0 [27] (-58.7102203,-12.3737135) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=15 (-31.849966,50.8485832 -10.5254354,64.2056046 16.8680305,62.8380051 36.7561607,47.4234695) t=0 [29] (-31.849966,50.8485832) tEnd=0.999999628 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::activeOp id=4 t=1 tEnd=0 op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
SkOpSegment::markDone id=4 (64.2353287,52.562561 60.2773972,57.3994484 55.7858162,61.773819 50.8459854,65.6024933) t=0 [7] (64.2353287,52.562561) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=3 (75.0056381,-35.5408783 88.7386475,-6.55867052 84.545517,27.7420006 64.2353287,52.562561) t=0 [5] (75.0056381,-35.5408783) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=2 (0,-83 32.0712242,-83 61.2726326,-64.5230865 75.0056381,-35.5408783) t=0 [3] (0,-83) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
SkOpSegment::markDone id=16 (36.7561607,47.4234695 50.8459854,65.6024933) t=0 [31] (36.7561607,47.4234695) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
SkOpSegment::findNextOp from:[16] to:[5] start=13582764 end=13582868
bridgeOp current id=16 from=(36.7561607,47.4234695) to=(50.8459854,65.6024933)
SkOpSegment::findNextOp
SkOpAngle::dumpOne [5/3] next=6/4 sect=25/25  s=1 [10] e=0 [9] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=-1
SkOpAngle::dumpOne [6/4] next=15/7 sect=1/1  s=0 [11] e=1 [12] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=0 done
SkOpAngle::dumpOne [15/7] next=15/6 sect=1/1  s=0.999999628 [33] e=1 [30] sgn=-1 windVal=1 windSum=1 oppVal=0 oppSum=0 done operand
SkOpAngle::dumpOne [15/6] next=5/3 sect=17/17  s=0.999999628 [33] e=0 [29] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=0 done operand
SkOpSegment::activeOp id=6 t=0 tEnd=1 op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
SkOpSegment::activeOp id=15 t=0.999999628 tEnd=1 op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
SkOpSegment::activeOp id=15 t=0.999999628 tEnd=0 op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1
SkOpSegment::markDone id=5 (50.8459854,65.6024933 36.756134,47.423481) t=0 [9] (50.8459854,65.6024933) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
SkOpSegment::findNextOp from:[5] to:[15] start=13585868 end=13585412
bridgeOp current id=5 from=(50.8459854,65.6024933) to=(36.756134,47.423481)
path.lineTo(50.8459854,65.6024933);
path.lineTo(36.756134,47.423481);
</div>
</div>

<script type="text/javascript">

var testDivs = [
    battleOp183,
];

var decimal_places = 3; // make this 3 to show more precision

var tests = [];
var testLines = [];
var testTitles = [];
var testIndex = 0;
var ctx;

var xmin, xmax, focusXmin, focusXmax;
var ymin, ymax, focusYmin, focusYmax;
var scale;
var mouseX, mouseY;
var srcLeft, srcTop;
var screenWidth, screenHeight;
var drawnPts, drawnLines, drawnQuads, drawnConics, drawnCubics;
var curveT = 0;

var pt_labels = 2;
var collect_bounds = false;
var control_lines = 0;
var curve_t = false;
var debug_xy = 1;
var focus_enabled = false;
var focus_on_selection = false;
var step_limit = 0;
var draw_active = false;
var draw_add = false;
var draw_angle = 0;
var draw_coincidence = false;
var draw_deriviatives = 0;
var draw_hints = false;
var draw_id = false;
var draw_intersection = 0;
var draw_intersectT = false;
var draw_legend = true;
var draw_log = false;
var draw_mark = false;
var draw_midpoint = false;
var draw_op = 0;
var draw_sequence = false;
var draw_sort = 0;
var draw_top = false;
var draw_path = 3;
var draw_computed = 0;
var retina_scale = !!window.devicePixelRatio;

var activeCount = 0;
var addCount = 0;
var angleCount = 0;
var coinCount = 0;
var opCount = 0;
var sectCount = 0;
var sortCount = 0;
var topCount = 0;
var markCount = 0;
var activeMax = 0;
var addMax = 0;
var angleMax = 0;
var coinMax = 0;
var sectMax = 0;
var sectMax2 = 0;
var sortMax = 0;
var topMax = 0;
var markMax = 0;
var opMax = 0;
var stepMax = 0;
var lastIndex = 0;
var hasPath = false;
var hasComputedPath = false;
var angleBetween = false;
var afterIndex = 0;

var firstActiveSpan = -1;
var logStart = -1;
var logRange = 0;

var SPAN_ID = 0;
var SPAN_X1 = SPAN_ID + 1;
var SPAN_Y1 = SPAN_X1 + 1;
var SPAN_X2 = SPAN_Y1 + 1;
var SPAN_Y2 = SPAN_X2 + 1;

var SPAN_L_T = SPAN_Y2 + 1;
var SPAN_L_TX = SPAN_L_T + 1;
var SPAN_L_TY = SPAN_L_TX + 1;
var SPAN_L_TEND = SPAN_L_TY + 1;
var SPAN_L_OTHER = SPAN_L_TEND + 1;
var SPAN_L_OTHERT = SPAN_L_OTHER + 1;
var SPAN_L_OTHERI = SPAN_L_OTHERT + 1;
var SPAN_L_SUM = SPAN_L_OTHERI + 1;
var SPAN_L_VAL = SPAN_L_SUM + 1;
var SPAN_L_OPP = SPAN_L_VAL + 1;

var SPAN_X3 = SPAN_Y2 + 1;
var SPAN_Y3 = SPAN_X3 + 1;

var SPAN_Q_T = SPAN_Y3 + 1;
var SPAN_Q_TX = SPAN_Q_T + 1;
var SPAN_Q_TY = SPAN_Q_TX + 1;
var SPAN_Q_TEND = SPAN_Q_TY + 1;
var SPAN_Q_OTHER = SPAN_Q_TEND + 1;
var SPAN_Q_OTHERT = SPAN_Q_OTHER + 1;
var SPAN_Q_OTHERI = SPAN_Q_OTHERT + 1;
var SPAN_Q_SUM = SPAN_Q_OTHERI + 1;
var SPAN_Q_VAL = SPAN_Q_SUM + 1;
var SPAN_Q_OPP = SPAN_Q_VAL + 1;

var SPAN_K_W = SPAN_Y3 + 1;
var SPAN_K_T = SPAN_K_W + 1;
var SPAN_K_TX = SPAN_K_T + 1;
var SPAN_K_TY = SPAN_K_TX + 1;
var SPAN_K_TEND = SPAN_K_TY + 1;
var SPAN_K_OTHER = SPAN_K_TEND + 1;
var SPAN_K_OTHERT = SPAN_K_OTHER + 1;
var SPAN_K_OTHERI = SPAN_K_OTHERT + 1;
var SPAN_K_SUM = SPAN_K_OTHERI + 1;
var SPAN_K_VAL = SPAN_K_SUM + 1;
var SPAN_K_OPP = SPAN_K_VAL + 1;

var SPAN_X4 = SPAN_Y3 + 1;
var SPAN_Y4 = SPAN_X4 + 1;

var SPAN_C_T = SPAN_Y4 + 1;
var SPAN_C_TX = SPAN_C_T + 1;
var SPAN_C_TY = SPAN_C_TX + 1;
var SPAN_C_TEND = SPAN_C_TY + 1;
var SPAN_C_OTHER = SPAN_C_TEND + 1;
var SPAN_C_OTHERT = SPAN_C_OTHER + 1;
var SPAN_C_OTHERI = SPAN_C_OTHERT + 1;
var SPAN_C_SUM = SPAN_C_OTHERI + 1;
var SPAN_C_VAL = SPAN_C_SUM + 1;
var SPAN_C_OPP = SPAN_C_VAL + 1;

var ACTIVE_LINE_SPAN =        1;
var ACTIVE_QUAD_SPAN =        ACTIVE_LINE_SPAN + 1;
var ACTIVE_CONIC_SPAN =       ACTIVE_QUAD_SPAN + 1;
var ACTIVE_CUBIC_SPAN =       ACTIVE_CONIC_SPAN + 1;

var ADD_MOVETO =              ACTIVE_CUBIC_SPAN + 1;
var ADD_LINETO =              ADD_MOVETO + 1;
var ADD_QUADTO =              ADD_LINETO + 1;
var ADD_CONICTO =             ADD_QUADTO + 1;
var ADD_CUBICTO =             ADD_CONICTO + 1;
var ADD_CLOSE =               ADD_CUBICTO + 1;
var ADD_FILL =                ADD_CLOSE + 1;

var PATH_LINE =               ADD_FILL + 1;
var PATH_QUAD =               PATH_LINE + 1;
var PATH_CONIC =              PATH_QUAD + 1;
var PATH_CUBIC =              PATH_CONIC + 1;

var INTERSECT_LINE =          PATH_CUBIC + 1;
var INTERSECT_LINE_2 =        INTERSECT_LINE + 1;
var INTERSECT_LINE_NO =       INTERSECT_LINE_2 + 1;
var INTERSECT_QUAD_LINE =     INTERSECT_LINE_NO + 1;
var INTERSECT_QUAD_LINE_2 =   INTERSECT_QUAD_LINE + 1;
var INTERSECT_QUAD_LINE_NO =  INTERSECT_QUAD_LINE_2 + 1;
var INTERSECT_QUAD =          INTERSECT_QUAD_LINE_NO + 1;
var INTERSECT_QUAD_2 =        INTERSECT_QUAD + 1;
var INTERSECT_QUAD_NO =       INTERSECT_QUAD_2 + 1;
var INTERSECT_CONIC_LINE =    INTERSECT_QUAD_NO + 1;
var INTERSECT_CONIC_LINE_2 =  INTERSECT_CONIC_LINE + 1;
var INTERSECT_CONIC_LINE_NO = INTERSECT_CONIC_LINE_2 + 1;
var INTERSECT_CONIC =         INTERSECT_CONIC_LINE_NO + 1;
var INTERSECT_CONIC_2 =       INTERSECT_CONIC + 1;
var INTERSECT_CONIC_NO =      INTERSECT_CONIC_2 + 1;
var INTERSECT_SELF_CUBIC =    INTERSECT_CONIC_NO + 1;
var INTERSECT_SELF_CUBIC_NO = INTERSECT_SELF_CUBIC + 1;
var INTERSECT_CUBIC_LINE =    INTERSECT_SELF_CUBIC_NO + 1;
var INTERSECT_CUBIC_LINE_2 =  INTERSECT_CUBIC_LINE + 1;
var INTERSECT_CUBIC_LINE_3 =  INTERSECT_CUBIC_LINE_2 + 1;
var INTERSECT_CUBIC_LINE_NO = INTERSECT_CUBIC_LINE_3 + 1;
var INTERSECT_CUBIC_QUAD =    INTERSECT_CUBIC_LINE_NO + 1;
var INTERSECT_CUBIC_QUAD_2 =  INTERSECT_CUBIC_QUAD + 1;
var INTERSECT_CUBIC_QUAD_3 =  INTERSECT_CUBIC_QUAD_2 + 1;
var INTERSECT_CUBIC_QUAD_4 =  INTERSECT_CUBIC_QUAD_3 + 1;
var INTERSECT_CUBIC_QUAD_NO = INTERSECT_CUBIC_QUAD_4 + 1;
var INTERSECT_CUBIC =         INTERSECT_CUBIC_QUAD_NO + 1;
var INTERSECT_CUBIC_2 =       INTERSECT_CUBIC + 1;
var INTERSECT_CUBIC_3 =       INTERSECT_CUBIC_2 + 1;
var INTERSECT_CUBIC_4 =       INTERSECT_CUBIC_3 + 1;
// FIXME: add cubic 5- 9
var INTERSECT_CUBIC_NO =      INTERSECT_CUBIC_4 + 1;

var SORT_UNARY =              INTERSECT_CUBIC_NO + 1;
var SORT_BINARY =             SORT_UNARY + 1;

var OP_DIFFERENCE =           SORT_BINARY + 1;
var OP_INTERSECT =            OP_DIFFERENCE + 1;
var OP_UNION =                OP_INTERSECT + 1;
var OP_XOR =                  OP_UNION + 1;

var MARK_LINE =               OP_XOR + 1;
var MARK_QUAD =               MARK_LINE + 1;
var MARK_CONIC =              MARK_QUAD + 1;
var MARK_CUBIC =              MARK_CONIC + 1;
var MARK_DONE_LINE =          MARK_CUBIC + 1;
var MARK_DONE_QUAD =          MARK_DONE_LINE + 1;
var MARK_DONE_CONIC =         MARK_DONE_QUAD + 1;
var MARK_DONE_CUBIC =         MARK_DONE_CONIC + 1;
var MARK_UNSORTABLE_LINE =    MARK_DONE_CUBIC + 1;
var MARK_UNSORTABLE_QUAD =    MARK_UNSORTABLE_LINE + 1;
var MARK_UNSORTABLE_CONIC =   MARK_UNSORTABLE_QUAD + 1;
var MARK_UNSORTABLE_CUBIC =   MARK_UNSORTABLE_CONIC + 1;
var MARK_SIMPLE_LINE =        MARK_UNSORTABLE_CUBIC + 1;
var MARK_SIMPLE_QUAD =        MARK_SIMPLE_LINE + 1;
var MARK_SIMPLE_CONIC =       MARK_SIMPLE_QUAD + 1;
var MARK_SIMPLE_CUBIC =       MARK_SIMPLE_CONIC + 1;
var MARK_SIMPLE_DONE_LINE =   MARK_SIMPLE_CUBIC + 1;
var MARK_SIMPLE_DONE_QUAD =   MARK_SIMPLE_DONE_LINE + 1;
var MARK_SIMPLE_DONE_CONIC =  MARK_SIMPLE_DONE_QUAD + 1;
var MARK_SIMPLE_DONE_CUBIC =  MARK_SIMPLE_DONE_CONIC + 1;
var MARK_DONE_UNARY_LINE =    MARK_SIMPLE_DONE_CUBIC + 1;
var MARK_DONE_UNARY_QUAD =    MARK_DONE_UNARY_LINE + 1;
var MARK_DONE_UNARY_CONIC =   MARK_DONE_UNARY_QUAD + 1;
var MARK_DONE_UNARY_CUBIC =   MARK_DONE_UNARY_CONIC + 1;
var MARK_ANGLE_LAST =         MARK_DONE_UNARY_CUBIC + 1;

var COMPUTED_SET_1 =          MARK_ANGLE_LAST + 1;
var COMPUTED_SET_2 =          COMPUTED_SET_1 + 1;

var ANGLE_AFTER =             COMPUTED_SET_2 + 1;
var ANGLE_AFTERPART =         ANGLE_AFTER + 1;

var ACTIVE_OP =               ANGLE_AFTERPART + 1;

var COIN_MAIN_SPAN =          ACTIVE_OP + 1;
var COIN_OPP_SPAN =           COIN_MAIN_SPAN + 1;

var FRAG_TYPE_LAST =          COIN_OPP_SPAN;

var REC_TYPE_UNKNOWN = -1;
var REC_TYPE_PATH = 0;
var REC_TYPE_PATH2 = 1;
var REC_TYPE_SECT = 2;
var REC_TYPE_ACTIVE = 3;
var REC_TYPE_ADD = 4;
var REC_TYPE_SORT = 5;
var REC_TYPE_OP = 6;
var REC_TYPE_MARK = 7;
var REC_TYPE_COMPUTED = 8;
var REC_TYPE_COIN = 9;
var REC_TYPE_ANGLE = 10;
var REC_TYPE_ACTIVE_OP = 11;
var REC_TYPE_AFTERPART = 12;
var REC_TYPE_TOP = 13;
var REC_TYPE_COINCIDENCE = 14;
var REC_TYPE_LAST = REC_TYPE_COINCIDENCE;

function strs_to_nums(strs) {
    var result = [];
    for (var idx = 1; idx < strs.length; ++idx) {
        var str = strs[idx];
        var num = parseFloat(str);
        if (isNaN(num)) {
            result.push(str);
        } else {
            result.push(num);
        }
    }
    return result;
}

function filter_str_by(id, str, regex, array) {
    if (regex.test(str)) {
        var strs = regex.exec(str);
        var result = strs_to_nums(strs);
        array.push(id);
        array.push(result);
        return true;
    }
    return false;
}

function construct_regexp2(pattern) {
    var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
    escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
    escape = escape.replace(/CUBIC_VAL/g, "\\(P_VAL P_VAL P_VAL P_VAL\\)");
    escape = escape.replace(/CONIC_VAL/g, "\\(P_VAL P_VAL P_VAL W_VAL\\)");
    escape = escape.replace(/QUAD_VAL/g, "\\(P_VAL P_VAL P_VAL\\)");
    escape = escape.replace(/LINE_VAL/g, "\\(P_VAL P_VAL\\)");
    escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
    escape = escape.replace(/PTR_VAL/g, "0x[0-9A-F]+");
    escape = escape.replace(/PT_VAL/g, "\\(P_VAL\\)");
    escape = escape.replace(/P_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?, ?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
    escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
    escape = escape.replace(/W_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
    escape = escape.replace(/PATH/g, "pathB?");
    escape = escape.replace(/IDX/g, "(-?\\d+)");
    escape = escape.replace(/NUM/g, "(-?\\d+)");
    escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
    return new RegExp(escape, 'i');
}

function construct_regexp2c(pattern) {
    var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
    escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
    escape = escape.replace(/CUBIC_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
    escape = escape.replace(/CONIC_VAL/g, "(?:\\$\\d = )?\\{\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}, W_VAL\\}");
    escape = escape.replace(/QUAD_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
    escape = escape.replace(/LINE_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
    escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
    escape = escape.replace(/PTR_VAL/g, "0x[0-9A-F]+");
    escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}");
    escape = escape.replace(/P_VAL/g, "(?:f?[xX] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?, *(?: f?[yY] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
    escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
    escape = escape.replace(/W_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
    escape = escape.replace(/OPER/g, "[a-z]+");
    escape = escape.replace(/PATH/g, "pathB?");
    escape = escape.replace(/T_F/g, "([TF])");
    escape = escape.replace(/IDX/g, "(-?\\d+)");
    escape = escape.replace(/NUM/g, "(-?\\d+)");
    escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
    return new RegExp(escape, 'i');
}

function match_regexp(str, lineNo, array, id, pattern) {
    var regex = construct_regexp2(pattern);
    if (filter_str_by(id, str, regex, array)) {
        return true;
    }
    regex = construct_regexp2c(pattern);
    return filter_str_by(id, str, regex, array);
}

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function parse_all(test) {
    var lines = test.match(/[^\r\n]+/g);
    var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add
    var record = [];
    var recType = REC_TYPE_UNKNOWN;
    var lastLineNo;
    var moveX, moveY;
    for (var lineNo = 0; lineNo < lines.length; ++lineNo) {
        var line = lines[lineNo];
        if (line.length == 0) {
            continue;
        }
        var opStart = "SkOpSegment::";
        if (line.lastIndexOf(opStart, 0) === 0) {
            line = line.substr(opStart.length);
        }
        var angleStart = "SkOpAngle::";
        if (line.lastIndexOf(angleStart, 0) === 0) {
            line = line.substr(angleStart.length);
        }
        var coinStart = "SkOpCoincidence::";
        if (line.lastIndexOf(coinStart, 0) === 0) {
            line = line.substr(coinStart.length);
        }
        var type = line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE
                : line.lastIndexOf("debugShowCoincidence", 0) === 0 ? REC_TYPE_COINCIDENCE
                : line.lastIndexOf("((SkOpSegment*)", 0) === 0 ? REC_TYPE_PATH2
                : line.lastIndexOf("debugShowTs", 0) === 0 ? REC_TYPE_COIN 
                : line.lastIndexOf("afterPart", 0) === 0 ? REC_TYPE_AFTERPART
                : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT
                : line.lastIndexOf("activeOp", 0) === 0 ? REC_TYPE_ACTIVE_OP
                : line.lastIndexOf("computed", 0) === 0 ? REC_TYPE_COMPUTED
                : line.lastIndexOf("debugOne", 0) === 0 ? REC_TYPE_SORT
                : line.lastIndexOf("dumpOne", 0) === 0 ? REC_TYPE_SORT
                : line.lastIndexOf("findTop", 0) === 0 ? REC_TYPE_TOP
                : line.lastIndexOf("pathB.", 0) === 0 ? REC_TYPE_ADD
                : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD
                : line.lastIndexOf("after", 0) === 0 ? REC_TYPE_ANGLE
                : line.lastIndexOf("mark", 0) === 0 ? REC_TYPE_MARK
                : line.lastIndexOf("  {{", 0) === 0 ? REC_TYPE_COMPUTED
                : line.lastIndexOf("seg=", 0) === 0 ? REC_TYPE_PATH
                : line.lastIndexOf("op", 0) === 0 ? REC_TYPE_OP
                : line.lastIndexOf("$", 0) === 0 ? REC_TYPE_PATH
                : REC_TYPE_UNKNOWN;
        if (recType != type || recType == REC_TYPE_ADD || recType == REC_TYPE_SECT
                || recType == REC_TYPE_ACTIVE_OP || recType == REC_TYPE_ANGLE) {
            if (recType != REC_TYPE_UNKNOWN) {
                records.push(recType);
                records.push(lastLineNo);
                records.push(record);
            }
            record = [];
            recType = type;
            lastLineNo = lineNo;
        }
        var found = false;
        switch (recType) {
            case REC_TYPE_ACTIVE:
                found = match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
" id=IDX LINE_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
" id=IDX QUAD_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, ACTIVE_CONIC_SPAN, "debugShowActiveSpans" +
" id=IDX CONIC_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
" id=IDX CUBIC_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
" id=IDX LINE_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
                ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
" id=IDX QUAD_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
                ) || match_regexp(line, lineNo, record, ACTIVE_CONIC_SPAN, "debugShowActiveSpans" +
" id=IDX CONIC_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
                ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
" id=IDX CUBIC_VAL t=T_VAL PT_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
                );
                break;
            case REC_TYPE_ACTIVE_OP:
                found = match_regexp(line, lineNo, record, ACTIVE_OP, "activeOp" +
" id=IDX t=T_VAL tEnd=T_VAL op=OPER miFrom=NUM miTo=NUM suFrom=NUM suTo=NUM result=IDX"
                );
                break;
            case REC_TYPE_ADD:
                if (match_regexp(line, lineNo, record, ADD_MOVETO, "PATH.moveTo(P_VAL);")) {
                    moveX = record[1][0];
                    moveY = record[1][1];
                    found = true;
                } else if (match_regexp(line, lineNo, record, ADD_LINETO, "PATH.lineTo(P_VAL);")) {
                    record[1].unshift(moveY);
                    record[1].unshift(moveX);
                    moveX = record[1][2];
                    moveY = record[1][3];
                    found = true;
                } else if (match_regexp(line, lineNo, record, ADD_QUADTO, "PATH.quadTo(P_VAL, P_VAL);")) {
                    record[1].unshift(moveY);
                    record[1].unshift(moveX);
                    moveX = record[1][4];
                    moveY = record[1][5];
                    found = true;
                } else if (match_regexp(line, lineNo, record, ADD_CONICTO, "PATH.conicTo(P_VAL, P_VAL, T_VAL);")) {
                    record[1].unshift(moveY);
                    record[1].unshift(moveX);
                    moveX = record[1][4];
                    moveY = record[1][5];
                    found = true;
                } else if (match_regexp(line, lineNo, record, ADD_CUBICTO, "PATH.cubicTo(P_VAL, P_VAL, P_VAL);")) {
                    record[1].unshift(moveY);
                    record[1].unshift(moveX);
                    moveX = record[1][6];
                    moveY = record[1][7];
                    found = true;
                } else if (match_regexp(line, lineNo, record, ADD_FILL, "PATH.setFillType(FILL_TYPE);")) {
                    found = true;
                } else {
                    found = match_regexp(line, lineNo, record, ADD_CLOSE, "PATH.close();");
                }
                break;
            case REC_TYPE_AFTERPART:
                found = match_regexp(line, lineNo, record, PATH_LINE, "afterPart LINE_VAL")
                    || match_regexp(line, lineNo, record, PATH_QUAD, "afterPart QUAD_VAL")
                    || match_regexp(line, lineNo, record, PATH_CONIC, "afterPart CONIC_VAL")
                    || match_regexp(line, lineNo, record, PATH_CUBIC, "afterPart CUBIC_VAL")
                break;
            case REC_TYPE_ANGLE:
                found = match_regexp(line, lineNo, record, ANGLE_AFTER, "after " +
"[IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL < [IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL < [IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL  T_F IDX");
                break;
            case REC_TYPE_COIN:
                found = true;
                break;
            case REC_TYPE_COINCIDENCE:
                found = match_regexp(line, lineNo, record, COIN_MAIN_SPAN, "debugShowCoincidence" +
" + id=IDX t=T_VAL tEnd=T_VAL"
                ) || match_regexp(line, lineNo, record, COIN_OPP_SPAN, "debugShowCoincidence" +
" - id=IDX t=T_VAL tEnd=T_VAL"
                );
                break;
            case REC_TYPE_COMPUTED:
                found = line ==  "computed quadratics given"
                  || match_regexp(line, lineNo, record, COMPUTED_SET_1, "computed quadratics set 1"
                ) || match_regexp(line, lineNo, record, COMPUTED_SET_2, "computed quadratics set 2"
                ) || match_regexp(line, lineNo, record, PATH_QUAD, "  QUAD_VAL,"
                ) || match_regexp(line, lineNo, record, PATH_CONIC, "  CONIC_VAL,"
                ) || match_regexp(line, lineNo, record, PATH_CUBIC, "  CUBIC_VAL,"
                );
                break;
            case REC_TYPE_PATH:
                found = match_regexp(line, lineNo, record, PATH_LINE, "seg=IDX LINE_VAL"
                ) || match_regexp(line, lineNo, record, PATH_QUAD, "seg=IDX QUAD_VAL"
                ) || match_regexp(line, lineNo, record, PATH_CONIC, "seg=IDX CONIC_VAL"
                ) || match_regexp(line, lineNo, record, PATH_CUBIC, "seg=IDX CUBIC_VAL"
                );
                break;
            case REC_TYPE_PATH2:
                found = match_regexp(line, lineNo, record, PATH_LINE, "((SkOpSegment*) PTR_VAL) [IDX] {LINE_VAL}"
                ) || match_regexp(line, lineNo, record, PATH_QUAD, "((SkOpSegment*) PTR_VAL) [IDX] {QUAD_VAL}"
                ) || match_regexp(line, lineNo, record, PATH_CONIC, "((SkOpSegment*) PTR_VAL) [IDX] {CONIC_VAL}"
                ) || match_regexp(line, lineNo, record, PATH_CUBIC, "((SkOpSegment*) PTR_VAL) [IDX] {CUBIC_VAL}"
                );
                break;
            case REC_TYPE_SECT:
                found = match_regexp(line, lineNo, record, INTERSECT_LINE, "debugShowLineIntersection" +
" wtTs[0]=T_VAL LINE_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_LINE_2, "debugShowLineIntersection" +
" wtTs[0]=T_VAL LINE_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_LINE_NO, "debugShowLineIntersection" +
" no intersect LINE_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE, "debugShowQuadLineIntersection" +
" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_2, "debugShowQuadLineIntersection" +
" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_NO, "debugShowQuadLineIntersection" +
" no intersect QUAD_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD, "debugShowQuadIntersection" +
" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_2, "debugShowQuadIntersection" +
" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" +
" no intersect QUAD_VAL QUAD_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE, "debugShowConicLineIntersection" +
" wtTs[0]=T_VAL CONIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE_2, "debugShowConicLineIntersection" +
" wtTs[0]=T_VAL CONIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE_NO, "debugShowConicLineIntersection" +
" no intersect CONIC_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC, "debugShowConicIntersection" +
" wtTs[0]=T_VAL CONIC_VAL PT_VAL wnTs[0]=T_VAL CONIC_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_2, "debugShowConicIntersection" +
" wtTs[0]=T_VAL CONIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CONIC_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_NO, "debugShowConicIntersection" +
" no intersect CONIC_VAL CONIC_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_3, "debugShowCubicLineIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_NO, "debugShowCubicLineIntersection" +
" no intersect CUBIC_VAL LINE_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD, "debugShowCubicQuadIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_2, "debugShowCubicQuadIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_3, "debugShowCubicQuadIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_4, "debugShowCubicQuadIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL wtTs[3]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL wnTs[3]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_NO, "debugShowCubicQuadIntersection" +
" no intersect CUBIC_VAL QUAD_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC, "debugShowCubicIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_2, "debugShowCubicIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_3, "debugShowCubicIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_4, "debugShowCubicIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wtTs[3]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL wnTs[3]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" +
" no intersect CUBIC_VAL CUBIC_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
" no self intersect CUBIC_VAL"
                );
                break;
            case REC_TYPE_SORT:
                var hasDone = / done/.test(line);
                var hasUnorderable = / unorderable/.test(line);
                var hasSmall = / small/.test(line);
                var hasTiny = / tiny/.test(line);
                var hasOperand = / operand/.test(line);
                var hasStop = / stop/.test(line);
                line.replace(/[ a-z]+$/, "");
                found = match_regexp(line, lineNo, record, SORT_UNARY, "debugOne" +
" [IDX/IDX] next=IDX/IDX sect=IDX/IDX  s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
                ) || match_regexp(line, lineNo, record, SORT_BINARY, "debugOne" +
" [IDX/IDX] next=IDX/IDX sect=IDX/IDX  s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT oppVal=IDX oppSum=OPT"
                ) || match_regexp(line, lineNo, record, SORT_UNARY, "dumpOne" +
" [IDX/IDX] next=IDX/IDX sect=NUM/NUM  s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
                ) || match_regexp(line, lineNo, record, SORT_BINARY, "dumpOne" +
" [IDX/IDX] next=IDX/IDX sect=NUM/NUM  s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT oppVal=IDX oppSum=OPT"
                );
                if (found) {
                    record[1].push(hasDone);
                    record[1].push(hasUnorderable);
                    record[1].push(hasSmall);
                    record[1].push(hasTiny);
                    record[1].push(hasOperand);
                    record[1].push(hasStop);
                }
                break;
            case REC_TYPE_TOP:
                found = match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
" id=IDX s=T_VAL e=T_VAL cw=NUM swap=NUM inflections=NUM monotonic=NUM"
                ) || match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
" id=IDX s=T_VAL e=T_VAL (-) cw=NUM swap=NUM inflections=NUM monotonic=NUM"
                ) || match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
" id=IDX s=T_VAL e=T_VAL (+) cw=NUM swap=NUM inflections=NUM monotonic=NUM"
                );
                break;
            case REC_TYPE_MARK:
                found = match_regexp(line, lineNo, record, MARK_LINE, "markWinding" +
" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_QUAD, "markWinding" +
" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_CONIC, "markWinding" +
" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_CUBIC, "markWinding" +
" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_DONE_LINE, "markDone" +
" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
                ) || match_regexp(line, lineNo, record, MARK_DONE_QUAD, "markDone" +
" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
                ) || match_regexp(line, lineNo, record, MARK_DONE_CONIC, "markDone" +
" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
                ) || match_regexp(line, lineNo, record, MARK_DONE_CUBIC, "markDone" +
" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
                ) || match_regexp(line, lineNo, record, MARK_SIMPLE_LINE, "markWinding" +
" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_SIMPLE_QUAD, "markWinding" +
" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_SIMPLE_CONIC, "markWinding" +
" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_SIMPLE_CUBIC, "markWinding" +
" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
                ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
" last segment=IDX span=IDX"
                ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
" last segment=IDX span=IDX windSum=OPT");
                break;
            case REC_TYPE_OP:
                if (line.lastIndexOf("oppSign oppSign=", 0) === 0
                        || line.lastIndexOf("operator<", 0) === 0) {
                    found = true;
                    break;
                }
                found = match_regexp(line, lineNo, record, OP_DIFFERENCE, "op diff"
                ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op intersect"
                ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op sect"
                ) || match_regexp(line, lineNo, record, OP_UNION, "op union"
                ) || match_regexp(line, lineNo, record, OP_XOR, "op xor"
                );
                break;
            case REC_TYPE_UNKNOWN:
                found = true;
                break;
        }
        if (!found) {
            console.log(line + " [" + lineNo + "] of type " + type + " not found");
        }
    }
    if (recType != REC_TYPE_UNKNOWN) {
        records.push(recType);
        records.push(lastLineNo);
        records.push(record);
    }
    if (records.length >= 1) {
        tests[testIndex] = records;
        testLines[testIndex] = lines;
    }
}

function init(test) {
    var canvas = document.getElementById('canvas');
    if (!canvas.getContext) return;
    ctx = canvas.getContext('2d');
    var resScale = retina_scale && window.devicePixelRatio ? window.devicePixelRatio : 1;
    var unscaledWidth = window.innerWidth - 20;
    var unscaledHeight = window.innerHeight - 20;
    screenWidth = unscaledWidth;
    screenHeight = unscaledHeight;
    canvas.width = unscaledWidth * resScale;
    canvas.height = unscaledHeight * resScale;
    canvas.style.width = unscaledWidth + 'px';
    canvas.style.height = unscaledHeight + 'px';
    if (resScale != 1) {
        ctx.scale(resScale, resScale);
    }
    xmin = Infinity;
    xmax = -Infinity;
    ymin = Infinity;
    ymax = -Infinity;
    hasPath = hasComputedPath = false;
    firstActiveSpan = -1;
    for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
        var recType = test[tIndex];
        if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
            console.log("unknown rec type: " + recType);
            throw "stop execution";
        }
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
                console.log("unknown in range frag type: " + fragType);
                throw "stop execution";
            }
            var frags = records[recordIndex + 1];
            var first = 0;
            var last = -1;
            var first2 = 0;
            var last2 = 0;
            switch (recType) {
                case REC_TYPE_COMPUTED:
                    if (fragType == COMPUTED_SET_1 || fragType == COMPUTED_SET_2) {
                        break;
                    }
                    hasComputedPath = true;
                case REC_TYPE_PATH:
                    first = 1;
                    switch (fragType) {
                        case PATH_LINE:
                            last = 5;
                            break;
                        case PATH_CONIC:
                        case PATH_QUAD:
                            last = 7;
                            break;
                        case PATH_CUBIC:
                            last = 9;
                            break;
                        default:
                            console.log("unknown " + (recType == REC_TYPE_PATH ? "REC_TYPE_PATH" 
                                    : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
                            throw "stop execution";
                    }
                    if (recType == REC_TYPE_PATH) {
                        hasPath = true;
                    }
                    break;
                case REC_TYPE_PATH2:
                    first = 1;
                    switch (fragType) {
                        case PATH_LINE:
                            last = 5;
                            break;
                        case PATH_CONIC:
                        case PATH_QUAD:
                            last = 7;
                            break;
                        case PATH_CUBIC:
                            last = 9;
                            break;
                        default:
                            console.log("unknown " + (recType == REC_TYPE_PATH2 ? "REC_TYPE_PATH2" 
                                    : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
                            throw "stop execution";
                    }
                    if (recType == REC_TYPE_PATH2) {
                        hasPath = true;
                    }
                    break;
                case REC_TYPE_ACTIVE:
                    if (firstActiveSpan < 0) {
                        firstActiveSpan = tIndex;
                    }
                    first = 1;
                    switch (fragType) {
                        case ACTIVE_LINE_SPAN:
                            last = 5;
                            break;
                        case ACTIVE_CONIC_SPAN:
                        case ACTIVE_QUAD_SPAN:
                            last = 7;
                            break;
                        case ACTIVE_CUBIC_SPAN:
                            last = 9;
                            break;
                        default:
                            console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_ADD:
                    switch (fragType) {
                        case ADD_MOVETO:
                            break;
                        case ADD_LINETO:
                            last = 4;
                            break;
                        case ADD_CONICTO:
                        case ADD_QUADTO:
                            last = 6;
                            break;
                        case ADD_CUBICTO:
                            last = 8;
                            break;
                        case ADD_CLOSE:
                        case ADD_FILL:
                            break;
                        default:
                            console.log("unknown REC_TYPE_ADD frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_AFTERPART:
                    switch (fragType) {
                        case PATH_LINE:
                            last = 4;
                            break;
                        case PATH_CONIC:
                        case PATH_QUAD:
                            last = 6;
                            break;
                        case PATH_CUBIC:
                            last = 8;
                            break;
                        default:
                            console.log("unknown REC_TYPE_ACTIVEPART frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_SECT:
                    switch (fragType) {
                        case INTERSECT_LINE:
                            first = 1; last = 5; first2 = 8; last2 = 12;
                            break;
                        case INTERSECT_LINE_2:
                            first = 1; last = 5; first2 = 11; last2 = 15;
                            break;
                        case INTERSECT_LINE_NO:
                            first = 0; last = 4; first2 = 4; last2 = 8;
                            break;
                        case INTERSECT_CONIC_LINE:
                            first = 1; last = 7; first2 = 11; last2 = 15;
                            break;
                        case INTERSECT_QUAD_LINE:
                            first = 1; last = 7; first2 = 10; last2 = 14;
                            break;
                        case INTERSECT_CONIC_LINE_2:
                            first = 1; last = 7; first2 = 14; last2 = 18;
                            break;
                        case INTERSECT_QUAD_LINE_2:
                            first = 1; last = 7; first2 = 13; last2 = 17;
                            break;
                        case INTERSECT_CONIC_LINE_NO:
                            first = 0; last = 6; first2 = 7; last2 = 11;
                            break;
                        case INTERSECT_QUAD_LINE_NO:
                            first = 0; last = 6; first2 = 6; last2 = 10;
                            break;
                        case INTERSECT_CONIC:
                            first = 1; last = 7; first2 = 11; last2 = 17;
                            break;
                        case INTERSECT_QUAD:
                            first = 1; last = 7; first2 = 10; last2 = 16;
                            break;
                        case INTERSECT_CONIC_2:
                            first = 1; last = 7; first2 = 14; last2 = 20;
                            break;
                        case INTERSECT_QUAD_2:
                            first = 1; last = 7; first2 = 13; last2 = 19;
                            break;
                        case INTERSECT_CONIC_NO:
                            first = 0; last = 6; first2 = 7; last2 = 13;
                            break;
                        case INTERSECT_QUAD_NO:
                            first = 0; last = 6; first2 = 6; last2 = 12;
                            break;
                        case INTERSECT_SELF_CUBIC:
                            first = 1; last = 9;
                            break;
                        case INTERSECT_SELF_CUBIC_NO:
                            first = 0; last = 8;
                            break;
                        case INTERSECT_CUBIC_LINE:
                            first = 1; last = 9; first2 = 12; last2 = 16;
                            break;
                        case INTERSECT_CUBIC_LINE_2:
                            first = 1; last = 9; first2 = 15; last2 = 19;
                            break;
                        case INTERSECT_CUBIC_LINE_3:
                            first = 1; last = 9; first2 = 18; last2 = 22;
                            break;
                        case INTERSECT_CUBIC_LINE_NO:
                            first = 0; last = 8; first2 = 8; last2 = 12;
                            break;
                        case INTERSECT_CUBIC_QUAD:
                            first = 1; last = 9; first2 = 12; last2 = 18;
                            break;
                        case INTERSECT_CUBIC_QUAD_2:
                            first = 1; last = 9; first2 = 15; last2 = 21;
                            break;
                        case INTERSECT_CUBIC_QUAD_3:
                            first = 1; last = 9; first2 = 18; last2 = 24;
                            break;
                        case INTERSECT_CUBIC_QUAD_4:
                            first = 1; last = 9; first2 = 21; last2 = 27;
                            break;
                        case INTERSECT_CUBIC_QUAD_NO:
                            first = 0; last = 8; first2 = 8; last2 = 14;
                            break;
                        case INTERSECT_CUBIC:
                            first = 1; last = 9; first2 = 12; last2 = 20;
                            break;
                        case INTERSECT_CUBIC_2:
                            first = 1; last = 9; first2 = 15; last2 = 23;
                            break;
                        case INTERSECT_CUBIC_3:
                            first = 1; last = 9; first2 = 18; last2 = 26;
                            break;
                        case INTERSECT_CUBIC_4:
                            first = 1; last = 9; first2 = 21; last2 = 29;
                            break;
                        case INTERSECT_CUBIC_NO:
                            first = 0; last = 8; first2 = 8; last2 = 16;
                            break;
                        default:
                            console.log("unknown REC_TYPE_SECT frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                default:
                    continue;
            }
            for (var idx = first; idx < last; idx += 2) {
                xmin = Math.min(xmin, frags[idx]);
                xmax = Math.max(xmax, frags[idx]);
                ymin = Math.min(ymin, frags[idx + 1]);
                ymax = Math.max(ymax, frags[idx + 1]);
            }
            for (var idx = first2; idx < last2; idx += 2) {
                xmin = Math.min(xmin, frags[idx]);
                xmax = Math.max(xmax, frags[idx]);
                ymin = Math.min(ymin, frags[idx + 1]);
                ymax = Math.max(ymax, frags[idx + 1]);
            }
        }
    }
    var angleBounds = [Infinity, Infinity, -Infinity, -Infinity];
    for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
        var recType = test[tIndex];
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            var frags = records[recordIndex + 1];
            switch (recType) {
                case REC_TYPE_ACTIVE_OP:
                    if (!draw_op) {
                        break;
                    }
                    {
                        var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                        curve_extremes(curve, angleBounds);
                    }
                    break;
                case REC_TYPE_ANGLE:
                    if (!draw_angle) {
                        break;
                    }
                    {
                        var curve = curvePartialByID(test, frags[0], frags[4], frags[5]);
                        curve_extremes(curve, angleBounds);
                        curve = curvePartialByID(test, frags[6], frags[10], frags[11]);
                        curve_extremes(curve, angleBounds);
                        curve = curvePartialByID(test, frags[12], frags[16], frags[17]);
                    }
                    break;
                case REC_TYPE_COINCIDENCE:
                    if (!draw_coincidence) {
                        break;
                    }
                    {
                        var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                        curve_extremes(curve, angleBounds);
                    }
                    break;
                case REC_TYPE_SORT:
                    if (!draw_sort) {
                        break;
                    }
                    if (fragType == SORT_UNARY || fragType == SORT_BINARY) {
                        var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
                        curve_extremes(curve, angleBounds);
                    }
                    break;
                case REC_TYPE_TOP:
                    if (!draw_top) {
                        break;
                    }
                    {
                        var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                        curve_extremes(curve, angleBounds);
                    }
                    break;
            }
        }
    }
    xmin = Math.min(xmin, angleBounds[0]);
    ymin = Math.min(ymin, angleBounds[1]);
    xmax = Math.max(xmax, angleBounds[2]);
    ymax = Math.max(ymax, angleBounds[3]);
    setScale(xmin, xmax, ymin, ymax);
    if (hasPath == false && hasComputedPath == true && !draw_computed) {
        draw_computed = 7; // show quadratics, conics, and cubics
    }
    if (hasPath == true && hasComputedPath == false && draw_computed) {
        draw_computed = 0;
    }
}

function curveByID(test, id) {
    var tIndex = -3;
    while ((tIndex += 3) < test.length) {
        var recType = test[tIndex];
        if (recType == REC_TYPE_OP) {
            continue;
        }
        if (recType != REC_TYPE_PATH) {
            return [];
        }
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            var frags = records[recordIndex + 1];
            if (frags[0] == id) {
                switch (fragType) {
                    case PATH_LINE:
                        return [frags[1], frags[2], frags[3], frags[4]];
                    case PATH_QUAD:
                        return [frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6]];
                    case PATH_CONIC:
                        return [frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7]];
                    case PATH_CUBIC:
                        return [frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[8]];
                }
            }
        }
    }
    return [];
}

function curvePartialByID(test, id, t0, t1) {
    var tIndex = -3;
    while ((tIndex += 3) < test.length) {
        var recType = test[tIndex];
        if (recType == REC_TYPE_OP) {
            continue;
        }
        if (recType != REC_TYPE_PATH) {
            return [];
        }
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            var frags = records[recordIndex + 1];
            if (frags[0] == id) {
                switch (fragType) {
                    case PATH_LINE:
                        return linePartial(frags[1], frags[2], frags[3], frags[4], t0, t1);
                    case PATH_QUAD:
                        return quadPartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], t0, t1);
                    case PATH_CONIC:
                        return conicPartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], t0, t1);
                    case PATH_CUBIC:
                        return cubicPartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[8], t0, t1);
                }
            }
        }
    }
    return [];
}

function idByCurve(test, frag, type) {
    var tIndex = 0;
    while (tIndex < test.length) {
        var recType = test[tIndex];
        if (recType != REC_TYPE_PATH) {
            ++tIndex;
            continue;
        }
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            var frags = records[recordIndex + 1];
            if (frag.length != frags.length - 1) {
                continue;
            }
            switch (fragType) {
                case PATH_LINE:
                    if (frag[0] != frags[1] || frag[1] != frags[2]
                            || frag[2] != frags[3] || frag[3] != frags[4]) {
                        continue;
                    }
                    return frags[0];
                case PATH_QUAD:
                    if (frag[0] != frags[1] || frag[1] != frags[2]
                            || frag[2] != frags[3] || frag[3] != frags[4]
                            || frag[4] != frags[5] || frag[5] != frags[6]) {
                        continue;
                    }
                    return frags[0];
                case PATH_CONIC:
                    if (frag[0] != frags[1] || frag[1] != frags[2]
                            || frag[2] != frags[3] || frag[3] != frags[4]
                            || frag[4] != frags[5] || frag[5] != frags[6]
                            || frag[6] != frags[7]) {
                        continue;
                    }
                    return frags[0];
                case PATH_CUBIC:
                    if (frag[0] != frags[1] || frag[1] != frags[2]
                            || frag[2] != frags[3] || frag[3] != frags[4]
                            || frag[4] != frags[5] || frag[5] != frags[6]
                            || frag[6] != frags[7] || frag[7] != frags[8]) {
                        continue;
                    }
                    return frags[0];
            }
        }
        ++tIndex;
    }
    return -1;
}

function curve_extremes(curve, bounds) {
    var length = curve.length == 7 ? 6 : curve.length;
    for (var index = 0; index < curve.length; index += 2) {
        var x = curve[index];
        var y = curve[index + 1];
        bounds[0] = Math.min(bounds[0], x);
        bounds[1] = Math.min(bounds[1], y);
        bounds[2] = Math.max(bounds[2], x);
        bounds[3] = Math.max(bounds[3], y);
    }
}

function setScale(x0, x1, y0, y1) {
    var srcWidth = x1 - x0;
    var srcHeight = y1 - y0;
    var usableWidth = screenWidth;
    var xDigits = Math.ceil(Math.log(Math.abs(xmax)) / Math.log(10));
    var yDigits = Math.ceil(Math.log(Math.abs(ymax)) / Math.log(10));
    usableWidth -= (xDigits + yDigits) * 10;
    usableWidth -= decimal_places * 10;
    if (draw_legend) {
        usableWidth -= 40;
    }
    var hscale = usableWidth / srcWidth;
    var vscale = screenHeight / srcHeight;
    scale = Math.min(hscale, vscale);
    var invScale = 1 / scale;
    var sxmin = x0 - invScale * 5;
    var symin = y0 - invScale * 10;
    var sxmax = x1 + invScale * (6 * decimal_places + 10);
    var symax = y1 + invScale * 10;
    srcWidth = sxmax - sxmin;
    srcHeight = symax - symin;
    hscale = usableWidth / srcWidth;
    vscale = screenHeight / srcHeight;
    scale = Math.min(hscale, vscale);
    srcLeft = sxmin;
    srcTop = symin;
}

function drawArc(curve, op, from, to) {
    var type = PATH_LINE + (curve.length / 2 - 2);
    var pt = pointAtT(curve, type, op ? 0.4 : 0.6);
    var dy = pt.y - curve[1];
    var dx = pt.x - curve[0];
    var dist = Math.sqrt(dy * dy + dx * dx);
    var _dist = dist * scale;
    var angle = Math.atan2(dy, dx);
    var _px = (curve[0] - srcLeft) * scale;
    var _py = (curve[1] - srcTop) * scale;
    var divisor = 4;
    var endDist;
    do {
        var ends = [];
        for (var index = -1; index <= 1; index += 2) {
            var px = Math.cos(index * Math.PI / divisor);
            var py = Math.sin(index * Math.PI / divisor);
            ends.push(px);
            ends.push(py);
        }
        var endDx = (ends[2] - ends[0]) * scale * dist;
        var endDy = (ends[3] - ends[1]) * scale * dist;
        endDist = Math.sqrt(endDx * endDx + endDy * endDy);
        if (endDist < 100) {
            break;
        }
        divisor *= 2;
    } while (true);
    if (endDist < 30) {
        return;
    }
    if (op) {
        divisor *= 2;
    }
    ctx.strokeStyle = op ? "rgba(210,0,45, 0.4)" : "rgba(90,90,90, 0.5)";
    ctx.beginPath();
    ctx.arc(_px, _py, _dist, angle - Math.PI / divisor, angle + Math.PI / divisor, false);
    ctx.stroke();
    var saveAlign = ctx.textAlign;
    var saveStyle = ctx.fillStyle;
    var saveFont = ctx.font;
    ctx.textAlign = "center";
    ctx.fillStyle = "black";
    ctx.font = "normal 24px Arial";
    divisor *= 0.8;
    for (var index = -1; index <= 1; index += 2) {
        var px = curve[0] + Math.cos(angle + index * Math.PI / divisor) * dist;
        var py = curve[1] + Math.sin(angle + index * Math.PI / divisor) * dist;
        var _px = (px - srcLeft) * scale;
        var _py = (py - srcTop) * scale;
        ctx.fillText(index < 0 ? to.toString() : from.toString(), _px, _py + 8);
    }
    ctx.textAlign = saveAlign;
    ctx.fillStyle = saveStyle;
    ctx.font = saveFont;
}

function drawPoint(px, py, end) {
    var length = drawnPts.length == 7 ? 6 : drawnPts.length;
    for (var pts = 0; pts < length; pts += 2) {
        var x = drawnPts[pts];
        var y = drawnPts[pts + 1];
        if (px == x && py == y) {
            return;
        }
    }
    drawnPts.push(px);
    drawnPts.push(py);
    var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places);
    var _px = (px - srcLeft) * scale;
    var _py = (py - srcTop) * scale;
    ctx.beginPath();
    ctx.arc(_px, _py, 3, 0, Math.PI*2, true);
    ctx.closePath();
    if (end) {
        ctx.fill();
    } else {
        ctx.stroke();
    }
    if (debug_xy) {
        ctx.textAlign = "left";
        ctx.fillText(label, _px + 5, _py);
    }
}

function coordCount(curveType) {
    switch (curveType) {
        case PATH_LINE:
            return 4;
        case PATH_QUAD:
            return 6;
        case PATH_CONIC:
            return 6;
        case PATH_CUBIC:
            return 8;
    }
    return -1;
}

function drawPoints(ptArray, curveType, drawControls) {
    var count = coordCount(curveType);
    for (var idx = 0; idx < count; idx += 2) {
        if (!drawControls && idx != 0 && idx != count - 2) {
            continue;
        }
        drawPoint(ptArray[idx], ptArray[idx + 1], idx == 0 || idx == count - 2);
    }
}

function drawControlLines(curve, curveType, drawEnd) {
    if (curveType == PATH_LINE) {
        return;
    }
    ctx.strokeStyle = "rgba(0,0,0, 0.3)";
    drawLine(curve[0], curve[1], curve[2], curve[3]);
    drawLine(curve[2], curve[3], curve[4], curve[5]);
    if (curveType == PATH_CUBIC) {
        drawLine(curve[4], curve[5], curve[6], curve[7]);
        if (drawEnd > 1) {
            drawLine(curve[6], curve[7], curve[0], curve[1]);
            if (drawEnd > 2) {
                drawLine(curve[0], curve[1], curve[4], curve[5]);
                drawLine(curve[6], curve[7], curve[2], curve[3]);
            }
        }
    } else if (drawEnd > 1) {
        drawLine(curve[4], curve[5], curve[0], curve[1]);
    }
}

function pointAtT(curve, curveType, t) {
    var xy = {};
    switch (curveType) {
        case PATH_LINE:
            var a = 1 - t;
            var b = t;
            xy.x = a * curve[0] + b * curve[2];
            xy.y = a * curve[1] + b * curve[3];
            break;
        case PATH_QUAD:
            var one_t = 1 - t;
            var a = one_t * one_t;
            var b = 2 * one_t * t;
            var c = t * t;
            xy.x = a * curve[0] + b * curve[2] + c * curve[4];
            xy.y = a * curve[1] + b * curve[3] + c * curve[5];
            break;
        case PATH_CONIC:
            var one_t = 1 - t;
            var a = one_t * one_t;
            var b = 2 * one_t * t;
            var c = t * t;
            xy.x = a * curve[0] + b * curve[2] * curve[6] + c * curve[4];
            xy.y = a * curve[1] + b * curve[3] * curve[6] + c * curve[5];
            var d = a + b * curve[6] + c;
            xy.x /= d;
            xy.y /= d;
            break;
        case PATH_CUBIC:
            var one_t = 1 - t;
            var one_t2 = one_t * one_t;
            var a = one_t2 * one_t;
            var b = 3 * one_t2 * t;
            var t2 = t * t;
            var c = 3 * one_t * t2;
            var d = t2 * t;
            xy.x = a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
            xy.y = a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
            break;
    }
    return xy;
}
    
function drawPointAtT(curve, curveType) {
    var x, y;
    var xy = pointAtT(curve, curveType, curveT);
    drawPoint(xy.x, xy.y, true);
    if (!draw_intersectT) {
        return;
    }
    ctx.fillStyle = "red";
    drawTAtPointUp(xy.x, xy.y, curveT);
}

function drawTAtPointUp(px, py, t) {
    var label = t.toFixed(decimal_places);
    var _px = (px - srcLeft)* scale;
    var _py = (py - srcTop) * scale;
    ctx.fillText(label, _px + 5, _py - 10);
}

function drawTAtPointDown(px, py, t) {
    var label = t.toFixed(decimal_places);
    var _px = (px - srcLeft)* scale;
    var _py = (py - srcTop) * scale;
    ctx.fillText(label, _px + 5, _py + 10);
}

function alreadyDrawnLine(x1, y1, x2, y2) {
    if (collect_bounds) {
        if (focus_enabled) {
            focusXmin = Math.min(focusXmin, x1, x2);
            focusYmin = Math.min(focusYmin, y1, y2);
            focusXmax = Math.max(focusXmax, x1, x2);
            focusYmax = Math.max(focusYmax, y1, y2);
        }
        return true;
    }
    for (var pts = 0; pts < drawnLines.length; pts += 4) {
        if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]
                && x2 == drawnLines[pts + 2] && y2 == drawnLines[pts + 3]) {
            return true;
        }
    }
    drawnLines.push(x1);
    drawnLines.push(y1);
    drawnLines.push(x2);
    drawnLines.push(y2);
    return false;
}

function drawLine(x1, y1, x2, y2) {
    if (alreadyDrawnLine(x1, y1, x2, y2)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((x1 - srcLeft) * scale,
            (y1 - srcTop) * scale);
    ctx.lineTo((x2 - srcLeft) * scale,
            (y2 - srcTop) * scale);
    ctx.stroke();
}

function linePartial(x1, y1, x2, y2, t1, t2) {
    var dx = x1 - x2;
    var dy = y1 - y2;
    var array = [
        x1 - t1 * dx,
        y1 - t1 * dy,
        x1 - t2 * dx,
        y1 - t2 * dy
    ];
    return array;
}

function drawLinePartial(x1, y1, x2, y2, t1, t2) {
    var a = linePartial(x1, y1, x2, y2, t1, t2);
    var ax = a[0];
    var ay = a[1];
    var bx = a[2];
    var by = a[3];
    if (alreadyDrawnLine(ax, ay, bx, by)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((ax - srcLeft) * scale,
            (ay - srcTop) * scale);
    ctx.lineTo((bx - srcLeft) * scale,
            (by - srcTop) * scale);
    ctx.stroke();
}

function alreadyDrawnQuad(x1, y1, x2, y2, x3, y3) {
    if (collect_bounds) {
        if (focus_enabled) {
            focusXmin = Math.min(focusXmin, x1, x2, x3);
            focusYmin = Math.min(focusYmin, y1, y2, y3);
            focusXmax = Math.max(focusXmax, x1, x2, x3);
            focusYmax = Math.max(focusYmax, y1, y2, y3);
        }
        return true;
    }
    for (var pts = 0; pts < drawnQuads.length; pts += 6) {
        if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]
                && x2 == drawnQuads[pts + 2] && y2 == drawnQuads[pts + 3]
                && x3 == drawnQuads[pts + 4] && y3 == drawnQuads[pts + 5]) {
            return true;
        }
    }
    drawnQuads.push(x1);
    drawnQuads.push(y1);
    drawnQuads.push(x2);
    drawnQuads.push(y2);
    drawnQuads.push(x3);
    drawnQuads.push(y3);
    return false;
}

function drawQuad(x1, y1, x2, y2, x3, y3) {
    if (alreadyDrawnQuad(x1, y1, x2, y2, x3, y3)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((x1 - srcLeft) * scale,
            (y1 - srcTop) * scale);
    ctx.quadraticCurveTo((x2 - srcLeft) * scale,
            (y2 - srcTop) * scale,
            (x3 - srcLeft) * scale,
            (y3 - srcTop) * scale);
    ctx.stroke();
}

function interp(A, B, t) {
    return A + (B - A) * t;
}

function interp_quad_coords(x1, x2, x3, t)
{
    var ab = interp(x1, x2, t);
    var bc = interp(x2, x3, t);
    var abc = interp(ab, bc, t);
    return abc;
}

function quadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
    var ax = interp_quad_coords(x1, x2, x3, t1);
    var ay = interp_quad_coords(y1, y2, y3, t1);
    var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2);
    var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2);
    var cx = interp_quad_coords(x1, x2, x3, t2);
    var cy = interp_quad_coords(y1, y2, y3, t2);
    var bx = 2*dx - (ax + cx)/2;
    var by = 2*dy - (ay + cy)/2;
    var array = [
        ax, ay, bx, by, cx, cy
    ];
    return array;
}

function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
    var a = quadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
    var ax = a[0];
    var ay = a[1];
    var bx = a[2];
    var by = a[3];
    var cx = a[4];
    var cy = a[5];
    if (alreadyDrawnQuad(ax, ay, bx, by, cx, cy)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((ax - srcLeft) * scale,
            (ay - srcTop) * scale);
    ctx.quadraticCurveTo((bx - srcLeft) * scale,
            (by - srcTop) * scale,
            (cx - srcLeft) * scale,
            (cy - srcTop) * scale);
    ctx.stroke();
}

function alreadyDrawnConic(x1, y1, x2, y2, x3, y3, w) {
    if (collect_bounds) {
        if (focus_enabled) {
            focusXmin = Math.min(focusXmin, x1, x2, x3);
            focusYmin = Math.min(focusYmin, y1, y2, y3);
            focusXmax = Math.max(focusXmax, x1, x2, x3);
            focusYmax = Math.max(focusYmax, y1, y2, y3);
        }
        return true;
    }
    for (var pts = 0; pts < drawnConics.length; pts += 8) {
        if (x1 == drawnConics[pts] && y1 == drawnCubics[pts + 1]
                && x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3] 
                && x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5] 
                && w == drawnCubics[pts + 6]) {
            return true;
        }
    }
    drawnConics.push(x1);
    drawnConics.push(y1);
    drawnConics.push(x2);
    drawnConics.push(y2);
    drawnConics.push(x3);
    drawnConics.push(y3);
    drawnCubics.push(w);
    return false;
}

var kMaxConicToQuadPOW2 = 5;

function computeQuadPOW2(curve, tol) {
    var a = curve[6] - 1;
    var k = a / (4 * (2 + a));
    var x = k * (curve[0] - 2 * curve[2] + curve[4]);
    var y = k * (curve[1] - 2 * curve[3] + curve[5]);

    var error = Math.sqrt(x * x + y * y);
    var pow2;
    for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) {
        if (error <= tol) {
            break;
        }
        error *= 0.25;
    }
    return pow2;
}

function subdivide_w_value(w) {
    return Math.sqrt(0.5 + w * 0.5);
}

function chop(curve, part1, part2) {
    var w = curve[6];
    var scale = 1 / (1 + w);
    part1[0] = curve[0];
    part1[1] = curve[1];
    part1[2] = (curve[0] + curve[2] * w) * scale;
    part1[3] = (curve[1] + curve[3] * w) * scale;
    part1[4] = part2[0] = (curve[0] + (curve[2] * w) * 2 + curve[4]) * scale * 0.5;
    part1[5] = part2[1] = (curve[1] + (curve[3] * w) * 2 + curve[5]) * scale * 0.5;
    part2[2] = (curve[2] * w + curve[4]) * scale;
    part2[3] = (curve[3] * w + curve[5]) * scale;
    part2[4] = curve[4];
    part2[5] = curve[5];
    part1[6] = part2[6] = subdivide_w_value(w);
}

function subdivide(curve, level, pts) {
    if (0 == level) {
        pts.push(curve[2]);
        pts.push(curve[3]);
        pts.push(curve[4]);
        pts.push(curve[5]);
    } else {
        var part1 = [], part2 = [];
        chop(curve, part1, part2);
        --level;
        subdivide(part1, level, pts);
        subdivide(part2, level, pts);
    }
}

function chopIntoQuadsPOW2(curve, pow2, pts) {
    subdivide(curve, pow2, pts);
    return 1 << pow2;
}

function drawConicWithQuads(x1, y1, x2, y2, x3, y3, w) {
    if (alreadyDrawnConic(x1, y1, x2, y2, x3, y3, w)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((x1 - srcLeft) * scale,
            (y1 - srcTop) * scale);
    var tol = 1 / scale;
    var curve = [x1, y1, x2, y2, x3, y3, w];
    var pow2 = computeQuadPOW2(curve, tol);
    var pts = [];
    chopIntoQuadsPOW2(curve, pow2, pts);
    for (var i = 0; i < pts.length; i += 4) {
        ctx.quadraticCurveTo(
            (pts[i + 0] - srcLeft) * scale, (pts[i + 1] - srcTop) * scale,
            (pts[i + 2] - srcLeft) * scale, (pts[i + 3] - srcTop) * scale);
    }
    ctx.stroke();
}

function conic_eval_numerator(x1, x2, x3, w, t) {
    var src2w = x2 * w;
    var C = x1;
    var A = x3 - 2 * src2w + C;
    var B = 2 * (src2w - C);
    return (A * t + B) * t + C;
}


function conic_eval_denominator(w, t) {
    var B = 2 * (w - 1);
    var C = 1;
    var A = -B;
    return (A * t + B) * t + C;
}

function conicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2) {
    var ax = conic_eval_numerator(x1, x2, x3, w, t1);
    var ay = conic_eval_numerator(y1, y2, y3, w, t1);
    var az = conic_eval_denominator(w, t1);
    var midT = (t1 + t2) / 2;
    var dx = conic_eval_numerator(x1, x2, x3, w, midT);
    var dy = conic_eval_numerator(y1, y2, y3, w, midT);
    var dz = conic_eval_denominator(w, midT);
    var cx = conic_eval_numerator(x1, x2, x3, w, t2);
    var cy = conic_eval_numerator(y1, y2, y3, w, t2);
    var cz = conic_eval_denominator(w, t2);
    var bx = 2 * dx - (ax + cx) / 2;
    var by = 2 * dy - (ay + cy) / 2;
    var bz = 2 * dz - (az + cz) / 2;
    var dt = t2 - t1;
    var dt_1 = 1 - dt;
    var partW = (1 + dt * (w - 1)) / Math.sqrt(dt * dt + 2 * dt * dt_1 * w + dt_1 * dt_1);
    var array = [
        ax / az, ay / az, bx / bz, by / bz, cx / cz, cy / cz, partW
    ];
    return array;
}
    
function drawConicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2) {
    var a = conicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2);
    var ax = a[0];
    var ay = a[1];
    var bx = a[2];
    var by = a[3];
    var cx = a[4];
    var cy = a[5];
    var w_ = a[6];
    drawConicWithQuads(ax, ay, bx, by, cx, cy, w_);
}

function alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
    if (collect_bounds) {
        if (focus_enabled) {
            focusXmin = Math.min(focusXmin, x1, x2, x3, x4);
            focusYmin = Math.min(focusYmin, y1, y2, y3, y4);
            focusXmax = Math.max(focusXmax, x1, x2, x3, x4);
            focusYmax = Math.max(focusYmax, y1, y2, y3, y4);
        }
        return true;
    }
    for (var pts = 0; pts < drawnCubics.length; pts += 8) {
        if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]
                && x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3] 
                && x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5] 
                && x4 == drawnCubics[pts + 6] && y4 == drawnCubics[pts + 7]) {
            return true;
        }
    }
    drawnCubics.push(x1);
    drawnCubics.push(y1);
    drawnCubics.push(x2);
    drawnCubics.push(y2);
    drawnCubics.push(x3);
    drawnCubics.push(y3);
    drawnCubics.push(x4);
    drawnCubics.push(y4);
    return false;
}

function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
    if (alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((x1 - srcLeft) * scale,
            (y1 - srcTop) * scale);
    ctx.bezierCurveTo((x2 - srcLeft) * scale,
            (y2 - srcTop) * scale,
            (x3 - srcLeft) * scale,
            (y3 - srcTop) * scale,
            (x4 - srcLeft) * scale,
            (y4 - srcTop) * scale);
    ctx.stroke();
}

function interp_cubic_coords(x1, x2, x3, x4, t)
{
    var ab = interp(x1, x2, t);
    var bc = interp(x2, x3, t);
    var cd = interp(x3, x4, t);
    var abc = interp(ab, bc, t);
    var bcd = interp(bc, cd, t);
    var abcd = interp(abc, bcd, t);
    return abcd;
}

function cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
    var ax = interp_cubic_coords(x1, x2, x3, x4, t1);
    var ay = interp_cubic_coords(y1, y2, y3, y4, t1);
    var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3);
    var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3);
    var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3);
    var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3);
    var dx = interp_cubic_coords(x1, x2, x3, x4, t2);
    var dy = interp_cubic_coords(y1, y2, y3, y4, t2);
    var mx = ex * 27 - ax * 8 - dx;
    var my = ey * 27 - ay * 8 - dy;
    var nx = fx * 27 - ax - dx * 8;
    var ny = fy * 27 - ay - dy * 8;
    var bx = (mx * 2 - nx) / 18;
    var by = (my * 2 - ny) / 18;
    var cx = (nx * 2 - mx) / 18;
    var cy = (ny * 2 - my) / 18;
    var array = [
        ax, ay, bx, by, cx, cy, dx, dy
    ];
    return array;
}
    
function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
    var a = cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
    var ax = a[0];
    var ay = a[1];
    var bx = a[2];
    var by = a[3];
    var cx = a[4];
    var cy = a[5];
    var dx = a[6];
    var dy = a[7];
    if (alreadyDrawnCubic(ax, ay, bx, by, cx, cy, dx, dy)) {
        return;
    }
    ctx.beginPath();
    ctx.moveTo((ax - srcLeft) * scale,
            (ay - srcTop) * scale);
    ctx.bezierCurveTo((bx - srcLeft) * scale,
            (by - srcTop) * scale,
            (cx - srcLeft) * scale,
            (cy - srcTop) * scale,
            (dx - srcLeft) * scale,
            (dy - srcTop) * scale);
    ctx.stroke();
}

function drawCurve(c) {
    switch (c.length) {
        case 4:
            drawLine(c[0], c[1], c[2], c[3]);
            break;
        case 6:
            drawQuad(c[0], c[1], c[2], c[3], c[4], c[5]);
            break;
        case 7:
            drawConicWithQuads(c[0], c[1], c[2], c[3], c[4], c[5], c[6]);
            break;
        case 8:
            drawCubic(c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
            break;
    }
}

function boundsWidth(pts) {
    var min = pts[0];
    var max = pts[0];
    var length = pts.length == 7 ? 6 : pts.length;
    for (var idx = 2; idx < length; idx += 2) {
        min = Math.min(min, pts[idx]);
        max = Math.max(max, pts[idx]);
    }
    return max - min;
}

function boundsHeight(pts) {
    var min = pts[1];
    var max = pts[1];
    var length = pts.length == 7 ? 6 : pts.length;
    for (var idx = 3; idx < length; idx += 2) {
        min = Math.min(min, pts[idx]);
        max = Math.max(max, pts[idx]);
    }
    return max - min;
}

function tangent(pts) {
    var dx = pts[2] - pts[0];
    var dy = pts[3] - pts[1];
    if (dx == 0 && dy == 0 && pts.length > 4) {
        dx = pts[4] - pts[0];
        dy = pts[5] - pts[1];
        if (dx == 0 && dy == 0 && pts.length == 8) {
            dx = pts[6] - pts[0];
            dy = pts[7] - pts[1];
        }
    }
    return Math.atan2(-dy, dx);
}

function hodograph(cubic) {
    var hodo = [];
    hodo[0] = 3 * (cubic[2] - cubic[0]);
    hodo[1] = 3 * (cubic[3] - cubic[1]);
    hodo[2] = 3 * (cubic[4] - cubic[2]);
    hodo[3] = 3 * (cubic[5] - cubic[3]);
    hodo[4] = 3 * (cubic[6] - cubic[4]);
    hodo[5] = 3 * (cubic[7] - cubic[5]);
    return hodo;
}

function hodograph2(cubic) {
    var quad = hodograph(cubic);
    var hodo = [];
    hodo[0] = 2 * (quad[2] - quad[0]);
    hodo[1] = 2 * (quad[3] - quad[1]);
    hodo[2] = 2 * (quad[4] - quad[2]);
    hodo[3] = 2 * (quad[5] - quad[3]);
    return hodo;
}

function quadraticRootsReal(A, B, C, s) {
    if (A == 0) {
        if (B == 0) {
            s[0] = 0;
            return C == 0;
        }
        s[0] = -C / B;
        return 1;
    }
    /* normal form: x^2 + px + q = 0 */
    var p = B / (2 * A);
    var q = C / A;
    var p2 = p * p;
    if (p2 < q) {
        return 0;
    }
    var sqrt_D = 0;
    if (p2 > q) {
        sqrt_D = sqrt(p2 - q);
    }
    s[0] = sqrt_D - p;
    s[1] = -sqrt_D - p;
    return 1 + s[0] != s[1];
}

function add_valid_ts(s, realRoots, t) {
    var foundRoots = 0;
    for (var index = 0; index < realRoots; ++index) {
        var tValue = s[index];
        if (tValue >= 0 && tValue <= 1) {
            for (var idx2 = 0; idx2 < foundRoots; ++idx2) {
                if (t[idx2] != tValue) {
                    t[foundRoots++] = tValue;
                }
            }
        }
    }
    return foundRoots;
}

function quadraticRootsValidT(a, b, c, t) {
    var s = [];
    var realRoots = quadraticRootsReal(A, B, C, s);
    var foundRoots = add_valid_ts(s, realRoots, t);
    return foundRoots != 0;
}

function find_cubic_inflections(cubic, tValues) {
    var Ax = src[2] - src[0];
    var Ay = src[3] - src[1];
    var Bx = src[4] - 2 * src[2] + src[0];
    var By = src[5] - 2 * src[3] + src[1];
    var Cx = src[6] + 3 * (src[2] - src[4]) - src[0];
    var Cy = src[7] + 3 * (src[3] - src[5]) - src[1];
    return quadraticRootsValidT(Bx * Cy - By * Cx, (Ax * Cy - Ay * Cx),
            Ax * By - Ay * Bx, tValues);
}

function dxy_at_t(curve, type, t) {
    var dxy = {};
    if (type == PATH_QUAD) {
        var a = t - 1;
        var b = 1 - 2 * t;
        var c = t;
        dxy.x = a * curve[0] + b * curve[2] + c * curve[4];
        dxy.y = a * curve[1] + b * curve[3] + c * curve[5];
    } else if (type == PATH_CONIC) {
        var p20x = curve[4] - curve[0];
        var p20y = curve[5] - curve[1];
        var p10xw = (curve[2] - curve[0]) * curve[6];
        var p10yw = (curve[3] - curve[1]) * curve[6];
        var coeff0x = curve[6] * p20x - p20x;
        var coeff0y = curve[6] * p20y - p20y;
        var coeff1x = p20x - 2 * p10xw;
        var coeff1y = p20y - 2 * p10yw;
        dxy.x = t * (t * coeff0x + coeff1x) + p10xw;
        dxy.y = t * (t * coeff0y + coeff1y) + p10yw;
    } else if (type == PATH_CUBIC) {
        var one_t = 1 - t;
        var a = curve[0];
        var b = curve[2];
        var c = curve[4];
        var d = curve[6];
        dxy.x = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
        a = curve[1];
        b = curve[3];
        c = curve[5];
        d = curve[7];
        dxy.y = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
    }
    return dxy;
}

function drawLabel(num, px, py) {
    ctx.beginPath();
    ctx.arc(px, py, 8, 0, Math.PI*2, true);
    ctx.closePath();
    ctx.strokeStyle = "rgba(0,0,0, 0.4)";
    ctx.lineWidth = num == 0 || num == 3 ? 2 : 1;
    ctx.stroke();
    ctx.fillStyle = "black";
    ctx.font = "normal 10px Arial";
  //  ctx.rotate(0.001);
    ctx.fillText(num, px - 2, py + 3);
  //  ctx.rotate(-0.001);
}

function drawLabelX(ymin, num, loc) {
    var px = (loc - srcLeft) * scale;
    var py = (ymin - srcTop) * scale - 20;
    drawLabel(num, px, py);
}

function drawLabelY(xmin, num, loc) {
    var px = (xmin - srcLeft) * scale - 20;
    var py = (loc - srcTop) * scale;
    drawLabel(num, px, py);
}

function drawHodoOrigin(hx, hy, hMinX, hMinY, hMaxX, hMaxY) {
    ctx.beginPath();
    ctx.moveTo(hx, hy - 100);
    ctx.lineTo(hx, hy);
    ctx.strokeStyle = hMinY < 0 ? "green" : "blue";
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(hx, hy);
    ctx.lineTo(hx, hy + 100);
    ctx.strokeStyle = hMaxY > 0 ? "green" : "blue";
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(hx - 100, hy);
    ctx.lineTo(hx, hy);
    ctx.strokeStyle = hMinX < 0 ? "green" : "blue";
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(hx, hy);
    ctx.lineTo(hx + 100, hy);
    ctx.strokeStyle = hMaxX > 0 ? "green" : "blue";
    ctx.stroke();
}

function scalexy(x, y, mag) {
    var length = Math.sqrt(x * x + y * y);
    return mag / length;
}

function drawArrow(x, y, dx, dy, s) {
    var dscale = scalexy(dx, dy, 1 / scale * 100 * s);
    dx *= dscale;
    dy *= dscale;
    ctx.beginPath();
    ctx.moveTo((x - srcLeft) * scale, (y - srcTop) * scale);
    x += dx;
    y += dy;
    ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
    dx /= 10;
    dy /= 10;
    ctx.lineTo((x - dy - srcLeft) * scale, (y + dx - srcTop) * scale);
    ctx.lineTo((x + dx * 2 - srcLeft) * scale, (y + dy * 2 - srcTop) * scale);
    ctx.lineTo((x + dy - srcLeft) * scale, (y - dx - srcTop) * scale);
    ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
    ctx.strokeStyle = "rgba(0,75,0, 0.4)";
    ctx.stroke();
}

function x_at_t(curve, t) {
    var one_t = 1 - t;
    if (curve.length == 4) {
        return one_t * curve[0] + t * curve[2];
    }
    var one_t2 = one_t * one_t;
    var t2 = t * t;
    if (curve.length == 6) {
        return one_t2 * curve[0] + 2 * one_t * t * curve[2] + t2 * curve[4];
    }
    if (curve.length == 7) {
        return (one_t2 * curve[0] + 2 * one_t * t * curve[2] * curve[6] + t2 * curve[4])
                / (one_t2 +2 * one_t * t * curve[6] + t2);
    }
    var a = one_t2 * one_t;
    var b = 3 * one_t2 * t;
    var c = 3 * one_t * t2;
    var d = t2 * t;
    return a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
}

function y_at_t(curve, t) {
    var one_t = 1 - t;
    if (curve.length == 4) {
        return one_t * curve[1] + t * curve[3];
    }
    var one_t2 = one_t * one_t;
    var t2 = t * t;
    if (curve.length == 6) {
        return one_t2 * curve[1] + 2 * one_t * t * curve[3] + t2 * curve[5];
    }
    if (curve.length == 7) {
        return (one_t2 * curve[1] + 2 * one_t * t * curve[3] * curve[6] + t2 * curve[5])
                / (one_t2 +2 * one_t * t * curve[6] + t2);
    }
    var a = one_t2 * one_t;
    var b = 3 * one_t2 * t;
    var c = 3 * one_t * t2;
    var d = t2 * t;
    return a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
}

function drawOrder(curve, label) {
    var px = x_at_t(curve, 0.75);
    var py = y_at_t(curve, 0.75);
    var _px = (px - srcLeft) * scale;
    var _py = (py - srcTop) * scale;
    ctx.beginPath();
    ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.fillStyle = "white";
    ctx.fill();
    if (label == 'L') {
        ctx.strokeStyle = "rgba(255,0,0, 1)";
        ctx.fillStyle = "rgba(255,0,0, 1)";
    } else {
        ctx.strokeStyle = "rgba(0,0,255, 1)";
        ctx.fillStyle = "rgba(0,0,255, 1)";
    }
    ctx.stroke();
    ctx.font = "normal 16px Arial";
    ctx.textAlign = "center";
    ctx.fillText(label, _px, _py + 5);
    ctx.font = "normal 10px Arial";
}

function drawID(curve, id) {
    var px = x_at_t(curve, 0.5);
    var py = y_at_t(curve, 0.5);
    var _px = (px - srcLeft) * scale;
    var _py = (py - srcTop) * scale;
    draw_id_at(id, _px, _py);
}

function draw_id_at(id, _px, _py) {
    ctx.beginPath();
    ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.fillStyle = "white";
    ctx.fill();
    ctx.strokeStyle = "rgba(127,127,0, 1)";
    ctx.fillStyle = "rgba(127,127,0, 1)";
    ctx.stroke();
    ctx.font = "normal 16px Arial";
    ctx.textAlign = "center";
    ctx.fillText(id, _px, _py + 5);
    ctx.font = "normal 10px Arial";
}

function drawLinePartialID(id, x1, y1, x2, y2, t1, t2) {
    var curve = [x1, y1, x2, y2];
    drawCurvePartialID(id, curve, t1, t2);
}

function drawQuadPartialID(id, x1, y1, x2, y2, x3, y3, t1, t2) {
    var curve = [x1, y1, x2, y2, x3, y3];
    drawCurvePartialID(id, curve, t1, t2);
}

function drawConicPartialID(id, x1, y1, x2, y2, x3, y3, w, t1, t2) {
    var curve = [x1, y1, x2, y2, x3, y3, w];
    drawCurvePartialID(id, curve, t1, t2);
}

function drawCubicPartialID(id, x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
    var curve = [x1, y1, x2, y2, x3, y3, x4, y4];
    drawCurvePartialID(id, curve, t1, t2);
}

function  drawCurvePartialID(id, curve, t1, t2) {
    var px = x_at_t(curve, (t1 + t2) / 2);
    var py = y_at_t(curve, (t1 + t2) / 2);
    var _px = (px - srcLeft) * scale;
    var _py = (py - srcTop) * scale;
    draw_id_at(id, _px, _py);
}

function drawCurveSpecials(test, curve, type) {
    if (pt_labels) {
        drawPoints(curve, type, pt_labels == 2);
    }
    if (control_lines != 0) {
        drawControlLines(curve, type, control_lines);
    }
    if (curve_t) {
        drawPointAtT(curve, type);
    }
    if (draw_midpoint) {
        var mid = pointAtT(curve, type, 0.5);
        drawPoint(mid.x, mid.y, true);
    }
    if (draw_id) {
        var id = idByCurve(test, curve, type);
        if (id >= 0) {
            drawID(curve, id);
        }
    }
    if (type == PATH_LINE) {
        return;
    }
    if (draw_deriviatives > 0) {
        var d = dxy_at_t(curve, type, 0);
        drawArrow(curve[0], curve[1], d.x, d.y, 1);
        if (draw_deriviatives == 2) {
            d = dxy_at_t(curve, type, 1);
            if (type == PATH_CUBIC) {
                drawArrow(curve[6], curve[7], d.x, d.y, 1);
            } else {
                drawArrow(curve[4], curve[5], d.x, d.y, 1);
            }
        }
        if (draw_midpoint) {
            var mid = pointAtT(curve, type, 0.5);
            d = dxy_at_t(curve, type, 0.5);
            drawArrow(mid.x, mid.y, d.x, d.y, 1);
        }
    }
    if (type != PATH_CUBIC) {
        return;
    }
    if (draw_sequence) {
        var ymin = Math.min(curve[1], curve[3], curve[5], curve[7]);
        for (var i = 0; i < 8; i+= 2) {
            drawLabelX(ymin, i >> 1, curve[i]);
        }
        var xmin = Math.min(curve[0], curve[2], curve[4], curve[6]);
        for (var i = 1; i < 8; i+= 2) {
            drawLabelY(xmin, i >> 1, curve[i]);
        }
    }
}

function logCurves(test) {
    for (curves in test) {
        var curve = test[curves];
        dumpCurve(curve);
    }
}

function curveToString(curve) {
    var str = "{{";
    var length = curve.length == 7 ? 6 : curve.length;
    if (curve.length == 7) {
        str += "{";
    }
    for (i = 0; i < length; i += 2) {
        str += curve[i].toFixed(decimal_places) + "," + curve[i + 1].toFixed(decimal_places);
        if (i < curve.length - 2) {
            str += "}, {";
        }
    }
    str += "}";
    if (curve.length == 7) {
        str += "}, " + curve[6].toFixed(decimal_places);
    }
    str += "}";
    return str;
}

function dumpCurve(curve) {
    console.log(curveToString(curve));
}

function draw(test, lines, title) {
    ctx.fillStyle = "rgba(0,0,0, 0.1)";
    ctx.font = "normal 50px Arial";
    ctx.textAlign = "left";
    ctx.fillText(title, 50, 50);
    ctx.font = "normal 10px Arial";
    ctx.lineWidth = "1.001"; "0.999";
    var secondPath = test.length;
    var closeCount = 0;
    logStart = -1;
    logRange = 0;
    // find last active rec type at this step
    var curType = test[0];
    var curStep = 0;
    var hasOp = false;
    var lastActive = 0;
    var lastAdd = 0;
    var lastCoin = 0;
    var lastSect = 0;
    var lastSort = 0;
    var lastMark = 0;
    var lastTop = 0;
    activeCount = 0;
    addCount = 0;
    angleCount = 0;
    opCount = 0;
    sectCount = 0;
    sortCount = 0;
    topCount = 0;
    markCount = 0;
    activeMax = 0;
    addMax = 0;
    angleMax = 0;
    coinMax = 0;
    opMax = 0;
    sectMax = 0;
    sectMax2 = 0;
    sortMax = 0;
    topMax = 0;
    markMax = 0;
    lastIndex = test.length - 3;
    for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
        var recType = test[tIndex];
        if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
            console.log("unknown rec type: " + recType);
            throw "stop execution";
        }
   //     if (curType == recType && curType != REC_TYPE_ADD) {
   //         continue;
   //     }
        var inStepRange = step_limit == 0 || curStep < step_limit;
        curType = recType;
        if (recType == REC_TYPE_OP) {
            hasOp = true;
            continue;
        }
        if (recType == REC_TYPE_UNKNOWN) {
            // these types do not advance step
            continue;
        }
        var bumpStep = false;
        var records = test[tIndex + 2];
        var fragType = records[0];
        if (recType == REC_TYPE_ADD) {
            if (records.length != 2) {
                console.log("expect only two elements: " + records.length);
                throw "stop execution";
            }
            if (fragType == ADD_MOVETO || fragType == ADD_CLOSE) {
                continue;
            }
            ++addMax;
            if (!draw_add || !inStepRange) {
                continue;
            }
            lastAdd = tIndex;
            ++addCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_PATH && hasOp) {
            secondPath = tIndex;
        }
        if (recType == REC_TYPE_PATH2 && hasOp) {
            secondPath = tIndex;
        }
        if (recType == REC_TYPE_ACTIVE) {
            ++activeMax;
            if (!draw_active || !inStepRange) {
                continue;
            }
            lastActive = tIndex;
            ++activeCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_ACTIVE_OP) {
            ++opMax;
            if (!draw_op || !inStepRange) {
                continue;
            }
            lastOp = tIndex;
            ++opCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_AFTERPART) {
            if (draw_angle != 3 || !inStepRange) {
                continue;
            }
            lastAngle = tIndex;
            ++angleCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_ANGLE) {
            ++angleMax;
            if (draw_angle == 0 || draw_angle == 3 || !inStepRange) {
                continue;
            }
            lastAngle = tIndex;
            ++angleCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_COINCIDENCE) {
            ++coinMax;
            if (!draw_coincidence || !inStepRange) {
                continue;
            }
            lastCoin = tIndex;
            ++coinCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_SECT) {
            if (records.length != 2) {
                console.log("expect only two elements: " + records.length);
                throw "stop execution";
            }
            ++sectMax;
            var sectBump = 1;
            switch (fragType) {
                case INTERSECT_LINE:
                case INTERSECT_QUAD_LINE:
                case INTERSECT_QUAD:
                case INTERSECT_CONIC_LINE:
                case INTERSECT_CONIC:
                case INTERSECT_SELF_CUBIC:
                case INTERSECT_CUBIC_LINE:
                case INTERSECT_CUBIC_QUAD:
                case INTERSECT_CUBIC:
                    sectBump = 1;
                    break;
                case INTERSECT_LINE_2:
                case INTERSECT_QUAD_LINE_2:
                case INTERSECT_QUAD_2:
                case INTERSECT_CONIC_LINE_2:
                case INTERSECT_CONIC_2:
                case INTERSECT_CUBIC_LINE_2:
                case INTERSECT_CUBIC_QUAD_2:
                case INTERSECT_CUBIC_2:
                    sectBump = 2;
                    break;
                case INTERSECT_LINE_NO:
                case INTERSECT_QUAD_LINE_NO:
                case INTERSECT_QUAD_NO:
                case INTERSECT_CONIC_LINE_NO:
                case INTERSECT_CONIC_NO:
                case INTERSECT_SELF_CUBIC_NO:
                case INTERSECT_CUBIC_LINE_NO:
                case INTERSECT_CUBIC_QUAD_NO:
                case INTERSECT_CUBIC_NO:
                    sectBump = 0;
                    break;
                case INTERSECT_CUBIC_LINE_3:
                case INTERSECT_CUBIC_QUAD_3:
                case INTERSECT_CUBIC_3:
                    sectBump = 3;
                    break;
                case INTERSECT_CUBIC_QUAD_4:
                case INTERSECT_CUBIC_4:
                    sectBump = 4;
                    break;
                default:
                    console.log("missing case " + records.length);
                    throw "stop execution";
            }
            sectMax2 += sectBump;
            if (draw_intersection <= 1 || !inStepRange) {
                continue;
            }
            lastSect = tIndex;
            sectCount += sectBump;
            bumpStep = true;
        }
        if (recType == REC_TYPE_SORT) {
            ++sortMax;
            if (!draw_sort || !inStepRange) {
                continue;
            }
            lastSort = tIndex;
            ++sortCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_TOP) {
            ++topMax;
            if (!draw_top || !inStepRange) {
                continue;
            }
            lastTop = tIndex;
            ++topCount;
            bumpStep = true;
        }
        if (recType == REC_TYPE_MARK) {
            ++markMax;
            if (!draw_mark || !inStepRange) {
                continue;
            }
            lastMark = tIndex;
            ++markCount;
            bumpStep = true;
        }
        if (bumpStep) {
            lastIndex = tIndex;
            logStart = test[tIndex + 1];
            logRange = records.length / 2;
            ++curStep;
        }
    }
    stepMax = (draw_add ? addMax : 0)
            + (draw_active ? activeMax : 0)
            + (draw_angle ? angleMax : 0)
            + (draw_coincidence ? coinMax : 0)
            + (draw_op ? opMax : 0)
            + (draw_sort ? sortMax : 0)
            + (draw_top ? topMax : 0)
            + (draw_mark ? markMax : 0)
            + (draw_intersection == 2 ? sectMax : draw_intersection == 3 ? sectMax2 : 0);
    if (stepMax == 0) {
        stepMax = addMax + activeMax + angleMax + coinMax + opMax + sortMax + topMax + markMax;
    }
    drawnPts = [];
    drawnLines = [];
    drawnQuads = [];
    drawnConics = [];
    drawnCubics = [];
    focusXmin = focusYmin = Infinity;
    focusXmax = focusYmax = -Infinity;
    var pathIndex = 0;
    var opLetter = 'S';
    for (var tIndex = lastIndex; tIndex >= 0; tIndex -= 3) {
        var recType = test[tIndex];
        var records = test[tIndex + 2];
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
                console.log("unknown in range frag type: " + fragType);
                throw "stop execution";
            }
            var frags = records[recordIndex + 1];
            focus_enabled = false;
            switch (recType) {
                case REC_TYPE_COMPUTED:
                    if (draw_computed == 0) {
                        continue;
                    }
                    ctx.lineWidth = 1;
                    ctx.strokeStyle = pathIndex == 0 ? "black" : "red";
                    ctx.fillStyle = "blue";
                    var drawThis = false;
                    switch (fragType) {
                        case PATH_QUAD:
                            if ((draw_computed & 0x9) == 1 || ((draw_computed & 8) != 0
                                    && (draw_computed & 7) == pathIndex)) {
                                drawQuad(frags[0], frags[1], frags[2], frags[3],
                                        frags[4], frags[5]);
                                drawThis = true;
                            }
                            break;
                        case PATH_CONIC:
                            if ((draw_computed & 0xA) == 2 || ((draw_computed & 8) != 0
                                    && (draw_computed & 7) == pathIndex)) {
                                drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
                                        frags[4], frags[5], frags[6]);
                                drawThis = true;
                            }
                            break;
                        case PATH_CUBIC:
                            if ((draw_computed & 0xC) == 4 || ((draw_computed & 8) != 0
                                     && (draw_computed & 7) == pathIndex)) {
                                drawCubic(frags[0], frags[1], frags[2], frags[3],
                                        frags[4], frags[5], frags[6], frags[7]);
                                drawThis = true;
                            }
                            ++pathIndex;
                            break;
                        case COMPUTED_SET_1:
                            pathIndex = 0;
                            break;
                        case COMPUTED_SET_2:
                            pathIndex = 1;
                            break;
                        default:
                            console.log("unknown REC_TYPE_COMPUTED frag type: " + fragType);
                            throw "stop execution";
                    }
                    if (!drawThis || collect_bounds) {
                        break;
                    }
                    drawCurveSpecials(test, frags, fragType);
                    break;
                case REC_TYPE_PATH:
                case REC_TYPE_PATH2:
                    if (!draw_path) {
                        continue;
                    }
                    var firstPath = tIndex < secondPath;
                    if ((draw_path & (firstPath ? 1 : 2)) == 0) {
                        continue;
                    }
                    ctx.lineWidth = 1;
                    ctx.strokeStyle = firstPath ? "black" : "red";
                    ctx.fillStyle = "blue";
                    var frags2 = []; 
                    switch (fragType) {
                        case PATH_LINE:
                            for (var i = 0; i < 4; ++ i) { frags2[i] = frags[i + 1]; }
                            drawLine(frags2[0], frags2[1], frags2[2], frags2[3]);
                            break;
                        case PATH_QUAD:
                            for (var i = 0; i < 6; ++ i) { frags2[i] = frags[i + 1]; }
                            drawQuad(frags2[0], frags2[1], frags2[2], frags2[3],
                                    frags2[4], frags2[5]);
                            break;
                        case PATH_CONIC:
                            for (var i = 0; i < 7; ++ i) { frags2[i] = frags[i + 1]; }
                            drawConicWithQuads(frags2[0], frags2[1], frags2[2], frags2[3],
                                    frags2[4], frags2[5], frags2[6]);
                            break;
                        case PATH_CUBIC:
                            for (var i = 0; i < 8; ++ i) { frags2[i] = frags[i + 1]; }
                            drawCubic(frags2[0], frags2[1], frags2[2], frags2[3],
                                    frags2[4], frags2[5], frags2[6], frags2[7]);
                            break;
                        default:
                            console.log("unknown REC_TYPE_PATH2 frag type: " + fragType);
                            throw "stop execution";
                    }
                    if (collect_bounds) {
                        break;
                    }
                    drawCurveSpecials(test, frags2, fragType);
                    break;
                case REC_TYPE_OP:
                    switch (fragType) {
                        case OP_INTERSECT: opLetter = 'I'; break;
                        case OP_DIFFERENCE: opLetter = 'D'; break;
                        case OP_UNION: opLetter = 'U'; break;
                        case OP_XOR: opLetter = 'X'; break;
                        default:
                            console.log("unknown REC_TYPE_OP frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_ACTIVE:
                    if (!draw_active || (step_limit > 0 && tIndex < lastActive)) {
                        continue;
                    }
                    var x1 = frags[SPAN_X1];
                    var y1 = frags[SPAN_Y1];
                    var x2 = frags[SPAN_X2];
                    var y2 = frags[SPAN_Y2];
                    var x3, y3, x3, y4, t1, t2, w;
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = "rgba(0,0,255, 0.3)";
                    focus_enabled = true;
                    switch (fragType) {
                        case ACTIVE_LINE_SPAN:
                            t1 = frags[SPAN_L_T];
                            t2 = frags[SPAN_L_TEND];
                            drawLinePartial(x1, y1, x2, y2, t1, t2);
                            if (draw_id) {
                                drawLinePartialID(frags[0], x1, y1, x2, y2, t1, t2);
                            }
                             break;
                        case ACTIVE_QUAD_SPAN:
                            x3 = frags[SPAN_X3];
                            y3 = frags[SPAN_Y3];
                            t1 = frags[SPAN_Q_T];
                            t2 = frags[SPAN_Q_TEND];
                            drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
                            if (draw_id) {
                                drawQuadPartialID(frags[0], x1, y1, x2, y2, x3, y3, t1, t2);
                            }
                            break;
                        case ACTIVE_CONIC_SPAN:
                            x3 = frags[SPAN_X3];
                            y3 = frags[SPAN_Y3];
                            t1 = frags[SPAN_K_T];
                            t2 = frags[SPAN_K_TEND];
                            w = frags[SPAN_K_W];
                            drawConicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2);
                            if (draw_id) {
                                drawConicPartialID(frags[0], x1, y1, x2, y2, x3, y3, w, t1, t2);
                            }
                            break;
                        case ACTIVE_CUBIC_SPAN:
                            x3 = frags[SPAN_X3];
                            y3 = frags[SPAN_Y3];
                            x4 = frags[SPAN_X4];
                            y4 = frags[SPAN_Y4];
                            t1 = frags[SPAN_C_T];
                            t2 = frags[SPAN_C_TEND];
                            drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
                            if (draw_id) {
                                drawCubicPartialID(frags[0], x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
                            }
                            break;
                        default:
                            console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_ACTIVE_OP:
                    if (!draw_op || (step_limit > 0 && tIndex < lastOp)) {
                        continue;
                    }
                    focus_enabled = true;
                    ctx.lineWidth = 3;
                    var activeSpan = frags[7] == "1";
                    ctx.strokeStyle = activeSpan ? "rgba(45,160,0, 0.3)" : "rgba(255,45,0, 0.5)";
                    var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                    drawCurve(curve);
                    if (draw_op > 1) {
                        drawArc(curve, false, frags[3], frags[4]);
                        drawArc(curve, true, frags[5], frags[6]);
                    }
                    break;
                case REC_TYPE_ADD:
                    if (!draw_add) {
                        continue;
                    }
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = closeCount == 0 ? "rgba(0,0,255, 0.3)"
                            : closeCount == 1 ? "rgba(0,127,0, 0.3)"
                            : closeCount == 2 ? "rgba(0,127,127, 0.3)"
                            : closeCount == 3 ? "rgba(127,127,0, 0.3)"
                            : "rgba(127,0,127, 0.3)";
                    focus_enabled = true;
                    switch (fragType) {
                        case ADD_MOVETO:
                            break;
                        case ADD_LINETO:
                            if (step_limit == 0 || tIndex >= lastAdd) {
                                drawLine(frags[0], frags[1], frags[2], frags[3]);
                            }
                            break;
                        case ADD_QUADTO:
                            if (step_limit == 0 || tIndex >= lastAdd) {
                                drawQuad(frags[0], frags[1], frags[2], frags[3], frags[4], frags[5]);
                            }
                            break;
                        case ADD_CONICTO:
                            if (step_limit == 0 || tIndex >= lastAdd) {
                                drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
                                        frags[4], frags[5], frags[6]);
                            }
                            break;
                        case ADD_CUBICTO:
                            if (step_limit == 0 || tIndex >= lastAdd) {
                                drawCubic(frags[0], frags[1], frags[2], frags[3],
                                        frags[4], frags[5], frags[6], frags[7]);
                            }
                            break;
                        case ADD_CLOSE:
                            ++closeCount;
                            break;
                        case ADD_FILL:
                            break;
                        default:
                            console.log("unknown REC_TYPE_ADD frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_ANGLE:
                    angleBetween = frags[18] == "T";
                    afterIndex = 0;
                    if (draw_angle == 0 || draw_angle == 3 || (step_limit > 0 && tIndex < lastAngle)) {
                        continue;
                    }
                    focus_enabled = true;
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = "rgba(127,45,127, 0.3)";
                    var leftCurve = curvePartialByID(test, frags[0], frags[4], frags[5]);
                    var midCurve = curvePartialByID(test, frags[6], frags[10], frags[11]);
                    var rightCurve = curvePartialByID(test, frags[12], frags[16], frags[17]);
                    drawCurve(leftCurve);
                    drawCurve(rightCurve);
                    ctx.strokeStyle = angleBetween ? "rgba(0,160,45, 0.3)" : "rgba(255,0,45, 0.5)";
                    drawCurve(midCurve);
                    if (draw_angle > 1) {
                        drawOrder(leftCurve, 'L');
                        drawOrder(rightCurve, 'R');
                    }
                    break;
                case REC_TYPE_AFTERPART:
                    if (draw_angle != 3 || (step_limit > 0 && tIndex < lastAngle)) {
                        continue;
                    }
                    ctx.strokeStyle = afterIndex == 0 ? "rgba(255,0,0, 1.0)"
                            : (afterIndex == 1) == angleBetween ? "rgba(0,128,0, 1.0)"
                            :  "rgba(0,0,255, 1.0)";
                    switch (fragType) {
                        case PATH_LINE:
                            drawLine(frags[0], frags[1], frags[2], frags[3]);
                            break;
                        case PATH_QUAD:
                            drawQuad(frags[0], frags[1], frags[2], frags[3],
                                     frags[4], frags[5]);
                            break;
                        case PATH_CONIC:
                            drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
                                     frags[4], frags[5], frags[6]);
                            break;
                        case PATH_CUBIC:
                            drawCubic(frags[0], frags[1], frags[2], frags[3],
                                     frags[4], frags[5], frags[6], frags[7]);
                            break;
                        default:
                            console.log("unknown REC_TYPE_AFTERPART frag type: " + fragType);
                            throw "stop execution";
                    }
                    ++afterIndex;
                    break;
                case REC_TYPE_COINCIDENCE:
                    if (!draw_coincidence || (step_limit > 0 && tIndex < lastCoin)) {
                        continue;
                    }
                    focus_enabled = true;
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = "rgba(127,45,63, 0.3)";
                    var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                    drawCurve(curve);
                    break;
                case REC_TYPE_SECT:
                    if (!draw_intersection) {
                        continue;
                    }
                    if (draw_intersection != 1 && (step_limit > 0 && tIndex < lastSect)) {
                        continue;
                    }
                    // draw_intersection == 1 : show all
                    // draw_intersection == 2 : step == 0 ? show all : show intersection line #step
                    // draw_intersection == 3 : step == 0 ? show all : show intersection #step
                    ctx.lineWidth = 1;
                    ctx.strokeStyle = "rgba(0,0,255, 0.3)";
                    ctx.fillStyle = "blue";
                    focus_enabled = true;
                    var f = [];
                    var c1s;
                    var c1l;
                    var c2s;
                    var c2l;
                    switch (fragType) {
                        case INTERSECT_LINE:
                            f.push(5, 6, 0, 7);
                            c1s = 1; c1l = 4; c2s = 8; c2l = 4;
                            break;
                        case INTERSECT_LINE_2:
                            f.push(5, 6, 0, 10);
                            f.push(8, 9, 7, 15);
                            c1s = 1; c1l = 4; c2s = 11; c2l = 4;
                            break;
                        case INTERSECT_LINE_NO:
                            c1s = 0; c1l = 4; c2s = 4; c2l = 4;
                            break;
                        case INTERSECT_QUAD_LINE:
                            f.push(7, 8, 0, 9);
                            c1s = 1; c1l = 6; c2s = 10; c2l = 4;
                            break;
                        case INTERSECT_QUAD_LINE_2:
                            f.push(7, 8, 0, 12);
                            f.push(10, 11, 9, 17);
                            c1s = 1; c1l = 6; c2s = 13; c2l = 4;
                            break;
                        case INTERSECT_QUAD_LINE_NO:
                            c1s = 0; c1l = 6; c2s = 6; c2l = 4;
                            break;
                        case INTERSECT_QUAD:
                            f.push(7, 8, 0, 9);
                            c1s = 1; c1l = 6; c2s = 10; c2l = 6;
                            break;
                        case INTERSECT_QUAD_2:
                            f.push(7, 8, 0, 12);
                            f.push(10, 11, 9, 19);
                            c1s = 1; c1l = 6; c2s = 13; c2l = 6;
                            break;
                        case INTERSECT_QUAD_NO:
                            c1s = 0; c1l = 6; c2s = 6; c2l = 6;
                            break;
                        case INTERSECT_CONIC_LINE:
                            f.push(8, 9, 0, 10);
                            c1s = 1; c1l = 7; c2s = 11; c2l = 4;
                            break;
                        case INTERSECT_CONIC_LINE_2:
                            f.push(8, 9, 0, 12);
                            f.push(11, 12, 10, 18);
                            c1s = 1; c1l = 7; c2s = 14; c2l = 4;
                            break;
                        case INTERSECT_CONIC_LINE_NO:
                            c1s = 0; c1l = 7; c2s = 7; c2l = 4;
                            break;
                        case INTERSECT_CONIC:
                            f.push(8, 9, 0, 10);
                            c1s = 1; c1l = 7; c2s = 11; c2l = 7;
                            break;
                        case INTERSECT_CONIC_2:
                            f.push(8, 9, 0, 13);
                            f.push(11, 12, 10, 21);
                            c1s = 1; c1l = 7; c2s = 14; c2l = 7;
                            break;
                        case INTERSECT_CONIC_NO:
                            c1s = 0; c1l = 7; c2s = 7; c2l = 7;
                            break;
                        case INTERSECT_SELF_CUBIC:
                            f.push(9, 10, 0, 11);
                            c1s = 1; c1l = 8; c2s = 0; c2l = 0;
                            break;
                        case INTERSECT_SELF_CUBIC_NO:
                            c1s = 0; c1l = 8; c2s = 0; c2l = 0;
                            break;
                        case INTERSECT_CUBIC_LINE:
                            f.push(9, 10, 0, 11);
                            c1s = 1; c1l = 8; c2s = 12; c2l = 4;
                            break;
                        case INTERSECT_CUBIC_LINE_2:
                            f.push(9, 10, 0, 14);
                            f.push(12, 13, 11, 19);
                            c1s = 1; c1l = 8; c2s = 15; c2l = 4;
                            break;
                        case INTERSECT_CUBIC_LINE_3:
                            f.push(9, 10, 0, 17);
                            f.push(12, 13, 11, 22);
                            f.push(15, 16, 14, 23);
                            c1s = 1; c1l = 8; c2s = 18; c2l = 4;
                            break;
                        case INTERSECT_CUBIC_QUAD_NO:
                            c1s = 0; c1l = 8; c2s = 8; c2l = 6;
                            break;
                        case INTERSECT_CUBIC_QUAD:
                            f.push(9, 10, 0, 11);
                            c1s = 1; c1l = 8; c2s = 12; c2l = 6;
                            break;
                        case INTERSECT_CUBIC_QUAD_2:
                            f.push(9, 10, 0, 14);
                            f.push(12, 13, 11, 21);
                            c1s = 1; c1l = 8; c2s = 15; c2l = 6;
                            break;
                        case INTERSECT_CUBIC_QUAD_3:
                            f.push(9, 10, 0, 17);
                            f.push(12, 13, 11, 24);
                            f.push(15, 16, 14, 25);
                            c1s = 1; c1l = 8; c2s = 18; c2l = 6;
                            break;
                        case INTERSECT_CUBIC_QUAD_4:
                            f.push(9, 10, 0, 20);
                            f.push(12, 13, 11, 27);
                            f.push(15, 16, 14, 28);
                            f.push(18, 19, 17, 29);
                            c1s = 1; c1l = 8; c2s = 21; c2l = 6;
                            break;
                        case INTERSECT_CUBIC_LINE_NO:
                            c1s = 0; c1l = 8; c2s = 8; c2l = 4;
                            break;
                        case INTERSECT_CUBIC:
                            f.push(9, 10, 0, 11);
                            c1s = 1; c1l = 8; c2s = 12; c2l = 8;
                            break;
                        case INTERSECT_CUBIC_2:
                            f.push(9, 10, 0, 14);
                            f.push(12, 13, 11, 23);
                            c1s = 1; c1l = 8; c2s = 15; c2l = 8;
                            break;
                        case INTERSECT_CUBIC_3:
                            f.push(9, 10, 0, 17);
                            f.push(12, 13, 11, 26);
                            f.push(15, 16, 14, 27);
                            c1s = 1; c1l = 8; c2s = 18; c2l = 8;
                            break;
                        case INTERSECT_CUBIC_4:
                            f.push(9, 10, 0, 20);
                            f.push(12, 13, 11, 29);
                            f.push(15, 16, 14, 30);
                            f.push(18, 19, 17, 31);
                            c1s = 1; c1l = 8; c2s = 21; c2l = 8;
                            break;
                        case INTERSECT_CUBIC_NO:
                            c1s = 0; c1l = 8; c2s = 8; c2l = 8;
                            break;
                        default:
                            console.log("unknown REC_TYPE_SECT frag type: " + fragType);
                            throw "stop execution";
                    }
                    if (draw_intersection != 1) {
                        var id = -1;
                        var curve;
                        switch (c1l) {
                            case 4: 
                                drawLine(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]);
                                if (draw_id) {
                                    curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]];
                                    id = idByCurve(test, curve, PATH_LINE);
                                }
                                break;
                            case 6:
                                drawQuad(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                        frags[c1s + 4], frags[c1s + 5]);
                                if (draw_id) {
                                    curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                            frags[c1s + 4], frags[c1s + 5]];
                                    id = idByCurve(test, curve, PATH_QUAD);
                                }
                                break;
                            case 7:
                                drawConicWithQuads(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                        frags[c1s + 4], frags[c1s + 5], frags[c1s + 6]);
                                if (draw_id) {
                                    curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                            frags[c1s + 4], frags[c1s + 5], frags[c1s + 6]];
                                    id = idByCurve(test, curve, PATH_CONIC);
                                }
                                break;
                            case 8:
                                drawCubic(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                        frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]);
                                if (draw_id) {
                                    curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
                                            frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]];
                                    id = idByCurve(test, curve, PATH_CUBIC);
                                }
                                break;
                        }
                        if (id >= 0) {
                            drawID(curve, id);
                        }
                        id = -1;
                        switch (c2l) {
                            case 0:
                                break;
                            case 4: 
                                drawLine(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]);
                                if (draw_id) {
                                    curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]];
                                    id = idByCurve(test, curve, PATH_LINE);
                                }
                                break;
                            case 6:
                                drawQuad(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                        frags[c2s + 4], frags[c2s + 5]);
                                if (draw_id) {
                                    curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                            frags[c2s + 4], frags[c2s + 5]];
                                    id = idByCurve(test, curve, PATH_QUAD);
                                }
                                break;
                            case 7:
                                drawConicWithQuads(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                        frags[c2s + 4], frags[c2s + 5], frags[c2s + 6]);
                                if (draw_id) {
                                    curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                            frags[c2s + 4], frags[c2s + 5], frags[c2s + 6]];
                                    id = idByCurve(test, curve, PATH_CONIC);
                                }
                                break;
                            case 8:
                                drawCubic(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                        frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]);
                                if (draw_id) {
                                    curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
                                            frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]];
                                    id = idByCurve(test, curve, PATH_CUBIC);
                                }
                                break;
                        }
                        if (id >= 0) {
                            drawID(curve, id);
                        }
                    }
                    if (collect_bounds) {
                        break;
                    }
                    if (draw_intersection != 3 || step_limit == 0 || tIndex >= lastSect) {
                        for (var idx = 0; idx < f.length; idx += 4) {
                            drawPoint(frags[f[idx]], frags[f[idx + 1]], true);
                        }
                    }
                    if (!draw_intersectT) {
                        break;
                    }
                    ctx.fillStyle = "red";
                    if (draw_intersection != 3 || step_limit == 0 || tIndex >= lastSect) {
                        for (var idx = 0; idx < f.length; idx += 4) {
                            drawTAtPointUp(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 2]]);
                            drawTAtPointDown(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 3]]);
                        }
                    }
                    break;
                case REC_TYPE_SORT:
                    if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
                        continue;
                    }
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = "rgba(127,127,0, 0.5)";
                    focus_enabled = true;
                    switch (fragType) {
                        case SORT_UNARY:
                        case SORT_BINARY:
                            var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
                            drawCurve(curve);
                            break;
                        default:
                            console.log("unknown REC_TYPE_SORT frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                case REC_TYPE_TOP:
                    if (!draw_top || (step_limit > 0 && tIndex < lastTop)) {
                        continue;
                    }
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = "rgba(127,127,0, 0.5)";
                    focus_enabled = true;
                    {
                        var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
                        drawCurve(curve);
                        var type = PATH_LINE + (curve.length / 2 - 2);
                        var mid = pointAtT(curve, type, 0.5);
                        var d = dxy_at_t(curve, type, 0.5);
                        drawArrow(mid.x, mid.y, d.x, d.y, 0.3);
                    }
                    break;
                case REC_TYPE_MARK:
                    if (!draw_mark || (step_limit > 0 && tIndex < lastMark)) {
                        continue;
                    }
                    ctx.lineWidth = 3;
                    ctx.strokeStyle = fragType >= MARK_DONE_LINE ?
                            "rgba(127,0,127, 0.5)" : "rgba(127,127,0, 0.5)";
                    focus_enabled = true;
                    switch (fragType) {
                        case MARK_LINE:
                        case MARK_DONE_LINE:
                        case MARK_UNSORTABLE_LINE:
                        case MARK_SIMPLE_LINE:
                        case MARK_SIMPLE_DONE_LINE:
                        case MARK_DONE_UNARY_LINE:
                            drawLinePartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[9]);
                            if (draw_id) {
                                drawLinePartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[9]);
                            }
                            break;
                        case MARK_QUAD:
                        case MARK_DONE_QUAD:
                        case MARK_UNSORTABLE_QUAD:
                        case MARK_SIMPLE_QUAD:
                        case MARK_SIMPLE_DONE_QUAD:
                        case MARK_DONE_UNARY_QUAD:
                            drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[11]);
                            if (draw_id) {
                                drawQuadPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[11]);
                            }
                            break;
                        case MARK_CUBIC:
                        case MARK_DONE_CUBIC:
                        case MARK_UNSORTABLE_CUBIC:
                        case MARK_SIMPLE_CUBIC:
                        case MARK_SIMPLE_DONE_CUBIC:
                        case MARK_DONE_UNARY_CUBIC:
                            drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
                            if (draw_id) {
                                drawCubicPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
                                frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
                            }
                            break;
                        case MARK_ANGLE_LAST:
                            // FIXME: ignored for now
                            break;
                        default:
                            console.log("unknown REC_TYPE_MARK frag type: " + fragType);
                            throw "stop execution";
                    }
                    break;
                default:
                    continue;
            }
        }
        switch (recType) {
            case REC_TYPE_SORT:
                if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
                    break;
                }
                var angles = []; // use tangent lines to describe arcs
                var windFrom = [];
                var windTo = [];
                var opp = [];
                var minXY = Number.MAX_VALUE;
                var partial;
                focus_enabled = true;
                var someUnsortable = false;
                for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
                    var fragType = records[recordIndex];
                    var frags = records[recordIndex + 1];
                    var unsortable = (fragType == SORT_UNARY && frags[14]) ||
                            (fragType == SORT_BINARY && frags[16]);
                    someUnsortable |= unsortable;
                    switch (fragType) {
                        case SORT_UNARY:
                        case SORT_BINARY:
                            partial = curvePartialByID(test, frags[0], frags[6], frags[8]);
                            break;
                        default:
                            console.log("unknown REC_TYPE_SORT frag type: " + fragType);
                            throw "stop execution";
                    }
                    var dx = boundsWidth(partial);
                    var dy = boundsHeight(partial);
                    minXY = Math.min(minXY, dx * dx + dy * dy);
                    if (collect_bounds) {
                        continue;
                    }
                    angles.push(tangent(partial));
                    var from = frags[12];
                    var to = frags[12];
                    var sgn = frags[10];
                    if (sgn < 0) {
                        from -= frags[11];
                    } else if (sgn > 0) {
                        to -= frags[11];
                    }
                    windFrom.push(from + (unsortable ? "!" : ""));
                    windTo.push(to + (unsortable ? "!" : ""));
                    opp.push(fragType == SORT_BINARY);
                    if (draw_sort == 1) {
                        drawOrder(partial, frags[12]);
                    } else {
                        drawOrder(partial, (recordIndex / 2) + 1);
                    }
                }
                var radius = Math.sqrt(minXY) / 2 * scale;
                radius = Math.min(50, radius);
                var scaledRadius = radius / scale;
                var centerX = partial[0];
                var centerY = partial[1];
                if (collect_bounds) {
                    if (focus_enabled) {
                        focusXmin = Math.min(focusXmin, centerX - scaledRadius);
                        focusYmin = Math.min(focusYmin, centerY - scaledRadius);
                        focusXmax = Math.max(focusXmax, centerX + scaledRadius);
                        focusYmax = Math.max(focusYmax, centerY + scaledRadius);
                    }
                    break;
                }
                break;
            default:
                break;
        }
    }
    if (collect_bounds) {
        return;
    }
    if (draw_log && logStart >= 0) {
        ctx.font = "normal 10px Arial";
        ctx.textAlign = "left";
        ctx.beginPath();
        var top = screenHeight - 20 - (logRange + 2) * 10;
        ctx.rect(50, top, screenWidth - 100, (logRange + 2) * 10);
        ctx.fillStyle = "white";
        ctx.fill();
        ctx.fillStyle = "rgba(0,0,0, 0.5)";
        if (logStart > 0) {
            ctx.fillText(lines[logStart - 1], 50, top + 8);
        }
        ctx.fillStyle = "black";
        for (var idx = 0; idx < logRange; ++idx) {
            ctx.fillText(lines[logStart + idx], 50, top + 18 + 10 * idx);
        }
        ctx.fillStyle = "rgba(0,0,0, 0.5)";
        if (logStart + logRange < lines.length) {
            ctx.fillText(lines[logStart + logRange], 50, top + 18 + 10 * logRange);
        }
    }
    if (draw_legend) {
        var pos = 0;
        var drawSomething = draw_add | draw_active | draw_angle | draw_coincidence | draw_sort | draw_mark;
   //     drawBox(pos++, "yellow", "black", opLetter, true, '');
        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_intersection > 1 ? sectCount : sectMax2, draw_intersection, intersectionKey);
        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_add ? addCount : addMax, draw_add, addKey);
        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_active ? activeCount : activeMax, draw_active, activeKey);
        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_angle ? angleCount : angleMax, draw_angle, angleKey);
        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_coincidence ? coinCount : coinMax, draw_coincidence, coincidenceKey);
        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_op ? opCount : opMax, draw_op, opKey);
        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_sort ? sortCount : sortMax, draw_sort, sortKey);
        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_top ? topCount : topMax, draw_top, topKey);
        drawBox(pos++, "rgba(127,0,127, 0.3)", "black", draw_mark ? markCount : markMax, draw_mark, markKey);
        drawBox(pos++, "black", "white", 
                (new Array('P', 'P1', 'P2', 'P'))[draw_path], draw_path != 0, pathKey);
        drawBox(pos++, "rgba(0,63,0, 0.7)", "white",
                (new Array('Q', 'Q', 'C', 'QC', 'Qc', 'Cq'))[draw_computed],
                draw_computed != 0, computedKey);
        drawBox(pos++, "green", "black", step_limit, drawSomething, '');
        drawBox(pos++, "green", "black", stepMax, drawSomething, '');
        drawBox(pos++, "rgba(255,0,0, 0.6)", "black", lastIndex, drawSomething & draw_log, '');
        drawBox(pos++, "rgba(255,0,0, 0.6)", "black", test.length - 1, drawSomething & draw_log, '');
        if (curve_t) {
            drawCurveTControl();
        }
        ctx.font = "normal 20px Arial";
        ctx.fillStyle = "rgba(0,0,0, 0.3)";
        ctx.textAlign = "right";
        ctx.fillText(scale.toFixed(decimal_places) + 'x' , screenWidth - 10, screenHeight - 5);
    }
    if (draw_hints) {
        ctx.font = "normal 10px Arial";
        ctx.fillStyle = "rgba(0,0,0, 0.5)";
        ctx.textAlign = "right";
        var y = 4;
        ctx.fillText("control lines : " +  controlLinesKey, ctx.screenWidthwidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("curve t : " +  curveTKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("deriviatives : " +  deriviativesKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("intersect t : " +  intersectTKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("log : " +  logKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("log curve : " +  logCurvesKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("mid point : " +  midpointKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("points : " +  ptsKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("sequence : " +  sequenceKey, screenWidth - 10, pos * 50 + y++ * 10);
        ctx.fillText("xy : " +  xyKey, screenWidth - 10, pos * 50 + y++ * 10);
    }
}

function drawBox(y, backC, foreC, str, enable, label) {
    ctx.beginPath();
    ctx.fillStyle = backC;
    ctx.rect(screenWidth - 40, y * 50 + 10, 40, 30);
    ctx.fill();
    ctx.font = "normal 16px Arial";
    ctx.fillStyle = foreC;
    ctx.textAlign = "center";
    ctx.fillText(str, screenWidth - 20, y * 50 + 32);
    if (!enable) {
        ctx.fillStyle = "rgba(255,255,255, 0.5)";
        ctx.fill();
    }
    if (label != '') {
        ctx.font = "normal 9px Arial";
        ctx.fillStyle = "black";
        ctx.fillText(label, screenWidth - 47, y * 50 + 40);
    }
}

function drawCurveTControl() {
    ctx.lineWidth = 2;
    ctx.strokeStyle = "rgba(0,0,0, 0.3)";
    ctx.beginPath();
    ctx.rect(screenWidth - 80, 40, 28, screenHeight - 80);
    ctx.stroke();
    var ty = 40 + curveT * (screenHeight - 80);
    ctx.beginPath();
    ctx.moveTo(screenWidth - 80, ty);
    ctx.lineTo(screenWidth - 85, ty - 5);
    ctx.lineTo(screenWidth - 85, ty + 5);
    ctx.lineTo(screenWidth - 80, ty);
    ctx.fillStyle = "rgba(0,0,0, 0.6)";
    ctx.fill();
    var num = curveT.toFixed(decimal_places);
    ctx.font = "normal 10px Arial";
    ctx.textAlign = "left";
    ctx.fillText(num, screenWidth - 78, ty);
}

function ptInTControl() {
    var e = window.event;
	var tgt = e.target || e.srcElement;
    var left = tgt.offsetLeft;
    var top = tgt.offsetTop;
    var x = (e.clientX - left);
    var y = (e.clientY - top);
    if (x < screenWidth - 80 || x > screenWidth - 50) {
        return false;
    }
    if (y < 40 || y > screenHeight - 80) {
        return false;
    }
    curveT = (y - 40) / (screenHeight - 120);
    if (curveT < 0 || curveT > 1) {
        throw "stop execution";
    }
    return true;
}

function drawTop() {
    if (tests[testIndex] == null) {
        var str = testDivs[testIndex].textContent;
        parse_all(str);
        var title = testDivs[testIndex].id.toString();
        testTitles[testIndex] = title;
    }
    init(tests[testIndex]);
    redraw();
}

function redraw() {
    if (focus_on_selection) {
        collect_bounds = true;
        draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
        collect_bounds = false;
        if (focusXmin < focusXmax && focusYmin < focusYmax) {
            setScale(focusXmin, focusXmax, focusYmin, focusYmax);
        }
    }
    ctx.beginPath();
    ctx.fillStyle = "white";
    ctx.rect(0, 0, screenWidth, screenHeight);
    ctx.fill();
    draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
}

function dumpCurvePartial(test, id, t0, t1) {
    var curve = curveByID(test, id);
    var name = ["line", "quad", "cubic"][curve.length / 2 - 2];
    console.log("id=" + id + " " + name + "=" +  curveToString(curve)
        + " t0=" + t0 + " t1=" + t1
        + " partial=" + curveToString(curvePartialByID(test, id, t0, t1)));
}

function dumpAngleTest(test, id, t0, t1) {
    var curve = curveByID(test, id);
    console.log("    { {" + curveToString(curve) + "}, " 
            + curve.length / 2 + ", " + t0 + ", " + t1 + ", {} }, //");
}

function dumpLogToConsole() {
    if (logStart < 0) {
        return;
    }
    var test = tests[testIndex];
    var recType = REC_TYPE_UNKNOWN;
    var records;
    for (var index = 0; index < test.length; index += 3) {
        var lastLineNo = test[index + 1];
        if (lastLineNo >= logStart && lastLineNo < logStart + logRange) {
            recType = test[index];
            records = test[index + 2];
            break;
        }
    }
    if (recType == REC_TYPE_UNKNOWN) {
        return;
    }
    var lines = testLines[testIndex];
    for (var idx = 0; idx < logRange; ++idx) {
        var line = lines[logStart + idx];
        console.log(line);
        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
            var fragType = records[recordIndex];
            var frags = records[recordIndex + 1];
            if (recType == REC_TYPE_ANGLE && fragType == ANGLE_AFTER) {
                dumpCurvePartial(test, frags[0], frags[4], frags[5]);
                dumpCurvePartial(test, frags[6], frags[10], frags[11]);
                dumpCurvePartial(test, frags[12], frags[16], frags[17]);
                console.log("\nstatic IntersectData intersectDataSet[] = { //");
                dumpAngleTest(test, frags[0], frags[4], frags[5]);
                dumpAngleTest(test, frags[6], frags[10], frags[11]);
                dumpAngleTest(test, frags[12], frags[16], frags[17]);
                console.log("}; //");
            }
        }
    }
}

var activeKey = 'a';
var pathKey = 'b';
var pathBackKey = 'B';
var centerKey = 'c';
var coincidenceKey = 'C';
var addKey = 'd';
var deriviativesKey = 'f';
var angleKey = 'g';
var angleBackKey = 'G';
var intersectionKey = 'i';
var intersectionBackKey = 'I';
var sequenceKey = 'j';
var midpointKey = 'k';
var logKey = 'l';
var logToConsoleKey = 'L';
var markKey = 'm';
var sortKey = 'o';
var opKey = 'p';
var opBackKey = 'P';
var computedKey = 'q';
var computedBackKey = 'Q';
var stepKey = 's';
var stepBackKey = 'S';
var intersectTKey = 't';
var topKey = 'T';
var curveTKey = 'u';
var controlLinesBackKey = 'V';
var controlLinesKey = 'v';
var ptsKey = 'x';
var xyKey = 'y';
var logCurvesKey = 'z';
var focusKey = '`';
var idKey = '.';
var retinaKey = '\\';

function doKeyPress(evt) {
    var char = String.fromCharCode(evt.charCode);
    var focusWasOn = false;
    switch (char) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        decimal_places = char - '0';
        redraw();
        break;
    case activeKey:
        draw_active ^= true;
        redraw(); 
        break;
    case addKey:
        draw_add ^= true;
        redraw(); 
        break;
    case angleKey:
        draw_angle = (draw_angle + 1) % 4;
        redraw();
        break;
    case angleBackKey:
        draw_angle = (draw_angle + 2) % 3;
        redraw();
        break;
    case centerKey:
        setScale(xmin, xmax, ymin, ymax);
        redraw(); 
        break;
    case coincidenceKey:
        draw_coincidence ^= true;
        redraw();
        break;
    case controlLinesBackKey:
        control_lines = (control_lines + 3) % 4;
        redraw(); 
        break;
    case controlLinesKey:
        control_lines = (control_lines + 1) % 4;
        redraw(); 
        break;
    case computedBackKey:
        draw_computed = (draw_computed + 5) % 6;
        redraw(); 
        break;
    case computedKey:
        draw_computed = (draw_computed + 1) % 6;
        redraw(); 
        break;
    case curveTKey:
        curve_t ^= true;
        if (curve_t) {
            draw_legend = true;
        }
        redraw();
        break;
    case deriviativesKey:
        draw_deriviatives = (draw_deriviatives + 1) % 3;
        redraw();
        break;
    case focusKey:
        focus_on_selection ^= true;
        setScale(xmin, xmax, ymin, ymax);
        redraw();
        break;
    case idKey:
        draw_id ^= true;
        redraw();
        break;
    case intersectionBackKey:
        draw_intersection = (draw_intersection + 3) % 4;
        redraw(); 
        break;
    case intersectionKey:
        draw_intersection = (draw_intersection + 1) % 4;
        redraw(); 
        break;
    case intersectTKey:
        draw_intersectT ^= true;
        redraw();
        break;
    case logCurvesKey:
        logCurves(tests[testIndex]);
        break;
    case logKey:
        draw_log ^= true;
        redraw();
        break;
    case logToConsoleKey:
        if (draw_log) {
            dumpLogToConsole();
        }
        break;
    case markKey:
        draw_mark ^= true;
        redraw();
        break;
    case midpointKey:
        draw_midpoint ^= true;
        redraw();
        break;
    case opKey:
        draw_op = (draw_op + 1) % 3;
        redraw();
        break;
    case opBackKey:
        draw_op = (draw_op + 2) % 3;
        redraw();
        break;
    case pathKey:
        draw_path = (draw_path + 1) % 4;
        redraw(); 
        break;
    case pathBackKey:
        draw_path = (draw_path + 3) % 4;
        redraw(); 
        break;
    case ptsKey:
        pt_labels = (pt_labels + 1) % 3;
        redraw();
        break;
    case retinaKey:
        retina_scale ^= true;
        drawTop();
        break;
    case sequenceKey:
        draw_sequence ^= true;
        redraw();
        break;
    case sortKey:
        draw_sort = (draw_sort + 1) % 3;
        drawTop();
        break;
    case stepKey:
        step_limit++;
        if (step_limit > stepMax) {
            step_limit = stepMax;
        }
        redraw();
        break;
    case stepBackKey:
        step_limit--;
        if (step_limit < 0) {
            step_limit = 0;
        }
        redraw();
        break;
    case topKey:
        draw_top ^= true;
        redraw();
        break;
    case xyKey:
        debug_xy = (debug_xy + 1) % 3;
        redraw();
        break;
    case '-':
        focusWasOn = focus_on_selection;
        if (focusWasOn) {
            focus_on_selection = false;
            scale /= 1.2;
        } else {
            scale /= 2;
            calcLeftTop();
        }
        redraw();
        focus_on_selection = focusWasOn;
        break;
    case '=':
    case '+':
        focusWasOn = focus_on_selection;
        if (focusWasOn) {
            focus_on_selection = false;
            scale *= 1.2;
        } else {
            scale *= 2;
            calcLeftTop();
        }
        redraw();
        focus_on_selection = focusWasOn;
        break;
    case '?':
        draw_hints ^= true;
        if (draw_hints && !draw_legend) {
            draw_legend = true;
        }
        redraw();
        break;
    case '/':
        draw_legend ^= true;
        redraw();
        break;
    }
}

function doKeyDown(evt) {
    var char = evt.keyCode;
    var preventDefault = false;
    switch (char) {
    case 37: // left arrow
        if (evt.shiftKey) {
            testIndex -= 9;
        }
        if (--testIndex < 0)
            testIndex = tests.length - 1;
        drawTop();
        preventDefault = true;
        break;
    case 39: // right arrow
        if (evt.shiftKey) {
            testIndex += 9;
        }
        if (++testIndex >= tests.length)
            testIndex = 0;
        drawTop();
        preventDefault = true;
        break;
    }
    if (preventDefault) {
          evt.preventDefault();
          return false;
    }
    return true;
}

(function() {
    var hidden = "hidden";

    // Standards:
    if (hidden in document)
        document.addEventListener("visibilitychange", onchange);
    else if ((hidden = "mozHidden") in document)
        document.addEventListener("mozvisibilitychange", onchange);
    else if ((hidden = "webkitHidden") in document)
        document.addEventListener("webkitvisibilitychange", onchange);
    else if ((hidden = "msHidden") in document)
        document.addEventListener("msvisibilitychange", onchange);
    // IE 9 and lower:
    else if ('onfocusin' in document)
        document.onfocusin = document.onfocusout = onchange;
    // All others:
    else
        window.onpageshow = window.onpagehide 
            = window.onfocus = window.onblur = onchange;

    function onchange (evt) {
        var v = 'visible', h = 'hidden',
            evtMap = { 
                focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h 
            };

        evt = evt || window.event;
        if (evt.type in evtMap)
            document.body.className = evtMap[evt.type];
        else        
            document.body.className = this[hidden] ? "hidden" : "visible";
    }
})();

function calcXY() {
    var e = window.event;
	var tgt = e.target || e.srcElement;
    var left = tgt.offsetLeft;
    var top = tgt.offsetTop;
    mouseX = (e.clientX - left) / scale + srcLeft;
    mouseY = (e.clientY - top) / scale + srcTop;
}

function calcLeftTop() {
    srcLeft = mouseX - screenWidth / 2 / scale;
    srcTop = mouseY - screenHeight / 2 / scale;
}

var disableClick = false;

function handleMouseClick() {
    if (disableClick) {
        return;
    }
    if (!curve_t || !ptInTControl()) {
        calcXY();
        calcLeftTop();
    }
    redraw();
//    if (!curve_t || !ptInTControl()) {
//        mouseX = screenWidth / 2 / scale + srcLeft;
//        mouseY = screenHeight / 2 / scale + srcTop;
//    }
}

function handleMouseOver() {
    calcXY();
    if (debug_xy != 2) {
        return;
    }
    var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
    ctx.beginPath();
    ctx.rect(300,100,num.length * 6,10);
    ctx.fillStyle="white";
    ctx.fill();
    ctx.font = "normal 10px Arial";
    ctx.fillStyle="black";
    ctx.textAlign = "left";
    ctx.fillText(num, 300, 108);
}

function start() {
    for (var i = 0; i < testDivs.length; ++i) {
        tests[i] = null;
    }
    testIndex = 0;
    drawTop();
    window.addEventListener('keypress', doKeyPress, true);
    window.addEventListener('keydown', doKeyDown, true);
    window.onresize = function() {
        drawTop();
    }
    /*
    window.onpagehide = function() {
        disableClick = true;
    }
    */
    window.onpageshow = function () {
        disableClick = false;
    }
}

</script>
</head>

<body onLoad="start();">
<canvas id="canvas" width="750" height="500"
    onmousemove="handleMouseOver()"
    onclick="handleMouseClick()"
    ></canvas >
</body>
</html>