| 130520 | } |
| 130521 | cases[t2 << 3].forEach(stitch); |
| 130522 | function stitch(line) { |
| 130523 | var start = [ |
| 130524 | line[0][0] + x, |
| 130525 | line[0][1] + y |
| 130526 | ], end = [ |
| 130527 | line[1][0] + x, |
| 130528 | line[1][1] + y |
| 130529 | ], startIndex = index(start), endIndex = index(end), f, g; |
| 130530 | if (f = fragmentByEnd[startIndex]) { |
| 130531 | if (g = fragmentByStart[endIndex]) { |
| 130532 | delete fragmentByEnd[f.end]; |
| 130533 | delete fragmentByStart[g.start]; |
| 130534 | if (f === g) { |
| 130535 | f.ring.push(end); |
| 130536 | callback(f.ring); |
| 130537 | } else fragmentByStart[f.start] = fragmentByEnd[g.end] = { |
| 130538 | start: f.start, |
| 130539 | end: g.end, |
| 130540 | ring: f.ring.concat(g.ring) |
| 130541 | }; |
| 130542 | } else { |
| 130543 | delete fragmentByEnd[f.end]; |
| 130544 | f.ring.push(end); |
| 130545 | fragmentByEnd[f.end = endIndex] = f; |
| 130546 | } |
| 130547 | } else if (f = fragmentByStart[endIndex]) { |
| 130548 | if (g = fragmentByEnd[startIndex]) { |
| 130549 | delete fragmentByStart[f.start]; |
| 130550 | delete fragmentByEnd[g.end]; |
| 130551 | if (f === g) { |
| 130552 | f.ring.push(end); |
| 130553 | callback(f.ring); |
| 130554 | } else fragmentByStart[g.start] = fragmentByEnd[f.end] = { |
| 130555 | start: g.start, |
| 130556 | end: f.end, |
| 130557 | ring: g.ring.concat(f.ring) |
| 130558 | }; |
| 130559 | } else { |
| 130560 | delete fragmentByStart[f.start]; |
| 130561 | f.ring.unshift(start); |
| 130562 | fragmentByStart[f.start = startIndex] = f; |
| 130563 | } |
| 130564 | } else fragmentByStart[startIndex] = fragmentByEnd[endIndex] = { |
| 130565 | start: startIndex, |
| 130566 | end: endIndex, |
| 130567 | ring: [ |
| 130568 | start, |
| 130569 | end |
| 130570 | ] |
| 130571 | }; |
| 130572 | } |
| 130573 | } |
| 130574 | function index(point) { |
| 130575 | return point[0] * 2 + point[1] * (dx + 1) * 4; |